private Task CopySolutionAsync(SolutionRewriteContext context, SolutionExplorer sourceExplorer, string destinationPath)
        {
            Log.Debug($"Copying solution from  \"{sourceExplorer.SolutionPath}\" to \"{destinationPath}\".");
            context.CancellationToken.ThrowIfCancellationRequested();

            var endsWithComparer = new EndsWithComparer();
            var blackList        = Configuration.GetFileCopyBlackListElements().Select(s => s.TrimStart('*')).ToImmutableHashSet();
            var sourceFiles      = new HashSet <string>(
                sourceExplorer
                .GetAllReferencedDocuments()
                .Concat(sourceExplorer.GetAllAdditiontalDocuments())
                .Concat(sourceExplorer.GetAllProjectFiles())
                .Concat(new [] { sourceExplorer.SolutionPath })
                );

            foreach (var sourceFile in sourceFiles)
            {
                if (context.CancellationToken.IsCancellationRequested)
                {
                    return(Task.CompletedTask);
                }

                var relativePath = GetRelativePath(SolutionPath, sourceFile);
                var destFileName = Path.Combine(destinationPath, relativePath);
                var fileInfo     = new FileInfo(destFileName);
                if (blackList.Contains(fileInfo.Name, endsWithComparer))
                {
                    continue;
                }

                if (!fileInfo.Directory.Exists)
                {
                    fileInfo.Directory.Create();
                }
                File.Copy(sourceFile, destFileName);
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
 public ProjectRewriteContext(ProjectRewriteCache cache, string projectPath, CancellationToken cancellationToken, Configuration configuration, SolutionExplorer explorer)
 {
     Cache             = cache ?? throw new ArgumentNullException(nameof(cache));
     ProjectPath       = projectPath ?? throw new ArgumentNullException(nameof(projectPath));
     CancellationToken = cancellationToken;
     Configuration     = configuration;
     Explorer          = explorer;
 }
 public ProjectRewriteCache(SolutionExplorer explorer, string rootTemplatePath)
 {
     Explorer         = explorer;
     RootTemplatePath = rootTemplatePath;
 }
Beispiel #4
0
        public async Task <bool> ExecuteAsync(CancellationToken cancellationToken, IProgress <string> progress)
        {
            ConfigurationViewModel viewModel;

            try
            {
                viewModel = new ConfigurationViewModel(Configuration);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(false);
            }

            if (!viewModel.CanBuild())
            {
                Log.Error($"cannot build the configuration [{Configuration.Name}] because of validation errors.");
                foreach (var error in viewModel.ValidationErrors)
                {
                    Log.Error(error);
                }

                return(false);
            }
            if (Configuration.OutputFolders.Count == 0)
            {
                Log.Error($"No output paths specified.");
                progress.Report($"No output paths specified.");
                await Task.Delay(3000, cancellationToken);

                return(false);
            }

            var tempFolder = CreateTempFolder();
            var context    = new SolutionRewriteContext(cancellationToken, progress, Configuration);

            if (!Directory.Exists(tempFolder))
            {
                progress.Report($"Failed to create temp folder");
                await Task.Delay(3000, cancellationToken);

                Log.Error($"Failed to create temp folder");
                return(false);
            }

            var explorer = await SolutionExplorer.CreateAsync(SolutionPath, progress, cancellationToken);

            await CopySolutionAsync(context, explorer, tempFolder);

            if (!await RewriteSolutionAsync(context, tempFolder))
            {
                progress.Report($"Solution rewrite of {SolutionPath} failed.{Environment.NewLine}See logs for details.");
                return(false);
            }

            await DistributeArtifacts(cancellationToken, context, tempFolder);

            Log.Info($"Deleting temporary working folder {tempFolder}.");
            Directory.Delete(tempFolder, true);

            Log.Info($"Execution finished succesfully.");

            return(true);
        }