示例#1
0
 /// <summary>
 /// Throw exception if Service entities depend on other entities that are missing. Usable when business-validating data
 /// coming from configuration file.
 /// </summary>
 /// <param name="config">Service Host configuration container to validate</param>
 /// <exception cref="DependencyFailureException" />
 public void CheckServiceDependencies(ServiceHostConfiguration config)
 {
     foreach (var entity in config.Services)
     {
         CheckOtherServiceDependency(entity, config);
     }
 }
示例#2
0
 /// <summary>
 ///     This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     ServiceHost.Run(
         host =>
     {
         host.RegisterStatefulActorService <SubscriptionService, SubscriptionActor>("SubscriptionActor");
         host.ConfigureServices(
             services =>
         {
             services.AddSingleton <IDarcRemoteFactory, DarcRemoteFactory>();
             services.AddGitHubTokenProvider();
             services.AddSingleton(
                 provider => ServiceHostConfiguration.Get(
                     provider.GetRequiredService <IHostingEnvironment>()));
             services.AddDbContext <BuildAssetRegistryContext>(
                 (provider, options) =>
             {
                 var config = provider.GetRequiredService <IConfigurationRoot>();
                 options.UseSqlServer(config.GetSection("BuildAssetRegistry")["ConnectionString"]);
             });
             services.Configure <GitHubTokenProviderOptions>(
                 (options, provider) =>
             {
                 var config = provider.GetRequiredService <IConfigurationRoot>();
                 IConfigurationSection section = config.GetSection("GitHub");
                 section.Bind(options);
                 options.ApplicationName    = "Maestro";
                 options.ApplicationVersion = Assembly.GetEntryAssembly()
                                              .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                              ?.InformationalVersion;
             });
         });
     });
 }
示例#3
0
        /// <summary>
        ///     This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            ServiceHost.Run(
                host =>
            {
                host.RegisterStatefulActorService <SubscriptionActor>("SubscriptionActor");
                host.RegisterStatefulActorService <PullRequestActor>("PullRequestActor");
                host.ConfigureContainer(
                    builder =>
                {
                    builder.AddServiceFabricActor <IPullRequestActor>();
                    builder.AddServiceFabricActor <ISubscriptionActor>();
                });
                host.ConfigureServices(
                    services =>
                {
                    services.AddSingleton <IActionRunner, ActionRunner>();
                    services.AddSingleton <IMergePolicyEvaluator, MergePolicyEvaluator>();
                    services.AddSingleton <IRemoteFactory, DarcRemoteFactory>();
                    services.AddGitHubTokenProvider();
                    services.AddAzureDevOpsTokenProvider();
                    // We do not use AddMemoryCache here. We use our own cache because we wish to
                    // use a sized cache and some components, such as EFCore, do not implement their caching
                    // in such a way that will work with sizing.
                    services.AddSingleton <DarcRemoteMemoryCache>();
                    services.AddSingleton(
                        provider => ServiceHostConfiguration.Get(
                            provider.GetRequiredService <IHostingEnvironment>()));
                    services.AddDbContext <BuildAssetRegistryContext>(
                        (provider, options) =>
                    {
                        var config = provider.GetRequiredService <IConfigurationRoot>();
                        options.UseSqlServer(config.GetSection("BuildAssetRegistry")["ConnectionString"]);
                    });
                    services.Configure <GitHubTokenProviderOptions>(
                        (options, provider) =>
                    {
                        var config = provider.GetRequiredService <IConfigurationRoot>();
                        IConfigurationSection section = config.GetSection("GitHub");
                        section.Bind(options);
                        options.ApplicationName    = "Maestro";
                        options.ApplicationVersion = Assembly.GetEntryAssembly()
                                                     .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                                     ?.InformationalVersion;
                    });
                    services.Configure <AzureDevOpsTokenProviderOptions>(
                        (options, provider) =>
                    {
                        var config   = provider.GetRequiredService <IConfigurationRoot>();
                        var tokenMap = config.GetSection("AzureDevOps:Tokens").GetChildren();
                        foreach (IConfigurationSection token in tokenMap)
                        {
                            options.Tokens.Add(token.GetValue <string>("Account"), token.GetValue <string>("Token"));
                        }
                    });

                    services.AddMergePolicies();
                });
            });
        }
