public void PrintUsages(ICommand cmd, IBaseWorker w, IList <string> remainArgs) { if (_quiteMode) { return; } // ReSharper disable once IdentifierTypo var cmds = cmd.backtraceTitles; if (string.IsNullOrWhiteSpace(cmds)) { cmds = " [Commands]"; } else if (cmd.SubCommands.Count > 0) { cmds += " [Sub-Commands]"; } var tails = "[Tail Args]|[Options]|[Parent/Global Options]"; if (!string.IsNullOrWhiteSpace(cmd.TailArgs)) { tails = cmd.TailArgs; } oln(""); oln("Usages:"); oln($" {_root?.AppInfo.AppName} {cmds} {tails}"); }
public void ShowHelpScreen(IBaseWorker w, IList <string> remainArgs) { var commandLines = new SortedDictionary <string, List <TwoString> >(); var optionLines = new SortedDictionary <int, CmdFlagLines>(); // var writer = ColorifyEnabler.Colorify; // Console.Out; var command = w.ParsedCommand ?? w.RootCommand; tabStopCalculated = w.TabStop; const bool noBacktrace = false; w.Walk(command, commandsWatcherBuilder(w, commandLines, tabStopCalculated, noBacktrace), flagsWatcherBuilder(w, optionLines, tabStopCalculated, noBacktrace)); Painter.Setup(command, w, remainArgs); Painter.PrintPrologue(command, w, remainArgs); Painter.PrintPreface(command, w, remainArgs); Painter.PrintHeadLines(command, w, false, remainArgs); Painter.PrintUsages(command, w, remainArgs); Painter.PrintExamples(command, w, remainArgs); // ShowIt(command, commandLines, optionLines, writer, tabStop); Painter.PrintCommandsAndOptions(command, commandLines, optionLines, tabStopCalculated, false, w, remainArgs); Painter.PrintTailLines(command, w, remainArgs); Painter.PrintEpilogue(command, w, remainArgs); // writer.WriteLine(""); }
/// <summary> /// Terminates the workers. /// </summary> private void TerminateWorkers() { var workers = (IBaseWorker[] )null; lock (_workers) { workers = new IBaseWorker[_workers.Count]; _workers.CopyTo(workers); } foreach (var worker in workers) { (worker as BaseWorker).Terminate(); } foreach (var worker in workers) { TerminateWorker(worker); } while (true) { lock (_workers) { if (_workers.Count == 0) { break; } } Thread.Sleep(100); } }
/// <summary> /// Removes the worker. /// </summary> /// <param name="worker">The worker.</param> private void RemoveWorker(IBaseWorker worker) { lock (_workers) { _workers.Remove(worker); } }
// ReSharper disable once InconsistentNaming private static void listAction(IBaseWorker w, IBaseOpt cmd, IEnumerable <string> args) { var enumerable = args.ToList(); var mdxFile = enumerable.ElementAtOrDefault(0); var word = enumerable.ElementAtOrDefault(1); if (string.IsNullOrWhiteSpace(mdxFile)) { w.ShowHelpScreen(w, enumerable); // w.ErrorPrint("no valid mdx file specified."); return; } Console.WriteLine($"{mdxFile} / {word}"); var mdx = new MDictLoader(mdxFile) { PreloadAll = true }; if (!mdx.Process()) { // w.ErrorPrint($"CANNOT load and process the mdx file: {mdxFile}."); return; } Console.WriteLine($"Header: \n\n{mdx.DictHeader}\n\nIndex: \n\n{mdx.DictIndex}\n\n"); }
public void PrintExamples(ICommand cmd, IBaseWorker w, IList <string> remainArgs) { if (_quiteMode) { return; } if (!string.IsNullOrWhiteSpace(cmd.DescriptionLong)) { oln("\nDescription:"); olnIndent(cmd.DescriptionLong, ColorDesc, 4); } else if (!string.IsNullOrWhiteSpace(cmd.Description)) { oln("\nDescription:"); olnIndent(cmd.Description, ColorDesc, 4); } // ReSharper disable once InvertIf if (!string.IsNullOrWhiteSpace(cmd.Examples)) { oln(""); oln("Examples:"); olnIndent(cmd.Examples, ColorDesc, 4); } }
// ReSharper disable once InconsistentNaming private static void lookupAction(IBaseWorker w, IBaseOpt cmd, IEnumerable <string> args) { var enumerable = args.ToList(); var mdxFile = enumerable.ElementAtOrDefault(0); var word = enumerable.ElementAtOrDefault(1); if (string.IsNullOrWhiteSpace(mdxFile)) { w.ShowHelpScreen(w, enumerable); // w.ErrorPrint("no valid mdx file specified."); return; } var mdx = new MDictLoader(mdxFile); if (!mdx.Process()) { // w.ErrorPrint($"CANNOT load and process the mdx file: {mdxFile}."); return; } Console.WriteLine($"<!--\n\nHeader: \n\n{mdx.DictHeader}\n\nIndex: \n\n{mdx.DictIndex}\n\n-->\n"); if (!string.IsNullOrWhiteSpace(word)) { // Console.WriteLine($"Lookup for word '{word}'..."); // Console.WriteLine(word); var s = mdx.Query(word); Console.WriteLine(s); } }
/// <summary> /// Spawns the worker. /// </summary> /// <param name="worker">The worker.</param> /// <param name="waitmsec">The waitmsec.</param> /// <returns></returns> protected IBaseWorker SpawnWorker(IBaseWorker worker, int waitmsec = 0) { WorkPackage.WorkManager.SpawnWorker(worker); WaitForWorkerOnState(worker, BaseThreadState.Started, waitmsec); return(worker); }
void IAction.Invoke(IBaseWorker w, IEnumerable <string> remainsArgs) { // foreach (var filename in remainsArgs) // { // if (string.IsNullOrEmpty(filename)) continue; // // w.log.Information($"loading {filename} ..."); // // using var l = new MDictLoader(filename); // try // { // // l.Process(); // // Console.WriteLine($"header: {l.DictHeader}"); // } // catch (Exception ex) // { // Debug.WriteLine(ex.ToString()); // // throw; // } // finally // { // w.ParsedCount++; // // w.log.Information($"#{w.ParsedCount} parsed."); // // // l.Dispose(); // } // } // // if (w.ParsedCount == 0) // w.log.Warning("Nothing to parsed."); w.ShowHelpScreen(w, remainsArgs.ToArray()); }
public void ShowBuildInfoScreen(IBaseWorker w, IList <string> remainArgs) { var command = w.ParsedCommand ?? w.RootCommand; tabStopCalculated = w.TabStop; Painter.Setup(command, w, remainArgs); if (w.AppQuietMode) { Painter.PrintBuildInfo(command, tabStopCalculated, w, remainArgs); return; } Painter.PrintPrologue(command, w, remainArgs); Painter.PrintPreface(command, w, remainArgs); Painter.PrintHeadLines(command, w, true, remainArgs); // Painter.PrintUsages(command, w, remainArgs); // Painter.PrintExamples(command, w, remainArgs); Painter.PrintBuildInfo(command, tabStopCalculated, w, remainArgs); // Painter.PrintTailLines(command, w, remainArgs); Painter.PrintEpilogue(command, w, remainArgs); // writer.WriteLine(""); }
/// <summary> /// Adds the worker. /// </summary> /// <param name="worker">The worker.</param> private void AddWorker(IBaseWorker worker) { lock (_workers) { _workers.Add(worker); } }
public void PrintEpilogue(ICommand cmd, IBaseWorker w, IList <string> remainArgs) { if (_quiteMode) { return; } oln(""); }
internal Func <ICommand, ICommand, int, bool>?commandsWatcherBuilder(IBaseWorker w, IDictionary <string, List <TwoString> > commandLines, int tabStop, bool noBacktrace) { return((owner, cmd, level) => { if (level > 0) { return true; } if (cmd.Hidden) { return true; } var sb = new StringBuilder(" "); if (!string.IsNullOrWhiteSpace(cmd.Short)) { sb.Append($"{cmd.Short}, "); } if (!string.IsNullOrWhiteSpace(cmd.Long)) { sb.Append($"{cmd.Long}"); } if (cmd.Aliases.Length > 0) { sb.Append(", ").AppendJoin(',', cmd.Aliases); } var sb2 = new StringBuilder(); if (!string.IsNullOrWhiteSpace(cmd.Description)) { sb2.Append(cmd.Description); } else if (!string.IsNullOrWhiteSpace(cmd.DescriptionLong)) { sb2.Append(cmd.DescriptionLong); } if (!commandLines.ContainsKey(cmd.Group)) { commandLines.TryAdd(cmd.Group, new List <TwoString>()); } if (sb.Length >= tabStopCalculated) { tabStopCalculated = sb.Length + 1; } commandLines[cmd.Group].Add(new TwoString { Level = level, Part1 = sb.ToString(), Part2 = sb2.ToString() }); return true; }); }
public void Setup(ICommand cmd, IBaseWorker w, IList <string> remainArgs) { // Console.WriteLine("Setup..."); // _quiteMode = Parse(Cmdr.Instance.Store.Get("quiet").ToString()); _quiteMode = Cmdr.Instance.Store.GetAs("quiet", _quiteMode); _root = cmd.FindRoot(); // int qi = Cmdr.Instance.Store.GetAs("quiet", 0); // Console.WriteLine($"qi={qi}"); }
public void Execute(IBaseWorker w, IBaseOpt cmd, IEnumerable <string> remainArgs) { // throw new System.NotImplementedException(); Console.WriteLine( value: $"Hit: {cmd}, Remains: {remainArgs}. Count: {Cmdr.Instance.Store.GetAs<int>(key: "count")}"); // for (var i = 0; i < Count; i++) // { // // Prompt.GetPassword("Enter your password: "); // } }
public void PrintTailLines(ICommand cmd, IBaseWorker w, IList <string> remainArgs) { if (_quiteMode) { return; } oln("", ColorDesc); oln("Type '-h'/'-?' or '--help' to get command help screen.", ColorDesc); oln("More: '-D'/'--debug', '-v'/'--verbose', '-V'/'--version', '-#'/'--build-info'...", ColorDesc); }
/// <summary> /// Joins the specified worker. /// </summary> /// <param name="worker">The worker.</param> /// <param name="waitmsec">The waitmsec.</param> public void Join(IBaseWorker worker, int waitmsec) { if (waitmsec != 0) { long sleep = waitmsec; while ((sleep > 0 || waitmsec == Timeout.Infinite) && !_terminated && worker.ActiveThread != null) { PassiveSleep(100); sleep -= 100; } } }
public void PrintHeadLines(ICommand cmd, IBaseWorker w, bool singleLine, IList <string> remainArgs) { if (_quiteMode) { return; } var author = _root?.AppInfo.Author; if (string.IsNullOrWhiteSpace(author)) { author = "Freeman"; } oln($"{_root?.AppInfo.AppName} - {_root?.AppInfo.AppVersion} - {author}"); if (singleLine) { return; } if (!string.IsNullOrWhiteSpace(_root?.AppInfo.Copyright)) { olnIndent(_root?.AppInfo.Copyright, ColorDesc, 4); } if (!string.IsNullOrWhiteSpace(_root?.Description)) { // oln("\nDescription:"); oln(""); olnIndent(_root?.Description, ColorDesc, 4); } // ReSharper disable once InvertIf if (Cmdr.Instance.Store.GetAs <bool>("verbose")) { if (!string.IsNullOrWhiteSpace(_root?.DescriptionLong)) { oln(""); olnIndent(_root?.DescriptionLong, ColorDesc, 4); } // ReSharper disable once InvertIf if (!string.IsNullOrWhiteSpace(_root?.Examples)) { oln(""); oln("Examples:"); olnIndent(_root?.Examples, ColorDesc, 4); } } }
private void buildParentFlags(IBaseWorker w, ICommand?oo, IDictionary <int, CmdFlagLines> optionLines, int tabStop, bool noBacktrace) { // var oo = owner.Owner; while (oo != null && !ReferenceEquals(oo, oo.Owner)) { w.Walk(oo, (o, c, l) => true, flagsWatcherBuilder(w, optionLines, tabStop, noBacktrace) ); oo = oo.Owner; } }
public SpeechDisordersDetector( IAudioService audioService, IFileWorkerService fileWorkerService, IFeatureExtractorService featureExtractorService, INeuralNetworkService neuralNetworkService, IBaseWorker baseWorker) { _audioService = audioService; _fileWorkerService = fileWorkerService; _featureExtractorService = featureExtractorService; _neuralNetworkService = neuralNetworkService; _baseWorker = baseWorker; InitializeComponent(); }
/// <summary> /// Disposes the worker. /// </summary> /// <param name="worker">The worker.</param> private void DisposeWorker(IBaseWorker worker) { try { if (worker != null) { worker.Dispose(); } } catch (Exception ex) { var eMsg = string.Format("An unhandled exception was detected disposing Worker '{0}'", worker.Name); Notification.SendException(new WorkManagerException(eMsg, ex), true); } }
public void Invoke(IBaseWorker w, IEnumerable <string> remainsArgs) { var count = 0; foreach (var filename in remainsArgs) { count++; if (string.IsNullOrEmpty(filename)) { continue; } w.log.logInfo($"loading {filename} ..."); using var l = new MDictLoader(filename); try { l.Process(); Console.WriteLine($"header: {l.DictHeader}"); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); // throw; } finally { w.ParsedCount++; // w.log.Information($"#{w.ParsedCount} parsed."); // l.Dispose(); } } if (count == 0) { w.ShowHelpScreen(w, remainsArgs.ToArray()); return; } if (w.ParsedCount == 0) { w.log.logWarning(null, "Nothing to parsed."); } }
/// <summary> /// Waits the state of for worker on. /// </summary> /// <param name="worker">The worker.</param> /// <param name="state">The state.</param> /// <param name="waitmsec">The waitmsec.</param> /// <returns></returns> protected bool WaitForWorkerOnState(IBaseWorker worker, BaseThreadState state, int waitmsec) { if (waitmsec != 0) { long sleep = waitmsec; while ((sleep > 0 || waitmsec == Timeout.Infinite) && !_terminated) { if (worker.ThreadState == state) { break; } PassiveSleep(100); sleep -= 100; } } return(ThreadState == state); }
public void PrintDumpForDebug(ICommand cmd, IBaseWorker w, int tabStop, bool hitOnly = true, bool enabled = false) { if (!enabled) { return; } if (Util.GetEnvValueBool("CMDR_DUMP_NO_STORE") == false) { oln("Dump the Store:"); var store = Cmdr.Instance.Store; store.Dump(o); } if (Util.GetEnvValueBool("CMDR_DUMP_NO_HIT") == false) { oln("\n\nDump the Flags (Hit only):"); dumpValues(w.RootCommand, w, tabStop, hitOnly); oln(string.Empty); } }
public void OnSetHandler(IBaseWorker w, object newValue, object oldValue) { throw new NotImplementedException(); }
public void PostInvoke(IBaseWorker w, IEnumerable <string> remainsArgs) { Console.WriteLine($"{w}: {remainsArgs}"); }
/// <summary> /// Terminates the worker. /// </summary> /// <param name="worker">The worker.</param> internal void TerminateWorker(IBaseWorker worker) { _messageManager.SendMessage(MessageManagerId.TerminateWorker, worker); }
/// <summary> /// Spawns the worker. /// </summary> /// <param name="worker">The worker.</param> /// <returns></returns> internal IBaseWorker SpawnWorker(IBaseWorker worker) { _messageManager.SendMessage(MessageManagerId.SpawnWorker, worker); return(worker); }
private static void ExternalConfigLoader(IBaseWorker w, IRootCommand root) { // throw new NotImplementedException(); }
public void PrintCommandsAndOptions(ICommand cmd, SortedDictionary <string, List <TwoString> > commandLines, SortedDictionary <int, CmdFlagLines> optionLines, // Format writer, int tabStop, bool treeMode, IBaseWorker w, IList <string> remainArgs) { if (_quiteMode) { return; } if (treeMode) { var title = cmd.IsRoot ? "-ROOT-" : cmd.backtraceTitles; if (commandLines.Count > 0) { oln($"\nCommands Tree For '{title}':"); ShowLinesOneByOne(commandLines, tabStop); } else { oln($"\nNO SUB-COMMANDS For '{title}'"); } } else { if (commandLines.Count > 0) { if (cmd.Owner != null && cmd.Owner.IsRoot) { oln("\nCommands:"); } else { oln("\nSub-Commands:"); } ShowLinesOneByOne(commandLines, tabStop); } } // ReSharper disable once InvertIf if (optionLines.Count > 0) { var step = 0; // ReSharper disable once UnusedVariable foreach (var(lvl, cf) in optionLines) { if (!treeMode) { // writer.WriteLine($"\nOptions {UpperBoundLevel - lvl}:"); if (cf.cmd.IsRoot) { oln($"\nGlobal Options:"); } else if (step == 0) { oln($"\nOptions:"); // {lvl}/{WorkerFunctions.UpperBoundLevel - lvl}:"); } else if (step == 1) { oln($"\nParent Options ({cf.cmd.backtraceTitles}):"); } else { oln($"\nParents Options ({cf.cmd.backtraceTitles}):"); } } ShowLinesOneByOne(cf.lines, tabStop, step); step++; } } else if (!treeMode) { oln($"\nOptions:\n None"); } }