private const string MimeTypeName = "text/plain"; // since these are assumed to #endregion Fields #region Methods /// <summary> /// ugliness of downloading and reuploading whole blob. /// </summary> /// <param name="blob"></param> /// <param name="toAdd"></param> public static void appendToBlob(CloudBlob blob, string toAdd) { string oldLogData = ""; if (Exists(blob)) oldLogData = blob.DownloadText(); blob.DeleteIfExists(); blob.UploadText(oldLogData + "\r\n" + toAdd); }
private bool _handleWebException(CloudBlob blob, WebException err) { var response = (HttpWebResponse)err.Response; if (response.StatusCode == HttpStatusCode.NotFound) { _azureDirectory.CreateContainer(); blob.UploadText(_lockFile); return true; } return false; }
private bool _handleStorageClientException(CloudBlob blob, StorageClientException err) { switch (err.ErrorCode) { case StorageErrorCode.ResourceNotFound: blob.UploadText(_lockFile); return true; case StorageErrorCode.ContainerNotFound: // container is missing, we should create it. _azureDirectory.BlobContainer.Delete(); _azureDirectory.CreateContainer(); return true; default: return false; } }
// Serialize NameValueCollection To Blob private static void SerializeNameValueCollectionToBlob(NameValueCollection collection, CloudBlob blob) { try { SoapFormatter ser = new SoapFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { ser.Serialize(memoryStream, collection); byte[] b = memoryStream.GetBuffer(); string serilizedNameValueCollection = Encoding.Default.GetString(b); blob.UploadText(serilizedNameValueCollection); } } catch (Exception ex) { Trace.TraceError("Failed to SerializeNameValueCollectionToBlob. Error: {0}", ex.Message); } }