示例#4
0
        public void LoadFromFile(string fileName)
        {
            try
            {
                settings = facadeImpl.LoadConfigurationFromFile(fileName);

                new DependencyValidator(facadeImpl).CheckServiceDependencies(settings);

                facadeImpl.ResetConnection();
                ShowPage("General");
                view.SetServiceNodesAndRedraw(uiFactory.GetCoreServiceNames(settings), uiFactory.GetCustomServiceNames(settings));
                view.SetCoreServiceNodesEnabled(false);
                currentFileNameValue = fileName;
            }
            catch (InvalidFilenameException ex)
            {
                view.ShowErrorMessage(ex.Message);
            }
            catch (DependencyFailureException)
            {
                settings = facadeImpl.CreateConfiguration();
                view.SetServiceNodesAndRedraw(null, null);
                view.ShowErrorMessage(Resources.ServiceDependenciesInFileInvalid);
            }
        }
示例#5
0
 /// <summary>
 ///     This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     ServiceHost.Run(
         host =>
     {
         host.RegisterStatelessService <AzureDevOpsTimeline>("AzureDevOpsTimelineType");
         host.ConfigureServices(
             services =>
         {
             services.AddSingleton(
                 provider => ServiceHostConfiguration.Get(
                     provider.GetRequiredService <IHostingEnvironment>()));
             services.Configure <AzureDevOpsTimelineOptions>((o, p) =>
             {
                 var c = p.GetRequiredService <IConfigurationRoot>();
                 o.AzureDevOpsAccessToken      = c["AzureDevOpsAccessToken"];
                 o.AzureDevOpsProjects         = c["AzureDevOpsProjects"];
                 o.AzureDevOpsOrganization     = c["AzureDevOpsOrganization"];
                 o.AzureDevOpsUrl              = c["AzureDevOpsUrl"];
                 o.KustoQueryConnectionString  = c["KustoQueryConnectionString"];
                 o.KustoIngestConnectionString = c["KustoIngestConnectionString"];
                 o.KustoDatabase    = c["KustoDatabase"];
                 o.ParallelRequests = c["ParallelRequests"];
                 o.InitialDelay     = c["InitialDelay"];
                 o.Interval         = c["Interval"];
                 o.BuildBatchSize   = c["BuildBatchSize"];
             });
         });
     });
 }
        public object ResolveModel(string pageKey, ServiceHostConfiguration parentModel)
        {
            var state = mappings[pageKey];

            if (pageKey == "General")
            {
                return(parentModel);
            }

            return(parentModel[state.EntityType]);
        }
示例#7
0
        /// <summary>
        /// Throw exception if entity depends on other entity that is missing.
        /// </summary>
        /// <param name="entity">entity to validate</param>
        /// <param name="config">Service Host configuration container</param>
        /// <exception cref="DependencyFailureException" />
        public void CheckOtherServiceDependency(BaseServiceEntity entity, ServiceHostConfiguration config)
        {
            var attributes = entity.GetType().GetCustomAttributes(typeof(DependsOnServiceAttribute), false);

            if (attributes.Length < 1)
            {
                return;
            }

            foreach (var attribute in attributes.Cast <DependsOnServiceAttribute>().Where(attribute => config[attribute.ServiceType] == null))
            {
                throw new DependencyFailureException(attribute.ServiceType, "Service dependency does not exist");
            }
        }
        /// <summary>
        /// Enumerate custom service nodes
        /// </summary>
        /// <param name="config">Settings container</param>
        public IEnumerable <string> GetCustomServiceNames(ServiceHostConfiguration config)
        {
            IList <string> names = new List <string>();

            foreach (var mapping in mappings)
            {
                var entity = config[mapping.Value.EntityType];

                if (entity != null && mapping.Value.Group == ServicesGroup.Custom)
                {
                    names.Add(mapping.Key);
                }
            }

            return(names);
        }
示例#9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (HostingEnvironment.IsDevelopment())
            {
                services.AddDataProtection();
            }
            else
            {
                IConfigurationSection dpConfig = Configuration.GetSection("DataProtection");
                services.AddDataProtection()
                .PersistKeysToAzureBlobStorage(new Uri(dpConfig["KeyFileUri"]))
                .ProtectKeysWithAzureKeyVault(ServiceHostConfiguration.GetKeyVaultClient(null), dpConfig["KeyIdentifier"]);
            }

            ConfigureApiServices(services);

            services.Configure <CookiePolicyOptions>(
                options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <BuildAssetRegistryContext>(
                options =>
            {
                options.UseSqlServer(Configuration.GetSection("BuildAssetRegistry")["ConnectionString"]);
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining <Startup>())
            .AddRazorPagesOptions(
                options =>
            {
                options.Conventions.AuthorizeFolder("/");
                options.Conventions.AllowAnonymousToPage("/Index");
            });

            ConfigureAuthServices(services);

            services.AddSingleton <BackgroundQueue>();
            services.AddSingleton <IHostedService>(provider => provider.GetRequiredService <BackgroundQueue>());

            services.AddServiceFabricService <IDependencyUpdater>("fabric:/MaestroApplication/DependencyUpdater");
        }
示例#10
0
 /// <summary>
 ///     This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     ServiceHost.Run(
         host =>
     {
         host.RegisterStatefulService <ReleasePipelineRunner>("ReleasePipelineRunnerType");
         host.ConfigureContainer(builder => { builder.AddServiceFabricService <IDependencyUpdater>("fabric:/MaestroApplication/DependencyUpdater"); });
         host.ConfigureServices(
             services =>
         {
             services.AddSingleton(
                 provider => ServiceHostConfiguration.Get(
                     provider.GetRequiredService <IHostingEnvironment>()));
             services.AddDbContext <BuildAssetRegistryContext>(
                 (provider, options) =>
             {
                 var config = provider.GetRequiredService <IConfigurationRoot>();
                 options.UseSqlServer(config.GetSection("BuildAssetRegistry")["ConnectionString"]);
             });
             services.AddAzureDevOpsTokenProvider();
             services.Configure <AzureDevOpsTokenProviderOptions>(
                 (options, provider) =>
             {
                 var config   = provider.GetRequiredService <IConfigurationRoot>();
                 var tokenMap = config.GetSection("AzureDevOps:Tokens").GetChildren();
                 foreach (IConfigurationSection token in tokenMap)
                 {
                     options.Tokens.Add(token.GetValue <string>("Account"), token.GetValue <string>("Token"));
                 }
             });
             services.AddGitHubTokenProvider();
             services.Configure <GitHubTokenProviderOptions>(
                 (options, provider) =>
             {
                 var config = provider.GetRequiredService <IConfigurationRoot>();
                 IConfigurationSection section = config.GetSection("GitHub");
                 section.Bind(options);
                 options.ApplicationName    = "Maestro";
                 options.ApplicationVersion = Assembly.GetEntryAssembly()
                                              .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                              ?.InformationalVersion;
             });
         });
     });
 }
        /// <summary>
        /// Dump settings XML to file.
        /// </summary>
        /// <param name="settings">Configuration entity</param>
        /// <param name="fileName">Path to output file</param>
        // TODO decide on whether throwing exception when validation fails lets us get better code
        public ConfigurationValidationResult SaveConfigurationToFile(ServiceHostConfiguration settings, string fileName)
        {
            var validationResult = ValidateConfiguration(settings);

            if (!validationResult.IsValid)
            {
                return(validationResult);
            }

            try {
                serializer.Serialize(settings.Services);
                serializer.SaveToFile(fileName);
            } catch (Exception ex) {
                ProcessException("Failed to flush data to file", ex);
            }

            return(validationResult);
        }
