Example #1
0
        public IEnumerable <ProcessorItem> Process(IProcessorPipeline pipeline, IEnumerable <ProcessorItem> items)
        {
            foreach (ProcessorItem item in items)
            {
                item.Value = template.Make(pipeline.PropertyProvider, pipeline.PropertyStore, item);

                yield return(item);
            }
        }
Example #2
0
        public IEnumerable <ProcessorItem> Process(IProcessorPipeline pipeline, IEnumerable <ProcessorItem> items)
        {
            if (pipeline.Simulate)
            {
                pipeline.Output.WriteLine(Utility.Level.Info, $"\n&-c;-------- Simulation Mode Active! --------&-^;\n");
            }

            foreach (ProcessorItem item in items)
            {
                string srcFilepath = item.Value;
                string dstFilepath = dstTemplate.Make(pipeline.PropertyProvider, pipeline.PropertyStore, item);

                pipeline.Output.WriteLine(Utility.Level.Info, $"Copying: &-6;{srcFilepath}&-^; -> &-6;{dstFilepath}&-^;");

                if (!pipeline.Simulate)
                {
                    if (File.Exists(srcFilepath))
                    {
                        string dir = Path.GetDirectoryName(dstFilepath);
                        if (!string.IsNullOrEmpty(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        if (!File.Exists(dstFilepath))
                        {
                            File.Copy(srcFilepath, dstFilepath);
                        }
                        else
                        {
                            pipeline.Output.WriteLine(Utility.Level.Info, $"  - &-c;Destination filepath already exists! Ignoring...&-^;");
                        }
                    }
                    else
                    {
                        pipeline.Output.WriteLine(Utility.Level.Info, $"  - &-c;Source filepath doesn't exist! Ignoring...&-^;");
                    }
                }
            }

            return(items);
        }
Example #3
0
        public IEnumerable <ProcessorItem> Process(IProcessorPipeline pipeline, IEnumerable <ProcessorItem> items)
        {
            if (pipeline.Simulate)
            {
                pipeline.Output.WriteLine(Level.Info, $"\n&-c;-------- Simulation Mode Active! --------&-^;\n");
            }

            foreach (ProcessorItem item in items)
            {
                string path = template.Make(pipeline.PropertyProvider, pipeline.PropertyStore, item);

                pipeline.Output.WriteLine(Level.Info, $"MkDir: &-6;{path}&-^;");

                if (!pipeline.Simulate)
                {
                    Directory.CreateDirectory(path);
                }
            }

            return(items);
        }
Example #4
0
        public IEnumerable <ProcessorItem> Process(IProcessorPipeline pipeline, IEnumerable <ProcessorItem> items)
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo()
            {
                CreateNoWindow         = noWindow,
                ErrorDialog            = false,
                UseShellExecute        = !noWindow,
                RedirectStandardOutput = noWindow,
                RedirectStandardError  = noWindow
            };

            if (pipeline.Simulate)
            {
                pipeline.Output.WriteLine(Utility.Level.Info, $"\n&-c;-------- Simulation Mode Active! --------&-^;\n");
            }


            foreach (ProcessorItem item in items)
            {
                string exeFilepath = exeTemplate.Make(pipeline.PropertyProvider, pipeline.PropertyStore, item);


                string exeArguments = argsTemplate.Make(pipeline.PropertyProvider, pipeline.PropertyStore, item);


                info.FileName  = exeFilepath;
                info.Arguments = exeArguments;


                System.Diagnostics.Process process = !pipeline.Simulate ? new System.Diagnostics.Process {
                    StartInfo = info
                } : null;

                if (noWindow && !pipeline.Simulate)
                {
                    process.OutputDataReceived += (p, data) => pipeline.Output.WriteLine(Level.None, data.Data, true);
                    process.ErrorDataReceived  += (p, data) => pipeline.Output.WriteLine(Level.None, data.Data, true);
                }

                try {
                    process?.Start();

                    pipeline.Output.WriteLine(Level.None, $"Executing: {exeFilepath} {exeArguments}");

                    if (noWindow)
                    {
                        process?.BeginErrorReadLine();
                        process?.BeginOutputReadLine();
                    }

                    if (wait)
                    {
                        process?.WaitForExit();
                    }
                } catch (Win32Exception) {
                    pipeline.Output.WriteLine(Level.Error, $"&-c;Failed to execute: {exeFilepath} {exeArguments}&-^;");
                }
            }

            return(items);
        }