Пример #1
0
 public static IAppMessage UnhandledExecutionError(ICommandSpec spec, Exception e)
 => error("Error executing command @CommandName: @ErrorDetail",
          new
 {
     CommandName = spec.CommandName,
     ErrorDetail = e.ToString()
 });
Пример #2
0
 public static IAppMessage CompletedCommandExecution(ICommandSpec spec, object payload = null)
 => inform($"Executed @SpecName", new
 {
     spec.CommandName,
     spec.SpecName,
     Description = spec.ToString()
 });
Пример #3
0
    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);
    }
Пример #4
0
 public CommandEmission(ICommandSpec CommandSpec, Option <FilePath> OutputPath)
 {
     this.CommandSpec = CommandSpec;
     this.OutputPath  = OutputPath;
     this.Description = Succeeded
         ? AppMessage.Inform($"Emitted {CommandSpec.SpecName}")
         : OutputPath.Message;
 }
Пример #5
0
    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));
    }
Пример #6
0
    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);
    }
Пример #7
0
 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()
 });
Пример #8
0
 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);
Пример #9
0
    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);
    }
Пример #10
0
 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();
 }
Пример #11
0
    /// <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)));
    }
Пример #12
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)));
        }
    }
Пример #13
0
    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);
    }
Пример #14
0
    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);
    }
Пример #15
0
    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);
    }
Пример #16
0
 Option <CommandSubmission> ICommandSubmitter.Submit(ICommandSpec command, SystemNode target, CorrelationToken?ct)
 => Submit(command, ct);
Пример #17
0
 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")
 {
 }
Пример #19
0
 protected CommandProgression(CommandProgression src)
 {
     this.spec = src.spec;
     this.json = src.json;
     this.ct   = src.ct;
 }
Пример #20
0
 IOption ICommandExecutionService.TryExecute(ICommandSpec spec, CommandExecutionContext ec)
 => TryExecute((TSpec)spec, ec);
Пример #21
0
 public static Option <CommandSubmission> Submit(this ICommandPatternSystem CPS, ICommandSpec Command, SystemNode DstNode, CorrelationToken?ct)
 => CPS.Submit(array(Command), DstNode, ct).Map(x => x.FirstOrDefault());
Пример #22
0
 Option <CommandSubmission> ICommandQueue.Enqueue(ICommandSpec command, SystemNode target, CorrelationToken?ct)
 => Enqueue((TSpec)command, target, ct);
Пример #23
0
 public Json Encode(ICommandSpec spec)
 => JsonSerializer.ObjectToJson(spec);
Пример #24
0
 void ICommandPatternObserver.OnCommandSpecified(ICommandSpec spec)
 => Specified?.Invoke((TSpec)spec);
Пример #25
0
 public static IAppMessage ExecutingCommand(ICommandSpec spec)
 => inform("Executing the @SpecName specification of the @CommandName command", new
 {
     spec.CommandName,
     spec.SpecName
 });
Пример #26
0
 public ConstructedCommand(ICommandSpec Command, RelativePath OutputLocation = null)
 {
     this.Command        = Command;
     this.OutputLocation = OutputLocation ?? string.Empty;
 }
Пример #27
0
 public static IAppMessage EmptyCommandResult(ICommandSpec command)
 => inform($"No result available for the @CommandName command", new
 {
     CommandName = command.CommandName,
     Detail      = command.ToString()
 });
Пример #28
0
 protected CommandProgression(ICommandSpec spec, string json, CorrelationToken?ct = null)
 {
     this.spec = spec;
     this.json = json;
     this.ct   = ct;
 }
Пример #29
0
 protected CommandProgression(ICommandProgression src)
 {
     this.spec = src.Spec;
     this.json = src.CommandJson;
     this.ct   = src.CorrelationToken;
 }
Пример #30
0
 public static CommandEmission Create(ICommandSpec command, Option <FilePath> OutputPath)
 => new CommandEmission(command, OutputPath);