/// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var events = CurrentElement.Parent.Parent.Parent.Service.SelectMany(s => s.Contract.Events.Event);

            // Filter those events that already processed by the component
            events = events.Where(e => !CurrentElement.Subscribes.SubscribedEventLinks.Any(el => el.EventReference.Value == e));

            // Get event names
            var existingEventNames = events.Select(e => e.InstanceName).ToList();

            var viewModel = new EventReadOnlyPickerViewModel(existingEventNames);

            var picker = WindowFactory.CreateDialog <EventReadOnlyPicker>(viewModel);

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    foreach (var selectedElement in viewModel.SelectedItems)
                    {
                        var selectedEvent = events.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        CurrentElement.Subscribes.CreateLink(selectedEvent);
                    }

                    SagaHelper.CheckAndPromptForSagaUpdate(CurrentElement, MessageBoxService, WindowFactory);
                }
            }

            // TODO: Implement command automation code
            //	TODO: Use tracer.Warning() to note expected and recoverable errors
            //	TODO: Use tracer.Verbose() to note internal execution logic decisions
            //	TODO: Use tracer.Info() to note key results of execution
            //	TODO: Raise exceptions for all other errors
        }
        /// <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();
                    }
                }
            }
        }
示例#3
0
        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);
                        }
                    }
                }
            }
        }