コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="accountKey"></param>
        /// <param name="azureDriveContainerName"></param>
        /// <param name="azureDrivePageBlobName"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public static string SnapshotAzureDrive(string accountName, string accountKey, string azureDriveContainerName, string azureDrivePageBlobName)
        {
            try
            {
                CloudStorageAccount csa = WAStorageHelper.GetCloudStorageAccount(accountName, accountKey, false);
                // Create the blob client

                CloudBlobClient client = csa.CreateCloudBlobClient();
                // Create the blob container which will contain the pageblob corresponding to the azure drive.
                CloudBlobContainer container = client.GetContainerReference(azureDriveContainerName);
                container.CreateIfNotExist();

                // Get the page blob reference which will be used by the azure drive.
                CloudPageBlob blob  = container.GetPageBlobReference(azureDrivePageBlobName);
                CloudDrive    drive = new CloudDrive(blob.Uri, csa.Credentials);
                if (drive != null)
                {
                    return(drive.Snapshot().ToString());
                }
            }
            catch (Exception ex)
            {
                WindowsAzureSystemHelper.LogError(String.Format("Error in snapshot drive  {0} - {1}", azureDrivePageBlobName, ex.Message));
            }

            return(string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// Gets the Storage Helper object based on account name and account key.
        /// It reads the following from the configuration file
        /// BlobStorageEndpoint, QueueStorageEndpoint, TableStorageEndpoint
        /// </summary>
        /// <param name="accountName">Storage Account Name</param>
        /// <param name="accountKey">Storage Account Key</param>
        /// <returns></returns>
        public static WindowsAzureStorageHelper GetStorageHelper(string accountName, string accountKey)
        {
            if (!string.IsNullOrEmpty(accountName) && !string.IsNullOrEmpty(accountKey))
            {
                try
                {
                    string blobStorageEndPoint  = WindowsAzureSystemHelper.GetStringConfigurationValue("BlobStorageEndpoint");
                    string queueStorageEndpoint = WindowsAzureSystemHelper.GetStringConfigurationValue("QueueStorageEndpoint");
                    string tableStorageEndpoint = WindowsAzureSystemHelper.GetStringConfigurationValue("TableStorageEndpoint");

                    return(new WindowsAzureStorageHelper(
                               accountName,
                               accountKey, false,
                               blobStorageEndPoint,
                               queueStorageEndpoint,
                               tableStorageEndpoint));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }//if

            return(null);
        }
コード例 #3
0
        public static bool CanAccessWindowsDir(out string winDir)
        {
            WindowsAzureSystemHelper.LogInfo("Can access Windows Directory?");
            winDir = string.Empty;
            bool ret = false;
            try
            {
                winDir = Environment.GetEnvironmentVariable("windir");


                WindowsAzureSystemHelper.LogInfo("Windows Directory is " + winDir);

                if (!string.IsNullOrEmpty(winDir))
                    ret = true;
            }
            catch (Exception ex)
            {

                WindowsAzureSystemHelper.LogError("Error in CanAccessSystemDir " + ex.Message);

            }

            return ret;

        }
コード例 #4
0
        public static bool CanAccessLocalStorage(string localStorageName)
        {
            WindowsAzureSystemHelper.LogInfo("Can access Local Storage?");
            bool ret = false;
            try
            {
                string fp = WindowsAzureSystemHelper.GetLocalStorageRootPath(localStorageName) + "proazure.txt";
                using (StreamWriter sw = File.CreateText(fp))
                {
                    WindowsAzureSystemHelper.LogInfo("Created File " + fp);
                    sw.WriteLine("This is a Pro Azure file.");
                    WindowsAzureSystemHelper.LogInfo("Wrote in File " + fp);
                }//using

                string fpNew = WindowsAzureSystemHelper.GetLocalStorageRootPath(localStorageName) + "proazure2.txt";
                File.Copy(fp, fpNew);
                string fpNew2 = WindowsAzureSystemHelper.GetLocalStorageRootPath(localStorageName) + "proazure3.txt";
                File.Move(fp, fpNew2);
                WindowsAzureSystemHelper.LogInfo("Deleting File " + fpNew2);
                File.Delete(fpNew2);
                WindowsAzureSystemHelper.LogInfo("Deleted File " + fpNew2);
                WindowsAzureSystemHelper.LogInfo("Deleting File " + fpNew);
                File.Delete(fpNew);
                WindowsAzureSystemHelper.LogInfo("Deleted File " + fpNew);

                ret = true;

            }
            catch (Exception ex)
            {
                WindowsAzureSystemHelper.LogError("Error in CanAccessSystemDir " + ex.Message);
            }

            return ret;
        }
コード例 #5
0
 public static string GetLogLevel()
 {
     try
     {
         return WindowsAzureSystemHelper.GetStringConfigurationValue("LogLevel").ToLower();
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message, "Error");
     }
     return "Info";
 }
コード例 #6
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));
     }
 }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="csa"></param>
 /// <param name="uriString"></param>
 public static void UnmountAzureDrive(CloudStorageAccount csa, string uriString)
 {
     try
     {
         CloudDrive drive = new CloudDrive(new Uri(uriString), csa.Credentials);
         if (drive != null)
         {
             drive.Unmount();
         }
     }
     catch (Exception ex)
     {
         WindowsAzureSystemHelper.LogError(String.Format("Error unmounting drive with Uri {0} - {1}", uriString, ex.Message));
     }
 }
コード例 #8
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));
     }
 }
コード例 #9
0
        /// <summary>
        /// Snapshot the specified drive
        /// </summary>
        /// <param name="drive"></param>
        public static string SnapshotAzureDrive(CloudDrive drive)
        {
            try
            {
                if (drive != null)
                {
                    return(drive.Snapshot().ToString());
                }
            }
            catch (Exception ex)
            {
                WindowsAzureSystemHelper.LogError(String.Format("Error in shapshot drive {0} ", ex.Message));
            }

            return(string.Empty);
        }
コード例 #10
0
        public static string Test(string localStorageName)
        {
            StringBuilder strb = new StringBuilder();
            strb.AppendLine("Root Path for Local Storage:" + WindowsAzureSystemHelper.GetLocalStorageRootPath(localStorageName));
            strb.AppendLine("CanAccessLocalStorage:" + WindowsAzureSystemHelper.CanAccessLocalStorage(localStorageName));
            string sysDir;
            strb.Append("CanAccessSystemDir:" + WindowsAzureSystemHelper.CanAccessSystemDir(out sysDir));
            strb.AppendLine("System Directory:" + sysDir);
            strb.Append("CanAccessWindowsDir:" + WindowsAzureSystemHelper.CanAccessWindowsDir(out sysDir));
            strb.AppendLine("Windows Directory:" + sysDir);

            string output = strb.ToString();
            WindowsAzureSystemHelper.LogInfo(output);

            return output;

        }
コード例 #11
0
        /// <summary>
        /// Snapshot the drive
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="accountKey"></param>
        /// <param name="uriString"></param>
        public static string SnapshotAzureDrive(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)
                {
                    return(drive.Snapshot().ToString());
                }
            }
            catch (Exception ex)
            {
                WindowsAzureSystemHelper.LogError(String.Format("Error in snapshot drive with Uri {0} - {1}", uriString, ex.Message));
            }

            return(string.Empty);
        }
コード例 #12
0
        public static bool CanAccessSystemDir(out string sysDir)
        {
            WindowsAzureSystemHelper.LogInfo("Can access System Directory?");
            sysDir = string.Empty;
            bool ret = false;
            try
            {
                sysDir = Environment.SystemDirectory;

                WindowsAzureSystemHelper.LogInfo("System Directory is " + sysDir);

                if (!string.IsNullOrEmpty(sysDir))
                    ret = true;
            }
            catch (Exception ex)
            {

                WindowsAzureSystemHelper.LogError("Error in CanAccessSystemDir " + ex.Message);

            }

            return ret;

        }
コード例 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static string GetCommonCacheName()
 {
     return(WindowsAzureSystemHelper.GetLocalStorageRootPath(LOCAL_STORAGE_NAME) + "cache");
 }