public virtual T Get(string objId, out OptimisticConcurrencyContext context)
        {
            OptimisticConcurrencyContext optimisticContext = null;
            var result = this.StorageRetryPolicy.ExecuteAction <T>(() =>
            {
                try
                {
                    CloudBlob blob = this.Container.GetBlobReference(objId);
                    blob.FetchAttributes();
                    optimisticContext = new OptimisticConcurrencyContext(blob.Properties.ETag)
                    {
                        ObjectId = objId
                    };
                    return(this.ReadObject(blob));
                }
                catch (StorageClientException ex)
                {
                    TraceHelper.TraceWarning(ex.TraceInformation());
                    if (HttpStatusCode.NotFound.Equals(ex.StatusCode) &&
                        (StorageErrorCode.BlobNotFound.Equals(ex.ErrorCode) ||
                         StorageErrorCode.ResourceNotFound.Equals(ex.ErrorCode)))
                    {
                        optimisticContext = this.GetContextForUnexistentBlob(objId);
                        return(default(T));
                    }
                    throw;
                }
            });

            context = optimisticContext;
            return(result);
        }
Beispiel #2
0
        public virtual T Get(string objId, out OptimisticConcurrencyContext context)
        {
            OptimisticConcurrencyContext optimisticContext = null;
            var result = this.StorageRetryPolicy.ExecuteAction <T>(() =>
            {
                try
                {
                    var blob = this.Container.GetBlockBlobReference(objId);
                    blob.FetchAttributes();
                    optimisticContext = new OptimisticConcurrencyContext(blob.Properties.ETag)
                    {
                        ObjectId = objId
                    };
                    return(this.ReadObject(blob));
                }
                catch (StorageException ex)
                {
                    var requestInformation = ex.RequestInformation;
                    var statusCode         = (System.Net.HttpStatusCode)requestInformation.HttpStatusCode;//request

                    TraceHelper.TraceWarning(ex.TraceInformation());
                    if (HttpStatusCode.NotFound.Equals(statusCode))
                    {
                        optimisticContext = this.GetContextForUnexistentBlob(objId);
                        return(default(T));
                    }
                    throw;
                }
            });

            context = optimisticContext;
            return(result);
        }
        public virtual T Get(string objId, out OptimisticConcurrencyContext context)
        {
            OptimisticConcurrencyContext optimisticContext = null;
            var result = this.StorageRetryPolicy.ExecuteAction <T>(() =>
            {
                try
                {
                    return(this.DoGet(objId, out optimisticContext));
                }
                catch (StorageClientException ex)
                {
                    TraceHelper.TraceWarning(ex.TraceInformation());
                    if (HttpStatusCode.NotFound.Equals(ex.StatusCode) &&
                        (StorageErrorCode.BlobNotFound.Equals(ex.ErrorCode) ||
                         StorageErrorCode.ResourceNotFound.Equals(ex.ErrorCode)))
                    {
                        optimisticContext = this.GetContextForUnexistentBlob(objId);
                        return(default(T));
                    }
                    throw;
                }
            });

            context = optimisticContext;
            return(result);
        }
Beispiel #4
0
        public virtual void Save(string objId, T obj)
        {
            var context = new OptimisticConcurrencyContext()
            {
                ObjectId = objId
            };

            this.Save(context, obj);
        }
        protected override void DoSave(string objId, T obj)
        {
            OptimisticConcurrencyContext context = new OptimisticConcurrencyContext()
            {
                ObjectId = objId
            };

            this.DoSave(context, obj);
        }
        protected override byte[] DoGet(string objId, out OptimisticConcurrencyContext context)
        {
            CloudBlob blob = this.Container.GetBlobReference(objId);

            blob.FetchAttributes();
            context = new OptimisticConcurrencyContext(blob.Properties.ETag)
            {
                ObjectId = objId
            };
            return(blob.DownloadByteArray());
        }
        protected override T DoGet(string objId, out OptimisticConcurrencyContext context)
        {
            CloudBlob blob = this.Container.GetBlobReference(objId);

            blob.FetchAttributes();
            context = new OptimisticConcurrencyContext(blob.Properties.ETag)
            {
                ObjectId = objId
            };
            return(new JavaScriptSerializer().Deserialize <T>(blob.DownloadText()));
        }
 protected abstract T DoGet(string objId, out OptimisticConcurrencyContext context);