/// <summary> /// Executes this commmand. /// </summary> /// <remarks></remarks> public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var currentComponent = CurrentElement.As <IComponent>(); var service = currentComponent.Parent.Parent; var viewModel = new ServiceAndCommandPickerViewModel(service); var picker = WindowFactory.CreateDialog <ServiceAndCommandPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedCommand = viewModel.SelectedCommand; // Figure out if new or existing command var newCommand = false; var command = service.Contract.Commands.Command.FirstOrDefault(x => x.InstanceName == selectedCommand); if (command == null) { newCommand = true; command = service.Contract.Commands.CreateCommand(selectedCommand); } // Link command to current component currentComponent.Publishes.CreateLink(command); // Assign handler if command if (newCommand) { if (viewModel.SelectedHandlerComponent == null) { service.Components.CreateComponent(command.InstanceName + "Handler", x => x.Subscribes.CreateLink(command)); } else { var handlerComponent = viewModel.SelectedHandlerComponent; handlerComponent.Subscribes.CreateLink(command); SagaHelper.CheckAndPromptForSagaUpdate(handlerComponent, MessageBoxService, WindowFactory); } } // Code Generation Guidance if (currentComponent.UnfoldedCustomCode) { var userCode = (UserCodeChangeRequired)WindowFactory.CreateDialog <UserCodeChangeRequired>(); userCode.UriService = UriService; userCode.Solution = Solution; userCode.Component = currentComponent; userCode.Code = String.Format("var {0} = new {1}.{2}();\r\nBus.Send({0});", command.CodeIdentifier.LowerCaseFirstCharacter(), command.Parent.Namespace, command.CodeIdentifier); userCode.ShowDialog(); } } } }
/// <summary> /// Executes this commmand. /// </summary> /// <remarks></remarks> public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var currentComponent = CurrentElement.As<IComponent>(); var service = currentComponent.Parent.Parent; var viewModel = new ServiceAndCommandPickerViewModel(service); var picker = WindowFactory.CreateDialog<ServiceAndCommandPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedCommand = viewModel.SelectedCommand; // Figure out if new or existing command var newCommand = false; var command = service.Contract.Commands.Command.FirstOrDefault(x => x.InstanceName == selectedCommand); if (command == null) { newCommand = true; command = service.Contract.Commands.CreateCommand(selectedCommand); } // Link command to current component currentComponent.Publishes.CreateLink(command); // Assign handler if command if (newCommand) { if (viewModel.SelectedHandlerComponent == null) { service.Components.CreateComponent(command.InstanceName + "Handler", x => x.Subscribes.CreateLink(command)); } else { var handlerComponent = viewModel.SelectedHandlerComponent; handlerComponent.Subscribes.CreateLink(command); SagaHelper.CheckAndPromptForSagaUpdate(handlerComponent, MessageBoxService, WindowFactory); } } // Code Generation Guidance if (currentComponent.UnfoldedCustomCode) { var userCode = (UserCodeChangeRequired)WindowFactory.CreateDialog<UserCodeChangeRequired>(); userCode.UriService = UriService; userCode.Solution = Solution; userCode.Component = currentComponent; userCode.Code = String.Format("var {0} = new {1}.{2}();\r\nBus.Send({0});", command.CodeIdentifier.LowerCaseFirstCharacter(), command.Parent.Namespace, command.CodeIdentifier); userCode.ShowDialog(); } } } }
public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var endpoint = CurrentElement.As<IAbstractEndpoint>(); var app = CurrentElement.Root.As<IApplication>(); var viewModel = new ServiceAndCommandPickerViewModel(app, endpoint); var picker = WindowFactory.CreateDialog<ServiceAndCommandPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedService = viewModel.SelectedService; var selectedCommand = viewModel.SelectedCommand; var service = app.Design.Services.Service.FirstOrDefault(x => x.InstanceName == selectedService) ?? app.Design.Services.CreateService(selectedService); var newCommand = false; var command = service.Contract.Commands.Command.FirstOrDefault(x => x.InstanceName == selectedCommand); if (command == null) { newCommand = true; command = service.Contract.Commands.CreateCommand(selectedCommand); } // create and deploy new publisher command var publisherComponent = service.Components.CreateComponent(command.InstanceName + "Sender", x => x.Publishes.CreateLink(command)); var deployToEndpoint = default(EventHandler); deployToEndpoint = (s, e) => { var c = s as IComponent; if (c != null && c == publisherComponent) { c.DeployTo(endpoint); app.OnInstantiatedComponent -= deployToEndpoint; } }; app.OnInstantiatedComponent += deployToEndpoint; if (newCommand) { if (viewModel.SelectedHandlerComponent == null) { service.Components.CreateComponent(command.InstanceName + "Handler", x => x.Subscribes.CreateLink(command)); } else { var handlerComponent = viewModel.SelectedHandlerComponent; handlerComponent.Subscribes.CreateLink(command); SagaHelper.CheckAndPromptForSagaUpdate(handlerComponent, MessageBoxService, WindowFactory); } } } } }
public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var endpoint = CurrentElement.As <IAbstractEndpoint>(); var app = CurrentElement.Root.As <IApplication>(); var viewModel = new ServiceAndCommandPickerViewModel(app, endpoint); var picker = WindowFactory.CreateDialog <ServiceAndCommandPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedService = viewModel.SelectedService; var selectedCommand = viewModel.SelectedCommand; var service = app.Design.Services.Service.FirstOrDefault(x => x.InstanceName == selectedService) ?? app.Design.Services.CreateService(selectedService); var newCommand = false; var command = service.Contract.Commands.Command.FirstOrDefault(x => x.InstanceName == selectedCommand); if (command == null) { newCommand = true; command = service.Contract.Commands.CreateCommand(selectedCommand); } // create and deploy new publisher command var publisherComponent = service.Components.CreateComponent(command.InstanceName + "Sender", x => x.Publishes.CreateLink(command)); var deployToEndpoint = default(EventHandler); deployToEndpoint = (s, e) => { var c = s as IComponent; if (c != null && c == publisherComponent) { c.DeployTo(endpoint); app.OnInstantiatedComponent -= deployToEndpoint; } }; app.OnInstantiatedComponent += deployToEndpoint; if (newCommand) { if (viewModel.SelectedHandlerComponent == null) { service.Components.CreateComponent(command.InstanceName + "Handler", x => x.Subscribes.CreateLink(command)); } else { var handlerComponent = viewModel.SelectedHandlerComponent; handlerComponent.Subscribes.CreateLink(command); SagaHelper.CheckAndPromptForSagaUpdate(handlerComponent, MessageBoxService, WindowFactory); } } } } }