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
5 changed files
with
117 additions
and
2 deletions.
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
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
58 changes: 58 additions & 0 deletions
58
src/ServiceControlInstaller.Packaging.Tasks/DedupeArtifactsTask.cs
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,58 @@ | ||
namespace ServiceControlInstaller.Packaging.Tasks; | ||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
public class DedupeArtifactsTask : Task | ||
{ | ||
[Required] | ||
public string ArtifactsPath { get; set; } = string.Empty; | ||
|
||
public override bool Execute() | ||
{ | ||
var sharedPath = Path.Combine(ArtifactsPath, "InstanceShared"); | ||
|
||
var primary = Path.Combine(ArtifactsPath, "Particular.ServiceControl\\ServiceControl"); | ||
var audit = Path.Combine(ArtifactsPath, "Particular.ServiceControl.Audit\\ServiceControl.Audit"); | ||
var monitoring = Path.Combine(ArtifactsPath, "Particular.ServiceControl.Monitoring\\ServiceControl.Monitoring"); | ||
|
||
var primaryFiles = EnumerateFiles(primary); | ||
var auditFiles = EnumerateFiles(audit); | ||
var monitoringFiles = EnumerateFiles(monitoring); | ||
|
||
primaryFiles.IntersectWith(auditFiles); | ||
primaryFiles.IntersectWith(monitoringFiles); | ||
|
||
foreach (var file in primaryFiles) | ||
{ | ||
var destination = Path.Combine(sharedPath, file); | ||
var destinationPath = Path.GetDirectoryName(destination); | ||
|
||
if (!string.IsNullOrWhiteSpace(destinationPath) && !Directory.Exists(destinationPath)) | ||
{ | ||
Directory.CreateDirectory(destinationPath); | ||
} | ||
|
||
File.Copy(Path.Combine(primary, file), destination, true); | ||
|
||
File.Delete(Path.Combine(primary, file)); | ||
File.Delete(Path.Combine(audit, file)); | ||
File.Delete(Path.Combine(monitoring, file)); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
static HashSet<string> EnumerateFiles(string path) | ||
{ | ||
HashSet<string> files = []; | ||
|
||
foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) | ||
{ | ||
var fileName = file.Substring(path.Length + 1); | ||
files.Add(fileName); | ||
} | ||
|
||
return files; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/ServiceControlInstaller.Packaging.Tasks/ServiceControlInstaller.Packaging.Tasks.csproj
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net472;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>12.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Build.Utilities.Core" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
</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