Example #1
0
        private void CreateLibrariesPanel(ISolutionBuilderViewModel solutionBuilderModel, IProductElement product, IApplication application, int position)
        {
            var commandsVM = new InnerPanelViewModel();

            commandsVM.Title = "Libraries";
            var globalLibraries = application.Design.Libraries.Library.Where(l =>
                                                                             product.As <IComponent>().LibraryReferences.LibraryReference
                                                                             .Any(lr => lr.LibraryId == l.As <IProductElement>().Id))
                                  .Select(l => l.As <IProductElement>());

            commandsVM.Items.Add(new InnerPanelTitle {
                Text = "Global Libraries", Product = null, MenuFilters = new string[] { }, ForceText = true
            });
            foreach (var gl in globalLibraries)
            {
                commandsVM.Items.Add(new InnerPanelItem {
                    Product = gl, Text = gl.InstanceName
                });
            }
            var serviceLibraries = product.As <IComponent>().Parent.Parent.ServiceLibraries.ServiceLibrary.Where(l =>
                                                                                                                 product.As <IComponent>().LibraryReferences.LibraryReference
                                                                                                                 .Any(lr => lr.LibraryId == l.As <IProductElement>().Id))
                                   .Select(l => l.As <IProductElement>());

            commandsVM.Items.Add(new InnerPanelTitle {
                Text = "Service Libraries", Product = null, MenuFilters = new string[] { }, ForceText = true
            });
            foreach (var sl in serviceLibraries)
            {
                commandsVM.Items.Add(new InnerPanelItem {
                    Product = sl, Text = sl.InstanceName
                });
            }
            this.SetPanel(position, new LogicalView(new LogicalViewModel(solutionBuilderModel, commandsVM)));
        }
Example #2
0
        public void InternalAddRelatedElement(IProductElement element, bool isStarting = false, bool createLink = false)
        {
            if (element != null)
            {
                var command   = element.As <ICommand>();
                var @event    = element.As <IEvent>();
                var endpoint  = element.As <IAbstractEndpoint>();
                var component = element.As <IComponent>();

                IUseCaseLink link = null;

                if (createLink)
                {
                    link = this.CreateUseCaseLink(element.Id.ToString());
                    link.LinkedElementId = element.Id;
                    if (command != null)
                    {
                        link.ElementType = "Command";
                    }
                    else if (@event != null)
                    {
                        link.ElementType = "Event";
                    }
                    else if (endpoint != null)
                    {
                        link.ElementType = "Endpoint";
                    }
                    else if (component != null)
                    {
                        link.ElementType = "Component";
                    }

                    link.StartsUseCase = isStarting;
                }

                if (command != null && !this.relatedCommands.Contains(command))
                {
                    this.relatedCommands.Add(command);
                }
                else if (@event != null && !this.relatedEvents.Contains(@event))
                {
                    this.relatedEvents.Add(@event);
                }
                else if (endpoint != null)
                {
                    if (isStarting && !this.endpointsStartingUseCases.Contains(endpoint))
                    {
                        this.endpointsStartingUseCases.Add(endpoint);
                    }
                    else if (!this.relatedEndpoints.Contains(endpoint) && !this.endpointsStartingUseCases.Contains(endpoint))
                    {
                        this.relatedEndpoints.Add(endpoint);
                    }
                }
                else if (component != null && !this.relatedComponents.Contains(component))
                {
                    this.relatedComponents.Add(component);
                }
            }
        }
Example #3
0
        public void RemoveRelatedElement(IProductElement element)
        {
            var command   = element.As <ICommand>();
            var @event    = element.As <IEvent>();
            var endpoint  = element.As <IAbstractEndpoint>();
            var component = element.As <IComponent>();
            var link      = this.UseCaseLinks.FirstOrDefault(l => l.LinkedElementId == element.Id);

            if (link != null)
            {
                link.Delete();
            }

            if (command != null && relatedCommands.Contains(command))
            {
                this.relatedCommands.Remove(command);
            }
            else if (@event != null && this.relatedEvents.Contains(@event))
            {
                this.relatedEvents.Remove(@event);
            }
            else if (endpoint != null && this.relatedEndpoints.Contains(endpoint))
            {
                this.relatedEndpoints.Remove(endpoint);
            }
            else if (component != null && this.relatedComponents.Contains(component))
            {
                this.relatedComponents.Remove(component);
            }
        }
