public override void Execute() { var mvcEndpoint = CurrentElement.As <INServiceBusMVC>(); if (!mvcEndpoint.IsSignalREnabled) { var project = CurrentElement.GetProject(); if (project == null) { return; } // TODO: Remove the Nugetpackages for SignalR // Modify the route config var filePath = String.Format("{0}\\App_Start\\RouteConfig.cs", mvcEndpoint.Namespace); var item = Solution.FindItem(filePath); if (item != null) { var contents = File.ReadAllText(item.PhysicalPath); //TODO: Remove hack - either add the MapHubs in a new file rather than Modifying RouteConfig or use proper code DOM to locate the function rather than relying that position of the function! // Hack begin - read using a better code dom rather than traversing using {! var newContents = contents.Replace("routes.MapHubs();", ""); item.SetContent(newContents); // Hack end } } }
/// <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 }
public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var application = CurrentElement.Root.As <IApplication>(); var command = CurrentElement.As <ICommand>(); var handlerLinks = application.Design.Services.Service .SelectMany(s => s.Components.Component.SelectMany(c => c.Subscribes.ProcessedCommandLinks.Where(l => l.CommandReference.Value == command))) .ToList(); var senderLinks = application.Design.Services.Service .SelectMany(s => s.Components.Component.SelectMany(c => c.Publishes.CommandLinks.Where(l => l.CommandReference.Value == command))) .ToList(); var relatedComponents = handlerLinks.Select(l => l.Parent.Parent) .Concat(senderLinks.Select(l => l.Parent.Parent)) .Distinct() .ToList(); if (relatedComponents.Count == 0) { return; } var viewModel = new RelatedComponentsPickerViewModel(relatedComponents, command) { Title = "Related Components" }; var picker = WindowFactory.CreateDialog <RelatedComponentsPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { foreach (var component in viewModel.SelectedComponents) { component.Delete(); } } foreach (var link in handlerLinks) { link.Delete(); } foreach (var link in senderLinks) { link.Delete(); } } }
/// <summary> ///Matches the current state of the component's signalr integration with that of the provided value /// </summary> /// <returns>true if values match, false otherwise</returns> public override bool Evaluate() { var app = CurrentElement.Root.As <IApplication>(); var component = CurrentElement.As <NServiceBusStudio.IComponent>(); return(IsDeployed == app.Design.Endpoints.GetAll() .Any(ep => ep.EndpointComponents.AbstractComponentLinks.Any(cl => cl.ComponentReference.Value == component))); }
void DeleteSolutionItemsInComponentForCommand(string commandId) { var component = CurrentElement.As <IComponent>(); var artifactLink = component.References.First(t => t.Tag.Contains(commandId)); var solutionItem = UriService.TryResolveUri <IItemContainer>(new Uri(artifactLink.Value)); // Delete the actual solution item and its reference in the component. solutionItem.Delete(); artifactLink.Delete(); }
/// <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 events = CurrentService.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 = 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 }
public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var app = CurrentElement.Root.As <IApplication>(); var command = CurrentElement.As <ICommand>(); var viewModel = new SenderEndpointPickerViewModel( app, e => e.EndpointComponents.AbstractComponentLinks .Any(c => c.ComponentReference.Value.Publishes.CommandLinks.Any(cl => cl.CommandReference.Value == command))) { Title = "Send from...", }; var picker = WindowFactory.CreateDialog <SenderEndpointPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var service = command.GetParentService(); foreach (var endpoint in viewModel.SelectedEndpoints) { var closureEndpoint = endpoint; // 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(closureEndpoint); app.OnInstantiatedComponent -= deployToEndpoint; } }; app.OnInstantiatedComponent += deployToEndpoint; } } } }
public override void Execute() { var nserviceBusMVC = CurrentElement.As <INServiceBusMVC>(); if (!nserviceBusMVC.IsSignalREnabled) { var project = CurrentElement.GetProject(); if (project == null) { return; } project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Owin", "1.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.Web.Infrastructure", "1.0.0.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.Owin.Host.SystemWeb", "1.0.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.AspNet.SignalR.Core", "1.0.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.AspNet.SignalR.Owin", "1.0.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.AspNet.SignalR.JS", "1.0.0"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.AspNet.SignalR", "1.0.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 }
public override void Execute() { var nserviceBusMVC = CurrentElement.As <INServiceBusMVC>(); if (nserviceBusMVC == null) { return; } var project = CurrentElement.GetProject(); if (project == null) { return; } if (!nserviceBusMVC.TestControllerSupportDeployed) { project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "jQuery", "1.7.1"); project.InstallNugetPackageForSpecifiedVersion(VsPackageInstallerServices, VsPackageInstaller, StatusBar, "Microsoft.jQuery.Unobtrusive.Ajax", "2.0.30506.0"); nserviceBusMVC.TestControllerSupportDeployed = true; } }
public override void Execute() { var mvcEndpoint = CurrentElement.As <INServiceBusMVC>(); if (!mvcEndpoint.IsSignalREnabled) { var filePath = String.Format("{0}\\App_Start\\RouteConfig.cs", mvcEndpoint.Namespace); var item = Solution.FindItem(filePath); if (item != null) { var contents = File.ReadAllText(item.PhysicalPath); //TODO: Remove hack - either add the MapHubs in a new file rather than Modifying RouteConfig or use proper code DOM to locate the function rather than relying that position of the function! // Hack begin - read using a better code dom rather than traversing using {! var indexToAdd = GetNthIndex(contents, '{', 3); var firstPart = contents.Substring(0, indexToAdd + 1); var stringToAdd = "\t\t\troutes.MapHubs();"; var finalPart = contents.Substring(indexToAdd + 1); var newContents = string.Format("{0}\r\n{1}\r\n{2}", firstPart, stringToAdd, finalPart); item.SetContent(newContents); // Hack end } } }
public override void Execute() { var itemsToRemove = new [] { "GenerateSignalRHub", "GenerateSignalRBroadcastHandler", "GenerateHighlightCSS", "GenerateHighlightJS", "GenerateGuidanceCSS" }; foreach (var item in itemsToRemove) { var command = (IAutomationExtension <ICommandSettings>)CurrentElement.AutomationExtensions.FirstOrDefault(c => c.Name.Equals(item, StringComparison.OrdinalIgnoreCase)); if (command == null) { throw new Exception(string.Format("{0} does not map to an existing command", item)); } var commandId = command.Settings.Id.ToString("D"); DeleteSolutionItemsInComponentForCommand(commandId); } // Set the Broadcasting via SignalR flag on the component level to false; CurrentElement.As <IComponent>().IsBroadcastingViaSignalR = false; }
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); } } } } } }
public override void Execute() { // Verify all [Required] and [Import]ed properties have valid values. this.ValidateObject(); var application = CurrentElement.Root.As <IApplication>(); var command = CurrentElement.As <ICommand>(); var handlerLinks = application.Design.Services.Service .SelectMany(s => s.Components.Component.SelectMany(c => c.Subscribes.ProcessedCommandLinks.Where(l => l.CommandReference.Value == command))) .ToList(); var senderLinks = application.Design.Services.Service .SelectMany(s => s.Components.Component.SelectMany(c => c.Publishes.CommandLinks.Where(l => l.CommandReference.Value == command))) .ToList(); var relatedComponents = handlerLinks.Select(l => l.Parent.Parent) .Concat(senderLinks.Select(l => l.Parent.Parent)) .Where(c => c != null) .Distinct() .ToList(); tracer.Verbose( "Prompting for confirmation of deletion for command '{0}' with related components {1}", command.InstanceName, string.Join(", ", relatedComponents.Select(c => "'" + c.InstanceName + "'"))); var viewModel = new RelatedComponentsPickerViewModel(relatedComponents, command) { Title = "Delete the component?" }; var picker = WindowFactory.CreateDialog <RelatedComponentsPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedComponents = viewModel.SelectedComponents.ToList(); tracer.Info( "Deleting command '{0}' and related components {1}", command.InstanceName, string.Join(", ", selectedComponents.Select(c => "'" + c.InstanceName + "'"))); foreach (var component in selectedComponents) { component.Delete(); } foreach (var link in handlerLinks) { link.Delete(); } foreach (var link in senderLinks) { link.Delete(); } command.Delete(); } else { tracer.Verbose("Deletion for command '{0}' cancelled", command.InstanceName); } } }
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>(); // Get available events var elements = app.Design.Services.Service .Select(s => Tuple.Create( s.InstanceName, (ICollection <string>)s.Contract.Events.Event.Select(x => x.InstanceName).OrderBy(c => c).ToList())) .OrderBy(t => t.Item1).ToList(); var viewModel = new ElementHierarchyPickerViewModel(elements) { MasterName = "Service Name", SlaveName = "Event Name", Title = "Publish Event" }; var picker = WindowFactory.CreateDialog <ElementHierarchyPicker>(viewModel); using (new MouseCursor(Cursors.Arrow)) { if (picker.ShowDialog().GetValueOrDefault()) { var selectedService = viewModel.SelectedMasterItem; var selectedEvent = viewModel.SelectedSlaveItem; var service = app.Design.Services.Service.FirstOrDefault(x => x.InstanceName == selectedService); if (service == null) { service = app.Design.Services.CreateService(selectedService); } var @event = service.Contract.Events.Event.FirstOrDefault(x => x.InstanceName == selectedEvent); if (@event == null) { @event = service.Contract.Events.CreateEvent(selectedEvent); } var component = service.Components.Component.FirstOrDefault(x => x.Publishes.EventLinks.Any(y => y.EventReference.Value == @event)); if (component == null) { component = service.Components.CreateComponent(@event.InstanceName + "Sender", x => x.Publishes.CreateLink(@event)); var deployToEndpoint = default(EventHandler); deployToEndpoint = (s, e) => { var c = s as IComponent; if (c != null && c == component) { c.DeployTo(endpoint); app.OnInstantiatedComponent -= deployToEndpoint; } }; app.OnInstantiatedComponent += deployToEndpoint; } else { component.DeployTo(endpoint); } } } }
/// <summary> ///Matches the current state of the component's signalr integration with that of the provided value /// </summary> /// <returns>true if values match, false otherwise</returns> public override bool Evaluate() { var component = CurrentElement.As <NServiceBusStudio.IComponent>(); return(component.IsBroadcastingViaSignalR == IsBroadcastingViaSignalR); }