コード例 #1
0
ファイル: WorkerRole.cs プロジェクト: yovannyr/Agile.Cqrs
        private static void InitializeStorageResources(CloudStorageAccount storageAccount)
        {
            var blobStorage = storageAccount.CreateCloudBlobClient();

            LogBlobContainer     = blobStorage.GetContainerReference("logitems");
            CommandBlobContainer = blobStorage.GetContainerReference("commands");

            var queueStorage = storageAccount.CreateCloudQueueClient();

            LogQueue     = queueStorage.GetQueueReference("logmessages");
            CommandQueue = queueStorage.GetQueueReference("commandmessages");

            bool isStorageFinalized = false;

            while (!isStorageFinalized)
            {
                try
                {
                    LogBlobContainer.CreateIfNotExist();
                    LogQueue.CreateIfNotExist();
                    CommandBlobContainer.CreateIfNotExist();
                    CommandQueue.CreateIfNotExist();

                    isStorageFinalized = true;
                }
                catch (StorageClientException sce)
                {
                    if (sce.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError("Storage services initialization failure.  " +
                                         "Check your storage account configuration settings.  " +
                                         "If running locally, ensure that the Development Storage service is running.  " +
                                         "Message: '{0}'", sce.Message);
                    }
                    else
                    {
                        throw sce;
                    }
                }
            }
        }