public CommandExecDescriptor(Type PatternType, CommandSpecDescriptor SpecDescriptor) { this.CommandName = SpecDescriptor.CommandName; this.PatternType = PatternType; this.SpecType = SpecType; this.CommandDescription = SpecDescriptor.CommandDescription; }
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 };
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); } } }
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()); }
static CommandName GetCommandName <TSpec>() where TSpec : CommandSpec <TSpec>, new() => CommandSpecDescriptor.FromSpecType <TSpec>().CommandName;
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()));
static IAppMessage OrchestrationStartError(Type SpecType, Exception e) => AppMessage.Error("@CommandName orchestration start error: @ErrorDetail", new { CommandName = CommandSpecDescriptor.FromSpecType(SpecType).CommandName, ErrorDetail = e.ToString() });
protected CommandBuilder(IApplicationContext C, CommandSpecDescriptor descriptor) : base(C) { TargetCommandName = descriptor.CommandName; }
public static IAppMessage CancelingOrchestration(CommandSpecDescriptor d) => inform("Command orchestration for @CommandName was cancelled", new { d.CommandName });
public static IAppMessage EnqueuedNewCommands(CommandSpecDescriptor d, int Count) => AppMessage.Warn("Enqueued @Count new @CommandName commands", new { d.CommandName, Count });
public static IAppMessage OrchestratedTasksStillExecuting(CommandSpecDescriptor d) => AppMessage.Warn("@CommandName commands are still executing", new { d.CommandName });