コード例 #1
0
        public override async Task Run(Batch batch, MapDocument document)
        {
            var pcs  = Process;
            var args = Arguments;
            var wd   = WorkingDirectory;

            if (!File.Exists(pcs))
            {
                // Only show this notice once at most
                if (batch.Successful)
                {
                    var tlate  = Container.Get <ITranslationStringProvider>();
                    var prefix = GetType().FullName;
                    MessageBox.Show(tlate.GetString(prefix, "ProgramNotFoundMessage"), tlate.GetString(prefix, "ProgramNotFoundTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                batch.Successful = false;
                await Oy.Publish("Compile:Error", "Process not found: " + pcs + "\n");

                return;
            }

            // Replace {Variables} in the strings
            foreach (var kv in batch.Variables)
            {
                var s = '{' + kv.Key + '}';
                pcs  = pcs.Replace(s, kv.Value);
                args = args.Replace(s, kv.Value);
                wd   = wd.Replace(s, kv.Value);
            }

            await Oy.Publish("Compile:Information", $"{pcs} {args}\r\n");

            var process = new Process
            {
                StartInfo = new ProcessStartInfo(pcs, args)
                {
                    CreateNoWindow         = InterceptOutput,
                    UseShellExecute        = !InterceptOutput,
                    RedirectStandardOutput = InterceptOutput,
                    RedirectStandardError  = InterceptOutput,
                    WorkingDirectory       = wd
                },
                EnableRaisingEvents = true
            };

            // Use a task to signal process completion
            var tcs = new TaskCompletionSource <bool>();

            process.Exited += (s, e) =>
            {
                tcs.SetResult(true);
                process.Dispose();
            };

            // Listen to events if we're intercepting
            if (InterceptOutput)
            {
                process.OutputDataReceived += (sender, a) => Oy.Publish("Compile:Output", a.Data + "\r\n");
                process.ErrorDataReceived  += (sender, a) => Oy.Publish("Compile:Error", a.Data + "\r\n");
            }

            process.Start();

            if (InterceptOutput)
            {
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }

            await tcs.Task;
        }
コード例 #2
0
 public override Task Run(Batch batch, MapDocument document)
 {
     return(_callback(batch, document));
 }
コード例 #3
0
 public abstract Task Run(Batch batch, MapDocument document);