public TaskAgent(A ComputationAgent, Action <R> PayloadObserver = null, Action <IAppMessage> MessageObserver = null) { this.ComputationAgent = ComputationAgent; this.MessageObserver = MessageObserver ?? (message => SystemConsole.Get().Write(message)); this.PayloadObserver = PayloadObserver ?? (payload => { }); this._Task = defer(() => task(() => { iter(Compute(), result => { }); return(Wait()); })); }
public static Task <CommandProcessExecutionLog> Invoke(FilePath ExecutablePath, string args, string workdir = null) { var proc = new Process { StartInfo = new ProcessStartInfo { FileName = ExecutablePath, Arguments = args, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, WorkingDirectory = workdir ?? Environment.CurrentDirectory }, EnableRaisingEvents = true, }; var result = new CommandProcessExecutionLog(); proc.OutputDataReceived += (sender, e) => { if (isNotBlank(e.Data)) { result.StatusMessages.Add(e.Data); SystemConsole.Get().Write(AppMessage.Inform(e.Data)); } }; proc.ErrorDataReceived += (sender, e) => { if (isNotBlank(e.Data)) { result.ErrorMessages.Add(e.Data); SystemConsole.Get().Write(AppMessage.Error(e.Data)); } }; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); return(Task.Run(() => { proc.WaitForExit(); result.ExitCode = proc.ExitCode; proc.Dispose(); return result; })); }
protected override Option <R> TryExecute(C spec) { var name = typeof(BuildManager).AssemblyQualifiedName; var bm = BuildManager.DefaultBuildManager; var logger = new ConsoleLogger(); var console = SystemConsole.Get(); var loggers = new List <ILogger> { new ConsoleLogger() }; var bg = console.BackgroundColor; console.BackgroundColor = ConsoleColor.Black; console.Clear(); var props = spec.Properties.Map(p => (p.Name, p.Value)).ToDictionary(x => x.Item1, x => toString(x.Item2)); var request = new BuildRequestData(spec.ProjectFile, props, null, spec.Targets.ToArray(), null); //var request = new BuildRequestData(spec.ProjectFile, // new Dictionary<string, string> // { // { "Configuration", "Debug" }, // { "Platform", "Any CPU" } // }, null, new[] { "Rebuild" }, null); var parms = new BuildParameters(); parms.Loggers = loggers; var result = bm.Build(parms, request); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); console.BackgroundColor = bg; return(new R( result.OverallResult == BuildResultCode.Success, result.ResultsByTarget.Values.Where( x => x.Exception != null).Select(x => x.Exception.Message) )); }
/// <summary> /// Emits the value to the console /// </summary> /// <typeparam name="T">The type of value to print</typeparam> /// <param name="value">The value to print</param> public static void print <T>(T value) => SystemConsole.Get().Write(inform(show(value)));