public static bool TryParse(string connectionString, out AzureConnectionString obj)
        {
            if (connectionString.Equals("development", StringComparison.OrdinalIgnoreCase))
            {
                obj = DevelopmentConnection;
                return(true);
            }

            obj = null;
            var splits = connectionString.Split(';', StringSplitOptions.RemoveEmptyEntries);

            if (splits.Length < 2 || splits.Length > 4)
            {
                return(false);
            }

            string protocol = "https", account = null, key = null, suffix = "core.windows.net";

            foreach (var split in splits)
            {
                if (split.StartsWith("DefaultEndpointsProtocol=", StringComparison.OrdinalIgnoreCase))
                {
                    protocol = split.Substring(25);
                }
                else if (split.StartsWith("AccountName=", StringComparison.OrdinalIgnoreCase))
                {
                    account = split.Substring(12);
                }
                else if (split.StartsWith("AccountKey=", StringComparison.OrdinalIgnoreCase))
                {
                    key = split.Substring(11);
                }
                else if (split.StartsWith("EndpointSuffix=", StringComparison.OrdinalIgnoreCase))
                {
                    suffix = split.Substring(15);
                }
            }

            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(key))
            {
                return(false);
            }

            obj = new AzureConnectionString
            {
                EndpointsProtocol = protocol,
                AccountName       = account,
                AccountKey        = key,
                EndpointSuffix    = suffix
            };

            return(true);
        }
Exemplo n.º 2
0
 public BackupRemote(string name, string baseFolder, AzureConnectionString connectionString)
 {
     Name             = name ?? throw new ArgumentNullException(nameof(name));
     BaseFolder       = baseFolder ?? throw new ArgumentNullException(nameof(baseFolder));
     ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
 }