-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
6 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"dotnet-test-explorer.testProjectPath": "GraphBuilder/tests" | ||
"dotnet-test-explorer.testProjectPath": "*/tests" | ||
} |
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,32 @@ | ||
using System.Text; | ||
using System.Security.Cryptography; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace PackageAnalyzer | ||
{ | ||
public static class HashAlgorithmExtensions | ||
{ | ||
public static async Task<byte[]> ComputeHashAsync(this HashAlgorithm alg, IEnumerable<FileInfo> files, string rootPath) | ||
{ | ||
using (var cs = new CryptoStream(Stream.Null, alg, CryptoStreamMode.Write)) | ||
{ | ||
foreach (var file in files) | ||
{ | ||
// Will either include the rootPath or not. | ||
string fileName = file.FullName.Substring(rootPath.Length, file.FullName.Length - rootPath.Length); | ||
var pathBytes = Encoding.UTF8.GetBytes(fileName); | ||
cs.Write(pathBytes, 0, pathBytes.Length); | ||
|
||
using (var fs = file.OpenRead()) | ||
await fs.CopyToAsync(cs); | ||
} | ||
|
||
cs.FlushFinalBlock(); | ||
} | ||
|
||
return alg.Hash; | ||
} | ||
} | ||
} |
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,47 @@ | ||
using System; | ||
using System.Text; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Security.Cryptography; | ||
using System.Linq; | ||
|
||
namespace PackageAnalyzer | ||
{ | ||
public class PackageHasher | ||
{ | ||
public Dictionary<string, string> HashFolders(List<string> folders) | ||
{ | ||
Dictionary<string, string> hasedFolders = new Dictionary<string, string>(); | ||
|
||
|
||
return hasedFolders; | ||
} | ||
async Task<string> HashFolder(DirectoryInfo folder, bool excludeRoot, string searchPattern = "*", SearchOption searchOption = SearchOption.AllDirectories) | ||
{ | ||
string rootPath = String.Empty; | ||
|
||
if(excludeRoot) | ||
{ | ||
rootPath = folder.FullName.Substring(0, folder.FullName.Length - folder.FullName.Split('\\').Last().Length ); | ||
} | ||
|
||
using(var alg = MD5.Create()) | ||
{ | ||
|
||
var result = await alg.ComputeHashAsync(folder.EnumerateFiles(searchPattern, searchOption), rootPath); | ||
|
||
// Build the final string by converting each byte | ||
// into hex and appending it to a StringBuilder | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < result.Length; i++) | ||
{ | ||
sb.Append(result[i].ToString("X2")); | ||
} | ||
|
||
// And return it | ||
return sb.ToString(); | ||
|
||
} | ||
} | ||
} | ||
} |
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,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,15 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace PackageAnalyzer.PackageHasher.Tests | ||
{ | ||
|
||
[TestClass] | ||
public class PackageHasherTests | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} | ||
|
||
} |
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |