Esempio n. 1
0
        /// <summary>
        /// Initialization of the package; this method is called right
        /// after the package is sited, so this is the place where you
        /// can put all the initialization code that rely on services
        /// provided by VisualStudio.
        /// </summary>
        ///
        /// <param name="cancellationToken">
        /// A cancellation token to monitor
        /// for initialization cancellation,
        /// which can occur when VS is
        /// shutting down.
        /// </param>
        ///
        /// <param name="progress">
        /// A provider for progress updates.
        /// </param>
        ///
        /// <returns>
        /// A task representing the async work of package initialization,
        /// or an already completed task if there is none. Do not return
        /// null from this method.
        /// </returns>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            OleMenuCommandService oleMenuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            IVsSolution vsSolution = await GetServiceAsync(typeof(IVsSolution)) as IVsSolution;

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            IMessageProvider messageProvider = new VsixMessageProvider(vsSolution, new ErrorListProvider(this));
            IProjectProvider projectProvider = new VsixProjectProvider();

            RegisterService(messageProvider);
            RegisterService(projectProvider);

            IOptionProvider optionProvider = new OptionProvider(messageProvider);

            RegisterService(optionProvider);

            VsixPackageOption vsixPackageOption = ((VsixPackageOption)GetDialogPage(typeof(VsixPackageOption)));

            AbstractSwitch projectSwtich = new ProjectSwitch(ReferenceType.ProjectReference, vsixPackageOption, projectProvider, messageProvider);
            AbstractSwitch packageSwitch = new PackageSwitch(ReferenceType.PackageReference, vsixPackageOption, projectProvider, messageProvider);
            AbstractSwitch librarySwitch = new LibrarySwitch(ReferenceType.Reference, vsixPackageOption, projectProvider, messageProvider);

            ICommandProvider commandRouter = new CommandProvider(vsixPackageOption, projectSwtich, packageSwitch, librarySwitch);

            new CommandProject(commandRouter, messageProvider).Initialize(oleMenuCommandService, new Guid("c6018e68-fcab-41d2-a34a-42f7df92b162"), 0x0100);
            new CommandPackage(commandRouter, messageProvider).Initialize(oleMenuCommandService, new Guid("c6018e68-fcab-41d2-a34a-42f7df92b162"), 0x0200);
            new CommandLibrary(commandRouter, messageProvider).Initialize(oleMenuCommandService, new Guid("c6018e68-fcab-41d2-a34a-42f7df92b162"), 0x0300);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var applicationId  = "3E37AC18-A00F-47A5-B84E-C79E0823F6D4";
            var application2Id = "6A302E7D-05E9-4188-9612-4A2920E5C1AE";

            // Add framework services.
            services.AddMvc();
            services.AddConfigServer()
            .UseConfigSet <SampleConfigSet>()
            .UseInMemoryProvider()
            .UseLocalConfigServerClient(applicationId)
            .WithConfig <SampleConfig>();
            services.AddTransient <IOptionProvider, OptionProvider>();

            var optionProvider = new OptionProvider();
            var config         = new SampleConfig
            {
                LlamaCapacity = 23,
                Name          = "Name",
                Decimal       = 23.47m,
                StartDate     = new DateTime(2013, 10, 10),
                IsLlamaFarmer = false,
                Option        = optionProvider.GetOptions().First(),
                MoarOptions   = optionProvider.GetOptions().Take(2).ToList(),
                ListOfConfigs = new List <ListConfig>
                {
                    new ListConfig {
                        Name = "Value One", Value = 1
                    },
                    new ListConfig {
                        Name = "Value Two", Value = 2
                    }
                }
            };
            var config2 = new SampleConfig
            {
                LlamaCapacity = 41,
                Name          = "Name 2",
                Decimal       = 41.47m,
                StartDate     = new DateTime(2013, 11, 11),
                IsLlamaFarmer = true,
                Option        = optionProvider.GetOptions().First(),
                MoarOptions   = optionProvider.GetOptions().Take(2).ToList(),
            };
            var serviceProvider = services.BuildServiceProvider();
            var configRepo      = serviceProvider.GetService <IConfigRepository>();

            configRepo.UpdateClientAsync(new ConfigurationClient {
                ClientId = applicationId, Name = "Mvc App", Description = "Embeded Application"
            }).Wait();
            configRepo.UpdateClientAsync(new ConfigurationClient {
                ClientId = application2Id, Name = "Mvc App 2", Description = "Second Application"
            }).Wait();

            configRepo.UpdateConfigAsync(new ConfigInstance <SampleConfig>(config, applicationId)).Wait();
            configRepo.UpdateConfigAsync(new ConfigInstance <SampleConfig>(config2, application2Id)).Wait();
        }
        public void CanBuildModelDefinition_ThatCanReturnOptions()
        {
            var optionProvider = new OptionProvider();
            var expected       = optionProvider.Get().ToList();

            target.PropertyWithOptions(x => x.OptionProperty, (OptionProvider provider) => provider.Get(), option => option.IntKey, option => option.DisplayValue);
            var result  = GetPropertyWithOption(target.Build()).BuildOptionSet(mockServiceProvider.Object);
            var options = result.OptionSelections.ToList();

            Assert.Equal(expected.Count, options.Count);
            Assert.Equal(expected.Single(s => s.IntKey == 2).DisplayValue, options.Single(s => s.Key == 2.ToString()).DisplayValue);
        }
        public void CanBuildModelDefinition_ThatCanReturnOptionByKey_IfExists()
        {
            var optionProvider = new OptionProvider();
            var expected       = optionProvider.Get().ToList();

            target.PropertyWithOptions(x => x.OptionProperty, (OptionProvider provider) => provider.Get(), opt => opt.IntKey, opt => opt.DisplayValue);
            var    result = GetPropertyWithOption(target.Build()).BuildOptionSet(mockServiceProvider.Object);
            object output;
            var    option = result.TryGetValue(2.ToString(), out output);

            Assert.True(option);
            var outputAsOption = output as OptionTestClass;

            Assert.NotNull(outputAsOption);
            Assert.Equal(expected.Single(s => s.IntKey == 2).DisplayValue, outputAsOption.DisplayValue);
        }
