Exemplo n.º 1
0
        private void MountSnapshot(string snapshotUri)
        {
            string storageAccountName = txtStorageAccountName.Text;
            string storageAccountKey  = txtStorageAccountKey.Text;


            try
            {
                LocalResource resource  = WindowsAzureSystemHelper.GetLocalStorageResource(LOCAL_STORAGE_NAME);
                int           cacheSize = int.Parse(txtCacheSize.Text);
                if (resource.MaximumSizeInMegabytes < cacheSize)
                {
                    throw new Exception(String.Format("Cache size {0} MB cannot be more than maximum permitted size {1} MB", cacheSize, resource.MaximumSizeInMegabytes));
                }
                bool   wasAlreadyMounted;
                string driveName = WADriveHelper.MountAzureDrive(storageAccountName, storageAccountKey, new Uri(snapshotUri), LocalStoragePath + txtCacheDirName.Text + ".snapshot",
                                                                 int.Parse(txtCacheSize.Text),
                                                                 int.Parse(txtDriveSize.Text),
                                                                 DriveMountOptions.None, out wasAlreadyMounted);

                lblMsg.Text = String.Format("Mounted Snapshot {0} to Drive {1}", snapshotUri, driveName);


                ListAllMountedDrives();
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }
Exemplo n.º 2
0
        private void UnmountDrive()
        {
            TreeView1.Nodes.Clear();
            if (lstDrives.SelectedIndex > -1)
            {
                // string[] split = lstMountedDrives.SelectedItem.Text.Split(new string[]{">"}, StringSplitOptions.RemoveEmptyEntries);
                string[] split     = lstDrives.SelectedItem.Text.Split('>');
                string   driveName = split[0].Trim();
                string   uriString = split[1].Trim();

                string storageAccountName = txtStorageAccountName.Text;
                string storageAccountKey  = txtStorageAccountKey.Text;


                try
                {
                    WADriveHelper.UnmountAzureDrive(storageAccountName, storageAccountKey, uriString);

                    lblMsg.Text = String.Format("Unmounted drive {0} with blob Uri {1}.", driveName, uriString);
                    lstDrives.Items.Clear();
                    ListAllMountedDrives();
                    FillTree();
                }
                catch (Exception ex)
                {
                    lblMsg.Text = ex.Message;
                }
            }
            else
            {
                lblMsg.Text = "Please select a drive.";
            }
        }
Exemplo n.º 3
0
        private void MountDrive()
        {
            string storageAccountName = txtStorageAccountName.Text;
            string storageAccountKey  = txtStorageAccountKey.Text;


            try
            {
                LocalResource resource  = WindowsAzureSystemHelper.GetLocalStorageResource(LOCAL_STORAGE_NAME);
                int           cacheSize = int.Parse(txtCacheSize.Text);
                if (resource.MaximumSizeInMegabytes < cacheSize)
                {
                    throw new Exception(String.Format("Cache size {0} MB cannot be more than maximum permitted size {1} MB", cacheSize, resource.MaximumSizeInMegabytes));
                }
                bool   wasAlreadyMounted;
                string driveName = WADriveHelper.MountAzureDrive(storageAccountName, storageAccountKey, txtContainerName.Text, txtPageBlobName.Text, LocalStoragePath + txtCacheDirName.Text,
                                                                 int.Parse(txtCacheSize.Text),
                                                                 int.Parse(txtDriveSize.Text),
                                                                 DriveMountOptions.None, out wasAlreadyMounted);

                lblMsg.Text = String.Format("Mounted Blob {0} to Drive {1}", txtPageBlobName.Text, driveName);

                if (cbCreateTestFile.Checked)
                {
                    try
                    {
                        WADriveHelper.WriteTestFile(driveName + System.Guid.NewGuid().ToString("N") + "silverlining-test.txt", "test");
                    }
                    catch (Exception ey)
                    {
                        lblMsg.Text = "Could not write test file to the drive " + ey.Message;
                    }
                }
                ListAllMountedDrives();
                FillTree();
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }
Exemplo n.º 4
0
        protected void btnSnapshot_Click(object sender, EventArgs e)
        {
            TreeView1.Nodes.Clear();
            if (lstDrives.SelectedIndex > -1)
            {
                // string[] split = lstMountedDrives.SelectedItem.Text.Split(new string[]{">"}, StringSplitOptions.RemoveEmptyEntries);
                string[] split     = lstDrives.SelectedItem.Text.Split('>');
                string   driveName = split[0].Trim();
                string   uriString = split[1].Trim();

                string storageAccountName = txtStorageAccountName.Text;
                string storageAccountKey  = txtStorageAccountKey.Text;


                try
                {
                    string snapshotUri = WADriveHelper.SnapshotAzureDrive(storageAccountName, storageAccountKey, uriString);

                    lblMsg.Text = String.Format("Snapshot of drive {0} has Uri {1}.", driveName, snapshotUri);

                    MountSnapshot(snapshotUri);

                    lstDrives.Items.Clear();
                    ListAllMountedDrives();
                    FillTree();
                }
                catch (Exception ex)
                {
                    lblMsg.Text = ex.Message;
                }
            }
            else
            {
                lblMsg.Text = "Please select a drive.";
            }
        }