Design improvements, comment and style fixes
This commit is contained in:
Родитель
e9460d3e11
Коммит
4e713e9103
|
@ -31,6 +31,9 @@ bld/
|
|||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio Code directory
|
||||
.vscode
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
|
|
|
@ -3,7 +3,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
@ -34,7 +33,7 @@ namespace Microsoft.Net.Insertions.Api
|
|||
/// <param name="defaultConfigPath">Path to the "default.config" file.</param>
|
||||
/// <param name="error">Description of the error occured during load.</param>
|
||||
/// <returns>True if the operation is successful. False otherwise.</returns>
|
||||
public bool Load(string defaultConfigPath, out string error)
|
||||
public bool TryLoad(string defaultConfigPath, out string error)
|
||||
{
|
||||
error = null;
|
||||
|
||||
|
@ -44,14 +43,23 @@ namespace Microsoft.Net.Insertions.Api
|
|||
return false;
|
||||
}
|
||||
|
||||
Trace.WriteLine($"Loading {InsertionConstants.DefaultConfigFile} content from {defaultConfigPath}.");
|
||||
var defaultConfigXml = XDocument.Load(defaultConfigPath, LoadOptions.SetLineInfo);
|
||||
Trace.WriteLine($"Loaded {InsertionConstants.DefaultConfigFile} content.");
|
||||
XDocument defaultConfigXml;
|
||||
try
|
||||
{
|
||||
Trace.WriteLine($"Loading {InsertionConstants.DefaultConfigFile} content from {defaultConfigPath}.");
|
||||
defaultConfigXml = XDocument.Load(defaultConfigPath, LoadOptions.SetLineInfo);
|
||||
Trace.WriteLine($"Loaded {InsertionConstants.DefaultConfigFile} content.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Trace.WriteLine($"Loading of {InsertionConstants.DefaultConfigFile} content has failed with exception:{Environment.NewLine} {e.ToString()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
_documentPaths[defaultConfigXml] = defaultConfigPath;
|
||||
LoadPackagesFromXml(defaultConfigXml);
|
||||
|
||||
var additionalConfigParent = defaultConfigXml.Element(ElementNameAdditionalConfigsParent);
|
||||
XElement additionalConfigParent = defaultConfigXml.Element(ElementNameAdditionalConfigsParent);
|
||||
if(additionalConfigParent != null)
|
||||
{
|
||||
string configsDirectory = Path.GetDirectoryName(defaultConfigPath);
|
||||
|
@ -74,9 +82,18 @@ namespace Microsoft.Net.Insertions.Api
|
|||
continue;
|
||||
}
|
||||
|
||||
Trace.WriteLine($"Loading content of .packageconfig at {defaultConfigPath}.");
|
||||
var packageConfigXDocument = XDocument.Load(configFileAbsolutePath);
|
||||
Trace.WriteLine($"Loaded .packageconfig content.");
|
||||
XDocument packageConfigXDocument;
|
||||
try
|
||||
{
|
||||
Trace.WriteLine($"Loading content of .packageconfig at {defaultConfigPath}.");
|
||||
packageConfigXDocument = XDocument.Load(configFileAbsolutePath);
|
||||
Trace.WriteLine($"Loaded .packageconfig content.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Trace.WriteLine($"Loading of .packageconfig file has failed with exception{Environment.NewLine}{e.ToString()}");
|
||||
continue;
|
||||
}
|
||||
|
||||
_documentPaths[packageConfigXDocument] = configFileAbsolutePath;
|
||||
LoadPackagesFromXml(packageConfigXDocument);
|
||||
|
@ -86,6 +103,40 @@ namespace Microsoft.Net.Insertions.Api
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to find the package with given id and update its version number.
|
||||
/// </summary>
|
||||
/// <param name="packageId">Id of the package to change the version of</param>
|
||||
/// <param name="version">Version number to assign</param>
|
||||
/// <returns>True if package was found. False otherwise.</returns>
|
||||
public bool TryUpdatePackage(string packageId, string version)
|
||||
{
|
||||
lock(_updateLock)
|
||||
{
|
||||
if (!_packageXElements.TryGetValue(packageId, out var xElement))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
xElement.Attribute("version").Value = version;
|
||||
_modifiedDocuments.Add(xElement.Document);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves all the modified default.config and .packageconfig files to disk.
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
foreach(var document in _modifiedDocuments)
|
||||
{
|
||||
var savePath = _documentPaths[document];
|
||||
Trace.WriteLine($"Saving modified config file: {savePath}");
|
||||
document.Save(savePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadPackagesFromXml(XDocument xDocument)
|
||||
{
|
||||
foreach (var packageXElement in xDocument.Descendants(ElementNamePackage))
|
||||
|
@ -113,37 +164,5 @@ namespace Microsoft.Net.Insertions.Api
|
|||
_packageXElements.Add(packageId, packageXElement);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to find the package with given id and update its version number.
|
||||
/// </summary>
|
||||
/// <param name="packageId">Id of the package to change the version of</param>
|
||||
/// <param name="version">Version number to assign</param>
|
||||
/// <returns>True if package was found. False otherwise.</returns>
|
||||
public bool TryUpdatePackage(string packageId, string version)
|
||||
{
|
||||
lock(_updateLock)
|
||||
{
|
||||
if (!_packageXElements.TryGetValue(packageId, out var xElement))
|
||||
return false;
|
||||
|
||||
xElement.Attribute("version").Value = version;
|
||||
_modifiedDocuments.Add(xElement.Document);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves all the modified default.config and .packageconfig files to disk.
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
foreach(var document in _modifiedDocuments)
|
||||
{
|
||||
var savePath = _documentPaths[document];
|
||||
Trace.WriteLine($"Saving modified config file: {savePath}");
|
||||
document.Save(savePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,9 +10,10 @@ namespace Microsoft.Net.Insertions.Api
|
|||
/// <summary>
|
||||
/// Creates an <see cref="IInsertionApi"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="maxWaitSeconds">Optional: boxed wait seconds integer.</param>
|
||||
/// <param name="maxConcurrency">Optional: boxed concurrency integer.</param>
|
||||
/// <returns><see cref="IInsertionApi"/> instance.</returns>
|
||||
/// <param name="maxWaitSeconds">Optional: Maximum number of seconds that the application
|
||||
/// is allowed to run. After that, operation will be cancelled.</param>
|
||||
/// <param name="maxConcurrency">Optional: Level of concurrency.</param>
|
||||
/// <returns><see cref="IInsertionApi"/> An IInsertionApi instance.</returns>
|
||||
IInsertionApi Create(int? maxWaitSeconds = null, int? maxConcurrency = null);
|
||||
}
|
||||
}
|
|
@ -172,7 +172,7 @@ namespace Microsoft.Net.Insertions.Api.Providers
|
|||
private bool TryLoadDefaultConfig(string defaultConfigPath, out DefaultConfigUpdater configUpdater, out string details)
|
||||
{
|
||||
configUpdater = new DefaultConfigUpdater();
|
||||
return configUpdater.Load(defaultConfigPath, out details);
|
||||
return configUpdater.TryLoad(defaultConfigPath, out details);
|
||||
}
|
||||
|
||||
private HashSet<string> LoadPackagesToIgnore(string ignoredPackagesFile)
|
||||
|
@ -264,7 +264,9 @@ namespace Microsoft.Net.Insertions.Api.Providers
|
|||
char c = filename[index++];
|
||||
|
||||
if (c > '0' && c <= '9')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '.')
|
||||
{
|
||||
|
@ -281,7 +283,9 @@ namespace Microsoft.Net.Insertions.Api.Providers
|
|||
|
||||
// we found a letter. This cannot be the start of the version number. Skip ahead
|
||||
while (index < filename.Length && filename[index] != '.')
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
versionNumberStart = index++;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace Microsoft.Net.Insertions.ConsoleApp
|
|||
Trace.WriteLine($"Duration: {results.DurationMilliseconds:N2}-ms.");
|
||||
Trace.WriteLine($"Successful updates: {results.UpdatedNuGets.Count():N0}.");
|
||||
Trace.WriteLine("Updated default.config NuGet package versions...");
|
||||
foreach (string updatedNuget in results.UpdatedNuGets)
|
||||
foreach (string updatedNuget in results.UpdatedNuGets.OrderBy(r => r)
|
||||
{
|
||||
Trace.WriteLine($" {updatedNuget}");
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ namespace Microsoft.Net.Insertions.ConsoleApp
|
|||
else
|
||||
{
|
||||
target = -1;
|
||||
Trace.WriteLine($"Specified value is not an integer. Default value will be used.");
|
||||
Trace.WriteLine("Specified value is not an integer. Default value will be used.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче