public static IAppMessage UnhandledExecutionError(ICommandSpec spec, Exception e) => error("Error executing command @CommandName: @ErrorDetail", new { CommandName = spec.CommandName, ErrorDetail = e.ToString() });
public static IAppMessage CompletedCommandExecution(ICommandSpec spec, object payload = null) => inform($"Executed @SpecName", new { spec.CommandName, spec.SpecName, Description = spec.ToString() });
public static TSpec Expand(ICommandSpec src) { if ((src as TSpec)?.Expanded ?? false) { return(src as TSpec); } var args = src.Arguments; var expansion = new TSpec { CommandName = src.CommandName, Expanded = true, }; iter(args, arg => { if (ParameterIndex.ContainsKey(arg.Name)) { if ((arg.Value as string) != null) { var argExpansion = ScriptText.SpecifyEnvironmentParameters((string)arg.Value); expansion[arg.Name] = new CommandArgument(arg.Name, argExpansion); } else { expansion[arg.Name] = new CommandArgument(arg.Name, arg.Value); } } }); return(expansion); }
public CommandEmission(ICommandSpec CommandSpec, Option <FilePath> OutputPath) { this.CommandSpec = CommandSpec; this.OutputPath = OutputPath; this.Description = Succeeded ? AppMessage.Inform($"Emitted {CommandSpec.SpecName}") : OutputPath.Message; }
public CommandResult Execute(ICommandSpec command) { var json = Serializer.Encode(command); var submission = new CommandSubmission(command, increment(ref cmdid), json); var dispatch = new CommandDispatch(submission); return(Execute(dispatch)); }
public CommandSubmission Submit(ICommandSpec command, CorrelationToken?ct) { var submission = new CommandSubmission(command, NextSubmissionId(), C.Service <IJsonSerializer>().ObjectToJson(command), ct, now()); SubmissionQueue.Enqueue(submission); return(submission); }
public static IAppMessage Error(this ICommandSpec spec, Exception e) => error("An occurred during execution of the @CommandName - @ErrorDescription: @ErrorDetail", new { spec.CommandName, ErrorDescription = e.Message, ErrorDetail = e.ToString() });
public static CommandStatusMessage CreateErrorStatus ( ICommandSpec spec, long?subid, string template, object content, CorrelationToken?ct = null, [CallerMemberName] string messageType = null ) => new CommandStatusMessage(spec, subid, EventLevel.Error, template, ct, messageType);
public Option <FilePath> ExportSpec(ICommandSpec spec, FolderPath root, FileExtension Extension, bool FlattenHierarchy) { var ext = Extension ?? ".spec"; var dstFolder = FlattenHierarchy ? root : root.GetCombinedFolderPath(spec.CommandName.Identifier.Split('/').Last()); dstFolder.CreateIfMissing().Require(); var path = dstFolder + (new FileName(spec.SpecName) + ext); var json = serializer.Encode(spec); File.WriteAllText(path, json); return(path); }
internal CommandStatusMessage(ICommandSpec spec, long?subid, EventLevel level, string template, CorrelationToken?ct, string MessageType) { _SubmissionId = subid; _Content = spec; _CommandName = spec.CommandName; _CommandSpecName = spec.SpecName; _Antecedent = AppMessage.Empty; _EventLevel = level; _MessageType = MessageType; _Arguments = spec.Arguments; _MessageTemplate = template; _CorrelationToken = ct; _MessageId = Guid.NewGuid(); }
/// <summary> /// Synchronously processes a single command /// </summary> /// <param name="command">The command to process</param> /// <returns></returns> public CommandResult ProcessCommand(ICommandSpec command) { var completion = from p in CPS.Pattern(command) let q = p.Queue let x = p.Executor from s in q.Enqueue(command, SystemNode.Local) from d in q.Dispatch() let r = x.Execute(d) from c in CPS.ExecStore.Complete(r) select r; return(completion.ValueOrElse(() => new CommandResult(command, null, false, completion.Message, 0))); }
public IOption ExecuteCommand(ICommandSpec command, bool save) { var pattern = Self.Pattern(command); if (pattern.IsNone()) { return(pattern.WithMessage(ExecutorNotFound(command.CommandName))); } try { return(ExecuteCommand(pattern.Require(), command, save)); } catch (Exception e) { return(none <ICommandExecutionService>(UnhandledExecutionError(command, e))); } }
IOption ExecuteCommand(ICommandExecutionService pattern, ICommandSpec command, bool save) { Notify(ExecutingCommand(command)); if (save) { var saved = CommandStore?.SaveSpec(command); if (!saved.HasValue) { return(saved); } else if (!saved.Value) { return(saved); } } var expansion = command.ExpandVariables(); var option = pattern.TryExecute(expansion); if (option != null) { if (option.IsNone) { Notify(option.Message); } else { if (option.Message.IsEmpty) { Notify(CompletedCommandExecution(command, option.Value)); } else { Notify(option.Message); } } } else { Notify(EmptyCommandResult(command)); } return(option); }
public Option <int> SaveSpec(ICommandSpec spec, FileExtension Extension, bool FlattenHierarchy) { var ext = Extension ?? ".spec"; var filename = new FileName(spec.SpecName) + ext; var outdir = FlattenHierarchy ? new FolderPath(Settings.CommandFolder) : new FolderPath(Path.Combine(Settings.CommandFolder, spec.CommandName)); if (!Directory.Exists(outdir)) { Directory.CreateDirectory(outdir); } var outpath = outdir + filename; var json = serializer.Encode(spec); File.WriteAllText(outpath, json); return(1); }
public static ICommandSpec AssignArgs(this ICommandSpec command, CommandArguments args, bool defineSpecName = true) { var propIndex = command.GetType().GetPublicProperties(true, true).ToDictionary(x => x.Name.ToLower()); foreach (var arg in args) { if (propIndex.TryGetValue(arg.Name.ToLower(), out PropertyInfo prop)) { var typedVal = Parsers.Convert(prop.PropertyType, arg.Value); prop.SetValue(command, typedVal); } } if (defineSpecName) { var specNameProp = nameof(ICommandSpec.SpecName).ToLower(); var argHash = string.Join(",", args.Select(a => $"{a.Name}:={a.Value}")).GetHashCode(); propIndex[specNameProp].SetValue(command, $"{command.CommandName}/{argHash}"); } return(command); }
Option <CommandSubmission> ICommandSubmitter.Submit(ICommandSpec command, SystemNode target, CorrelationToken?ct) => Submit(command, ct);
Option <ICommandExecutionService> ICommandPatternSystem.Pattern(ICommandSpec spec) => Pattern(spec.CommandName);
internal InvalidMenuToolbarOptionsException(ICommandSpec cmd) : base($"Neither toolbar nor menu option is specified for {cmd.Title} ({cmd.UserId}) command. Use") { }
protected CommandProgression(CommandProgression src) { this.spec = src.spec; this.json = src.json; this.ct = src.ct; }
IOption ICommandExecutionService.TryExecute(ICommandSpec spec, CommandExecutionContext ec) => TryExecute((TSpec)spec, ec);
public static Option <CommandSubmission> Submit(this ICommandPatternSystem CPS, ICommandSpec Command, SystemNode DstNode, CorrelationToken?ct) => CPS.Submit(array(Command), DstNode, ct).Map(x => x.FirstOrDefault());
Option <CommandSubmission> ICommandQueue.Enqueue(ICommandSpec command, SystemNode target, CorrelationToken?ct) => Enqueue((TSpec)command, target, ct);
public Json Encode(ICommandSpec spec) => JsonSerializer.ObjectToJson(spec);
void ICommandPatternObserver.OnCommandSpecified(ICommandSpec spec) => Specified?.Invoke((TSpec)spec);
public static IAppMessage ExecutingCommand(ICommandSpec spec) => inform("Executing the @SpecName specification of the @CommandName command", new { spec.CommandName, spec.SpecName });
public ConstructedCommand(ICommandSpec Command, RelativePath OutputLocation = null) { this.Command = Command; this.OutputLocation = OutputLocation ?? string.Empty; }
public static IAppMessage EmptyCommandResult(ICommandSpec command) => inform($"No result available for the @CommandName command", new { CommandName = command.CommandName, Detail = command.ToString() });
protected CommandProgression(ICommandSpec spec, string json, CorrelationToken?ct = null) { this.spec = spec; this.json = json; this.ct = ct; }
protected CommandProgression(ICommandProgression src) { this.spec = src.Spec; this.json = src.CommandJson; this.ct = src.CorrelationToken; }
public static CommandEmission Create(ICommandSpec command, Option <FilePath> OutputPath) => new CommandEmission(command, OutputPath);