public ContainerRegistrationAnalysisStageProcess(IDaemonProcess process, IContextBoundSettingsStore settingsStore, ITypeUsageManager typeUsageManager, IPatternManager patternManager)
 {
     this.process = process;
     this.settingsStore = settingsStore;
     this.typeUsageManager = typeUsageManager;
     this.patternManager = patternManager;
 }
 public ContainerRegistrationAnalysisStageProcess(IDaemonProcess process, IContextBoundSettingsStore settingsStore, ITypeUsageManager typeUsageManager, IPatternManager patternManager)
 {
     this.process          = process;
     this.settingsStore    = settingsStore;
     this.typeUsageManager = typeUsageManager;
     this.patternManager   = patternManager;
 }
Beispiel #3
0
        public OnElementLoadedEvent(
            [Import(AllowDefault = true)] IPatternManager patternManager,
            [Import(AllowDefault = true)] IInstanceBase currentElement)
        {
            this.currentElement = currentElement;
            this.patternManager = patternManager;

            this.sourceEvent = WeakObservable.FromEvent <EventArgs>(
                handler => this.ElementLoaded += handler,
                handler => this.ElementLoaded -= handler);

            if (patternManager != null)
            {
                this.patternManager.IsOpenChanged += (sender, args) => this.OnOpenChanged();

                if (this.patternManager.IsOpen)
                {
                    this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IInstanceBase> >(
                        handler => this.patternManager.Store.ElementLoaded += handler,
                        handler => this.patternManager.Store.ElementLoaded -= handler);

                    this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreElementLoaded);
                }
            }
        }
Beispiel #4
0
        public static GenerateProductCodeCommand CreateTempGenerateCodeCommand(this IProductElement element,
                                                                               IServiceProvider sp
                                                                               , string targetFileName
                                                                               , string targetPath
                                                                               , string templateUri
                                                                               , string namePrefix  = "GenerateCode"
                                                                               , string buildAction = "Compile")
        {
            var                  guid           = Guid.NewGuid();
            ISolution            solution       = sp.TryGetService <ISolution>();
            IPatternManager      patternManager = sp.TryGetService <IPatternManager>();
            IUriReferenceService uriService     = sp.TryGetService <IUriReferenceService>();
            var                  command        = new GenerateProductCodeCommand
            {
                TargetBuildAction  = buildAction,
                TargetCopyToOutput = CopyToOutput.DoNotCopy,
                Settings           = new EmptySettings {
                    Name = String.Format("{0}{1}", namePrefix, guid.ToString()), Id = guid
                },
                PatternManager  = patternManager,
                UriService      = uriService,
                Solution        = solution,
                ServiceProvider = sp,
                TargetFileName  = targetFileName,
                TargetPath      = targetPath,
                CurrentElement  = element,
                TemplateUri     = new Uri(templateUri)
            };

            return(command);
        }
        public ProductStateValidator(IServiceProvider serviceProvider)
        {
            Guard.NotNull(() => serviceProvider, serviceProvider);

            this.patternManager           = serviceProvider.GetService <IPatternManager>();
            this.buildEvents              = serviceProvider.GetService <SDTE, DTE>().Events.BuildEvents;
            this.buildEvents.OnBuildDone += OnBuildDone;
        }