Esempio n. 5
0
        /// <summary>
        /// Iterates through the dependencies provided in the lock file and matches
        /// against items found in the directories listed in the configuration file.
        /// For each matched item, the passed delegate is executed.
        /// </summary>
        ///
        /// <exception cref="SwitcherFileNotFoundException"/>
        ///
        /// <exception cref="FileNotFoundException"/>
        ///
        /// <exception cref="ArgumentException">
        protected virtual void IterateAndExecute(IEnumerable <IProjectReference> references, Action <IProjectReference, LockFileTargetLibrary, string> func)
        {
            MessageProvider.Clear();

            ReadOnlyDictionary <string, string> items = OptionProvider.GetIncludeItems(Type);

            foreach (IProjectReference reference in references)
            {
                foreach (LockFileTargetLibrary library in GetProjectTarget(reference).Libraries)
                {
                    if (items.TryGetValue(library.Name, out string absolutePath))
                    {
                        func(reference, library, absolutePath);
                    }
                }

                reference.Save();
            }
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var applicationId  = "3E37AC18-A00F-47A5-B84E-C79E0823F6D4";
            var application2Id = "6A302E7D-05E9-4188-9612-4A2920E5C1AE";

            services.AddMvc();
            // Add framework services.
            services.AddConfigServer()
            .UseConfigSet <SampleConfigSet>()
            .UseInMemoryProvider();
            services.AddTransient <IOptionProvider, OptionProvider>();
            var options1 = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One", Value = 2.4
                },
                new OptionFromConfigSet {
                    Id = 2, Description = "Two", Value = 12.4
                }
            };
            var options2 = new List <OptionFromConfigSet>
            {
                new OptionFromConfigSet {
                    Id = 1, Description = "One", Value = 24.4
                },
                new OptionFromConfigSet {
                    Id = 2, Description = "Two", Value = 12.4
                }
            };
            var optionProvider = new OptionProvider();
            var config         = new SampleConfig
            {
                LlamaCapacity = 23,
                Name          = "Name",
                Decimal       = 23.47m,
                StartDate     = new DateTime(2013, 10, 10),
                IsLlamaFarmer = false,
                Option        = optionProvider.GetOptions().First(),
                OptionId      = optionProvider.GetOptions().First().Id,
                MoarOptions   = optionProvider.GetOptions().Take(2).ToList(),
                ListOfConfigs = new List <ListConfig>
                {
                    new ListConfig {
                        Name = "Value One", Value = 1
                    },
                    new ListConfig {
                        Name = "Value Two", Value = 2
                    }
                },
                OptionFromConfigSet     = options1[1],
                MoarOptionFromConfigSet = new List <OptionFromConfigSet> {
                    options1[0]
                },
                MoarOptionValues = optionProvider.GetOptions().Select(s => s.Id).Where(w => w % 2 == 0).ToList()
            };
            var config2 = new SampleConfig
            {
                LlamaCapacity           = 41,
                Name                    = "Name 2",
                Decimal                 = 41.47m,
                StartDate               = new DateTime(2013, 11, 11),
                Choice                  = Choice.OptionThree,
                IsLlamaFarmer           = true,
                Option                  = optionProvider.GetOptions().First(),
                OptionId                = optionProvider.GetOptions().First().Id,
                MoarOptions             = optionProvider.GetOptions().Take(2).ToList(),
                OptionFromConfigSet     = options2[0],
                MoarOptionFromConfigSet = new List <OptionFromConfigSet> {
                    options2[0], options2[1]
                },
                MoarOptionValues = new List <int> {
                    optionProvider.GetOptions().First().Id
                }
            };
            var serviceProvider = services.BuildServiceProvider();
            var configRepo      = serviceProvider.GetService <IConfigRepository>();

            configRepo.UpdateClientAsync(new ConfigurationClient {
                ClientId = applicationId, Name = "Mvc App Live", Group = "My app", Enviroment = "Live", Description = "Embeded Application"
            }).Wait();
            configRepo.UpdateClientAsync(new ConfigurationClient {
                ClientId = application2Id, Name = "Mvc App Test", Group = "My app", Enviroment = "UAT", Description = "Second Application"
            }).Wait();
            configRepo.UpdateConfigAsync(new ConfigCollectionInstance <OptionFromConfigSet>(options1, applicationId)).Wait();
            configRepo.UpdateConfigAsync(new ConfigCollectionInstance <OptionFromConfigSet>(options2, application2Id)).Wait();
            configRepo.UpdateConfigAsync(new ConfigInstance <SampleConfig>(config, applicationId)).Wait();
            configRepo.UpdateConfigAsync(new ConfigInstance <SampleConfig>(config2, application2Id)).Wait();
        }