Ejemplo n.º 1
0
        private IEnumerator <IAsyncResult> DeleteQueueContainerImpl(string containerName, IContainerCondition conditions, AsyncIteratorContext <NoResults> context)
        {
            IStringDataEventStream verboseDebug = Logger <INormalAndDebugLogger> .Instance.VerboseDebug;

            object[] objArray = new object[] { containerName, this.Timeout };
            verboseDebug.Log("DeleteQueueContainerImpl({0},{1})", objArray);
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = new Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer()
                    {
                        AccountName = this._account.Name,
                        QueueName   = containerName
                    };
                    queueContainer = DbQueueContainer.LoadQueueContainer(dbContext, queueContainer);
                    DbQueueContainer.CheckQueueContainerCondition(queueContainer, conditions);
                    dbContext.QueueContainers.DeleteOnSubmit(queueContainer);
                    dbContext.SubmitChanges();
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("StorageAccount.DeleteBlobContainerImpl"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Ejemplo n.º 2
0
        private IEnumerator <IAsyncResult> PeekMessageImpl(int numberOfMessages, AsyncIteratorContext <IEnumerable <IMessageData> > context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <List <IMessageData> >((TimeSpan remaining) => {
                List <IMessageData> messageDatas;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    this._queue = queueContainer;
                    IQueryable <QueueMessage> queueMessages = (
                        from m in dbContext.QueueMessages
                        where (m.AccountName == this._queue.AccountName) && (m.QueueName == this._queue.QueueName) && (m.VisibilityStartTime <= DateTime.UtcNow) && (m.ExpiryTime >= DateTime.UtcNow)
                        orderby m.VisibilityStartTime
                        select m).Take <QueueMessage>(numberOfMessages);
                    List <IMessageData> messageDatas1 = new List <IMessageData>();
                    foreach (QueueMessage queueMessage in queueMessages)
                    {
                        messageDatas1.Add(new DbMessageData(queueMessage, true));
                    }
                    messageDatas = messageDatas1;
                }
                return(messageDatas);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.PeekMessage"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <List <IMessageData> >(asyncResult);
        }
Ejemplo n.º 3
0
 private void OnLoaded()
 {
     DevelopmentStorageDbDataContext.AdjustSqlDateTime(ref this._LastModificationTime);
     DevelopmentStorageDbDataContext.AdjustSqlDateTime(ref this._CreationTime);
     this._VersionTimestamp = DateTime.SpecifyKind(this._VersionTimestamp, DateTimeKind.Utc);
     DevelopmentStorageDbDataContext.AdjustSqlDateTime(ref this._LeaseEndTime);
 }
Ejemplo n.º 4
0
        private IEnumerator <IAsyncResult> DeleteMessageImpl(IQueueMessageReceipt queueMessageReceipt, AsyncIteratorContext <bool> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <bool>((TimeSpan remaining) => {
                bool flag;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    context.ResultData        = false;
                    Receipt receipt           = (Receipt)queueMessageReceipt;
                    Guid messageId            = receipt.MessageId;
                    DateTime visibilityStart  = receipt.VisibilityStart;
                    QueueMessage queueMessage = (
                        from m in dbContext.QueueMessages
                        where (m.AccountName == this._queue.AccountName) && (m.QueueName == this._queue.QueueName) && (m.VisibilityStartTime == visibilityStart) && (m.MessageId == messageId)
                        select m).FirstOrDefault <QueueMessage>();
                    if (queueMessage == null)
                    {
                        throw new MessageNotFoundException();
                    }
                    dbContext.QueueMessages.DeleteOnSubmit(queueMessage);
                    dbContext.SubmitChanges();
                    this._queue = queueContainer;
                    flag        = true;
                }
                return(flag);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.DeleteMessageImpl"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <bool>(asyncResult);
        }
Ejemplo n.º 5
0
        private TableRow GetSqlEntity(string partitionKey, string rowKey, DateTime?timeStamp)
        {
            string   str      = partitionKey;
            string   str1     = rowKey;
            TableRow tableRow = null;

            str  = DevelopmentStorageDbDataContext.EncodeKeyString(str);
            str1 = DevelopmentStorageDbDataContext.EncodeKeyString(str1);
            if (!timeStamp.HasValue || !timeStamp.HasValue)
            {
                tableRow = (
                    from r in this.m_dbContext.TableRows
                    where (r.AccountName == this.AccountName) && (r.TableName == this.m_currentResourceContainer.Name.ToLowerInvariant()) && (r.PartitionKey == str) && (r.RowKey == str1)
                    select r).FirstOrDefault <TableRow>();
            }
            else
            {
                DateTime sql2005DateTime = DevelopmentStorageDbDataContext.GetSql2005DateTime(timeStamp.Value);
                tableRow = (
                    from r in this.m_dbContext.TableRows
                    where (r.AccountName == this.AccountName) && (r.TableName == this.m_currentResourceContainer.Name.ToLowerInvariant()) && (r.PartitionKey == str) && (r.RowKey == str1) && (r.Timestamp == sql2005DateTime)
                    select r).FirstOrDefault <TableRow>();
            }
            return(tableRow);
        }
Ejemplo n.º 6
0
        public static IEnumerator <T> GetProjectedWrapperTypedEnumerator <T>(IEnumerator <TableRow> enumerator, int propertyCount, string propertyListName, string resourceTypeName, string[] projectedProperties)
            where T : ProjectedWrapper
        {
            List <T> ts = new List <T>();

            while (enumerator.MoveNext())
            {
                TableRow current = enumerator.Current;
                Dictionary <string, object> strs = new Dictionary <string, object>();
                strs["PartitionKey"] = DevelopmentStorageDbDataContext.DecodeKeyString(current.PartitionKey);
                strs["RowKey"]       = DevelopmentStorageDbDataContext.DecodeKeyString(current.RowKey);
                strs["Timestamp"]    = current.Timestamp;
                XmlUtility.AddObjectsToDictionaryFromXml(current.Data, strs, true);
                object[] objArray = new object[propertyCount];
                for (int i = 0; i < propertyCount; i++)
                {
                    if (!strs.TryGetValue(projectedProperties[i], out objArray[i]))
                    {
                        objArray[i] = null;
                    }
                }
                ProjectedWrapperCreator projectedWrapperCreator = ProjectedWrapperCreator.GetProjectedWrapperCreator(propertyCount);
                ts.Add((T)projectedWrapperCreator.CreateProjectedWrapper(objArray, propertyListName, resourceTypeName));
            }
            return(ts.GetEnumerator());
        }
Ejemplo n.º 7
0
        public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
        {
            string str;

            if (this.m_currentResourceContainer == null || !name.Equals(this.m_currentResourceContainer.ResourceType.Name, StringComparison.OrdinalIgnoreCase))
            {
                if (!TableResourceContainer.IsUtilityTables(name))
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        str = (
                            from t in dbContext.TableContainers
                            where (t.AccountName == this.AccountName) && (t.TableName == name.ToLowerInvariant())
                            select t.CasePreservedTableName).FirstOrDefault <string>();
                    }
                    if (str == null)
                    {
                        resourceSet = null;
                        throw new ContainerNotFoundException();
                    }
                    this.m_currentResourceContainer = TableResourceContainer.GetResourceContainer(this.AccountName, str, false);
                }
                else
                {
                    this.m_currentResourceContainer = TableResourceContainer.GetResourceContainer(this.AccountName, "Tables", false);
                }
            }
            resourceSet = this.m_currentResourceContainer;
            return(true);
        }
Ejemplo n.º 8
0
        private IEnumerator <IAsyncResult> SnapshotBlobImpl(byte[] metadata, IBlobObjectCondition condition, AsyncIteratorContext <DateTime> context)
        {
            IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute <DateTime>((TimeSpan param0) => {
                DateTime value;
                StorageStampHelpers.ValidateApplicationMetadata(metadata);
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        base.LoadContainer(dbContext);
                        BlockBlob blockBlob         = base.LoadBlockBlob(dbContext);
                        BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow);
                        DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, false);
                        DateTime?nullable  = null;
                        DateTime?nullable1 = null;
                        dbContext.SnapshotBlockBlob(blockBlob.AccountName, blockBlob.ContainerName, blockBlob.BlobName, metadata, ref nullable, ref nullable1);
                        transactionScope.Complete();
                        nullable       = new DateTime?(DateTime.SpecifyKind(nullable.Value, DateTimeKind.Utc));
                        this._blob     = blockBlob;
                        this.LeaseInfo = blobLeaseInfo;
                        if (nullable1.HasValue)
                        {
                            this._blob.LastModificationTime = new DateTime?(nullable1.Value);
                        }
                        value = nullable.Value;
                    }
                }
                return(value);
            }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("BlobObject.SnapshotBlobImpl"));

            yield return(asyncResult);

            context.ResultData = this._storageManager.AsyncProcessor.EndExecute <DateTime>(asyncResult);
        }