示例#12
0
        public void AddTestServiceMappingIfRequired(ServiceHostConfiguration config, TestPublishProjectMapping mapping)
        {
            //foreach (var entity in config.Services)
            //{
            //    if (!(entity is QCServiceEntity))
            //    {
            //        continue;
            //    }

            //    var qcEntity = (QCServiceEntity)entity;

            //    if (qcEntity.Projects.Any(qcProject => string.Equals(qcProject.Id, mapping.DestinationProject)))
            //    {
            //        return;
            //    }

            //    var newProject = new QCProject { Id = mapping.DestinationProject, VersionOneProject = mapping.Name };
            //    qcEntity.Projects.Add(newProject);
            //}
        }
        /// <summary>
        /// Create UI page, usually to configure a single service
        /// </summary>
        /// <param name="pageKey">Page key, the same as in <see cref="mappings"/></param>
        /// <param name="model">Settings container</param>
        /// <param name="formController">Reference to form controller</param>
        /// <returns>Representation of a configuration page</returns>
        public Control GetNextPage(string pageKey, ServiceHostConfiguration model, IFormController formController)
        {
            if (currentController != null)
            {
                currentController.UnregisterFormController(formController);
            }

            var stateDef      = RequestStateDef(pageKey);
            var modelResolved = ResolveModel(pageKey, model);

            var view       = Activator.CreateInstance(stateDef.ViewType);
            var controller = (IPageController)Activator.CreateInstance(stateDef.ControllerType, new[] { modelResolved, Facade.Instance });

            currentController = controller;

            controller.RegisterView(view);
            controller.RegisterFormController(formController);
            controller.PrepareView();

            return((Control)view);
        }
示例#14
0
 /// <summary>
 ///     This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     ServiceHost.Run(
         host =>
     {
         host.RegisterStatefulService <DependencyUpdater>("DependencyUpdaterType");
         host.ConfigureContainer(builder => { builder.AddServiceFabricActor <ISubscriptionActor>(); });
         host.ConfigureServices(
             services =>
         {
             services.AddSingleton(
                 provider => ServiceHostConfiguration.Get(
                     provider.GetRequiredService <IHostingEnvironment>()));
             services.AddDbContext <BuildAssetRegistryContext>(
                 (provider, options) =>
             {
                 var config = provider.GetRequiredService <IConfigurationRoot>();
                 options.UseSqlServer(config.GetSection("BuildAssetRegistry")["ConnectionString"]);
             });
         });
     });
 }
        /// <summary>
        /// Validate service configurations
        /// </summary>
        /// <param name="config">Settings to validate</param>
        /// <returns>Validation result</returns>
        public ConfigurationValidationResult ValidateConfiguration(ServiceHostConfiguration config)
        {
            var result        = new ConfigurationValidationResult();
            var configResults = ValidateEntity(config);

            foreach (var configResult in configResults)
            {
                result.AddError(configResult.Message);
            }

            foreach (var entity in config.Services)
            {
                var results = ValidateEntity(entity);

                if (!results.IsValid)
                {
                    var messages = results.Select(x => x.Message).ToList();
                    result.AddEntity(entity, messages);
                }
            }

            return(result);
        }
示例#16
0
 public Startup(IHostingEnvironment env)
 {
     HostingEnvironment = env;
     Configuration      = ServiceHostConfiguration.Get(env);
 }