Example #4
0
        public static string GetComponentsHandlerOrder(this IProductElement endpoint)
        {
            var sb               = new StringBuilder();
            var app              = endpoint.Root.As <NServiceBusStudio.IApplication>();
            var endpoints        = app.Design.Endpoints.GetAll();
            var sourceComponents = (endpoint.As <IToolkitInterface>() as IAbstractEndpoint).EndpointComponents.AbstractComponentLinks.OrderBy(o => o.Order);
            var components       = sourceComponents.Select(ac => ac.ComponentReference.Value)
                                   .Where(c => c.Subscribes.ProcessedCommandLinks.Any() || c.Subscribes.SubscribedEventLinks.Any())
                                   .Select(cmp => HandlerTypeFromComponent(cmp));

            // Add authentication first if needed
            if (app.HasAuthentication && (endpoint.As <IToolkitInterface>() as IAbstractEndpoint).Project != null)
            {
                components = new string[] { string.Format("{0}.Infrastructure.Authentication", (endpoint.As <IToolkitInterface>() as IAbstractEndpoint).Project.Data.RootNamespace) }.Union(components);
            }

            ////
            if (components.Count() > 1)
            {
                sb.Append(@"
	    public void SpecifyOrder(Order order)
	    {
	        order.Specify("    );

                int pos = 1;
                foreach (var c in components)
                {
                    if (pos == 1)
                    {
                        sb.AppendFormat("First<{0}>", c);
                    }
                    else if (pos == 2)
                    {
                        sb.AppendFormat(".Then<{0}>()", c);
                    }
                    else
                    {
                        sb.AppendFormat(".AndThen<{0}>()", c);
                    }
                    pos++;
                }
                sb.Append(@");
	    }"    );
            }

            ////

            return(sb.ToString());
        }
Example #5
0
        public static string GetMessageConventions(this IProductElement endpoint)
        {
            var generatedConventions = string.Empty;

            try
            {
                var app = endpoint.Root.As <NServiceBusStudio.IApplication>();

                var rootNameSpace           = string.Empty;
                var applicationName         = app.CodeIdentifier;
                var projectNameForInternal  = app.ProjectNameInternalMessages;
                var projectNameForContracts = app.ProjectNameContracts;

                var project = endpoint.As <IAbstractEndpoint>().As <IProductElement>().GetProject();
                if (project != null)
                {
                    rootNameSpace = project.Data.RootNamespace;
                }
                generatedConventions = GetMessageConventions(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
            }
            catch (Exception ex)
            {
                //TODO: Why are we catching the exception here??
            }
            return(generatedConventions);
        }
        public static string GetMessageConventions(this IProductElement endpoint)
        {
            var generatedConventions = string.Empty;

            try
            {
                var app = endpoint.Root.As <IApplication>();

                var rootNameSpace           = string.Empty;
                var applicationName         = app.InstanceName;
                var projectNameForInternal  = app.ProjectNameInternalMessages;
                var projectNameForContracts = app.ProjectNameContracts;

                var project = endpoint.As <IAbstractEndpoint>().As <IProductElement>().GetProject();
                if (project != null)
                {
                    rootNameSpace = project.Data.RootNamespace;
                }

                generatedConventions =
                    app.TargetNsbVersion == TargetNsbVersion.Version4
                    ? GetMessageConventionsV4(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts)
                    : GetMessageConventionsV5(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
            }
            catch (Exception ex)
            {
                //TODO: Why are we catching the exception here??
            }

            return(generatedConventions);
        }
Example #7
0
        public static IComponent GetComponentFromLinkedElement(IProductElement currentElement)
        {
            IComponent component = null;

            if (currentElement.As <IComponent>() != null)
            {
                return(currentElement.As <IComponent>());
            }

            var subscribedEventLink  = currentElement.As <ISubscribedEventLink>();
            var processedCommandLink = currentElement.As <IProcessedCommandLink>();
            var eventLink            = currentElement.As <IEventLink>();
            var commandLink          = currentElement.As <ICommandLink>();

            if (subscribedEventLink != null)
            {
                component = subscribedEventLink.Parent.Parent;
            }
            else if (processedCommandLink != null)
            {
                component = processedCommandLink.Parent.Parent;
            }
            else if (eventLink != null)
            {
                component = eventLink.Parent.Parent;
            }
            else if (commandLink != null)
            {
                component = commandLink.Parent.Parent;
            }

            return(component);
        }
Example #8
0
        public static IComponent GetComponentFromLinkedElement(IProductElement currentElement)
        {
            IComponent component = null;

            if (currentElement.As<IComponent>() != null)
            {
                return currentElement.As<IComponent>();
            }

            var subscribedEventLink = currentElement.As<ISubscribedEventLink>();
            var processedCommandLink = currentElement.As<IProcessedCommandLink>();
            var eventLink = currentElement.As<IEventLink>();
            var commandLink = currentElement.As<ICommandLink>();

            if (subscribedEventLink != null)
            {
                component = subscribedEventLink.Parent.Parent;
            }
            else if (processedCommandLink != null)
            {
                component = processedCommandLink.Parent.Parent;
            }
            else if (eventLink != null)
            {
                component = eventLink.Parent.Parent;
            }
            else if (commandLink != null)
            {
                component = commandLink.Parent.Parent;
            }

            return component;
        }
Example #9
0
        public static string GetMessageConventions(this IProductElement endpoint)
        {
            var sb = new StringBuilder();

            try
            {
                var app = endpoint.Root.As <NServiceBusStudio.IApplication>();

                /*
                 * namespace <#= namespace #>
                 * {
                 *  public class MessageConventions : IWantToRunBeforeConfiguration
                 *  {
                 *      public void Init()
                 *      {
                 *          Configure.Instance
                 *              .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("<#= app.InternalMessagesProjectNamespace #>"))
                 *              .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("<#= app.ContractsProjectNamespace #>"));
                 *      }
                 *  }
                 * }
                 *
                 * */
                var project = endpoint.As <IAbstractEndpoint>().As <IProductElement>().GetProject();
                if (project != null)
                {
                    sb.AppendLine("namespace " + project.Data.RootNamespace);
                }
                sb.Append(@"{
    public class MessageConventions : IWantToRunBeforeConfiguration
    {
        public void Init()
        {
            Configure.Instance");
                sb.AppendLine();
                sb.AppendLine("            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith(\"" +
                              app.CodeIdentifier + "." + app.ProjectNameInternalMessages + "\"))");
                sb.AppendLine("            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith(\"" +
                              app.CodeIdentifier + "." + app.ProjectNameContracts + "\"));");
                sb.Append(@"        }
    }
}
");
            }
            catch (Exception ex)
            {
            }
            return(sb.ToString());
        }
Example #10
0
        public static INServiceBusMVC GetMvcEndpointFromLinkedElement(IProductElement currentElement)
        {
            var currentComponent = currentElement.As <NServiceBusStudio.IComponent>();
            var app = currentElement.Root.As <IApplication>();

            foreach (var endpoint in app.Design.Endpoints.GetMvcEndpoints())
            {
                var componentLinks = endpoint.EndpointComponents.AbstractComponentLinks;
                if (componentLinks.Select(link => link.ComponentReference.Value).Any(component => component == currentComponent))
                {
                    return(endpoint);
                }
            }

            return(null);
        }
Example #11
0
        public static INServiceBusMVC GetMvcEndpointFromLinkedElement(IProductElement currentElement)
        {
            var currentComponent = currentElement.As<NServiceBusStudio.IComponent>();
            var app = currentElement.Root.As<IApplication>();

            foreach (var endpoint in app.Design.Endpoints.GetMvcEndpoints())
            {
                var componentLinks = endpoint.EndpointComponents.AbstractComponentLinks;
                if (componentLinks.Select(link => link.ComponentReference.Value).Any(component => component == currentComponent))
                {
                    return endpoint;
                }
            }

            return null;
        }
Example #12
0
        public void RemoveRelatedElement(IProductElement element)
        {
            var command = element.As<ICommand>();
            var @event = element.As<IEvent>();
            var endpoint = element.As<IAbstractEndpoint>();
            var component = element.As<IComponent>();
            var link = this.UseCaseLinks.FirstOrDefault(l => l.LinkedElementId == element.Id);
            if (link != null)
            {
                link.Delete();
            }

            if (command != null && relatedCommands.Contains(command))
            {
                this.relatedCommands.Remove(command);
            }
            else if (@event != null && this.relatedEvents.Contains(@event))
            {
                this.relatedEvents.Remove(@event);
            }
            else if (endpoint != null && this.relatedEndpoints.Contains(endpoint))
            {
                this.relatedEndpoints.Remove(endpoint);
            }
            else if (component != null && this.relatedComponents.Contains(component))
            {
                this.relatedComponents.Remove(component);
            }
        }
Example #13
0
        public void InternalAddRelatedElement(IProductElement element, bool isStarting = false, bool createLink = false)
        {
            if (element != null)
            {
                var command = element.As<ICommand>();
                var @event = element.As<IEvent>();
                var endpoint = element.As<IAbstractEndpoint>();
                var component = element.As<IComponent>();

                IUseCaseLink link = null;

                if (createLink)
                {
                    link = this.CreateUseCaseLink(element.Id.ToString());
                    link.LinkedElementId = element.Id;
                    if (command != null)
                    {
                        link.ElementType = "Command";
                    }
                    else if (@event != null)
                    {
                        link.ElementType = "Event";
                    }
                    else if (endpoint != null)
                    {
                        link.ElementType = "Endpoint";
                    }
                    else if (component != null)
                    {
                        link.ElementType = "Component";
                    }

                    link.StartsUseCase = isStarting;
                }

                if (command != null && !this.relatedCommands.Contains(command))
                {
                    this.relatedCommands.Add(command);
                }
                else if (@event != null && !this.relatedEvents.Contains(@event))
                {
                    this.relatedEvents.Add(@event);
                }
                else if (endpoint != null)
                {
                    if (isStarting && !this.endpointsStartingUseCases.Contains(endpoint))
                    {
                        this.endpointsStartingUseCases.Add(endpoint);
                    }
                    else if (!this.relatedEndpoints.Contains(endpoint) && !this.endpointsStartingUseCases.Contains(endpoint))
                    {
                        this.relatedEndpoints.Add(endpoint);
                    }
                }
                else if (component != null && !this.relatedComponents.Contains(component))
                {
                    this.relatedComponents.Add(component);
                }
            }
        }
        public static string GetMessageEndpointMappingsConfig(this IProductElement endpoint)
        {
            var sb        = new StringBuilder();
            var app       = endpoint.Root.As <NServiceBusStudio.IApplication>();
            var endpoints = app.Design.Endpoints.GetAll();

            try
            {
                foreach (var component in (endpoint.As <IToolkitInterface>() as IAbstractEndpoint).EndpointComponents
                         .AbstractComponentLinks.Select(ac => ac.ComponentReference.Value)
                         .Where(c => c.Publishes.CommandLinks.Any() || c.Subscribes.SubscribedEventLinks.Any()))
                {
                    // Add mappings from the messages(command types) sent by this endpoint
                    // to the endpoints (root namespace for endpoint projects) processing them.
                    foreach (var command in component.Publishes.CommandLinks.Select(c => c.CommandReference.Value))
                    {
                        var componentProcessingCommand = app.Design.Services.Service
                                                         .SelectMany(s => s.Components.Component
                                                                     .Where(c => c.Subscribes.ProcessedCommandLinks
                                                                            .Any(cl => cl.CommandReference
                                                                                 .Value == command)))
                                                         .FirstOrDefault();
                        if (componentProcessingCommand != null)
                        {
                            foreach (var endpointHost in FindComponentHostEndpoints(endpoints, componentProcessingCommand))
                            {
                                if (endpointHost != null && endpoint.InstanceName != endpointHost.InstanceName)
                                {
                                    sb.AppendLine(String.Format("<add Messages=\"{0}\" Endpoint=\"{1}\" />",
                                                                command.Parent.Namespace + "." + command.CodeIdentifier + ", " + app.InternalMessagesProjectName,
                                                                (endpointHost != null) ? endpointHost.Project.Data.RootNamespace : ""));
                                }
                            }
                        }
                    }

                    // Add mappings from the messages(event types) subscribed by this endpoint
                    // to the endpoints (root namespace for endpoint projects) publishing them.
                    foreach (var eventt in component.Subscribes.SubscribedEventLinks.Select(c => c.EventReference.Value)
                             .Where(e => e != null))
                    {
                        var componentPublishingEvent = app.Design.Services.Service
                                                       .SelectMany(s => s.Components.Component
                                                                   .Where(c => c.Publishes.EventLinks
                                                                          .Any(el => el.EventReference
                                                                               .Value == eventt)))
                                                       .FirstOrDefault();
                        if (componentPublishingEvent != null)
                        {
                            foreach (var endpointHost in FindComponentHostEndpoints(endpoints, componentPublishingEvent))
                            {
                                sb.AppendLine(String.Format("<add Messages=\"{0}\" Endpoint=\"{1}\" />",
                                                            eventt.Parent.Namespace + "." + eventt.CodeIdentifier + ", " + app.ContractsProjectName,
                                                            (endpointHost != null) ? endpointHost.Project.Data.RootNamespace : ""));
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(sb.ToString());
        }
 private void CreateLibrariesPanel(ISolutionBuilderViewModel solutionBuilderModel, IProductElement product, IApplication application, int position)
 {
     var commandsVM = new InnerPanelViewModel();
     commandsVM.Title = "Libraries";
     var globalLibraries = application.Design.Libraries.Library.Where(l =>
                                     product.As<IComponent>().LibraryReferences.LibraryReference
                                             .Any(lr => lr.LibraryId == l.As<IProductElement>().Id))
                                     .Select(l => l.As<IProductElement>());
     commandsVM.Items.Add(new InnerPanelTitle { Text = "Global Libraries", Product = null, MenuFilters = new string[] { }, ForceText = true });
     foreach (var gl in globalLibraries)
     {
         commandsVM.Items.Add(new InnerPanelItem { Product = gl, Text = gl.InstanceName });
     }
     var serviceLibraries = product.As<IComponent>().Parent.Parent.ServiceLibraries.ServiceLibrary.Where(l =>
                                     product.As<IComponent>().LibraryReferences.LibraryReference
                                             .Any(lr => lr.LibraryId == l.As<IProductElement>().Id))
                                     .Select(l => l.As<IProductElement>());
     commandsVM.Items.Add(new InnerPanelTitle { Text = "Service Libraries", Product = null, MenuFilters = new string[] { }, ForceText = true });
     foreach (var sl in serviceLibraries)
     {
         commandsVM.Items.Add(new InnerPanelItem { Product = sl, Text = sl.InstanceName });
     }
     this.SetPanel(position, new LogicalView(new LogicalViewModel(solutionBuilderModel, commandsVM)));
 }