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

            var services             = CurrentElement.Parent.Parent.Parent.Parent.Service;
            var existingServiceNames = services.Select(e => e.InstanceName).ToList();

            var viewModel = new ServicePickerViewModel(existingServiceNames);

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

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    foreach (var selectedElement in viewModel.SelectedItems)
                    {
                        var selectedService = services.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        if (selectedService == null)
                        {
                            selectedService = CurrentElement.Parent.Parent.Parent.Parent.CreateService(selectedElement);
                        }

                        var component = selectedService.Components.CreateComponent(string.Format("{0}Handler", CurrentElement.InstanceName));
                        component.Subscribes.CreateLink(CurrentElement);
                    }
                }
            }
            // 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
        }
示例#2
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            CurrentComponent = CurrentElement.As <IComponent>();
            if (CurrentComponent == null)
            {
                CurrentComponent = CurrentElement.Parent.As <IComponent>();
            }

            var events     = CurrentComponent.Parent.Parent.Contract.Events.Event;
            var eventNames = events.Select(e => e.InstanceName).ToList();

            var viewModel = new ElementPickerViewModel(eventNames)
            {
                Title      = "Publish Event",
                MasterName = "Event name"
            };

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

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    var selectedElement = viewModel.SelectedItem;
                    var selectedEvent   =
                        events.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                    if (selectedEvent == null)
                    {
                        selectedEvent = CurrentComponent.Parent.Parent.Contract.Events.CreateEvent(selectedElement);
                    }

                    CurrentComponent.Publishes.CreateLink(selectedEvent);

                    // 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.Publish({0});",
                                                            selectedEvent.CodeIdentifier.LowerCaseFirstCharacter(),
                                                            selectedEvent.Parent.Namespace,
                                                            selectedEvent.CodeIdentifier);
                        userCode.ShowDialog();
                    }
                }
            }
            // Make initial trace statement for this command
            //tracer.Info(
            //    "Executing ShowElementTypePicker on current element '{0}' with AProperty '{1}'", this.CurrentElement.InstanceName, this.ElementType);

            //	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
        }
示例#3
0
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var element   = CurrentElement.As <NServiceBusStudio.IUseCase>();
            var endpoints = CurrentElement.Root.As <NServiceBusStudio.IApplication>()
                            .Design.Endpoints.GetAll()
                            .Where(e => !element.EndpointsStartingUseCases.Contains(e.As <IToolkitInterface>() as IAbstractEndpoint));

            // Get endpoint names
            var existingEndpointNames = endpoints.Select(e => String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName));
            var picker = WindowFactory.CreateDialog <EndpointPicker>() as IServicePicker;

            picker.Title = element.InstanceName + " Started by...";

            picker.Elements = new ObservableCollection <string>(endpoints.Select(e => e.As <IProductElement>().InstanceName));

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        var selectedEndpoint = default(IAbstractEndpoint);
                        if (existingEndpointNames.Contains(selectedElement))
                        {
                            selectedEndpoint = endpoints.FirstOrDefault(e => String.Equals(String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName), selectedElement, StringComparison.InvariantCultureIgnoreCase));
                            element.AddEndpointStartingUseCase(selectedEndpoint);
                        }
                    }
                }
            }
        }
示例#4
0
        public override void Execute()
        {
            using (new MouseCursor(Cursors.Arrow))
            {
                var picker  = WindowFactory.CreateDialog <UseCaseComponentPicker>();
                var usecase = this.CurrentElement.As <IUseCase>();
                var dialog  = picker as UseCaseComponentPicker;
                var app     = usecase.As <IProductElement>().Root.As <IApplication>();
                dialog.SetServices(app.Design.Services.Service);
                dialog.ServiceItemsFillFunction = svc => svc.Components.Component.Select(c => c.InstanceName);
                if (picker.ShowDialog() == true)
                {
                    var svc = app.Design.Services.Service.FirstOrDefault(s => s.InstanceName == dialog.SelectedService);
                    if (svc == null)
                    {
                        svc = app.Design.Services.CreateService(dialog.SelectedService);
                    }
                    var component = svc.Components.Component.FirstOrDefault(c => c.InstanceName == dialog.SelectedComponent);
                    if (component == null)
                    {
                        component = svc.Components.CreateComponent(dialog.SelectedComponent);
                    }

                    this.CurrentElement.As <IUseCase>().AddRelatedElement(component.As <IProductElement>());
                }
            }
        }
示例#5
0
        public override void Execute()
        {
            using (new MouseCursor(Cursors.Arrow))
            {
                var picker  = WindowFactory.CreateDialog <UseCaseComponentPicker>();
                var usecase = this.CurrentElement.As <IUseCase>();
                var dialog  = picker as UseCaseComponentPicker;
                dialog.Title = "Add Event to Use Case";
                dialog.SetComponentLabel("Event Name:");
                var app = usecase.As <IProductElement>().Root.As <IApplication>();
                dialog.SetServices(app.Design.Services.Service);
                dialog.ServiceItemsFillFunction = svc => svc.Contract.Events.Event.Select(c => c.InstanceName);
                if (picker.ShowDialog() == true)
                {
                    var svc = app.Design.Services.Service.FirstOrDefault(s => s.InstanceName == dialog.SelectedService);
                    if (svc == null)
                    {
                        svc = app.Design.Services.CreateService(dialog.SelectedService);
                    }
                    var @event = svc.Contract.Events.Event.FirstOrDefault(c => c.InstanceName == dialog.SelectedComponent);
                    if (@event == null)
                    {
                        @event = svc.Contract.Events.CreateEvent(dialog.SelectedComponent, null, true);
                        var senderName         = Component.TryGetComponentName(@event.InstanceName + "Publisher", svc);
                        var processorComponent = svc.Components.CreateComponent(senderName);

                        processorComponent.Publish(@event);
                        this.CurrentElement.As <IUseCase>().AddRelatedElement(processorComponent.As <IProductElement>());
                    }

                    this.CurrentElement.As <IUseCase>().AddRelatedElement(@event.As <IProductElement>());
                }
            }
        }
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var element = CurrentElement.As <IComponent>();
            var app     = CurrentElement.Root.As <NServiceBusStudio.IApplication>();

            var infrastructureLibraries = app.Design.Libraries.Library
                                          .Except(element.LibraryReferences.LibraryReference.Select(l => l.Library));

            var serviceLibraries = element.Parent.Parent.ServiceLibraries.ServiceLibrary
                                   .Except(element.LibraryReferences.LibraryReference.Select(l => l.ServiceLibrary));

            var picker = WindowFactory.CreateDialog <ComponentPicker>() as IServicePicker;

            picker.Elements = new ObservableCollection <string>(
                infrastructureLibraries.Select(l => string.Format("[Global] {0}", l.InstanceName))
                .Union(serviceLibraries.Select(l => string.Format("[Service] {0}", l.InstanceName)))
                );

            picker.Title = "Add Library References...";

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        if (selectedElement.StartsWith("[Service]"))
                        {
                            var name    = selectedElement.Substring(10);
                            var library = serviceLibraries.First(l => l.InstanceName == name);
                            element.LibraryReferences.CreateLibraryReference(name,
                                                                             r =>
                            {
                                r.LibraryId      = library.As <IProductElement>().Id;
                                r.ServiceLibrary = library;
                            });
                        }
                        else
                        {
                            var name    = selectedElement.Substring(9);
                            var library = infrastructureLibraries.First(l => l.InstanceName == name);
                            element.LibraryReferences.CreateLibraryReference(name,
                                                                             r =>
                            {
                                r.LibraryId = library.As <IProductElement>().Id;
                                r.Library   = library;
                            });
                        }
                    }

                    // TODO: Try to add the library links
                }
            }
        }
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            if (!CurrentElement.ProcessesMultipleMessages)
            {
                CurrentElement.Subscribes.ProcessedCommandLinks.ForEach(x => x.StartsSaga = true);
                CurrentElement.Subscribes.SubscribedEventLinks.ForEach(x => x.StartsSaga  = true);
                CurrentElement.IsSaga = true;
                return;
            }

            var existingMessageNames = new List <string>();

            existingMessageNames.AddRange(CurrentElement.Subscribes.ProcessedCommandLinks.Select(x => x.CommandReference.Value.InstanceName));
            existingMessageNames.AddRange(CurrentElement.Subscribes.SubscribedEventLinks.Select(x => x.EventReference.Value.InstanceName));

            // Filter those events that already processed by the component
            var existingMessageSagaStarterNames = new List <string>();

            existingMessageSagaStarterNames.AddRange(CurrentElement.Subscribes.ProcessedCommandLinks.Where(x => x.StartsSaga).Select(x => x.CommandReference.Value.InstanceName));
            existingMessageSagaStarterNames.AddRange(CurrentElement.Subscribes.SubscribedEventLinks.Where(x => x.StartsSaga).Select(x => x.EventReference.Value.InstanceName));

            var viewModel = new SagaStarterViewModel(existingMessageNames)
            {
                SelectedItems = existingMessageSagaStarterNames
            };

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

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    foreach (var cl in CurrentElement.Subscribes.ProcessedCommandLinks)
                    {
                        cl.StartsSaga = viewModel.SelectedItems.Contains(cl.CommandReference.Value.InstanceName);
                    }

                    foreach (var el in CurrentElement.Subscribes.SubscribedEventLinks)
                    {
                        el.StartsSaga = viewModel.SelectedItems.Contains(el.EventReference.Value.InstanceName);
                    }
                }
            }

            CurrentElement.IsSaga = true;

            // 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
        }
示例#8
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            this.CurrentService = this.CurrentElement.As <IService>();

            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var events     = CurrentService.Contract.Events.Event;
            var eventNames = events.Select(e => e.InstanceName);

            var picker = WindowFactory.CreateDialog <ElementPicker>() as IElementPicker;

            picker.Elements   = eventNames.ToList();
            picker.Title      = "Publish Event";
            picker.MasterName = "Event name";

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    var selectedElement = picker.SelectedItem;
                    var selectedEvent   = default(IEvent);
                    if (eventNames.Contains(selectedElement))
                    {
                        selectedEvent = events.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                    }
                    else
                    {
                        selectedEvent = CurrentService.Contract.Events.CreateEvent(selectedElement);
                    }

                    var component = CurrentService.Components.Component.FirstOrDefault(x => x.InstanceName == selectedElement + "Sender");
                    if (component == null)
                    {
                        component = CurrentService.Components.CreateComponent(selectedElement + "Sender", (c) => c.Publishes.CreateLink(selectedEvent));
                    }
                    else
                    {
                        component.Publishes.CreateLink(selectedEvent);
                    }
                }
            }
            // Make initial trace statement for this command
            //tracer.Info(
            //    "Executing ShowElementTypePicker on current element '{0}' with AProperty '{1}'", this.CurrentElement.InstanceName, this.ElementType);

            //	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
        }
示例#9
0
        /// <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);
            var picker             = WindowFactory.CreateDialog <EventReadOnlyPicker>() as IEventPicker;

            picker.Elements = new ObservableCollection <string>(existingEventNames);
            picker.Title    = "Subscribe to Event";
            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        var selectedEvent = events.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        CurrentElement.Subscribes.CreateLink(selectedEvent);
                    }

                    if (CurrentElement.Subscribes.ProcessedCommandLinks.Count() + CurrentElement.Subscribes.SubscribedEventLinks.Count() > 1)
                    {
                        var result = MessageBox.Show(String.Format("Convert ‘{0}’ to saga to correlate between commands & events?", CurrentElement.CodeIdentifier), "ServiceMatrix - Saga recommendation", MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            new ShowComponentSagaStarterPicker()
                            {
                                WindowFactory  = this.WindowFactory,
                                CurrentElement = CurrentElement
                            }.Execute();
                        }
                    }
                }
            }

            // 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
        }
示例#10
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var services             = CurrentElement.Parent.Parent.Parent.Parent.Service;
            var existingServiceNames = services.Select(e => e.InstanceName);
            var picker = WindowFactory.CreateDialog <ServicePicker>() as IServicePicker;

            picker.Elements = new ObservableCollection <string>(existingServiceNames);
            picker.Title    = "Add Subscriber...";

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        var selectedService = default(IService);
                        if (existingServiceNames.Contains(selectedElement))
                        {
                            selectedService = services.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        }
                        else
                        {
                            selectedService = CurrentElement.Parent.Parent.Parent.Parent.CreateService(selectedElement);
                        }

                        var component = selectedService.Components.CreateComponent(string.Format("{0}Processor", CurrentElement.InstanceName));
                        component.Subscribes.CreateSubscribedEventLink(CurrentElement.InstanceName, e => e.EventReference.Value = CurrentElement);
                    }
                }
            }
            // 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 element    = CurrentElement.As <IAbstractEndpointComponents>();
            var components = CurrentElement.Root.As <IApplication>().Design.Services.Service.SelectMany(s => s.Components.Component)
                             .Except(element.AbstractComponentLinks.Select(cl => cl.ComponentReference.Value));
            var existingServiceNames = components.Select(e => String.Format("{0}.{1}", e.Parent.Parent.InstanceName, e.InstanceName)).ToList();

            var viewModel = new ComponentPickerViewModel(existingServiceNames)
            {
                Title = "Deploy components..."
            };

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

            var currentEndpoint = CurrentElement.Parent.As <IAbstractEndpoint>();

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    foreach (var selectedElement in viewModel.SelectedItems)
                    {
                        var selectedCompoenent = default(NServiceBusStudio.IComponent);
                        if (existingServiceNames.Contains(selectedElement))
                        {
                            selectedCompoenent = components.FirstOrDefault(e => String.Equals(String.Format("{0}.{1}", e.Parent.Parent.InstanceName, e.InstanceName), selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        }

                        selectedCompoenent.DeployTo(currentEndpoint);
                        //var link = CurrentElement.As<IAbstractEndpointComponents>().CreateComponentLink(selectedCompoenent.InstanceName, e => e.ComponentReference.Value = selectedCompoenent);
                        //link.ComponentReference.Value.EndpointDefined(currentEndpoint);
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            CurrentService = CurrentElement.As <IService>();

            var commands     = CurrentService.Contract.Commands.Command;
            var commandNames = commands.Select(e => e.InstanceName).ToList();

            var viewModel = new ElementPickerViewModel(commandNames)
            {
                Title      = "Send Command",
                MasterName = "Command name"
            };

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

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    var selectedElement = viewModel.SelectedItem;
                    if (!commandNames.Contains(selectedElement))
                    {
                        CurrentService.Contract.Commands.CreateCommand(selectedElement);
                    }
                }
            }
            // Make initial trace statement for this command
            //tracer.Info(
            //    "Executing ShowElementTypePicker on current element '{0}' with AProperty '{1}'", this.CurrentElement.InstanceName, this.ElementType);

            //	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
        }
示例#13
0
        public override void Execute()
        {
            using (new MouseCursor(Cursors.Arrow))
            {
                var picker  = WindowFactory.CreateDialog <UseCaseComponentPicker>();
                var usecase = this.CurrentElement.As <IUseCase>();
                var dialog  = picker as UseCaseComponentPicker;
                dialog.Title = "Add Command to Use Case";
                dialog.SetComponentLabel("Command Name:");
                var app = usecase.As <IProductElement>().Root.As <IApplication>();
                dialog.SetServices(app.Design.Services.Service);
                dialog.ServiceItemsFillFunction = svc => svc.Contract.Commands.Command.Select(c => c.InstanceName);
                if (picker.ShowDialog() == true)
                {
                    var svc = app.Design.Services.Service.FirstOrDefault(s => s.InstanceName == dialog.SelectedService);
                    if (svc == null)
                    {
                        svc = app.Design.Services.CreateService(dialog.SelectedService);
                    }
                    var command = svc.Contract.Commands.Command.FirstOrDefault(c => c.InstanceName == dialog.SelectedComponent);
                    if (command == null)
                    {
                        command = svc.Contract.Commands.CreateCommand(dialog.SelectedComponent,
                                                                      cmd => cmd.DoNotAutogenerateComponents = true,
                                                                      true);

                        var processorName      = Component.TryGetComponentName(command.InstanceName + "Handler", svc);
                        var processorComponent = svc.Components.CreateComponent(processorName);

                        processorComponent.Subscribe(command);
                        this.CurrentElement.As <IUseCase>().AddRelatedElement(processorComponent.As <IProductElement>());
                    }

                    this.CurrentElement.As <IUseCase>().AddRelatedElement(command.As <IProductElement>());
                }
            }
        }
        /// <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 events     = CurrentElement.Parent.Parent.Parent.Parent.Service.SelectMany(s => s.Contract.Events.Event);
            var eventNames = events.Select(e => e.InstanceName);
            var picker     = WindowFactory.CreateDialog <EventReadOnlyPicker>() as IElementPicker;

            picker.Elements = eventNames.Union(new string[] { AnyMessageSupport.TextForUI }).ToList();
            picker.Title    = "Process Messages…";

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    var selectedElement = picker.SelectedItem;
                    var selectedEvent   = default(IEvent);
                    if (selectedElement == AnyMessageSupport.TextForUI)
                    {
                        CurrentElement.CreateSubscribedEventLink(AnyMessageSupport.TextForUI, p => p.EventReference.Value = null);
                    }
                    else if (eventNames.Contains(selectedElement))
                    {
                        selectedEvent = events.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                        CurrentElement.CreateSubscribedEventLink(selectedEvent.InstanceName, p => p.EventReference.Value = selectedEvent);
                    }
                }
            }

            // 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
        }
示例#16
0
        public override void Execute()
        {
            //var nserviceBusMVC = this.As<INServiceBusMVC>();
            //var components = nserviceBusMVC.NServiceBusMVCComponents.NServiceBusMVCComponentLinks.Select(cl => cl.As<NServiceBusMVCComponentLink>().ComponentReference.Value);
            //components = components.Where(c => c.IsSender);

            //foreach (var component in components)
            //{
            //    component.CodeIdentifier
            //}



            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var endpoints = this.CurrentElement.Root.As <NServiceBusStudio.IApplication>().Design.Endpoints.GetAll();

            // Filter those components that already have deploed
            var components = this.CurrentElement.Root.As <NServiceBusStudio.IApplication>().Design.Services.Service
                             .SelectMany(s => s.Components.Component)
                             .Where(c => !endpoints.Any(e => e.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == c)));

            // Get endpoint names
            var existingEndpointNames = endpoints.Select(e => String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName));
            var picker = WindowFactory.CreateDialog <EndpointPicker>() as IServicePicker;

            picker.Title = "Deploy to...";

            picker.Elements = new ObservableCollection <string>(existingEndpointNames);

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    // Add new endpoint
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        var selectedEndpoint = default(IAbstractEndpoint);
                        if (existingEndpointNames.Contains(selectedElement))
                        {
                            selectedEndpoint = endpoints.FirstOrDefault(e => String.Equals(String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName), selectedElement, StringComparison.InvariantCultureIgnoreCase));
                            foreach (var component in components)
                            {
                                component.DeployTo(selectedEndpoint);
                            }
                        }
                        else
                        {
                            var regexMatch   = System.Text.RegularExpressions.Regex.Match(selectedElement, "(?'name'[^\\[]*?)\\[(?'type'[^\\]]*?)\\]");
                            var selectedName = regexMatch.Groups["name"].Value.Trim();
                            var selectedType = regexMatch.Groups["type"].Value.Trim();

                            var app     = CurrentElement.Root.As <IApplication>();
                            var handler = default(System.EventHandler);
                            handler = new System.EventHandler((s, e) =>
                            {
                                foreach (var component in components)
                                {
                                    component.DeployTo((IAbstractEndpoint)s);
                                }
                                app.OnInstantiatedEndpoint -= handler;
                            });
                            app.OnInstantiatedEndpoint += handler;

                            if (selectedType == "NServiceBus ASP.NET MVC")
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusMVC(selectedName);
                            }
                            else if (selectedType == "NServiceBus ASP.NET Web Forms")
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusWeb(selectedName);
                            }
                            else
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusHost(selectedName);
                            }
                        }
                    }
                }
            }
        }
示例#17
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);
                        }
                    }
                }
            }
        }
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var element   = CurrentElement.As <NServiceBusStudio.IComponent>();
            var endpoints = this.CurrentElement.Root.As <NServiceBusStudio.IApplication>().Design.Endpoints.GetAll();

            if (element.Subscribes.ProcessedCommandLinks.Any() &&
                this.CurrentElement.Root.As <NServiceBusStudio.IApplication>().Design.Endpoints.GetAll()
                .Count(ep => ep.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == element)) >= 1)
            {
                var error = String.Format("The command-processing component {0}.{1} is already deployed. Please, undeploy the component from the endpoint and try again.", element.Parent.Parent.InstanceName, element.InstanceName);
                System.Windows.MessageBox.Show(error, "ServiceMatrix - Processing Component already Deployed", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return;
            }

            // Filter those endpoints that already have the component deploed
            endpoints = endpoints.Where(e => !e.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == element));

            // Get endpoint names
            var existingEndpointNames = endpoints.Select(e => String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName));
            var picker = WindowFactory.CreateDialog <EndpointPicker>() as IEndpointPicker;

            picker.Title         = "Deploy to...";
            picker.ComponentName = element.InstanceName + " component";

            picker.Elements = new ObservableCollection <string>(existingEndpointNames);

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    // Add new endpoint
                    foreach (var selectedElement in picker.SelectedItems)
                    {
                        var selectedEndpoint = default(IAbstractEndpoint);
                        if (existingEndpointNames.Contains(selectedElement))
                        {
                            selectedEndpoint = endpoints.FirstOrDefault(e => String.Equals(String.Format("{0}", (e as IToolkitInterface).As <IProductElement>().InstanceName), selectedElement, StringComparison.InvariantCultureIgnoreCase));
                            element.DeployTo(selectedEndpoint);
                        }
                        else
                        {
                            var regexMatch   = System.Text.RegularExpressions.Regex.Match(selectedElement, "(?'name'[^\\[]*?)\\[(?'type'[^\\]]*?)\\]");
                            var selectedName = regexMatch.Groups["name"].Value.Trim();
                            var selectedType = regexMatch.Groups["type"].Value.Trim();

                            var app     = CurrentElement.Root.As <IApplication>();
                            var handler = default(System.EventHandler);
                            handler = new System.EventHandler((s, e) =>
                            {
                                element.DeployTo((IAbstractEndpoint)s);
                                app.OnInstantiatedEndpoint -= handler;
                            });
                            app.OnInstantiatedEndpoint += handler;

                            if (selectedType == "NServiceBus ASP.NET MVC")
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusMVC(selectedName);
                            }
                            else if (selectedType == "NServiceBus ASP.NET Web Forms")
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusWeb(selectedName);
                            }
                            else
                            {
                                selectedEndpoint = app.Design.Endpoints.CreateNServiceBusHost(selectedName);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            this.CurrentComponent = this.CurrentElement.As <IComponent>();
            var createSenderComponent = false; // At Component Level, do not create sender

            if (this.CurrentComponent == null)
            {
                this.CurrentComponent = this.CurrentElement.Parent.As <IComponent>();
                createSenderComponent = true;
            }

            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var commands     = CurrentComponent.Parent.Parent.Contract.Commands.Command;
            var commandNames = commands.Select(e => e.InstanceName);

            var picker = WindowFactory.CreateDialog <ElementPicker>() as IElementPicker;

            picker.Elements   = commandNames.ToList();
            picker.Title      = "Send Command";
            picker.MasterName = "Command name";

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().Value)
                {
                    var selectedElement = picker.SelectedItem;
                    var selectedCommand = default(ICommand);
                    if (commandNames.Contains(selectedElement))
                    {
                        selectedCommand = commands.FirstOrDefault(e => string.Equals(e.InstanceName, selectedElement, StringComparison.InvariantCultureIgnoreCase));
                    }
                    else
                    {
                        selectedCommand = CurrentComponent.Parent.Parent.Contract.Commands.CreateCommand(selectedElement, (c) => c.DoNotAutogenerateSenderComponent = !createSenderComponent);
                    }

                    CurrentComponent.Publishes.CreateLink(selectedCommand);

                    // Code Generation Guidance
                    if (CurrentComponent.UnfoldedCustomCode)
                    {
                        var userCode = WindowFactory.CreateDialog <UserCodeChangeRequired>() as UserCodeChangeRequired;
                        userCode.UriService = this.UriService;
                        userCode.Solution   = this.Solution;
                        userCode.Component  = CurrentComponent;
                        userCode.Code       = String.Format("var {0} = new {1}.{2}();\r\nBus.Send({0});",
                                                            selectedCommand.CodeIdentifier.LowerCaseFirstCharacter(),
                                                            selectedCommand.Parent.Namespace,
                                                            selectedCommand.CodeIdentifier);

                        userCode.ShowDialog();
                    }
                }
            }
            // Make initial trace statement for this command
            //tracer.Info(
            //    "Executing ShowElementTypePicker on current element '{0}' with AProperty '{1}'", this.CurrentElement.InstanceName, this.ElementType);

            //	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
        }
示例#20
0
        public override void Execute()
        {
            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var element   = CurrentElement.As <IComponent>();
            var endpoints = CurrentElement.Root.As <IApplication>().Design.Endpoints.GetAll();

            if (element.Subscribes.ProcessedCommandLinks.Any() &&
                CurrentElement.Root.As <IApplication>().Design.Endpoints.GetAll()
                .Count(ep => ep.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == element)) >= 1)
            {
                var error = String.Format("The command-processing component {0}.{1} is already deployed. Please, undeploy the component from the endpoint and try again.", element.Parent.Parent.InstanceName, element.InstanceName);
                MessageBox.Show(error, "ServiceMatrix - Processing Component already Deployed", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Filter those endpoints that already have the component deployed
            endpoints = endpoints.Where(e => !e.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == element));

            // Get endpoint names
            var existingEndpointNames = endpoints.Select(e => String.Format("{0}", e.As <IProductElement>().InstanceName)).ToList();

            var viewModel = new EndpointPickerViewModel(existingEndpointNames)
            {
                Title         = "Deploy to...",
                ComponentName = element.InstanceName + " component"
            };

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

            using (new MouseCursor(Cursors.Arrow))
            {
                if (picker.ShowDialog().GetValueOrDefault())
                {
                    // Add new endpoint
                    foreach (var selectedElement in viewModel.SelectedItems)
                    {
                        IAbstractEndpoint selectedEndpoint;
                        if (existingEndpointNames.Contains(selectedElement))
                        {
                            selectedEndpoint = endpoints.FirstOrDefault(e => String.Equals(String.Format("{0}", e.As <IProductElement>().InstanceName), selectedElement, StringComparison.InvariantCultureIgnoreCase));
                            element.DeployTo(selectedEndpoint);

                            if (selectedEndpoint is INServiceBusMVC)
                            {
                                const string recommendationMessage = "Would you like to broadcast this via SignalR?";
                                var          result = MessageBoxService.Show(recommendationMessage, "ServiceMatrix - SignalR Integration", MessageBoxButton.YesNo);

                                if (result == MessageBoxResult.Yes)
                                {
                                    var componentElement = element.As <IProductElement>();

                                    // Find the Broadcast via SignalR command to execute
                                    var commandToExecute = componentElement.AutomationExtensions.First(c => c.Name.Equals("OnBroadcastViaSignalRCommand"));
                                    commandToExecute.Execute();
                                }
                            }
                        }
                        else
                        {
                            var regexMatch   = Regex.Match(selectedElement, "(?'name'[^\\[]*?)\\[(?'type'[^\\]]*?)\\]");
                            var selectedName = regexMatch.Groups["name"].Value.Trim();
                            var selectedType = regexMatch.Groups["type"].Value.Trim();

                            var app     = CurrentElement.Root.As <IApplication>();
                            var handler = default(EventHandler);
                            handler = (s, e) =>
                            {
                                element.DeployTo((IAbstractEndpoint)s);
                                app.OnInstantiatedEndpoint -= handler;
                            };
                            app.OnInstantiatedEndpoint += handler;

                            if (selectedType == "NServiceBus ASP.NET MVC")
                            {
                                app.Design.Endpoints.CreateNServiceBusMVC(selectedName);

                                // TODO: Figure out the NullRef Exception
                                //const string recommendationMessage = "Would you like to broadcast this via SignalR?";
                                //var result = MessageBoxService.Show(recommendationMessage, "ServiceMatrix - SignalR Integration", MessageBoxButton.YesNo);

                                //if (result == MessageBoxResult.Yes)
                                //{
                                //    var componentElement = element.As<IProductElement>();

                                //    // Find the Broadcast via SignalR command to execute
                                //    var commandToExecute = componentElement.AutomationExtensions.First(c => c.Name.Equals("OnBroadcastViaSignalRCommand"));
                                //    commandToExecute.Execute();
                                //}
                            }
                            else
                            {
                                app.Design.Endpoints.CreateNServiceBusHost(selectedName);
                            }
                        }
                    }
                }
            }
        }
        /// <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();
                    }
                }
            }
        }
示例#22
0
        /// <summary>
        /// Executes this commmand.
        /// </summary>
        /// <remarks></remarks>
        public override void Execute()
        {
            this.CurrentComponent = this.CurrentElement.As <IComponent>();
            if (this.CurrentComponent == null)
            {
                this.CurrentComponent = this.CurrentElement.Parent.As <IComponent>();
            }

            // Verify all [Required] and [Import]ed properties have valid values.
            this.ValidateObject();

            var processedCommandLink = default(IProcessedCommandLink);

            if (this.CurrentComponent.Subscribes.ProcessedCommandLinks.Count() > 1)
            {
                // TODO: Show picker for Command selection
                processedCommandLink = this.CurrentComponent.Subscribes.ProcessedCommandLinks.First(x => x.ProcessedCommandLinkReply == null);
            }
            else
            {
                processedCommandLink = this.CurrentComponent.Subscribes.ProcessedCommandLinks.First(x => x.ProcessedCommandLinkReply == null);
            }

            if (processedCommandLink.ProcessedCommandLinkReply == null)
            {
                // Create Message used for Response
                var service = this.CurrentComponent.Parent.Parent;
                var message = service.Contract.Messages.CreateMessage(processedCommandLink.CommandReference.Value.CodeIdentifier + "Response");

                // Set Message as ReplyWith for the ProcessedCommandLink
                processedCommandLink.CreateProcessedCommandLinkReply(message.InstanceName, (r) => r.MessageReference.Value = message);

                // Set Message as HandleMessage for the SenderComponent
                var senderComponent = this.CurrentComponent.Parent.Component.FirstOrDefault(c => c.Publishes.CommandLinks.Any(cl => cl.CommandReference.Value == processedCommandLink.CommandReference.Value));
                if (senderComponent != null)
                {
                    senderComponent.Subscribes.CreateHandledMessageLink(message.InstanceName, (h) => h.MessageReference.Value = message);

                    if (senderComponent.Subscribes.ProcessedCommandLinks.Any() ||
                        senderComponent.Subscribes.SubscribedEventLinks.Any())
                    {
                        var result = MessageBox.Show(String.Format("Convert ‘{0}’ to saga to correlate between request and response?", senderComponent.CodeIdentifier), "ServiceMatrix - Saga recommendation", MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            new ShowComponentSagaStarterPicker()
                            {
                                WindowFactory  = this.WindowFactory,
                                CurrentElement = senderComponent
                            }.Execute();
                        }
                    }

                    // Code Generation Guidance
                    if (CurrentComponent.UnfoldedCustomCode)
                    {
                        var userCode = WindowFactory.CreateDialog <UserCodeChangeRequired>() as UserCodeChangeRequired;
                        userCode.UriService = this.UriService;
                        userCode.Solution   = this.Solution;
                        userCode.Component  = CurrentComponent;
                        userCode.Code       = String.Format("var response = new {1}.{0}();\r\nBus.Reply(response);", message.CodeIdentifier, message.Parent.Namespace);

                        userCode.ShowDialog();
                    }
                }
            }

            // Make initial trace statement for this command
            //tracer.Info(
            //    "Executing ShowElementTypePicker on current element '{0}' with AProperty '{1}'", this.CurrentElement.InstanceName, this.ElementType);

            //	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
        }