コード例 #1
0
        /// <summary>
        /// This is called by Restore Service to and it stores the storage details along with the policy details in the reliable dictionary
        /// </summary>
        /// <param name="policies"></param>
        /// <param name="primaryClusterConnectionString"></param>
        /// <returns></returns>
        public async Task <bool> PostStorageDetails(List <PolicyStorageEntity> policies, string primaryClusterConnectionString)
        {
            IReliableDictionary <string, BackupStorage> myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, BackupStorage> >("storageDictionary");

            foreach (var entity in policies)
            {
                BackupStorage backupStorage = await GetStorageInfo(entity.policy, primaryClusterConnectionString);

                if (backupStorage != null && entity.backupStorage != null)
                {
                    backupStorage.connectionString  = entity.backupStorage.connectionString;
                    backupStorage.primaryUsername   = entity.backupStorage.primaryUsername;
                    backupStorage.primaryPassword   = entity.backupStorage.primaryPassword;
                    backupStorage.secondaryUsername = entity.backupStorage.secondaryUsername;
                    backupStorage.secondaryPassword = entity.backupStorage.secondaryPassword;
                    backupStorage.friendlyname      = entity.backupStorage.friendlyname;
                }
                else
                {
                    return(false);
                }
                using (var tx = this.StateManager.CreateTransaction())
                {
                    var result = await myDictionary.TryAddAsync(tx, entity.policy, backupStorage);

                    ServiceEventSource.Current.ServiceMessage(this.Context, result ? "Successfully added policy {0} storgae details" : "Already Exists", entity.policy);

                    // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are
                    // discarded, and nothing is saved to the secondary replicas.
                    await tx.CommitAsync();
                }
            }
            return(true);
        }
コード例 #2
0
        public async Task <BackupStorage> GetStorageInfo(string policy, string primaryClusterConnectionString)
        {
            string     URL           = "http://" + primaryClusterConnectionString + "/BackupRestore/BackupPolicies/" + policy;
            string     urlParameters = "?api-version=6.2-preview";
            HttpClient client        = new HttpClient();

            client.BaseAddress = new Uri(URL);
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync(urlParameters);

            if (response.IsSuccessStatusCode)
            {
                var           content       = response.Content.ReadAsAsync <JObject>().Result;
                JObject       objectData    = (JObject)content["Storage"];
                BackupStorage backupStorage = JsonConvert.DeserializeObject <BackupStorage>(objectData.ToString());
                return(backupStorage);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                return(null);
            }
        }
コード例 #3
0
        public async Task PostStorageDetails(string backupPolicy, BackupStorage backupStorage)
        {
            IReliableDictionary <string, BackupStorage> myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, BackupStorage> >("storageDictionary");

            using (var tx = this.StateManager.CreateTransaction())
            {
                var result = await myDictionary.TryAddAsync(tx, backupPolicy, backupStorage);

                ServiceEventSource.Current.ServiceMessage(this.Context, result ? "Successfully added policy {0} storgae details" : "Already Exists", backupPolicy);

                // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are
                // discarded, and nothing is saved to the secondary replicas.
                await tx.CommitAsync();
            }
        }
コード例 #4
0
        public BackupStorage DeepCopy()
        {
            BackupStorage newBackupStorage = (BackupStorage)this.MemberwiseClone();

            if (connectionString != null)
            {
                newBackupStorage.connectionString = String.Copy(connectionString);
            }
            if (containerName != null)
            {
                newBackupStorage.containerName = String.Copy(containerName);
            }
            if (friendlyname != null)
            {
                newBackupStorage.friendlyname = String.Copy(friendlyname);
            }
            if (path != null)
            {
                newBackupStorage.path = String.Copy(path);
            }
            if (primaryPassword != null)
            {
                newBackupStorage.primaryPassword = String.Copy(primaryPassword);
            }
            if (primaryUsername != null)
            {
                newBackupStorage.primaryUsername = String.Copy(primaryUsername);
            }
            if (secondaryPassword != null)
            {
                newBackupStorage.secondaryPassword = String.Copy(secondaryPassword);
            }
            if (secondaryUsername != null)
            {
                newBackupStorage.secondaryUsername = String.Copy(secondaryUsername);
            }
            if (StorageKind != null)
            {
                newBackupStorage.StorageKind = String.Copy(StorageKind);
            }
            return(newBackupStorage);
        }
コード例 #5
0
        public async Task <BackupStorage> GetStorageInfo(string policy, string primaryClusterConnectionString, string clusterThumbprint)
        {
            string URL           = primaryClusterConnectionString + "/";
            string URLParameters = "BackupRestore/BackupPolicies/" + policy + "?api-version=6.4";

            HttpResponseMessage response = await Utility.HTTPGetAsync(URL, URLParameters, clusterThumbprint);

            if (response.IsSuccessStatusCode)
            {
                // Parse the response body. Blocking!
                var           content       = response.Content.ReadAsAsync <JObject>().Result;
                JObject       objectData    = (JObject)content["Storage"];
                BackupStorage backupStorage = JsonConvert.DeserializeObject <BackupStorage>(objectData.ToString());
                return(backupStorage);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                return(null);
            }
        }
コード例 #6
0
        /// <summary>
        /// This returns the storage details for the policy specified
        /// </summary>
        /// <param name="policy"></param>
        /// <returns></returns>
        public async Task <BackupStorage> GetPolicyStorageDetails(String policy)
        {
            IReliableDictionary <string, BackupStorage> myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, BackupStorage> >("storageDictionary");

            using (ITransaction tx = this.StateManager.CreateTransaction())
            {
                ConditionalValue <BackupStorage> backupStorage = await myDictionary.TryGetValueAsync(tx, policy);

                if (backupStorage.HasValue)
                {
                    BackupStorage bstorage           = backupStorage.Value;
                    BackupStorage exportableBstorage = bstorage.DeepCopy();
                    exportableBstorage.Decrypt();
                    return(exportableBstorage);
                }
                else
                {
                    ServiceEventSource.Current.ServiceMessage(this.Context, "Policy not found");
                    return(null);
                }
            }
        }
コード例 #7
0
        public async Task <BackupStorage> GetStorageInfo(string policy, string primaryClusterConnectionString)
        {
            string URL           = "https://" + primaryClusterConnectionString + "/";
            string urlParameters = "BackupRestore/BackupPolicies/" + policy + "?api-version=6.2-preview";


            X509Certificate2  clientCert     = GetClientCertificate();
            WebRequestHandler requestHandler = new WebRequestHandler();

            requestHandler.ClientCertificates.Add(clientCert);
            requestHandler.ServerCertificateValidationCallback = this.MyRemoteCertificateValidationCallback;


            HttpClient client = new HttpClient(requestHandler)
            {
                BaseAddress = new Uri(URL)
            };

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            // List data response.
            HttpResponseMessage response = await client.GetAsync(urlParameters);  // Blocking call!

            if (response.IsSuccessStatusCode)
            {
                // Parse the response body. Blocking!
                var           content       = response.Content.ReadAsAsync <JObject>().Result;
                JObject       objectData    = (JObject)content["Storage"];
                BackupStorage backupStorage = JsonConvert.DeserializeObject <BackupStorage>(objectData.ToString());
                return(backupStorage);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                return(null);
            }
        }