Exemplo n.º 1
0
        private IEnumerator <IAsyncResult> ReleaseLeaseImpl(Guid leaseId, IContainerCondition condition, bool updateLastModificationTime, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer nullable = this.LoadBlobContainer(dbContext);
                    DbBlobContainer.CheckBlobContainerConditionWithoutLeaseCondition(nullable, condition);
                    DateTime utcNow = DateTime.UtcNow;
                    ContainerLeaseInfo containerLeaseInfo = new ContainerLeaseInfo(nullable, utcNow);
                    if (containerLeaseInfo.Id.HasValue && containerLeaseInfo.Id.Value != leaseId)
                    {
                        throw new LeaseLostException();
                    }
                    if (containerLeaseInfo.State.Value == LeaseState.Available)
                    {
                        throw new LeaseLostException();
                    }
                    nullable.LeaseEndTime = new DateTime?(utcNow);
                    nullable.LeaseState   = 0;
                    nullable.IsLeaseOp    = !updateLastModificationTime;
                    dbContext.SubmitChanges();
                    containerLeaseInfo.SetBlobContainer(nullable, utcNow);
                    this._container = nullable;
                    this.LeaseInfo  = containerLeaseInfo;
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbBlobContainer.ReleaseLease"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Exemplo n.º 2
0
        private IEnumerator <IAsyncResult> SetPropertiesImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer>((TimeSpan param0) => {
                Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer serviceMetadata = this.LoadBlobContainer(dbContext);
                    ContainerLeaseInfo containerLeaseInfo = new ContainerLeaseInfo(serviceMetadata, DateTime.UtcNow);
                    DbBlobContainer.CheckBlobContainerCondition(serviceMetadata, condition, containerLeaseInfo);
                    if ((propertyNames & ContainerPropertyNames.ServiceMetadata) != ContainerPropertyNames.None)
                    {
                        serviceMetadata.ServiceMetadata = ((IContainer)this).ServiceMetadata;
                    }
                    if ((propertyNames & ContainerPropertyNames.ApplicationMetadata) != ContainerPropertyNames.None)
                    {
                        serviceMetadata.Metadata = this.ApplicationMetadata;
                    }
                    dbContext.SubmitChanges();
                    this.LeaseInfo = containerLeaseInfo;
                    blobContainer  = serviceMetadata;
                }
                return(blobContainer);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbBlobContainer.SetProperties"));

            yield return(asyncResult);

            this._container = this.StorageManager.AsyncProcessor.EndExecute <Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer>(asyncResult);
        }
Exemplo n.º 3
0
        private DbQueueContainerCollection ReadListQueueContainersResult(string containerNamePrefix, string separator, int maxQueueNames, IQueryable <Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer> queues)
        {
            int    num       = 0;
            string queueName = null;
            List <IQueueContainer> queueContainers = new List <IQueueContainer>();

            foreach (Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queue in queues)
            {
                if (!string.IsNullOrEmpty(separator))
                {
                    queue.QueueName = DbBlobContainer.GetSummaryName(queue.QueueName, containerNamePrefix, separator);
                }
                if (maxQueueNames != 0)
                {
                    num++;
                    if (num > maxQueueNames)
                    {
                        queueName = queue.QueueName;
                        break;
                    }
                }
                queueContainers.Add(new DbQueueContainer(this, queue));
            }
            return(new DbQueueContainerCollection(queueContainers, queueName));
        }
Exemplo n.º 4
0
        private DbBlobContainerCollection ReadListBlobContainersResult(string containerNamePrefix, string separator, int maxContainerNames, IQueryable <Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer> containers)
        {
            int    num = 0;
            string str = null;
            List <IBlobContainer> blobContainers = new List <IBlobContainer>();

            foreach (Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer container in containers)
            {
                if (!string.IsNullOrEmpty(separator))
                {
                    container.ContainerName = DbBlobContainer.GetSummaryName(container.ContainerName, containerNamePrefix, separator);
                }
                if (maxContainerNames != 0)
                {
                    num++;
                    if (num > maxContainerNames)
                    {
                        str = string.Concat("/", this.Name, "/", container.ContainerName);
                        break;
                    }
                }
                blobContainers.Add(new DbBlobContainer(this, container, true));
            }
            return(new DbBlobContainerCollection(blobContainers, str));
        }
Exemplo n.º 5
0
        private IEnumerator <IAsyncResult> ChangeLeaseImpl(Guid leaseId, Guid proposedLeaseId, IContainerCondition condition, bool updateLastModificationTime, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer nullable = this.LoadBlobContainer(dbContext);
                    DbBlobContainer.CheckBlobContainerConditionWithoutLeaseCondition(nullable, condition);
                    DateTime utcNow = DateTime.UtcNow;
                    ContainerLeaseInfo containerLeaseInfo = new ContainerLeaseInfo(nullable, utcNow);
                    switch (containerLeaseInfo.State.Value)
                    {
                    case LeaseState.Available:
                        {
                            throw new LeaseNotPresentException();
                        }

                    case LeaseState.Leased:
                        {
                            if (!(leaseId != containerLeaseInfo.Id.Value) || !(proposedLeaseId != containerLeaseInfo.Id.Value))
                            {
                                break;
                            }
                            throw new LeaseHeldException();
                        }

                    case LeaseState.Expired:
                        {
                            throw new LeaseHeldException();
                        }

                    case LeaseState.Breaking:
                        {
                            if (!containerLeaseInfo.Id.HasValue || !(leaseId != containerLeaseInfo.Id.Value) || !(proposedLeaseId != containerLeaseInfo.Id.Value))
                            {
                                throw new LeaseBrokenException();
                            }
                            throw new LeaseHeldException();
                        }

                    case LeaseState.Broken:
                        {
                            throw new LeaseNotPresentException();
                        }
                    }
                    nullable.LeaseId   = new Guid?(proposedLeaseId);
                    nullable.IsLeaseOp = !updateLastModificationTime;
                    dbContext.SubmitChanges();
                    containerLeaseInfo.SetBlobContainer(nullable, utcNow);
                    this._container = nullable;
                    this.LeaseInfo  = containerLeaseInfo;
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbBlobContainer.ChangeLease"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Exemplo n.º 6
0
        private IEnumerator <IAsyncResult> GetPropertiesImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer = this.LoadBlobContainer(dbContext);
                    ContainerLeaseInfo containerLeaseInfo = new ContainerLeaseInfo(blobContainer, DateTime.UtcNow);
                    DbBlobContainer.CheckBlobContainerCondition(blobContainer, condition, containerLeaseInfo);
                    this._container = blobContainer;
                    this.LeaseInfo  = containerLeaseInfo;
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbBlobContainer.GetProperties"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Exemplo n.º 7
0
        private DbBlobObjectCollection ReadListBlobsResult(string blobNamePrefix, string separator, int maxBlobNames, IQueryable <Blob> blobs)
        {
            DbBlobObject       dbListBlobObject;
            int                num         = 0;
            string             blobName    = null;
            DateTime?          nullable    = null;
            List <IBlobObject> blobObjects = new List <IBlobObject>();

            foreach (Blob blob in blobs)
            {
                bool flag = false;
                if (!string.IsNullOrEmpty(separator))
                {
                    blob.BlobName = DbBlobContainer.GetSummaryName(blob.BlobName, blobNamePrefix, separator, out flag);
                }
                if (maxBlobNames != 0)
                {
                    num++;
                    if (num > maxBlobNames)
                    {
                        blobName = blob.BlobName;
                        nullable = new DateTime?(blob.VersionTimestamp);
                        break;
                    }
                }
                if (blob.BlobType == BlobType.ListBlob)
                {
                    dbListBlobObject = new DbListBlobObject(this.StorageManager, blob, BlobServiceVersion.Sept09);
                }
                else
                {
                    dbListBlobObject = new DbPageBlobObject(this.StorageManager, blob, BlobServiceVersion.Sept09);
                }
                DbBlobObject dbBlobObject = dbListBlobObject;
                blobObjects.Add(dbBlobObject);
                if (!flag)
                {
                    continue;
                }
                dbBlobObject.SetBlobNoneType();
            }
            return(new DbBlobObjectCollection(blobObjects, null, blobName, nullable));
        }
Exemplo n.º 8
0
 private Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer LoadBlobContainer(DevelopmentStorageDbDataContext context)
 {
     return(DbBlobContainer.LoadBlobContainer(context, this._container));
 }
Exemplo n.º 9
0
        internal static string GetSummaryName(string name, string prefix, string separator)
        {
            bool flag = false;

            return(DbBlobContainer.GetSummaryName(name, prefix, separator, out flag));
        }
Exemplo n.º 10
0
        private IEnumerator <IAsyncResult> DeleteContainerImpl(IContainerCondition conditions, Guid?leaseId, AsyncIteratorContext <NoResults> context)
        {
            object obj;
            IStringDataEventStream verboseDebug = Logger <INormalAndDebugLogger> .Instance.VerboseDebug;

            object[] timeout  = new object[2];
            object[] objArray = timeout;
            obj         = (leaseId.HasValue ? leaseId.Value.ToString() : "NULL");
            objArray[0] = obj;
            timeout[1]  = this.Timeout;
            verboseDebug.Log("DeleteContainerImpl({0},{1})", timeout);
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer = this.LoadBlobContainer(dbContext);
                    ContainerLeaseInfo containerLeaseInfo = new ContainerLeaseInfo(blobContainer, DateTime.UtcNow);
                    DbBlobContainer.CheckBlobContainerCondition(blobContainer, conditions, containerLeaseInfo);
                    LeaseState?state          = containerLeaseInfo.State;
                    LeaseState valueOrDefault = state.GetValueOrDefault();
                    if (state.HasValue)
                    {
                        switch (valueOrDefault)
                        {
                        case LeaseState.Available:
                        case LeaseState.Broken:
                            {
                                if (!leaseId.HasValue)
                                {
                                    break;
                                }
                                if (!containerLeaseInfo.Id.HasValue)
                                {
                                    throw new LeaseNotPresentException();
                                }
                                throw new LeaseLostException();
                            }

                        case LeaseState.Leased:
                        case LeaseState.Breaking:
                            {
                                if (leaseId.HasValue && !(leaseId.Value != containerLeaseInfo.Id.Value))
                                {
                                    break;
                                }
                                throw new LeaseHeldException();
                            }

                        case LeaseState.Expired:
                            {
                                if (!leaseId.HasValue)
                                {
                                    break;
                                }
                                throw new LeaseLostException();
                            }
                        }
                    }
                    dbContext.BlobContainers.DeleteOnSubmit(blobContainer);
                    dbContext.SubmitChanges();
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbBlobContainer.DeleteContainerImpl"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Exemplo n.º 11
0
 internal static void CheckBlobContainerConditionWithoutLeaseCondition(Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer, IContainerCondition condition)
 {
     DbBlobContainer.CheckBlobContainerCondition(blobContainer, condition, null, false, null);
 }
Exemplo n.º 12
0
 internal static void CheckBlobContainerCondition(Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer, IContainerCondition condition, ContainerLeaseInfo leaseInfo)
 {
     DbBlobContainer.CheckBlobContainerCondition(blobContainer, condition, null, true, leaseInfo);
 }
Exemplo n.º 13
0
 internal DbListBlobObject(DbBlobContainer container, string blobName, DateTime snapshot, BlobServiceVersion blobServiceVersion) : base(container, blobName, snapshot, BlobType.ListBlob, blobServiceVersion)
 {
 }