public override bool Run(StateProvider state) { log = OpenWindow <LoggerWindow>().Rename("Info"); properties = new List <string>(); sorted = new Dictionary <string, List <string> >(); count = 0; state.SetProgress(0); state.SetMaxProgress(files.Length); foreach (var file in from f in files where File.Exists(f) select new FileInfo(f)) { ReadShader(file); state.AddProgress(1); state.SetStatus($"[{state.Progress}%] - Reading \"{file.Name}\"..."); } state.SetMaxProgress(properties.Count); state.SetProgress(0); foreach (var prop in properties) { AddProperty(prop); state.AddProgress(1); state.SetStatus($"[{state.Progress}%] - Scanning..."); } output = OpenWindow <LoggerWindow>().Rename("Output"); state.SetMaxProgress(count); state.SetProgress(0); foreach (var group in sorted) { output.WriteLine(string.Format($"=== {group.Key} ==={nl}")); foreach (var prop in group.Value.OrderBy(s => s)) { output.WriteLine(prop); state.AddProgress(1); state.SetStatus($"[{state.Progress}%] - Displaying..."); } output.WriteLine($"{nl}{nl}"); } state.SetStatus($"Done!"); log.Dispose(); return(true); }
private void RunTool(Tool tool) { StateProvider provider = new StateProvider(Progress, Status); provider.SetProgress(0); provider.SetMaxProgress(100); provider.SetStatus($"Executing tool \"{Program.ToolManager.GetToolName(tool)}\"..."); SetToolStatus(false); tool.SetParent(this); if (tool.Prepare(provider)) { CancellationTokenSource source = new CancellationTokenSource(); CancellationToken token = source.Token; TaskFactory factory = new TaskFactory(token); tool.SetCancelToken(source); factory.StartNew(() => { try { tool.SetRunning(true); tool.Run(provider); if (tool.WasCanceled()) { tool.CloseResources(); } } catch (Exception e) { LoggerWindow logger = OpenWindow <LoggerWindow>() .Rename("Log - Exception"); logger.WriteLine(e.ToString()); } finally { tool.SetRunning(false); } }); } else { Reset(); } SetToolStatus(true); }
public override bool Run(StateProvider state) { var info = OpenWindow <LoggerWindow>().Rename("Output"); info.WriteLine("Begin task..."); const int length = 500000; state.SetMaxProgress(length); for (int i = 0; i <= length; i++) { state.SetProgress(i); state.SetStatus($"Task running... ({state.Progress}%)"); } info.WriteLine("Task complete!"); return(true); }