Beispiel #6
0
 private static bool IsValidExtensionPoint(
     Product product,
     IEnumerable <IExtensionPointInfo> extensionPoints,
     IPatternManager patternManager)
 {
     return(extensionPoints.Any(x => patternManager.GetCandidateExtensionPoints(x.RequiredExtensionPointId)
                                .Any(f => f.Id == product.ExtensionId && f.Schema.Pattern.Id == product.DefinitionId)));
 }
        public ProductStateValidator(IServiceProvider serviceProvider)
        {
            Guard.NotNull(() => serviceProvider, serviceProvider);

            this.patternManager = serviceProvider.GetService<IPatternManager>();
            this.buildEvents = serviceProvider.GetService<SDTE, DTE>().Events.BuildEvents;
            this.buildEvents.OnBuildDone += OnBuildDone;
        }
        public virtual void InitializeContext()
        {
            this.solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();
            this.dte = VsIdeTestHostContext.ServiceProvider.GetService<EnvDTE.DTE>();
            this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService<IPatternManager>();

            this.instanceName = "a" + Guid.NewGuid().ToString().Replace("-", "");
            this.solution.CreateInstance(this.DeploymentDirectory, this.instanceName);
        }
        /// <summary>
        /// Finds a pattern instance by name.
        /// </summary>
        /// <param name="manager">The pattern manager to find products in.</param>
        /// <param name="name">The pattern name.</param>
        /// <returns>The found pattern or <see langword="null"/> if the pattern with the given name has not been instantiated.</returns>
        public static IProduct Find(this IPatternManager manager, string name)
        {
            Guard.NotNull(() => manager, manager);
            Guard.NotNullOrEmpty(() => name, name);

            return(manager.IsOpen ?
                   manager.Products.FirstOrDefault(p => p.InstanceName.Equals(name, StringComparison.OrdinalIgnoreCase)) :
                   null);
        }
        public virtual void InitializeContext()
        {
            this.solution       = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
            this.dte            = VsIdeTestHostContext.ServiceProvider.GetService <EnvDTE.DTE>();
            this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();

            this.instanceName = "a" + Guid.NewGuid().ToString().Replace("-", "");
            this.solution.CreateInstance(this.DeploymentDirectory, this.instanceName);
        }
Beispiel #11
0
 private static bool HasSingletonExtensionPointsInView(
     IGrouping <Guid, Product> group,
     IEnumerable <IExtensionPointInfo> extensionPoints,
     IPatternManager patternManager)
 {
     return(extensionPoints.Any(x =>
                                (x.Cardinality == Cardinality.OneToOne || x.Cardinality == Cardinality.ZeroToOne) &&
                                patternManager.GetCandidateExtensionPoints(x.RequiredExtensionPointId)
                                .Any(f => f.Schema.Pattern.Id == group.Key && f.Id == group.First().ExtensionId)));
 }
            public void InitializeContext()
            {
                this.solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();
                this.solution.CreateInstance(this.DeploymentDirectory, "Blank");

                this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService<IPatternManager>();

                this.toolkit = patternManager.InstalledToolkits
                    .SingleOrDefault(t => t.Id == "NuPattern.Runtime.IntegrationTests.TestToolkit");
            }
Beispiel #13
0
            public void InitializeContext()
            {
                this.solution = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
                this.solution.CreateInstance(this.DeploymentDirectory, "Blank");

                this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();

                this.toolkit = patternManager.InstalledToolkits
                               .SingleOrDefault(t => t.Id == "NuPattern.Runtime.IntegrationTests.TestToolkit");
            }
        /// <summary>
        /// Deletes all products.
        /// </summary>
        /// <param name="patternManager">The pattern manager.</param>
        public static void DeleteAll(this IPatternManager patternManager)
        {
            Guard.NotNull(() => patternManager, patternManager);

            var productsToDelete = patternManager.Products.ToList();

            foreach (var product in productsToDelete)
            {
                patternManager.DeleteProduct(product);
            }
        }
        public void InitializeContext()
        {
            var solution = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();

            solution.Open(PathTo(@"EmptySolution.sln"));

            this.manager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();
            var componentModel    = VsIdeTestHostContext.ServiceProvider.GetService <SComponentModel, IComponentModel>();
            var installedToolkits = componentModel.GetService <IEnumerable <IInstalledToolkitInfo> >();

            this.toolkit = installedToolkits
                           .SingleOrDefault(toolkit => toolkit.Id.Equals("1530D736-97EA-4B4A-8A25-C6C7A089D1BB", StringComparison.OrdinalIgnoreCase));
        }
        public void InitializeContext()
        {
            var solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();

            solution.Open(PathTo(@"EmptySolution.sln"));

            this.manager = VsIdeTestHostContext.ServiceProvider.GetService<IPatternManager>();
            var componentModel = VsIdeTestHostContext.ServiceProvider.GetService<SComponentModel, IComponentModel>();
            var installedToolkits = componentModel.GetService<IEnumerable<IInstalledToolkitInfo>>();

            this.toolkit = installedToolkits
                .SingleOrDefault(toolkit => toolkit.Id.Equals("1530D736-97EA-4B4A-8A25-C6C7A089D1BB", StringComparison.OrdinalIgnoreCase));
        }
        public InfrastructureManager(IApplication application, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            this.PatternManager = patternManager;
            this.serviceProvider = serviceProvider;
            this.application = application;

            // Build features collection
            this.Features.Add(new Authentication.AuthenticationFeature());

            // Initialize features
            var infrastructure = application.Design.Infrastructure.As<IProductElement>();
            Features.ForEach(f => f.Initialize(this.application, infrastructure, serviceProvider, this.PatternManager));
        }
