Ejemplo n.º 1
0
 public static void AssertNoConflict(this IConcurrencyAware item, IConcurrencyAware against)
 {
     if (ConflictsWith(item, against))
     {
         throw new ConcurrencyConflictException(item.ETag, against.ETag);
     }
 }
Ejemplo n.º 2
0
        public static bool ConflictsWith(this IConcurrencyAware item, IConcurrencyAware against)
        {
            if (item.ETag != null && against.ETag != null)
            {
                return (item.ETag != against.ETag);
            }

            if (item.LastModofied.HasValue && against.LastModofied.HasValue)
            {
                return (item.LastModofied.Value != against.LastModofied.Value);
            }

            // if all values null it is OK
            if (!item.LastModofied.HasValue && !against.LastModofied.HasValue &&
                item.ETag == null && against.ETag == null)
                return false;

            throw new InvalidOperationException("Concurrency data not consistent");

        }
Ejemplo n.º 3
0
        private static void CheckConcurrency(IConcurrencyAware concurrencyAware,
                                             CloudBlockBlob blobReference)
        {
            if (concurrencyAware != null)
            {
                if (!string.IsNullOrEmpty(concurrencyAware.ETag) &&
                    blobReference.Properties.ETag != concurrencyAware.ETag)
                {
                    throw new ConcurrencyConflictException(concurrencyAware.ETag,
                                                           blobReference.Properties.ETag);
                }

                if (concurrencyAware.LastModofied != null &&
                    blobReference.Properties.LastModified != null &&
                    blobReference.Properties.LastModified != concurrencyAware.LastModofied)
                {
                    throw new ConcurrencyConflictException(concurrencyAware.LastModofied.Value,
                                                           blobReference.Properties.LastModified.Value);
                }
            }
        }
Ejemplo n.º 4
0
        public static bool ConflictsWith(this IConcurrencyAware item, IConcurrencyAware against)
        {
            if (item.ETag != null && against.ETag != null)
            {
                return(item.ETag != against.ETag);
            }

            if (item.LastModified.HasValue && against.LastModified.HasValue)
            {
                return(item.LastModified.Value != against.LastModified.Value);
            }

            // if all values null it is OK
            if (!item.LastModified.HasValue && !against.LastModified.HasValue &&
                item.ETag == null && against.ETag == null)
            {
                return(false);
            }

            throw new InvalidOperationException("Concurrency data not consistent");
        }
Ejemplo n.º 5
0
 public static void AssertNoConflict(this IConcurrencyAware item, IConcurrencyAware against)
 {
     if(ConflictsWith(item, against))
         throw new ConcurrencyConflictException(item.ETag, against.ETag);
 }
Ejemplo n.º 6
0
        private static void CheckConcurrency(IConcurrencyAware concurrencyAware,
            CloudBlockBlob blobReference)
        {
            if (concurrencyAware != null)
            {
                if (!string.IsNullOrEmpty(concurrencyAware.ETag) &&
                    blobReference.Properties.ETag != concurrencyAware.ETag)
                {
                    throw new ConcurrencyConflictException(concurrencyAware.ETag,
                        blobReference.Properties.ETag);
                }

                if (concurrencyAware.LastModofied != null &&
                    blobReference.Properties.LastModified != null &&
                   blobReference.Properties.LastModified != concurrencyAware.LastModofied)
                {
                    throw new ConcurrencyConflictException(concurrencyAware.LastModofied.Value,
                        blobReference.Properties.LastModified.Value);
                }
            }

        }