示例#1
0
 public CommandExecDescriptor(Type PatternType, CommandSpecDescriptor SpecDescriptor)
 {
     this.CommandName        = SpecDescriptor.CommandName;
     this.PatternType        = PatternType;
     this.SpecType           = SpecType;
     this.CommandDescription = SpecDescriptor.CommandDescription;
 }
示例#2
0
 IEnumerable <CommandExecDescriptor> Patterns(IEnumerable <Type> types)
 => from t in types
     where Attribute.IsDefined(t, typeof(CommandPatternAttribute)) &&
 t.BaseType.IsGenericType && !t.IsAbstract
 let typeArgs = t.BaseType.GetGenericArguments()
                    where typeArgs.Length >= 2
                let specType = typeArgs[1]
                               select new CommandExecDescriptor
 {
     PatternType = t,
     SpecType    = specType,
     CommandName = CommandSpecDescriptor.FromSpecType(specType).CommandName
 };
示例#3
0
    public void Absorb(IEnumerable <Type> types)
    {
        var specDescriptors =
            (from t in types
             let descriptor = CommandSpecDescriptor.TryGetFromType(t)
                              where descriptor.Exists
                              select descriptor.Require()
            );

        var descriptorDupes = from d in specDescriptors
                              group d by d.CommandName into nameGroup
                              where nameGroup.Count() > 1
                              select nameGroup.Key;
        var descriptorDupeList = rolist(descriptorDupes);

        if (descriptorDupeList.Count != 0)
        {
            throw new Exception($"Command names are required to be unique and {descriptorDupeList.Count} duplicates were found: " + string.Join("; ", descriptorDupeList));
        }

        var specDescriptorIndex = specDescriptors.ToDictionary(x => x.CommandName);

        var executors = Patterns(types).ToList();
        var execDupes = from x in executors
                        group x by x.SpecType into g
                        where g.Count() > 1
                        select g.Key;
        var execDupeList = rolist(execDupes);

        if (execDupeList.Count != 0)
        {
            throw new Exception($"Command names are required to be unique and {execDupeList.Count} duplicates were found: " + string.Join("; ", execDupeList));
        }

        var execDescriptorIndex = executors.ToDictionary(x => x.SpecType);

        foreach (var spec in specDescriptorIndex)
        {
            var specType = spec.Value.SpecType;
            DescribedSpecs[spec.Key] = spec.Value;
            if (execDescriptorIndex.ContainsKey(specType))
            {
                var execDescriptor = execDescriptorIndex[specType];
                DescribedPatterns[specType] = execDescriptor;
                PatternCache[specType]      = (ICommandExecutionService)Activator.CreateInstance(execDescriptor.PatternType, Context);
            }
        }
    }
示例#4
0
    public static IReadOnlyList <CommandExecDescriptor> DescribeExecutors(this Assembly a)
    {
        var q = from t in a.GetTypes()
                where Attribute.IsDefined(t, typeof(CommandPatternAttribute)) &&
                t.BaseType.IsGenericType && !t.IsAbstract
                let typeArgs = t.BaseType.GetGenericArguments()
                               where typeArgs.Length >= 2
                               let specType = typeArgs[1]
                                              select new CommandExecDescriptor
        {
            PatternType = t,
            SpecType    = specType,
            CommandName = CommandSpecDescriptor.FromSpecType(specType).CommandName
        };

        return(q.ToList());
    }
示例#5
0
 static CommandName GetCommandName <TSpec>()
     where TSpec : CommandSpec <TSpec>, new()
 => CommandSpecDescriptor.FromSpecType <TSpec>().CommandName;
示例#6
0
 public static IReadOnlyList <CommandSpecDescriptor> DescribeCommands(this Assembly a)
 => rolist((from t in a.GetTypes()
            let descriptor = CommandSpecDescriptor.TryGetFromType(t)
                                 where descriptor.IsSome()
                             select descriptor.Require()));
示例#7
0
 static IAppMessage OrchestrationStartError(Type SpecType, Exception e)
 => AppMessage.Error("@CommandName orchestration start error: @ErrorDetail", new
 {
     CommandName = CommandSpecDescriptor.FromSpecType(SpecType).CommandName,
     ErrorDetail = e.ToString()
 });
示例#8
0
 protected CommandBuilder(IApplicationContext C, CommandSpecDescriptor descriptor)
     : base(C)
 {
     TargetCommandName = descriptor.CommandName;
 }
示例#9
0
 public static IAppMessage CancelingOrchestration(CommandSpecDescriptor d)
 => inform("Command orchestration for @CommandName was cancelled", new
 {
     d.CommandName
 });
示例#10
0
 public static IAppMessage EnqueuedNewCommands(CommandSpecDescriptor d, int Count)
 => AppMessage.Warn("Enqueued @Count new @CommandName commands", new
 {
     d.CommandName,
     Count
 });
示例#11
0
 public static IAppMessage OrchestratedTasksStillExecuting(CommandSpecDescriptor d)
 => AppMessage.Warn("@CommandName commands are still executing", new
 {
     d.CommandName
 });