Skip to content
Permalink
Browse files

VSIX: Copy to CommonExtensions\DataDesign directory on build when Mod…

…elMapper #518
  • Loading branch information...
apobekiaris committed Aug 20, 2019
1 parent 288a07f commit 8d98dcd4e76025535775f31c8e4a87d409441cab
@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using EnvDTE;
using Xpand.VSIX.Extensions;

namespace Xpand.VSIX.Services{
public class ModelMapperService {
public static void Init() {
DteExtensions.DTE.Events.BuildEvents.OnBuildDone+=BuildEventsOnOnBuildDone;
}

private static IObservable<Unit> CopyFile(string s, string targetDirectory){
return Observable.Start(() => {
File.Copy(s, $@"{targetDirectory}\{Path.GetFileName(s)}",true);
return Unit.Default;
})
.OnErrorResumeNext(Observable.Return(Unit.Default));
}

private static void BuildEventsOnOnBuildDone(vsBuildScope scope, vsBuildAction action) {
var files = DteExtensions.DTE.Solution.Projects()
.Select(_ => _.FindOutputPath())
.SelectMany(s => Directory.GetFiles($"{Path.GetDirectoryName(s)}","*.dll"))
.Distinct().ToArray();
if (files.Any(s => $"{Path.GetFileName(s)}".Contains("ModelMapper"))) {
var targetDirectory =$@"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase}\CommonExtensions\DataDesign";
var modelMapperFiles = $@"{targetDirectory}\ModelMapperFiles.txt";
var deleteFiles=Observable.Empty<Unit>();
if (File.Exists(modelMapperFiles)) {
deleteFiles = File.ReadAllText(modelMapperFiles).Split(Environment.NewLine.ToCharArray()).ToObservable()
.SelectMany(s => Observable.Start(() => File.Delete($@"{targetDirectory}\{s}")).OnErrorResumeNext(Observable.Return(Unit.Default)))
.Finally(() => File.Delete(modelMapperFiles));
}
DteExtensions.DTE.WriteToOutput($"Copying files to {targetDirectory}");
deleteFiles.Concat(files.ToObservable()
.SelectMany(s => CopyFile(s, targetDirectory))
.Select(s => Unit.Default))
.Finally(() => {
File.WriteAllText(modelMapperFiles,string.Join(Environment.NewLine,files.Select(Path.GetFileName)));
DteExtensions.DTE.WriteToOutput("Finished");
})
.Subscribe();

}

}

}
}
@@ -113,7 +113,9 @@ public sealed class VSPackage : AsyncPackage ,IDTE2Provider{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

ExternalToolsService.Init();
ModelMapperService.Init();
Commands.Commands.Initialize();
}
}

}
@@ -118,6 +118,7 @@
<Compile Include="ModelEditor\METoolWindowControl.Designer.cs">
<DependentUpon>METoolWindowControl.cs</DependentUpon>
</Compile>
<Compile Include="Services\ModelMapperService.cs" />
<Compile Include="VSPackage\VSPackage1.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

0 comments on commit 8d98dcd

Please sign in to comment.
You can’t perform that action at this time.