/// <summary> /// Performs operation on the aggregate /// </summary> /// <param name="id">aggregate root ID</param> /// <param name="update">operation action</param> /// <param name="metadata">metadata</param> public void Perform(string id, Action <TAggregateRoot> update, ICommandMetadata metadata = null) { var aggregate = Get(id); update(aggregate); CommitEvents(id, aggregate, metadata); }
public void CreateShipment(string aggregateRootId, ICommandMetadata commandMetadata, string address) { Apply(new ShipmentCreated { Id = aggregateRootId, Address = address }); }
public void UpdateAddress(ICommandMetadata commandMetadata, string newAddress) { Apply(new ShipmentAddressChanged { Id = State.Id, NewAddress = newAddress }); }
internal LambdaBasedCommandObjectBuilder(ICommandMetadata commandMetadata, IEnumerable <LambdaBasedCommandOption> commandOptions, IServiceProvider serviceProvider, Func <CommandExecutionContext, Task <int> > executeCommand) : base(commandMetadata, commandOptions) { _serviceProvider = serviceProvider; _executeCommand = executeCommand; }
/// <summary> /// Задаёт метаданные для команды /// </summary> /// <param name="commandId">Идентификатор команды</param> /// <param name="metadata">Метаданные</param> public void SetMetadata(Guid commandId, ICommandMetadata metadata) { if (commandId == Guid.Empty || metadata == null) { throw new InvalidOperationException(string.Format(ControllerResources.HolderCannotReplaceValueFormat, commandId, this.GetType())); } this.SetValue(commandId, metadata); }
private ClassBasedCommandOptionMetadata(PropertyInfo propertyInfo, ICommandMetadata commandMetadata, List <IConverter> converters, IEnumerable <IPropertyOptionAlternateNameGenerator> optionAlternateNameGenerators) : base(propertyInfo.ExtractIsRequiredMetadata(), GetMultiValueIndicator(propertyInfo.PropertyType), propertyInfo.ExtractOptionDisplayInfoMetadata(optionAlternateNameGenerators), propertyInfo.ExtractDefaultValue()) { PropertyOption = propertyInfo; CommandMetadata = commandMetadata; Converter = propertyInfo.ExtractConverter(converters, DisplayInfo.Name, CommandMetadata.Name); }
public ICommand Create(ICommandMetadata metadata) { var name = metadata.Name; var found = (from t in assemblyCommands let attribute = GetCommandAttribute(t) where attribute != null where attribute.Name == name || attribute.Aliases.Any(a => a == name) select t).FirstOrDefault(); return(found == null ? null : (ICommand)Activator.CreateInstance(found)); }
public ICommand Create(ICommandMetadata metadata) { var name = metadata.Name; var found = (from t in typeof(CommandLocator).Assembly.GetTypes() where typeof(ICommand).IsAssignableFrom(t) let attribute = (ICommandMetadata)t.GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault() where attribute != null where attribute.Name == name || attribute.Aliases.Any(a => a == name) select t).FirstOrDefault(); return(found == null ? null : (ICommand)Activator.CreateInstance(found)); }
void PrintCommandHelp(string executable, ICommand command, ICommandMetadata commandMetadata, string commandName) { Console.ResetColor(); Console.Write("Usage: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(executable + " " + commandName + (!string.IsNullOrWhiteSpace(commandMetadata.Usage) ? " " + commandMetadata.Usage : "") + " [<options>]"); Console.ResetColor(); Console.WriteLine(); command.GetHelp(Console.Out); Console.WriteLine(); }
public ICommand Create(ICommandMetadata metadata) { var name = metadata.Name; var found = (from t in typeof(CommandLocator).Assembly.GetTypes() where typeof(ICommand).IsAssignableFrom(t) let attribute = (ICommandMetadata)t.GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault() where attribute != null where attribute.Name == name || attribute.Aliases.Any(a => a == name) select t).FirstOrDefault(); return found == null ? null : (ICommand)Activator.CreateInstance(found); }
public MetadataCommandParameter(ICommandMetadata command, string name, Type type, ParameterDirection direction = ParameterDirection.Input) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } _command = command; _name = name.Trim(); _type = type ?? throw new ArgumentNullException(nameof(type)); _direction = direction; }
/// <summary> /// Метаданные команды /// </summary> /// <param name="command">Командв</param> /// <param name="caption">Заголовок</param> /// <param name="hint">Полсказка</param> /// <param name="glyph">Картинка</param> private static void AcquireMetadata(ICommand command, ref string caption, ref string hint, ref Image glyph) { ICommandMetadata metadataFromData = command.Data as ICommandMetadata; ICommandMetadata metadata = (metadataFromData != null ? metadataFromData : CommandMetadataHolder.Instance.GetMetadata(command.Id)); if (metadata == null) { //throw new Exception(FormResources.NoCommandMetadataFormat(command.Id)); throw new Exception(); } caption = metadata.GetCaption(command.State); hint = metadata.GetHint(command.State); glyph = metadata.GetGlyph(command.State); }
/// <summary> /// Commits events to event store and event bus /// </summary> /// <param name="id">aggregate ID</param> /// <param name="aggregateRoot">aggregate</param> /// <param name="metadata">metadata</param> /// <returns>async task boid result</returns> public async Task CommitEventsAsync(string id, IAggregateRoot aggregateRoot, ICommandMetadata metadata) { var events = ExtractEvents(aggregateRoot, metadata).ToList(); var version = aggregateRoot.Version; events.ForEach(e => e.Version = version); await _eventSource.AppendEventsAsync(id, version, events).ConfigureAwait(false); _eventBus?.Publish(events); if (aggregateRoot.Version % SnapshotsInterval == 0) { await _snapshots.SaveAsync(new Snapshot(id, version, _serializer.Serialize(aggregateRoot.State))).ConfigureAwait(false); } }
private IEnumerable <IEvent> ExtractEvents(IAggregateRoot aggregate, ICommandMetadata metadata) { var currentTime = DateTime.UtcNow; foreach (var e in aggregate.UncommittedEvents) { e.Metadata.EventId = Guid.NewGuid().ToString(); e.Metadata.StoredDate = currentTime; e.Metadata.TypeName = e.GetType().AssemblyQualifiedName; // Take some metadata properties from command if (metadata != null) { e.Metadata.CommandId = metadata.CommandId; e.Metadata.ConnectionId = metadata.ConnectionId; e.Metadata.UserId = metadata.UserId; } yield return(e); } }
public CommandEnvelope(ICommand message, ICommandMetadata metadata) : base(message, metadata) { }
internal ClassBasedCommandObjectBuilder(ICommandMetadata commandMetadata, IEnumerable <ClassBasedCommandOptionMetadata> commandOptionMetadatas, ICommand command) : base(commandMetadata, commandOptionMetadatas.Select(metadata => new ClassBasedCommandOption(metadata, command)).ToList()) { _command = command; }
public IEnumerable <IMessageEnvelope> Execute(ICommand command, ICommandMetadata header, IState state) { throw new NotImplementedException(); }
/// <summary> /// Commits events to event store and event bus /// </summary> /// <param name="id">aggregate ID</param> /// <param name="aggregateRoot">aggregate</param> /// <param name="metadata">metadata</param> public void CommitEvents(string id, IAggregateRoot aggregateRoot, ICommandMetadata metadata) { CommitEventsAsync(id, aggregateRoot, metadata).Wait(); }
/// <summary> /// Initializes a new instance of <see cref="CommandObjectBuilderBase{TCommandOption}"/>. /// </summary> /// <param name="commandMetadata">The command metadata.</param> /// <param name="commandOptions">The command's options.</param> protected CommandObjectBuilderBase(ICommandMetadata commandMetadata, IEnumerable <TCommandOption> commandOptions) { CommandMetadata = commandMetadata; CommandOptions = commandOptions; }
internal static ClassBasedCommandOptionMetadata Create(PropertyInfo propertyInfo, ICommandMetadata commandMetadata, List <IConverter> converters, IEnumerable <IPropertyOptionAlternateNameGenerator> optionAlternateNameGenerators) { Guard.NotNull(propertyInfo, nameof(propertyInfo)); Guard.NotNull(commandMetadata, nameof(commandMetadata)); Guard.NotNull(converters, nameof(converters)); Guard.NotNull(optionAlternateNameGenerators, nameof(optionAlternateNameGenerators)); if (propertyInfo.ShouldBeIgnored()) { return(null); } if (!propertyInfo.IsValidOptionProperty()) { throw new CommandLineParserException( Constants.ExceptionMessages.ParserExtractMetadataPropertyShouldBeWritableOrICollection( propertyInfo.Name, commandMetadata.Name)); } var commandOption = new ClassBasedCommandOptionMetadata(propertyInfo, commandMetadata, converters, optionAlternateNameGenerators); return(commandOption); }
private static IEnumerable <ClassBasedCommandOptionMetadata> ExtractCommandOptions(Type commandType, ICommandMetadata commandMetadata, List <IConverter> converters, List <IPropertyOptionAlternateNameGenerator> optionAlternateNameGenerators) { foreach (var propertyInfo in commandType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi => pi.Name != nameof(ICommand.Arguments))) { var commandOption = ClassBasedCommandOptionMetadata.Create(propertyInfo, commandMetadata, converters, optionAlternateNameGenerators); if (commandOption != null) { yield return(commandOption); } } }
/// <summary> /// Execute command /// </summary> IEnumerable <IMessageEnvelope> IProcess.Execute(ICommand command, ICommandMetadata metadata, IState state) { return(ExecuteHandler(command, metadata, state)); }
/// <summary> /// Execute command /// </summary> public IEnumerable <IMessageEnvelope> Execute(ICommand <TId> command, ICommandMetadata metadata, TProcessState state) { return(ExecuteHandler(command, metadata, state)); }