コード例 #1
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <param name="drive"></param>
 public static void DeleteAzureDrive(CloudDrive drive)
 {
     try
     {
         if (drive != null)
         {
             drive.Delete();
         }
     }
     catch (Exception ex)
     {
         WindowsAzureSystemHelper.LogError(String.Format("Error deleting drive {0} ", ex.Message));
     }
 }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="accountName"></param>
 /// <param name="accountKey"></param>
 /// <param name="uriString"></param>
 public static void DeleteAzureDrive(string accountName, string accountKey, string uriString)
 {
     try
     {
         CloudStorageAccount csa   = WAStorageHelper.GetCloudStorageAccount(accountName, accountKey, false);
         CloudDrive          drive = new CloudDrive(new Uri(uriString), csa.Credentials);
         if (drive != null)
         {
             drive.Delete();
         }
     }
     catch (Exception ex)
     {
         WindowsAzureSystemHelper.LogError(String.Format("Error deleting drive with Uri {0} - {1}", uriString, ex.Message));
     }
 }
コード例 #3
0
        protected void NewDrive_Click(object sender, EventArgs e)
        {
            if (RoleEnvironment.IsAvailable)
            {
                // retrieve storage account
                CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                // build page blob URI for the new cloud drive by changing the extension in the original URI
                string imageStoreBlobUri = RoleEnvironment.GetConfigurationSettingValue("ImageStoreBlobUri");
                string cloneStoreBlobUri = Path.ChangeExtension(imageStoreBlobUri, "bak");

                // create drive and its associated page blob
                CloudDrive clonedDrive = account.CreateCloudDrive(cloneStoreBlobUri);
                if (this.MountedDrives.Items.Count < 2)
                {
                    try
                    {
                        clonedDrive.Create(16);
                    }
                    catch (CloudDriveException)
                    {
                        // cloud drive already exists
                    }

                    // mount the drive and retrieve its path
                    LocalResource cache           = RoleEnvironment.GetLocalResource("LocalDriveCache");
                    string        clonedStorePath = clonedDrive.Mount(cache.MaximumSizeInMegabytes / 2, DriveMountOptions.None);

                    // copy the contents from the original drive to the new drive
                    foreach (string sourceFileName in Directory.GetFiles(Global.ImageStorePath, "*.*").Where(name => name.EndsWith(".jpg") || name.EndsWith(".png")))
                    {
                        string destinationFileName = Path.Combine(clonedStorePath, Path.GetFileName(sourceFileName));
                        File.Copy(sourceFileName, destinationFileName, true);
                    }

                    this.SelectImageStore(clonedStorePath);
                }
                else
                {
                    clonedDrive.Unmount();
                    clonedDrive.Delete();
                    this.SelectImageStore(Global.ImageStorePath);
                }
            }
        }