Beispiel #18
0
        public InfrastructureManager(IApplication application, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            this.PatternManager  = patternManager;
            this.serviceProvider = serviceProvider;
            this.application     = application;

            // Build features collection
            this.Features.Add(new Authentication.AuthenticationFeature());

            // Initialize features
            var infrastructure = application.Design.Infrastructure.As <IProductElement>();

            Features.ForEach(f => f.Initialize(this.application, infrastructure, serviceProvider, this.PatternManager));
        }
        /// <summary>
        /// Deletes the pattern by name.
        /// </summary>
        /// <param name="manager">The pattern manager.</param>
        /// <param name="name">The pattern name.</param>
        public static bool Delete(this IPatternManager manager, string name)
        {
            Guard.NotNull(() => manager, manager);
            Guard.NotNullOrEmpty(() => name, name);

            var product = manager.Find(name);

            if (product == null)
            {
                return(false);
            }

            return(manager.DeleteProduct(product));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AddNewProductViewModel"/> class.
        /// </summary>
        /// <param name="patternManager">The pattern manager.</param>
        /// <param name="userMessageService">The user message service.</param>
        public AddNewProductViewModel(IPatternManager patternManager, IUserMessageService userMessageService)
        {
            Guard.NotNull(() => patternManager, patternManager);
            Guard.NotNull(() => userMessageService, userMessageService);

            this.allToolkits        = new ObservableCollection <InstalledToolkitInfo>(patternManager.InstalledToolkits.Select(it => new InstalledToolkitInfo(it)));
            this.toolkitsView       = new ListCollectionView(this.allToolkits);
            this.patternManager     = patternManager;
            this.userMessageService = userMessageService;
            this.CurrentToolkit     = this.allToolkits.FirstOrDefault();
            this.SortingItems       = GetSortingItems();
            this.SortingItem        = this.SortingItems.FirstOrDefault();
            this.InitializeCommands();
            this.ArrangeToolkits();
        }
        public void InitializeContext()
        {
            this.testClass = new ValidationTest();

            // Exports test class to MEF
            VsCompositionContainer.Create(new TypeCatalog(typeof(ValidationTest)), new VsExportProviderSettings(
                VsExportProvidingPreference.BeforeExportsFromOtherContainers));

            this.solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();
            this.solution.CreateInstance(this.DeploymentDirectory, "Blank");

            this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService<IPatternManager>();
            var toolkit = this.patternManager.InstalledToolkits.Single(f => f.Id == "NuPattern.Runtime.IntegrationTests.TestToolkit");
            UIThreadInvoker.Invoke(new Action(() => this.product = this.patternManager.CreateProduct(toolkit, "Foo")));
        }
Beispiel #22
0
        internal static void SetupCreateElement <T>(IPatternManager manager, T container) where T : class, IElementContainer
        {
            IElement element = null;

            Mock.Get <T>(container)
            .Setup(v => v.CreateElement(It.IsAny <Action <IElement> >(), It.IsAny <bool>()))
            .Callback(() =>
            {
                element = Mocks.Of <IElement>().First(x => x.Parent == container && x.InstanceName == "2second");
                ((IList <IAbstractElement>)container.AllElements).Add(element);
                Mock.Get(manager).Raise(x => x.ElementCreated      += null, new ValueEventArgs <IProductElement>(element));
                Mock.Get(manager).Raise(x => x.ElementInstantiated += null, new ValueEventArgs <IProductElement>(element));
            })
            .Returns(() => element);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AddNewProductViewModel"/> class.
        /// </summary>
        /// <param name="patternManager">The pattern manager.</param>
        /// <param name="userMessageService">The user message service.</param>
        public AddNewProductViewModel(IPatternManager patternManager, IUserMessageService userMessageService)
        {
            Guard.NotNull(() => patternManager, patternManager);
            Guard.NotNull(() => userMessageService, userMessageService);

            this.allToolkits = new ObservableCollection<InstalledToolkitInfo>(patternManager.InstalledToolkits.Select(it => new InstalledToolkitInfo(it)));
            this.toolkitsView = new ListCollectionView(this.allToolkits);
            this.patternManager = patternManager;
            this.userMessageService = userMessageService;
            this.CurrentToolkit = this.allToolkits.FirstOrDefault();
            this.SortingItems = GetSortingItems();
            this.SortingItem = this.SortingItems.FirstOrDefault();
            this.InitializeCommands();
            this.ArrangeToolkits();
        }
Beispiel #24
0
        /// <summary>
        /// Sync the extension points of the given view.
        /// </summary>
        internal static void SyncExtensionPointsFrom(
            this View view,
            IEnumerable <IExtensionPointInfo> extensionPoints,
            IPatternManager patternManager)
        {
            view.ExtensionProducts
            .Where(p => !IsValidExtensionPoint(p, extensionPoints, patternManager))
            .ToArray()
            .ForEach(p => p.Delete());

            view.ExtensionProducts
            .GroupBy(x => x.DefinitionId)
            .Where(x => x.Count() > 1 && HasSingletonExtensionPointsInView(x, extensionPoints, patternManager))
            .SelectMany(x => x.Skip(1))
            .ForEach(x => x.Delete());
        }
Beispiel #25
0
        public void InitializeContext()
        {
            this.testClass = new ValidationTest();

            // Exports test class to MEF
            VsCompositionContainer.Create(new TypeCatalog(typeof(ValidationTest)), new VsExportProviderSettings(
                                              VsExportProvidingPreference.BeforeExportsFromOtherContainers));

            this.solution = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
            this.solution.CreateInstance(this.DeploymentDirectory, "Blank");

            this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();
            var toolkit = this.patternManager.InstalledToolkits.Single(f => f.Id == "NuPattern.Runtime.IntegrationTests.TestToolkit");

            UIThreadInvoker.Invoke(new Action(() => this.product = this.patternManager.CreateProduct(toolkit, "Foo")));
        }
Beispiel #26
0
        // Initialization
        public void Initialize(IApplication app, IProductElement infrastructure, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            this.PatternManager = patternManager;
            UpdateElementsForUseCase(app, serviceProvider.TryGetService<ISolution>(), serviceProvider);

            var handler = new EventHandler((s, e) =>
            {
                UpdateElementsForUseCase(app, serviceProvider.TryGetService<ISolution>(), serviceProvider);
            });

            // Listen for a new endpoint initialization
            // in order to add the required artifacts (typically menu items)
            app.OnInitializingEndpoint += handler;
            Command.ElementInitialized += handler;
            Event.ElementInitialized += handler;
            Component.ElementInitialized += handler;
        }
Beispiel #27
0
        // Initialization
        public void Initialize(IApplication app, IProductElement infrastructure, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            this.PatternManager = patternManager;
            UpdateElementsForUseCase(app, serviceProvider.TryGetService <ISolution>(), serviceProvider);

            var handler = new EventHandler((s, e) =>
            {
                UpdateElementsForUseCase(app, serviceProvider.TryGetService <ISolution>(), serviceProvider);
            });

            // Listen for a new endpoint initialization
            // in order to add the required artifacts (typically menu items)
            app.OnInitializingEndpoint   += handler;
            Command.ElementInitialized   += handler;
            Event.ElementInitialized     += handler;
            Component.ElementInitialized += handler;
        }
Beispiel #28
0
        /// <summary>
        /// Returns the installed toolkit that contains the given template.
        /// </summary>
        /// <param name="patternManager">The PatternManager service</param>
        /// <param name="templateFile">The full path to the vstemplate file.
        /// i.e. (VS2010) %localappdata%\Microsoft\VisualStudio\10.0\Extensions\[author][\[extensionname]\[version]\Assets\Templates\Projects\~PC\Template.zip\Template.vstempate
        /// i.e. (VS2012) %localappdata%\Microsoft\VisualStudio\11.0\VTC\[guid]\~PC\Projects\Template.zip\Template.vstemplate
        /// </param>
        /// <returns></returns>
        internal static IInstalledToolkitInfo FindToolkitOrThrow(IPatternManager patternManager, string templateFile)
        {
            // Find the toolkit that shares the same path as this vstemplate (VS2010 only)
            var toolkitInfo = patternManager.InstalledToolkits
                              .FirstOrDefault(f => templateFile.StartsWith(f.Extension.InstallPath, StringComparison.OrdinalIgnoreCase));

#if VSVER11 || VSVER12
            // In VS2012, vstemplates are loaded from cache not from toolkit installation path.
            if (toolkitInfo == null)
            {
                // Find the toolkit that contains the vstemplate, by TemplateID or Name
                if (File.Exists(templateFile))
                {
                    var template = VsTemplateFile.Read(templateFile);
                    if (template != null)
                    {
                        if (!String.IsNullOrEmpty(template.TemplateData.TemplateID))
                        {
                            toolkitInfo = patternManager.InstalledToolkits
                                          .FirstOrDefault(it => it.Templates.Any(t => ((t.TemplateData.TemplateID != null) &&
                                                                                       (t.TemplateData.TemplateID.Equals(template.TemplateData.TemplateID, StringComparison.OrdinalIgnoreCase)))));
                        }
                        else
                        {
                            toolkitInfo = patternManager.InstalledToolkits
                                          .FirstOrDefault(it => it.Templates.Any(t => ((t.TemplateData.Name != null) &&
                                                                                       (t.TemplateData.Name.Value.Equals(template.TemplateData.Name.Value, StringComparison.OrdinalIgnoreCase)))));
                        }
                    }
                }
            }
#endif

            if (toolkitInfo == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Resources.InstantiationTemplateWizard_ToolkitInfoNotFound,
                                                        templateFile));
            }

            return(toolkitInfo);
        }