Ejemplo n.º 9
0
        private byte[] GetBytesFromCommittedBlocks(DevelopmentStorageDbDataContext dataContext, long start, long end, IOrderedQueryable <CommittedBlock> committedBlocks)
        {
            byte[] numArray = new byte[checked ((IntPtr)(end - start))];
            long   num      = (long)0;
            long   num1     = start;

            foreach (CommittedBlock committedBlock in committedBlocks)
            {
                BlockData blockDatum = (
                    from b in dataContext.BlocksData
                    where (b.AccountName == this._blob.AccountName) && (b.ContainerName == this._blob.ContainerName) && (b.BlobName == this._blob.BlobName) && ((DateTime?)b.VersionTimestamp == committedBlock.BlockVersion) && b.IsCommitted && (b.BlockId == committedBlock.BlockId)
                    select b).First <BlockData>();
                byte[] numArray1 = null;
                using (FileStream fileStream = new FileStream(blockDatum.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    fileStream.Seek(blockDatum.StartOffset.Value, SeekOrigin.Begin);
                    numArray1 = new byte[checked ((IntPtr)blockDatum.Length.Value)];
                    fileStream.Read(numArray1, 0, (int)numArray1.Length);
                }
                long num2   = (committedBlock.Offset < start ? start - committedBlock.Offset : (long)0);
                long?length = committedBlock.Length;
                long num3   = Math.Min(length.Value - num2, end - num1);
                Buffer.BlockCopy(numArray1, (int)num2, numArray, (int)num, (int)num3);
                num1 += num3;
                num  += num3;
            }
            return(numArray);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        private IEnumerator <IAsyncResult> CreateQueueContainerImpl(string containerName, DateTime?expiryTime, byte[] serviceMetadata, byte[] applicationMetadata, AsyncIteratorContext <IQueueContainer> context)
        {
            IStringDataEventStream verboseDebug = Logger <INormalAndDebugLogger> .Instance.VerboseDebug;

            object[] objArray = new object[] { containerName, expiryTime, serviceMetadata, applicationMetadata, this.Timeout };
            verboseDebug.Log("CreateQueueContainerImpl({0},{1},{2},{3},{4})", objArray);
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <DbQueueContainer>((TimeSpan param0) => {
                Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = new Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer()
                {
                    AccountName     = this._account.Name,
                    QueueName       = containerName,
                    ServiceMetadata = serviceMetadata,
                    Metadata        = applicationMetadata
                };
                DbQueueContainer dbQueueContainer = new DbQueueContainer(this, queueContainer);
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    dbContext.QueueContainers.InsertOnSubmit(queueContainer);
                    dbContext.SubmitChanges();
                }
                return(dbQueueContainer);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("StorageAccount.CreateQueueContainer"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <DbQueueContainer>(asyncResult);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 public static void AdjustSqlDateTime(ref DateTime?value)
 {
     if (!value.HasValue)
     {
         return;
     }
     value = new DateTime?(DevelopmentStorageDbDataContext.FromSql2005DateTime2(value.Value));
 }
Ejemplo n.º 14
0
        private BlockData TryLoadUncommittedBlock(DevelopmentStorageDbDataContext context, string blockId)
        {
            BlockData blockDatum = (
                from b in context.BlocksData
                where (b.AccountName == this._blob.AccountName) && (b.ContainerName == this._blob.ContainerName) && (b.BlobName == this._blob.BlobName) && (b.VersionTimestamp == this._blob.VersionTimestamp) && !b.IsCommitted && (b.BlockId == blockId)
                select b).FirstOrDefault <BlockData>();

            return(blockDatum);
        }
Ejemplo n.º 15
0
        private IEnumerator <IAsyncResult> GetBlockListImpl(IBlobObjectCondition condition, BlockListTypes blockListTypes, BlobServiceVersion blobServiceVersion, AsyncIteratorContext <IBlockLists> context)
        {
            IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute <BlockLists>((TimeSpan param0) => {
                BlockLists blockList;
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        base.LoadContainer(dbContext);
                        BlockBlob blockBlob         = base.LoadBlockBlob(dbContext, true);
                        BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow);
                        DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, false);
                        BlockLists dbBlockCollections = new BlockLists()
                        {
                            BlobLastModificationTime = blockBlob.LastModificationTime.Value,
                            BlobSize = blockBlob.ContentLength
                        };
                        if ((blockListTypes & BlockListTypes.Committed) != BlockListTypes.None)
                        {
                            List <IBlock> blocks = new List <IBlock>();
                            if (blockBlob.HasBlock.Value)
                            {
                                foreach (CommittedBlock committedBlock in
                                         from blck in dbContext.CommittedBlocks
                                         where (blck.AccountName == this._blob.AccountName) && (blck.ContainerName == this._blob.ContainerName) && (blck.BlobName == this._blob.BlobName) && (blck.VersionTimestamp == this._blob.VersionTimestamp)
                                         select blck)
                                {
                                    blocks.Add(new Block(DbListBlobObject.FromHexString(committedBlock.BlockId), committedBlock.Length.Value));
                                }
                            }
                            dbBlockCollections.CommittedBlockList = new DbListBlobObject.DbBlockCollection(blocks);
                        }
                        if ((blockListTypes & BlockListTypes.Uncommitted) != BlockListTypes.None)
                        {
                            List <IBlock> blocks1 = new List <IBlock>();
                            foreach (BlockData blockDatum in
                                     from blck in dbContext.BlocksData
                                     where (blck.AccountName == this._blob.AccountName) && (blck.ContainerName == this._blob.ContainerName) && (blck.BlobName == this._blob.BlobName) && (blck.VersionTimestamp == this._blob.VersionTimestamp) && !blck.IsCommitted
                                     select blck)
                            {
                                blocks1.Add(new Block(DbListBlobObject.FromHexString(blockDatum.BlockId), blockDatum.Length.Value));
                            }
                            dbBlockCollections.UncommittedBlockList = new DbListBlobObject.DbBlockCollection(blocks1);
                        }
                        transactionScope.Complete();
                        this._blob     = blockBlob;
                        this.LeaseInfo = blobLeaseInfo;
                        blockList      = dbBlockCollections;
                    }
                }
                return(blockList);
            }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.GetBlockList"));

            yield return(asyncResult);

            context.ResultData = this._storageManager.AsyncProcessor.EndExecute <BlockLists>(asyncResult);
        }
Ejemplo n.º 16
0
        private bool PutBlockList()
        {
            bool flag;
            bool flag1 = false;

            try
            {
                for (int i = 0; i < this._maxNumberOfRetries; i++)
                {
                    try
                    {
                        using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                            {
                                this.GetContainer(dbContext);
                                BlockBlob           blob     = this.GetBlob(dbContext, true) as BlockBlob;
                                BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blob.ServiceMetadata);
                                instance.CopyStatus         = "success";
                                instance.CopyProgressOffset = this._contentLength.ToString();
                                instance.CopyProgressTotal  = this._contentLength.ToString();
                                instance.CopyCompletionTime = new long?(DateTime.UtcNow.ToFileTimeUtc());
                                blob.HasBlock                 = new bool?((this._blockIds.Count > 1 ? true : this._contentLength < (long)4194304));
                                blob.ContentLength            = this._contentLength;
                                blob.ServiceMetadata          = instance.GetMetadata();
                                blob.IsCommitted              = new bool?(false);
                                blob.UncommittedBlockIdLength = null;
                                dbContext.SubmitChanges();
                                dbContext.CommitBlockList(this._accountName, this._containerName, this._blobName, DbListBlobObject.SerializeCommitBlockListEntryFromUncommitted(this._blockIds).ToString(), ref this._lastModifiedTime);
                                transactionScope.Complete();
                            }
                        }
                        IStringDataEventStream info = Logger <IRestProtocolHeadLogger> .Instance.Info;
                        object[] objArray           = new object[] { this._accountName, this._containerName, this._blobName, this._contentLength };
                        info.Log("Commited Blocks for: {0}/{1}/{2}, Length:{3}", objArray);
                        break;
                    }
                    catch (SqlException sqlException)
                    {
                        if (this.ShouldRethrowException(i, sqlException, out flag1))
                        {
                            throw;
                        }
                    }
                }
                return(true);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Logger <IRestProtocolHeadLogger> .Instance.Error.Log("CopyBlob: PutBlockList exception {0}", new object[] { exception });

                this.SetCopyFailed(exception, flag1, null);
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 17
0
        public static DevelopmentStorageDbDataContext GetDbContext()
        {
            DevelopmentStorageDbDataContext developmentStorageDbDataContext = new DevelopmentStorageDbDataContext(DevelopmentStorageDbDataContext.GetConnectionString())
            {
                Log = DevelopmentStorageDbDataContext.LinqToSqlLogStream
            };

            return(developmentStorageDbDataContext);
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
 private static void ExecuteCommands(DevelopmentStorageDbDataContext context, string fileText)
 {
     string[] strArrays = DevelopmentStorageDbDataContext.s_goRegex.Split(fileText);
     for (int i = 0; i < (int)strArrays.Length; i++)
     {
         string str = strArrays[i];
         context.ExecuteCommand(str, new object[0]);
     }
 }
Ejemplo n.º 20
0
        internal static object GetValueFromXml(string sqlType, string val)
        {
            string str  = sqlType;
            string str1 = str;

            if (str != null)
            {
                switch (str1)
                {
                case "int":
                {
                    return(XmlConvert.ToInt32(val));
                }

                case "bigint":
                {
                    return(XmlConvert.ToInt64(val));
                }

                case "datetime":
                {
                    return(DevelopmentStorageDbDataContext.CheckSqlBoundsAndReturnAptDate(XmlConvert.ToDateTime(val, XmlDateTimeSerializationMode.Utc)));
                }

                case "uniqueidentifier":
                {
                    return(XmlConvert.ToGuid(val));
                }

                case "float(53)":
                {
                    return(XmlConvert.ToDouble(val));
                }

                case "bit":
                {
                    return(XmlConvert.ToBoolean(val));
                }

                case "varbinary(max)":
                {
                    return(Convert.FromBase64String(val));
                }

                case "nvarchar(max)":
                {
                    return(DevelopmentStorageDbDataContext.DecodeDataString(val));
                }
                }
            }
            throw new ArgumentException();
        }
Ejemplo n.º 21
0
        private TableRow CreateAndPopulateSqlEntity(UtilityRow utilRow)
        {
            TableRow tableRow = new TableRow()
            {
                AccountName  = this.AccountName,
                TableName    = this.m_currentResourceContainer.Name.ToLowerInvariant(),
                PartitionKey = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.PartitionKey),
                RowKey       = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.RowKey),
                Data         = XmlUtility.GetXmlFromUtilityRow(utilRow)
            };

            return(tableRow);
        }
Ejemplo n.º 22
0
        private GeoReplicationStats LoadGeoReplicationStats(DevelopmentStorageDbDataContext dbContext)
        {
            DateTime dbUTCDate = dbContext.GetDbUTCDate();

            DevelopmentStorageDbDataContext.AdjustSqlDateTime(ref dbUTCDate);
            GeoReplicationStats geoReplicationStat = new GeoReplicationStats()
            {
                LastSyncTime = new DateTime?(dbUTCDate),
                Status       = new GeoReplicationStatus?(GeoReplicationStatus.Live)
            };

            return(geoReplicationStat);
        }
Ejemplo n.º 23
0
        private Account LoadAccount(DevelopmentStorageDbDataContext dataContext)
        {
            Account account = (
                from a in dataContext.Accounts
                where a.Name == this._account.Name
                select a).FirstOrDefault <Account>();

            if (account == null)
            {
                throw new AccountNotFoundException();
            }
            return(account);
        }
Ejemplo n.º 24
0
 public static void SetCopyStatusToFailedAfterRestart()
 {
     while (true)
     {
         IEnumerable <Blob> blobs = null;
         try
         {
             using (TransactionScope transactionScope = new TransactionScope())
             {
                 using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                 {
                     IQueryable <Blob> blobs1 =
                         from b in dbContext.Blobs
                         select b;
                     blobs = blobs1.Take <Blob>(100);
                     if (blobs == null || blobs.Count <Blob>() == 0)
                     {
                         break;
                     }
                     else
                     {
                         foreach (Blob blob in blobs)
                         {
                             BlobServiceMetaData instance = BlobServiceMetaData.GetInstance(blob.ServiceMetadata);
                             if (!"pending".Equals(instance.CopyStatus))
                             {
                                 continue;
                             }
                             instance.CopyStatus            = "failed";
                             instance.CopyStatusDescription = "500 InternalError \"Reset to failed during restart.\"";
                             Blob blob1 = DbBlobObject.ClearBlob(blob, instance.GetMetadata());
                             dbContext.Blobs.DeleteOnSubmit(blob);
                             dbContext.SubmitChanges();
                             using (DevelopmentStorageDbDataContext developmentStorageDbDataContext = DevelopmentStorageDbDataContext.GetDbContext())
                             {
                                 developmentStorageDbDataContext.Blobs.InsertOnSubmit(blob1);
                                 developmentStorageDbDataContext.SubmitChanges();
                             }
                         }
                     }
                 }
                 transactionScope.Complete();
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             Logger <IRestProtocolHeadLogger> .Instance.Error.Log("SetCopyStatusToFailedAfterRestart: Failed to change copy status! Exception {0}", new object[] { exception });
         }
     }
 }
Ejemplo n.º 25
0
        private IEnumerator <IAsyncResult> ClearQueueImpl(AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan remaining) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    dbContext.ClearQueue(queueContainer.AccountName, queueContainer.QueueName);
                    this._queue = queueContainer;
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.ClearQueue"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Ejemplo n.º 26
0
        private IEnumerator <IAsyncResult> GetPropertiesImpl(ContainerPropertyNames propertyNames, IContainerCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute((TimeSpan remaining) => {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    DbQueueContainer.CheckQueueContainerCondition(queueContainer, condition);
                    this._queue = queueContainer;
                }
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.GetPropertiesImpl"));

            yield return(asyncResult);

            this.StorageManager.AsyncProcessor.EndExecute(asyncResult);
        }
Ejemplo n.º 27
0
        private Blob GetBlob(DevelopmentStorageDbDataContext context, bool shouldCheckLMT)
        {
            Blob blob = (
                from b in context.Blobs
                where (b.AccountName == this._accountName) && (b.ContainerName == this._containerName) && (b.BlobName == this._blobName) && (b.VersionTimestamp == this._versionTimeStamp)
                select b).FirstOrDefault <Blob>();

            if (blob == null)
            {
                throw new BlobNotFoundException();
            }
            if (shouldCheckLMT && blob.LastModificationTime.HasValue && this._lastModifiedTime.HasValue && blob.LastModificationTime.Value.ToString("u") != this._lastModifiedTime.Value.ToString("u"))
            {
                throw new ConditionNotMetException();
            }
            return(blob);
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        private IEnumerator <IAsyncResult> PutMessageImpl(List <PushedMessage> messagesList, bool usePutMessageRowCommand, AsyncIteratorContext <List <IMessageData> > context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <List <IMessageData> >((TimeSpan remaining) => {
                List <IMessageData> messageDatas;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    DateTime utcNow = DateTime.UtcNow;
                    this.LoadQueueContainer(dbContext);
                    List <QueueMessage> queueMessages = new List <QueueMessage>();
                    List <IMessageData> messageDatas1 = new List <IMessageData>();
                    object obj = messagesList;
                    if (obj == null)
                    {
                        obj = Enumerable.Empty <PushedMessage>();
                    }
                    foreach (PushedMessage pushedMessage in (IEnumerable <PushedMessage>)obj)
                    {
                        QueueMessage queueMessage = new QueueMessage()
                        {
                            AccountName         = this._queue.AccountName,
                            QueueName           = this._queue.QueueName,
                            VisibilityStartTime = utcNow.Add(pushedMessage.VisibilityTimeout),
                            MessageId           = Guid.NewGuid()
                        };
                        QueueMessage queueMessage1 = queueMessage;
                        TimeSpan?messageTTL        = pushedMessage.MessageTTL;
                        queueMessage1.ExpiryTime   = utcNow.Add((messageTTL.HasValue ? messageTTL.GetValueOrDefault() : new TimeSpan((long)0)));
                        queueMessage.InsertionTime = utcNow;
                        queueMessage.DequeueCount  = 0;
                        queueMessage.Data          = pushedMessage.MessageText;
                        QueueMessage queueMessage2 = queueMessage;
                        queueMessages.Add(queueMessage2);
                        messageDatas1.Add(new DbMessageData(queueMessage2, false));
                    }
                    dbContext.QueueMessages.InsertAllOnSubmit <QueueMessage>(queueMessages);
                    dbContext.SubmitChanges();
                    messageDatas = messageDatas1;
                }
                return(messageDatas);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.PutMessage"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <List <IMessageData> >(asyncResult);
        }
Ejemplo n.º 30
0
        private IEnumerator <IAsyncResult> UpdateMessageImpl(IQueueMessageReceipt queueMessageReceipt, byte[] body, TimeSpan visibilityTimeout, TimeSpan?timeToLive, AsyncIteratorContext <IQueueMessageReceipt> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <IQueueMessageReceipt>((TimeSpan remaining) => {
                IQueueMessageReceipt receipt;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    this._queue = queueContainer;
                    QueueMessage queueMessage = (
                        from m in dbContext.QueueMessages
                        where (m.AccountName == this._queue.AccountName) && (m.QueueName == this._queue.QueueName) && (m.MessageId == ((Receipt)queueMessageReceipt).MessageId) && (m.VisibilityStartTime == ((Receipt)queueMessageReceipt).VisibilityStart)
                        select m).FirstOrDefault <QueueMessage>();
                    if (queueMessage == null)
                    {
                        throw new MessageNotFoundException();
                    }
                    DateTime utcNow            = DateTime.UtcNow;
                    QueueMessage queueMessage1 = new QueueMessage()
                    {
                        AccountName         = queueMessage.AccountName,
                        QueueName           = queueMessage.QueueName,
                        VisibilityStartTime = utcNow.Add(visibilityTimeout),
                        MessageId           = queueMessage.MessageId,
                        ExpiryTime          = queueMessage.ExpiryTime,
                        InsertionTime       = queueMessage.InsertionTime,
                        DequeueCount        = queueMessage.DequeueCount,
                        Data = body ?? queueMessage.Data
                    };
                    dbContext.QueueMessages.DeleteOnSubmit(queueMessage);
                    dbContext.QueueMessages.InsertOnSubmit(queueMessage1);
                    dbContext.SubmitChanges();
                    receipt = new Receipt()
                    {
                        MessageId       = ((Receipt)queueMessageReceipt).MessageId,
                        VisibilityStart = queueMessage1.VisibilityStartTime,
                        DequeueCount    = queueMessage1.DequeueCount
                    };
                }
                return(receipt);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.UpdateMessage"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <IQueueMessageReceipt>(asyncResult);
        }