-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
843ce66
commit 993e1c6
Showing
4 changed files
with
119 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
namespace DependenciesReport; | ||
|
||
public static class DependenciesTools | ||
{ | ||
public static Dictionary<string, Dictionary<string, string>> CreateDependenciesMap(string[] directories) | ||
{ | ||
var dependenciesMap = new Dictionary<string, Dictionary<string, string>>(); | ||
foreach (var directory in directories) | ||
{ | ||
var assemblies = Directory.GetFiles(directory, "*.dll"); | ||
|
||
foreach (var assembly in assemblies) | ||
{ | ||
var assemblyName = Path.GetFileName(assembly); | ||
var assemblyVersion = AssemblyUtils.GetAssemblyVersion(assembly); | ||
|
||
if (!dependenciesMap.TryGetValue(assemblyName, out var value)) | ||
{ | ||
value = new Dictionary<string, string>(); | ||
dependenciesMap[assemblyName] = value; | ||
} | ||
|
||
if (assemblyVersion != null) | ||
{ | ||
value[Path.GetFileName(directory)] = assemblyVersion; | ||
} | ||
} | ||
} | ||
|
||
return dependenciesMap; | ||
} | ||
|
||
public static void UpgradeDependencies(Dictionary<string, Dictionary<string, Dictionary<string, string>>> dependenciesMaps) | ||
{ | ||
foreach (var (yearDirectory, dependenciesMap) in dependenciesMaps) | ||
{ | ||
foreach (var assemblyName in dependenciesMap.Keys) | ||
{ | ||
string? maxVersion = null; | ||
string? maxVersionDirectory = null; | ||
|
||
foreach (var directory in dependenciesMap[assemblyName].Keys) | ||
{ | ||
var version = dependenciesMap[assemblyName][directory]; | ||
if (maxVersion == null || CompareVersions(version, maxVersion) > 0) | ||
{ | ||
maxVersion = version; | ||
maxVersionDirectory = directory; | ||
} | ||
} | ||
|
||
if (maxVersionDirectory is not null && maxVersion is not null) | ||
{ | ||
var maxVersionFilePath = Path.Combine(yearDirectory, maxVersionDirectory, assemblyName); | ||
|
||
foreach (var directory in dependenciesMap[assemblyName].Keys) | ||
{ | ||
if (directory != maxVersionDirectory) | ||
{ | ||
var targetFilePath = Path.Combine(yearDirectory, directory, assemblyName); | ||
var targetVersion = dependenciesMap[assemblyName][directory]; | ||
|
||
if (CompareVersions(targetVersion, maxVersion) < 0) | ||
{ | ||
File.Copy(maxVersionFilePath, targetFilePath, true); | ||
Console.WriteLine($"Assembly {targetFilePath} was upgraded from version {targetVersion} to version {maxVersion}."); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static int CompareVersions(string version1, string version2) | ||
{ | ||
var originVersion = new Version(version1); | ||
var targetVersion = new Version(version2); | ||
return originVersion.CompareTo(targetVersion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters