public AzureEventStoreClient(AzureStoreConfiguration config, EventStoreId storeId, string serverEndpoint = null)
     : base(storeId, serverEndpoint)
 {
     Config = config;
     _blob = config.GetPageBlob(storeId.Name + "/stream.dat");
     _blob.Container.CreateIfNotExist();
 }
        public PageBlobReadStream(CloudPageBlob blob)
        {
            _blob = blob;

            if (!_blob.Exists())
                throw new ArgumentException();

            _reader = new BinaryReader(_blob.OpenRead());
        }
        public Aligned_PageBlobStream(CloudPageBlob blob)
        {
            _blob = blob;

            if (!_blob.Exists())
                throw new ArgumentException();
            //_stream = _blob.OpenRead();
               // _reader = new BinaryReader(_blob.OpenRead());
        }
        AzureEventStoreChunk(CloudPageBlob blob, long offset, long size)
        {
            _blob = blob;
            _pageWriter = new PageWriter(512, WriteProc);
            _chunkContentSize = offset;
            _blobSpaceSize = size;

            if (offset > 0)
            {
                _pageWriter.CacheLastPageIfNeeded(offset, BufferTip);
            }
        }
예제 #5
0
 /// <summary>
 /// Returns a String value of the blob's DownloadLocation Metadata Property.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's download location, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_DownloadLocation(CloudPageBlob listBlobItem)
 {
     try
     {
         var DownloadLocation = listBlobItem.Uri;
         string SDownloadLocation = Convert.ToString(DownloadLocation);
         if (SDownloadLocation.Length < 1)
         { return "N/A"; }
         return XmlConvert.EncodeName(SDownloadLocation);
     }
     catch
     {
         return "N/A";
     }
 }
예제 #6
0
 /// <summary>
 /// Returns a String value of the blob's Last Modified Date in UTC.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's Last Modified Date in UTC, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_LastModifiedUtc(CloudPageBlob listBlobItem)
 {
     try
     {
         var LastModifiedUtc = listBlobItem.Properties.LastModifiedUtc;
         string SLastModifiedUtc = Convert.ToString(LastModifiedUtc);
         if (SLastModifiedUtc.Length < 1)
         { return "N/A"; }
         return XmlConvert.EncodeName(SLastModifiedUtc);
     }
     catch
     {
         return "N/A";
     }
 }
예제 #7
0
 private static string getDriveUriValue(CloudPageBlob pageBlob)
 {
     var blobList =
         pageBlob.Container.ListBlobs(new BlobRequestOptions
         {
             UseFlatBlobListing = true,
             BlobListingDetails = BlobListingDetails.Snapshots
         }).Cast<CloudPageBlob>().ToArray();
     var snapshotsOfThis = blobList.Where(blob => blob.Name == pageBlob.Name && blob.SnapshotTime.HasValue).OrderByDescending(blob => blob.SnapshotTime).ToArray();
     if (snapshotsOfThis.Length == 0)
         return pageBlob.Uri.AbsoluteUri;
     var snapshot = snapshotsOfThis[0];
     string snapshotUri = BlobRequest.Get(snapshot.Uri, 0, snapshot.SnapshotTime.Value.ToUniversalTime(), null).Address.AbsoluteUri;
     return snapshotUri;
 }
예제 #8
0
 /// <summary>
 /// Returns a String value of the blob's ContentType Metadata Property.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's Content Type, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_ContentType(CloudPageBlob listBlobItem)
 {
     try
     {
         var ContentType = listBlobItem.Properties.ContentType;
         string SContentType = Convert.ToString(ContentType);
         if (SContentType.Length < 1)
         { return "N/A"; }
         return XmlConvert.EncodeName(SContentType);
     }
     catch
     {
         return "N/A";
     }
 }
        public PageBlobAppendStream(CloudPageBlob blob)
        {
            _blob = blob;
            if (blob == null)
                throw new ArgumentNullException("blob");

            _reader = new BinaryReader(_blob.OpenRead());
            if (!blob.Exists())
            {
                _blob.Create(0);
                _lastPageIndex = -1;
                return;
            }

            _blobLength = _blob.Properties.Length;
            _lastPageIndex = (_blobLength / PageSize) - 1;
        }
        public void Resize_Blob(CloudPageBlob pageBlob, CloudBlobClient blobStorage, long newBlobSize)
        {
            Uri requestUri = pageBlob.Uri;
            if (blobStorage.Credentials.NeedsTransformUri)
            {
                requestUri = new Uri(blobStorage.Credentials.TransformUri(requestUri.ToString()));
            }

            HttpWebRequest request = BlobRequest.SetProperties(requestUri, timeout,
                           pageBlob.Properties, null, newBlobSize);
            request.Timeout = timeout;
            blobStorage.Credentials.SignRequest(request);
            using (WebResponse response = request.GetResponse())
            {
                // call succeeded
            };
        }
        static long PrepareStaging(IEnumerable<byte[]> events, CloudPageBlob blob)
        {
            using (var fs = AzureEventStoreChunk.CreateNewForWriting(blob))
            {
                var result = fs.Append("", events.Select(r =>
                {
                    if (r.Length > MessageSizeLimit)
                        throw new PlatformClientException(
                            string.Format("Messages can't be larger than {0} bytes",
                                MessageSizeLimit));

                    return r;
                }));

                if (result.WrittenEvents == 0)
                    throw new PlatformClientException("More than 0 events are expected in input collection");

                return result.ChunkPosition;
            }
        }
예제 #12
0
 public static string CalculatePageBlob_SHA512(CloudPageBlob blob, long BlobByteSize)
 {
     if ((BlobByteSize < Config.Settings.MaxDownloadSize) && (BlobByteSize > 0))
     {
         try
         {
             string filename = BlobStorage.Access.DownloadPageBlob(blob, Config.Settings.DownloadPath);
             string StaticFilePath = Config.Settings.DownloadPath + filename;
             string checksumSha512 = GetChecksum(StaticFilePath, Algorithms.SHA512);
             DeleteFile(StaticFilePath);
             if (checksumSha512.Equals("N/A"))
             { return "N/A"; }
             return checksumSha512;
         }
         catch
         {
             return "N/A";
         }
     }
     return "N/A";
 }
 public static AzureEventStoreChunk OpenExistingForWriting(CloudPageBlob blob, long offset, long length)
 {
     Ensure.Positive(length,"length");
     Ensure.Nonnegative(offset, "offset");
     return new AzureEventStoreChunk(blob, offset, length);
 }
예제 #14
0
 AzureEventPointer(CloudPageBlob blob, bool readOnly)
 {
     _readOnly = readOnly;
     _blob = blob;
 }
예제 #15
0
 public static AzureEventPointer OpenReadable(CloudPageBlob blob)
 {
     return new AzureEventPointer(blob, readOnly:true);
 }
예제 #16
0
        static void SetLength(CloudPageBlob blob, long newLength, int timeout = 10000)
        {
            var credentials = blob.ServiceClient.Credentials;

            var requestUri = blob.Uri;
            if (credentials.NeedsTransformUri)
                requestUri = new Uri(credentials.TransformUri(requestUri.ToString()));

            var request = BlobRequest.SetProperties(requestUri, timeout, blob.Properties, null, newLength);
            request.Timeout = timeout;

            credentials.SignRequest(request);

            using (request.GetResponse()) { }
        }
예제 #17
0
 /// <summary>
 /// Returns a String value of the blob's Name Metadata Property.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's Name, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_Name(CloudPageBlob listBlobItem)
 {
     try
     {
         var name = listBlobItem.Name;
         string Sname = Convert.ToString(name);
         if (Sname.Length < 1)
         { return "N/A"; }
         return XmlConvert.EncodeName(Sname);
     }
     catch
     {
         return "N/A";
     }
 }
예제 #18
0
        // Reset Windows Azure Drive On Another Thread
        public bool ResetWindowsAzureDriveOnAnotherThread()
        {
            Trace.TraceInformation("Started Reset for Windows Azure Drive...");

            try
            {
                // Stop all runtimes
                if (StopAllRuntimes() == false)
                {
                    UpdateProgressInformation("Unbale to stop all runtime and failed to reset Windows Azure Drive.", true);                    
                    return false;
                }

                // Delete PHP Web site from IIS (if any)
                ServerManager serverManager = new ServerManager();
                Site secondaryWebSite = serverManager.Sites[WindowsAzureVMManager.SecondaryWebSiteName];
                if (secondaryWebSite != null)
                {
                    UpdateProgressInformation("Deleting PHP Web site...", false);                    
                    DeletePHPWebSite();
                    UpdateProgressInformation("Deleted PHP Web site.", false);
                }
               
                // Unmount and delete Windows Azure Drive
                if (IsDriveMounted())
                {
                    if (drive != null)
                    {
                        UpdateProgressInformation("Unmounting Windows Azure Drive...", false);
                        UnmountXDrive();
                        UpdateProgressInformation("Unmounted Windows Azure Drive.", false);
                        Thread.Sleep(5000);

                        // Delete all snapshots and parent page blob
                        if (WindowsAzureVMManager.BlobExists(xdrivePageBlob))
                        {
                            xdrivePageBlob.Delete(new BlobRequestOptions()
                            {
                                DeleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots
                            });

                            UpdateProgressInformation("Deleted pageblob and associated snapshots for the Windows Azure Drive.", false);
                        }
                        else
                        {
                            // In devfabric, delete the drive
                            drive.Delete();
                            UpdateProgressInformation("Deleted Windows Azure Drive.", false);
                        }

                        // Reset references
                        xdrivePageBlob = null;
                        drive = null;
                    }
                }

                // Reset status.xml file
                UpdateProgressInformation("Resetting status.xml file...", false);
                installationStatusCollection.Clear();
                SerializeNameValueCollectionToBlob(installationStatusCollection, installationStatusBlob);
                UpdateProgressInformation("Reset status.xml file completed.", false);

                // Mount drive again
                UpdateProgressInformation("Mounting Windows Azure Drive again...", false);
                if (MountXDrive())
                {
                    UpdateProgressInformation("Reset Windows Azure Drive completed.", false);
                }
                else
                {
                    UpdateProgressInformation("Unable to reset Windows Azure Drive as Windows Azure Drive could not be remounted", false);
                    return false;
                }
            }
            catch (Exception ex)
            {
                UpdateProgressInformation("Unable to reset Windows Azure Drive. Error: " + ex.Message, true);
                return false;
            }

            ClearProgressInformation();
            return true;
        }
예제 #19
0
        // Mount XDrive
        public bool MountXDrive()
        {
            // Create HTTP storage endpoint, needed by Windows Azure Drive
            CloudStorageAccount xdriveStorageAccount = WindowsAzureVMManager.GetStorageAccount(false);

            // Initialize local cache
            LocalResource localCache = RoleEnvironment.GetLocalResource("XDriveLocalCache");
            Char[] backSlash = { '\\' };
            String localCachePath = localCache.RootPath.TrimEnd(backSlash);
            CloudDrive.InitializeCache(localCachePath, localCache.MaximumSizeInMegabytes);

            // Get Windows Azure Drive container and blob names from service configuration file
            string xdriveContainerName = RoleEnvironment.GetConfigurationSettingValue("PHPApplicationsBackupContainerName");
            string xdriveBlobName = RoleEnvironment.GetConfigurationSettingValue("XDrivePageBlobName");

            // Create blob container, if it does not exist
            CloudBlobClient blobClient = xdriveStorageAccount.CreateCloudBlobClient();
            blobClient.GetContainerReference(xdriveContainerName).CreateIfNotExist();

            // Get Windows Azure Drive page blob reference
            xdrivePageBlob = blobClient
                        .GetContainerReference(xdriveContainerName)
                        .GetPageBlobReference(xdriveBlobName);

            // Get a reference to the requested Windows Azure Drive
            drive = xdriveStorageAccount.CreateCloudDrive(
                    xdrivePageBlob.Uri.ToString()
                );

            // Create drive
            try
            {
                drive.Create(int.Parse(RoleEnvironment.GetConfigurationSettingValue("XDriveSizeInMB")));
            }
            catch (CloudDriveException)
            {
                // exception is also thrown if all is well but the drive already exists, hence ignore exception
            }

            try
            {
                // This is 1 VM solution only, so always mount drive in write mode. 
                string xdriveLetter = drive.Mount(
                    int.Parse(RoleEnvironment.GetConfigurationSettingValue("XDriveCacheSizeInMB")),
                    DriveMountOptions.None);
                Trace.TraceInformation("Mounted Windows Azure Drive at uri {0}", drive.Uri);
                Trace.TraceInformation("Applications are durable to Windows Azure Page Blob.");

                // Use different mechanism for devfabric and cloud to determine applicationsAndRuntimeResourceFolder
                if (RoleEnvironment.DeploymentId.StartsWith("deployment"))
                {
                    // This is Windows Azure SDK 1.3 Specific, so might break in future
                    string csrunEnv = Environment.GetEnvironmentVariable("_CSRUN_STATE_DIRECTORY");
                    if (string.IsNullOrEmpty(csrunEnv))
                    {
                        applicationsAndRuntimeResourceFolder = Path.Combine(
                            Environment.GetEnvironmentVariable("LOCALAPPDATA"),
                            @"dftmp\wadd\devstoreaccount1\");
                    }
                    else
                    {
                        applicationsAndRuntimeResourceFolder = Path.Combine(csrunEnv, @"wadd\devstoreaccount1\");
                    }

                    // Get Windows Azure Drive container and blob names from service configuration file
                    applicationsAndRuntimeResourceFolder = Path.Combine(applicationsAndRuntimeResourceFolder, xdriveContainerName);
                    applicationsAndRuntimeResourceFolder = Path.Combine(applicationsAndRuntimeResourceFolder, xdriveBlobName);
                }
                else
                {
                    applicationsAndRuntimeResourceFolder = xdriveLetter;
                }

                return true;
            }
            catch (Exception ex)
            {
                applicationsAndRuntimeResourceFolder = null;
                Trace.TraceError("Unable to Mount Windows Azure Drive. Error: {0}, StackTrace: {1}", ex.Message, ex.StackTrace);                
                return false;
            }
        }
 public static AzureEventStoreChunk CreateNewForWriting(CloudPageBlob blob)
 {
     blob.Create(ChunkSize);
     return new AzureEventStoreChunk(blob, 0, ChunkSize);
 }
 public TestAzurePointer(CloudPageBlob blob)
 {
     _blob = blob;
 }
예제 #22
0
 /// <summary>
 /// Returns a String value of the blob's MD5 Metadata Property.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's MD5, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_MD5(CloudPageBlob listBlobItem)
 {
     try
     {
         var md5 = listBlobItem.Properties.ContentMD5;
         string Smd5 = Convert.ToString(md5);
         if (Smd5.Length < 1)
         {return "N/A";}
         return XmlConvert.EncodeName(Smd5);
     }
     catch
     {
         return "N/A";
     }
 }
예제 #23
0
 public static AzureEventPointer OpenWriteable(CloudPageBlob blob)
 {
     return new AzureEventPointer(blob, readOnly:false);
 }
예제 #24
0
        /// <summary>
        /// Selects the protocol response.
        /// </summary>
        /// <param name="protocolItem">The protocol item.</param>
        /// <param name="service">The service.</param>
        /// <param name="container">The container.</param>
        /// <returns>The parsed <see cref="IListBlobItem"/>.</returns>
        internal static IListBlobItem SelectProtocolResponse(IListBlobEntry protocolItem, CloudBlobClient service, CloudBlobContainer container)
        {
            BlobEntry blob = protocolItem as BlobEntry;
            if (blob != null)
            {
                var attributes = blob.Attributes;
                CloudBlob cloudBlob;
                if (attributes.Properties.BlobType == BlobType.BlockBlob)
                {
                    cloudBlob = new CloudBlockBlob(attributes, service, ConvertDateTimeToSnapshotString(attributes.Snapshot));
                }
                else if (attributes.Properties.BlobType == BlobType.PageBlob)
                {
                    cloudBlob = new CloudPageBlob(attributes, service, ConvertDateTimeToSnapshotString(attributes.Snapshot));
                }
                else
                {
                    cloudBlob = new CloudBlob(attributes, service, ConvertDateTimeToSnapshotString(attributes.Snapshot));
                }

                return cloudBlob;
            }

            BlobPrefixEntry blobPrefix = protocolItem as BlobPrefixEntry;

            if (blobPrefix != null)
            {
                if (container != null)
                {
                    return container.GetDirectoryReference(blobPrefix.Name);
                }
                else
                {
                    return new CloudBlobDirectory(blobPrefix.Name, service);
                }
            }

            throw new InvalidOperationException("Invalid blob list item returned");
        }
 public static AzureEventStoreChunk OpenExistingForReading(CloudPageBlob blob, long length)
 {
     Ensure.Positive(length, "length");
     return new AzureEventStoreChunk(blob, -1, length);
 }
예제 #26
0
파일: Access.cs 프로젝트: tsangtmc/BlobIM
        public static string DownloadPageBlob(CloudPageBlob blob, string LocalDownloadPath)
        {
            try
            {
                string filename = Guid.NewGuid().ToString();
                string contianername = blob.Container.Name;
                string blobname = blob.Name;

                if (contianername.Length > 50)
                {
                    contianername = contianername.Substring(0, 49);
                }
                if (blobname.Length > 50)
                {
                    blobname = blobname.Substring(0, 49);
                }
                filename = filename.Substring(0, 8);
                filename = filename+"_" + contianername + "_" + blobname;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    filename = filename.Replace(c, '-');
                }

                using (var fileStream = System.IO.File.OpenWrite(LocalDownloadPath + "/" + filename))
                {
                    blob.DownloadToStream(fileStream);
                }
                return filename;
            }
            catch(Exception e)
            {
                Alerting.ErrorLogging.WriteTo_Log("Failed Download Blob", e.ToString());
                return "N/A";
            }
        }
예제 #27
0
 void TruncateBlob(long lastValidPosition, CloudPageBlob fileInfo)
 {
     var trunc = lastValidPosition;
     var remainder = lastValidPosition % 512;
     if (remainder > 0)
     {
         trunc += 512 - remainder;
     }
     Trace.WriteLine(string.Format("Truncating {0} to {1}", fileInfo.Name, trunc));
     _container.GetPageBlobReference(fileInfo.Name + ".bak").CopyFromBlob(fileInfo);
     SetLength(fileInfo, trunc);
 }
예제 #28
0
 /// <summary>
 /// Returns a String value of the blob's Size Metadata Property.
 /// </summary>
 /// <param name="listBlobItem">Consumes Microsoft.WindowsAzure.StorageClient.CloudBlockBlob</param>
 /// <returns>Returns string of blob's Size in Bytes, Will return "N/A" if getting the blob metadata was unsuccessful</returns>
 public static string GetBlob_Size(CloudPageBlob listBlobItem)
 {
     try
     {
         var size = listBlobItem.Properties.Length;
         string Ssize = Convert.ToString(size);
         if (Ssize.Length < 1)
         { return "N/A"; }
         return XmlConvert.EncodeName(Ssize);
     }
     catch
     {
         return "N/A";
     }
 }