/// <summary>
        /// <para>Part of the WebHost extension method pipeline. Calls the Entity Framework Core Migrate() method for the WebHost.</para>
        /// <para>Demonstrates the use of the `using` statement with a context provided by the .NET Core DI container.</para>
        /// </summary>
        public static async Task <IHost> CreateOrMigrateDatabase(this IHost webhost)
        {
            using (var serviceScope = webhost.Services.CreateScope())
            {
                var tenantService = serviceScope.ServiceProvider.GetService <ITenantService>();
                var tenants       = tenantService.GetAllTenants();

                foreach (var tenant in tenants)
                {
                    var factory         = serviceScope.ServiceProvider.GetService <IDatabaseFactory>();
                    var macheteContext  = factory.Get(tenant);
                    var readonlyBuilder = new SqlConnectionStringBuilder(tenant.ReadOnlyConnectionString);

                    await macheteContext.Database.MigrateAsync();

                    MacheteConfiguration.Seed(macheteContext, tenant.Timezone);
                    StartupConfiguration.AddDBReadOnlyUser(macheteContext, readonlyBuilder.Password);
                    await MacheteConfiguration.SeedAsync(macheteContext);

                    // populate static variables
                    var lookupServiceHelper = new LookupServiceHelper(macheteContext);
                    lookupServiceHelper.PopulateStaticIds();
                }
            }

            return(webhost);
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Console.WriteLine("\nListing all tags on the vCenter Server ...");
            Tag taggingService =
                vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig);
            List <string> tagList = taggingService.List();

            if (!tagList.Any())
            {
                Console.WriteLine("\nNo tags found !");
            }
            else
            {
                Console.WriteLine("\nTag Name\tTag Description");
                foreach (string tagId in tagList)
                {
                    Console.WriteLine(
                        taggingService.Get(tagId).GetName()
                        + "\t" + taggingService.Get(tagId).GetDescription());
                }
            }
            vapiAuthHelper.Logout();
        }
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Datacenter datacenterService =
                vapiAuthHelper.StubFactory.CreateStub <Datacenter>(
                    sessionStubConfig);
            List <DatacenterTypes.Summary> dcList =
                datacenterService.List(new DatacenterTypes.FilterSpec());

            Console.WriteLine("\nList of datacenters on the vcenter server:");
            foreach (DatacenterTypes.Summary dcSummary in dcList)
            {
                Console.WriteLine(dcSummary);
            }
            vapiAuthHelper.Logout();
        }