Beispiel #29
0
        public OnProductStoreSavedEvent(IPatternManager patternManager)
        {
            Guard.NotNull(() => patternManager, patternManager);

            this.patternManager = patternManager;
            this.patternManager.IsOpenChanged += (sender, args) => this.OnOpenChanged();

            this.sourceEvent = WeakObservable.FromEvent <EventArgs>(
                handler => this.ProductStoreSaved += handler,
                handler => this.ProductStoreSaved -= handler);

            if (this.patternManager.IsOpen)
            {
                this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IProductState> >(
                    handler => this.patternManager.StoreSaved += handler,
                    handler => this.patternManager.StoreSaved -= handler);

                this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreProductStoreSaved);
            }
        }
Beispiel #30
0
        public void InitializeContext()
        {
            this.dte     = VsIdeTestHostContext.ServiceProvider.GetService <EnvDTE.DTE>();
            this.manager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();
            var componentModel    = VsIdeTestHostContext.ServiceProvider.GetService <SComponentModel, IComponentModel>();
            var installedToolkits = componentModel.GetService <IEnumerable <IInstalledToolkitInfo> >();

            this.toolkit = installedToolkits.SingleOrDefault(t => t.Id == TestToolkitId);

#if VSVER11 || VSVER12
            //Copy TestToolkit template to VSExp template cache
            this.testToolkitTemplatePath = string.Format(CultureInfo.InvariantCulture, TestToolkitTemplateCacheFormat, dte.Version);
            Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate1.zip"));
            Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate2.zip"));
            File.Copy(Path.Combine(this.TestContext.DeploymentDirectory, @"MyTemplate1.gen.vstemplate"),
                      Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate1.zip\MyTemplate1.gen.vstemplate"), true);
            File.Copy(Path.Combine(this.TestContext.DeploymentDirectory, @"MyTemplate2.gen.vstemplate"),
                      Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate2.zip\MyTemplate2.gen.vstemplate"), true);
#endif
        }
        public void InitializeContext()
        {
            this.dte = VsIdeTestHostContext.ServiceProvider.GetService<EnvDTE.DTE>();
            this.manager = VsIdeTestHostContext.ServiceProvider.GetService<IPatternManager>();
            var componentModel = VsIdeTestHostContext.ServiceProvider.GetService<SComponentModel, IComponentModel>();
            var installedToolkits = componentModel.GetService<IEnumerable<IInstalledToolkitInfo>>();

            this.toolkit = installedToolkits.SingleOrDefault(t => t.Id == TestToolkitId);

#if VSVER11 || VSVER12
            //Copy TestToolkit template to VSExp template cache
            this.testToolkitTemplatePath = string.Format(CultureInfo.InvariantCulture, TestToolkitTemplateCacheFormat, dte.Version);
            Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate1.zip"));
            Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate2.zip"));
            File.Copy(Path.Combine(this.TestContext.DeploymentDirectory, @"MyTemplate1.gen.vstemplate"),
                Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate1.zip\MyTemplate1.gen.vstemplate"), true);
            File.Copy(Path.Combine(this.TestContext.DeploymentDirectory, @"MyTemplate2.gen.vstemplate"),
                Environment.ExpandEnvironmentVariables(this.testToolkitTemplatePath + @"\~PC\Projects\MyTemplate2.zip\MyTemplate2.gen.vstemplate"), true);
#endif
        }
Beispiel #32
0
        // This feature requires:
        // 1. A menu "Add Authentication" that generates Infrastructure\Security\Authentication Code.
        // 2. Add references to the infrastructure project from all the endpoints
        // 3. Also, add a new reference when a new endpoint has been instantiated
        // 4. Add a menu option for "Customize Authentication" on each endpoint
        // This should exist only if the endpoint doesn't have custom authentication already.


        // Initialization
        public void Initialize(IApplication app, IProductElement infrastructure, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            // InitializeAuthenticationValues
            InitializeAuthenticationValues(app, serviceProvider.TryGetService <ISolution>(), serviceProvider);

            // Listen for a new endpoint initialization
            // in order to add the required artifacts (typically menu items)
            app.OnInitializingEndpoint += (s, e) =>
            {
                UpdateEndpointsForAuthentication(app, serviceProvider.TryGetService <ISolution>(), serviceProvider);
            };

            // Listen for endpoint instantiated, in order to generate
            // associated code.
            app.OnInstantiatedEndpoint += (s, e) =>
            {
                GenerateAuthenticationCodeOnEndpoints(app, serviceProvider);
            };

            app.OnApplicationLoaded += (s, e) =>
            {
                GenerateAuthenticationCodeOnEndpoints(app, serviceProvider);
            };
        }
 private static bool HasSingletonExtensionPointsInView(
     IGrouping<Guid, Product> group,
     IEnumerable<IExtensionPointInfo> extensionPoints,
     IPatternManager patternManager)
 {
     return extensionPoints.Any(x =>
         (x.Cardinality == Cardinality.OneToOne || x.Cardinality == Cardinality.ZeroToOne) &&
         patternManager.GetCandidateExtensionPoints(x.RequiredExtensionPointId)
             .Any(f => f.Schema.Pattern.Id == group.Key && f.Id == group.First().ExtensionId));
 }
 private static bool IsValidExtensionPoint(
     Product product,
     IEnumerable<IExtensionPointInfo> extensionPoints,
     IPatternManager patternManager)
 {
     return extensionPoints.Any(x => patternManager.GetCandidateExtensionPoints(x.RequiredExtensionPointId)
             .Any(f => f.Id == product.ExtensionId && f.Schema.Pattern.Id == product.DefinitionId));
 }
        /// <summary>
        /// Sync the extension points of the given view.
        /// </summary>
        internal static void SyncExtensionPointsFrom(
            this View view,
            IEnumerable<IExtensionPointInfo> extensionPoints,
            IPatternManager patternManager)
        {
            view.ExtensionProducts
                .Where(p => !IsValidExtensionPoint(p, extensionPoints, patternManager))
                .ToArray()
                .ForEach(p => p.Delete());

            view.ExtensionProducts
                .GroupBy(x => x.DefinitionId)
                .Where(x => x.Count() > 1 && HasSingletonExtensionPointsInView(x, extensionPoints, patternManager))
                .SelectMany(x => x.Skip(1))
                .ForEach(x => x.Delete());
        }
        /// <summary>
        /// Gets the candidate extension points.
        /// </summary>
        /// <param name="manager">The manager.</param>
        /// <param name="extensionPointId">The extension point id.</param>
        public static IEnumerable <IInstalledToolkitInfo> GetCandidateExtensionPoints(this IPatternManager manager, string extensionPointId)
        {
            Guard.NotNull(() => manager, manager);

            return(manager.InstalledToolkits
                   .Where(f => f.Schema != null && f.Schema.Pattern != null &&
                          f.Schema.Pattern.ProvidedExtensionPoints.Any(e =>
                                                                       e.ExtensionPointId.Equals(extensionPointId, StringComparison.OrdinalIgnoreCase))));
        }
 public ContainerRegistrationAnalysisStage(IPatternManager patternManager)
 {
     this.patternManager = patternManager;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductStateEditorFactory"/> class.
 /// </summary>
 /// <param name="patternManager">The pattern manager.</param>
 public ProductStateEditorFactory(IPatternManager patternManager)
 {
     this.patternManager = patternManager;
 }
Beispiel #39
0
 public virtual void AddPatternManager(IPatternManager _patternManager)
 {
     patternManager = _patternManager;
     patternManager.SubscibeToPatternDataLoadedEvent(SetPatternData);
     patternManager.SubscibeToPattternDataStateChangedEvent(RefreshRecognizeablePatterns);
 }
Beispiel #40
0
 public virtual void InitializeContext()
 {
     solution       = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
     dte            = VsIdeTestHostContext.ServiceProvider.GetService <DTE>();
     patternManager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>();
 }
        // This feature requires:
        // 1. A menu "Add Authentication" that generates Infrastructure\Security\Authentication Code.
        // 2. Add references to the infrastructure project from all the endpoints
        // 3. Also, add a new reference when a new endpoint has been instantiated
        // 4. Add a menu option for "Customize Authentication" on each endpoint
        // This should exist only if the endpoint doesn't have custom authentication already.
        // Initialization
        public void Initialize(IApplication app, IProductElement infrastructure, IServiceProvider serviceProvider, IPatternManager patternManager)
        {
            // InitializeAuthenticationValues
            InitializeAuthenticationValues(app, serviceProvider.TryGetService<ISolution>(), serviceProvider);

            // Listen for a new endpoint initialization
            // in order to add the required artifacts (typically menu items)
            app.OnInitializingEndpoint += (s, e) =>
            {
                UpdateEndpointsForAuthentication(app, serviceProvider.TryGetService<ISolution>(), serviceProvider);
            };

            // Listen for endpoint instantiated, in order to generate
            // associated code.
            app.OnInstantiatedEndpoint += (s, e) =>
            {
                GenerateAuthenticationCodeOnEndpoints(app, serviceProvider);
            };

            app.OnApplicationLoaded += (s, e) =>
            {
                GenerateAuthenticationCodeOnEndpoints(app, serviceProvider);
            };
        }
Beispiel #42
0
            public void Initialize()
            {
                var hiddenView = CreateView("HiddenView", false);

                Mock.Get(hiddenView.Info).Setup(x => x.IsVisible).Returns(false);

                var views = new[]
                {
                    CreateView("View1", false, Create <IElement, IElementInfo>("Element1", Cardinality.OneToOne)),
                    CreateView("View2", true, Create <ICollection, ICollectionInfo>("Collection2", Cardinality.OneToOne), Create <IElement, IElementInfo>("Element2", Cardinality.ZeroToMany)),
                    hiddenView,
                };

                var view1Children = (List <IAbstractElementInfo>)views[0].Info.Elements;

                Mock.Get((IElementInfo)view1Children[0])
                .Setup(e => e.Parent)
                .Returns(views[0].Info);

                var view2Children = (List <IAbstractElementInfo>)views[1].Info.Elements;

                Mock.Get((ICollectionInfo)view2Children[0])
                .Setup(e => e.Parent)
                .Returns(views[1].Info);
                Mock.Get((IElementInfo)view2Children[1])
                .Setup(e => e.Parent)
                .Returns(views[1].Info);
                view2Children.Add(Mocks.Of <IElementInfo>().First(e =>
                                                                  e.Name == "Foo1" &&
                                                                  e.IsVisible == true &&
                                                                  e.AllowAddNew == true &&
                                                                  e.DisplayName == "Foo1" &&
                                                                  e.Cardinality == Cardinality.ZeroToMany));
                view2Children.Add(Mocks.Of <ICollectionInfo>().First(e =>
                                                                     e.Name == "Foo2" &&
                                                                     e.IsVisible == true &&
                                                                     e.AllowAddNew == true &&
                                                                     e.DisplayName == "Foo2" &&
                                                                     e.Cardinality == Cardinality.ZeroToMany));

                this.product = Mocks.Of <IProduct>().First(p =>
                                                           p.InstanceName == "Foo" &&
                                                           p.Views == views &&
                                                           p.CurrentView == views.FirstOrDefault(v => v.Info.IsDefault) &&
                                                           p.Info == new Mock <IPatternInfo>().Object);

                this.patternManager = Mocks.Of <IPatternManager>()
                                      .First(x => x.InstalledToolkits == Enumerable.Empty <IInstalledToolkitInfo>());

                var newNodeDialog = new Mock <IDialogWindow>();

                newNodeDialog.Setup(x => x.ShowDialog()).Returns(true);

                this.context = new SolutionBuilderContext
                {
                    PatternManager       = this.patternManager,
                    UserMessageService   = Mock.Of <IUserMessageService>(ums => ums.PromptWarning(It.IsAny <string>()) == true),
                    ShowProperties       = () => { },
                    NewNodeDialogFactory = x => newNodeDialog.Object,
                };

                var serviceProvider = Mocks.Of <IServiceProvider>()
                                      .First(x => x.GetService(typeof(ISolutionEvents)) == new Mock <ISolutionEvents>().Object);
                var explorer = new SolutionBuilderViewModel(context, serviceProvider);

                this.target = new ProductViewModel(this.product, context);

                this.target.RenderHierarchyRecursive();
            }
Beispiel #43
0
 public ContainerRegistrationAnalysisStage(IPatternManager patternManager)
 {
     this.patternManager = patternManager;
 }
Beispiel #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductStateEditorFactory"/> class.
 /// </summary>
 /// <param name="patternManager">The pattern manager.</param>
 public ProductStateEditorFactory(IPatternManager patternManager)
 {
     this.patternManager = patternManager;
 }
        /// <summary>
        /// Returns the installed toolkit that contains the given template.
        /// </summary>
        /// <param name="patternManager">The PatternManager service</param>
        /// <param name="templateFile">The full path to the vstemplate file. 
        /// i.e. (VS2010) %localappdata%\Microsoft\VisualStudio\10.0\Extensions\[author][\[extensionname]\[version]\Assets\Templates\Projects\~PC\Template.zip\Template.vstempate
        /// i.e. (VS2012) %localappdata%\Microsoft\VisualStudio\11.0\VTC\[guid]\~PC\Projects\Template.zip\Template.vstemplate
        /// </param>
        /// <returns></returns>
        internal static IInstalledToolkitInfo FindToolkitOrThrow(IPatternManager patternManager, string templateFile)
        {
            // Find the toolkit that shares the same path as this vstemplate (VS2010 only)
            var toolkitInfo = patternManager.InstalledToolkits
                .FirstOrDefault(f => templateFile.StartsWith(f.Extension.InstallPath, StringComparison.OrdinalIgnoreCase));

#if VSVER11 || VSVER12
            // In VS2012, vstemplates are loaded from cache not from toolkit installation path.
            if (toolkitInfo == null)
            {
                // Find the toolkit that contains the vstemplate, by TemplateID or Name
                if (File.Exists(templateFile))
                {
                    var template = VsTemplateFile.Read(templateFile);
                    if (template != null)
                    {
                        if (!String.IsNullOrEmpty(template.TemplateData.TemplateID))
                        {
                            toolkitInfo = patternManager.InstalledToolkits
                                .FirstOrDefault(it => it.Templates.Any(t => ((t.TemplateData.TemplateID != null) &&
                                (t.TemplateData.TemplateID.Equals(template.TemplateData.TemplateID, StringComparison.OrdinalIgnoreCase)))));
                        }
                        else
                        {
                            toolkitInfo = patternManager.InstalledToolkits
                                .FirstOrDefault(it => it.Templates.Any(t => ((t.TemplateData.Name != null) &&
                                (t.TemplateData.Name.Value.Equals(template.TemplateData.Name.Value, StringComparison.OrdinalIgnoreCase)))));
                        }
                    }
                }
            }
#endif

            if (toolkitInfo == null)
            {
                throw new InvalidOperationException(string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.InstantiationTemplateWizard_ToolkitInfoNotFound,
                    templateFile));
            }

            return toolkitInfo;
        }