GetService() public method

public GetService ( string service ) : Service
service string
return Service
Beispiel #1
0
        public Service GetService(int datacenter, string name)
        {
            Datacenter dc = this[datacenter];

            if (dc == null)
            {
                throw new KeyNotFoundException(String.Format(
                                                   CultureInfo.CurrentCulture,
                                                   Strings.DeploymentEnvironment_UnknownDatacenter,
                                                   datacenter));
            }
            return(dc.GetService(name));
        }
        protected async Task<AzureDefaults> LoadDefaultsFromAzure(Datacenter dc, string databaseConnectionString = null, string storageConnectionString = null)
        {
            bool expired = false;
            try
            {
                if (String.IsNullOrWhiteSpace(databaseConnectionString) ||
                    String.IsNullOrWhiteSpace(storageConnectionString))
                {
                    var config = await LoadServiceConfig(dc, dc.GetService("work"));

                    databaseConnectionString = databaseConnectionString ??
                        GetValueOrDefault(config, "Sql.Legacy");
                    storageConnectionString = storageConnectionString ??
                        GetValueOrDefault(config, "Storage.Legacy");
                }

                if (String.IsNullOrWhiteSpace(databaseConnectionString) ||
                    String.IsNullOrWhiteSpace(storageConnectionString))
                {
                    throw new InvalidOperationException(Strings.Command_MissingEnvironmentArguments);
                }

                await Console.WriteInfoLine(
                    Strings.Command_ConnectionInfo,
                    new SqlConnectionStringBuilder(databaseConnectionString).DataSource,
                    CloudStorageAccount.Parse(storageConnectionString).Credentials.AccountName);
            }
            catch (CloudException ex)
            {
                if (ex.ErrorCode == "AuthenticationFailed")
                {
                    expired = true;
                }
                else
                {
                    throw;
                }
            }

            if (expired)
            {
                await Console.WriteErrorLine(Strings.AzureCommandBase_TokenExpired);
                throw new OperationCanceledException();
            }

            return new AzureDefaults { DatabaseConnectionString = databaseConnectionString, StorageConnectionString = storageConnectionString };
        }