示例#17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (HostingEnvironment.IsDevelopment())
            {
                services.AddDataProtection()
                .SetDefaultKeyLifetime(LoginCookieLifetime * 2);
            }
            else
            {
                IConfigurationSection dpConfig = Configuration.GetSection("DataProtection");

                string         vaultUri = Configuration["KeyVaultUri"];
                string         keyVaultKeyIdentifierName = dpConfig["KeyIdentifier"];
                KeyVaultClient kvClient = ServiceHostConfiguration.GetKeyVaultClient(HostingEnvironment);
                KeyBundle      key      = kvClient.GetKeyAsync(vaultUri, keyVaultKeyIdentifierName).GetAwaiter().GetResult();
                services.AddDataProtection()
                .PersistKeysToAzureBlobStorage(new Uri(dpConfig["KeyFileUri"]))
                .ProtectKeysWithAzureKeyVault(kvClient, key.KeyIdentifier.ToString())
                .SetDefaultKeyLifetime(LoginCookieLifetime * 2)
                .SetApplicationName(typeof(Startup).FullName);
            }

            ConfigureApiServices(services);

            services.Configure <CookiePolicyOptions>(
                options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <BuildAssetRegistryContext>(
                options =>
            {
                options.UseSqlServer(Configuration.GetSection("BuildAssetRegistry")["ConnectionString"]);
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFluentValidation(options => options.RegisterValidatorsFromAssemblyContaining <Startup>())
            .AddRazorPagesOptions(
                options =>
            {
                options.Conventions.AuthorizeFolder("/", MsftAuthorizationPolicyName);
                options.Conventions.AllowAnonymousToPage("/Index");
                options.Conventions.AllowAnonymousToPage("/Error");
                options.Conventions.AllowAnonymousToPage("/SwaggerUi");
            })
            .AddGitHubWebHooks()
            .AddApiPagination()
            .AddCookieTempDataProvider(
                options =>
            {
                // Cookie Policy will not send this cookie unless we mark it as Essential
                // The application will not function without this cookie.
                options.Cookie.IsEssential = true;
            });

            services.AddSingleton <IConfiguration>(Configuration);

            ConfigureAuthServices(services);

            services.AddSingleton <BackgroundQueue>();
            services.AddSingleton <IHostedService>(provider => provider.GetRequiredService <BackgroundQueue>());

            services.AddServiceFabricService <IDependencyUpdater>("fabric:/MaestroApplication/DependencyUpdater");
            services.AddServiceFabricService <IReleasePipelineRunner>("fabric:/MaestroApplication/ReleasePipelineRunner");

            services.AddGitHubTokenProvider();
            services.Configure <GitHubTokenProviderOptions>(
                (options, provider) =>
            {
                IConfigurationSection section = Configuration.GetSection("GitHub");
                section.Bind(options);
                options.ApplicationName    = "Maestro";
                options.ApplicationVersion = Assembly.GetEntryAssembly()
                                             .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                             ?.InformationalVersion;
            });
            services.AddAzureDevOpsTokenProvider();
            services.Configure <AzureDevOpsTokenProviderOptions>(
                (options, provider) =>
            {
                var config   = provider.GetRequiredService <IConfiguration>();
                var tokenMap = config.GetSection("AzureDevOps:Tokens").GetChildren();
                foreach (IConfigurationSection token in tokenMap)
                {
                    options.Tokens.Add(token.GetValue <string>("Account"), token.GetValue <string>("Token"));
                }
            });

            services.AddMergePolicies();
        }
 public ConfigurationFormController(IFacade facade, IUIFactory uiFactory)
 {
     facadeImpl     = facade;
     this.uiFactory = uiFactory;
     settings       = facade.CreateConfiguration();
 }
示例#19
0
        /// <summary>
        /// Launches Initialization of the VMLogConfig
        /// </summary>
        public void Initialize()
        {
            _services.Clear();
            FillFromDiscoverer( _services );

            LogEntriesContainer.MaxCount = Config.User.GetOrSet( OUTPUT_MAX_COUNT, 100 );
            DoLog = Config.User.GetOrSet( GLOBAL_LOGS, true );

            _hostConfiguration = new ServiceHostConfiguration( this );
            _pluginRunner = _vmiContext.Context.GetService<PluginRunner>( true );
            _vmiContext.Context.PluginRunner.ServiceHost.Add( _hostConfiguration );

            Apply();

            if( _logService != null ) //The service is set as "Optional TryStart", prevent any null ref exception
                _logService.LogTriggered += new LogTriggeredEventHandler( OnLogTriggered );
        }