public static void AssertNoConflict(this IConcurrencyAware item, IConcurrencyAware against) { if (ConflictsWith(item, against)) { throw new ConcurrencyConflictException(item.ETag, against.ETag); } }
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"); }
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); } } }
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"); }
public static void AssertNoConflict(this IConcurrencyAware item, IConcurrencyAware against) { if(ConflictsWith(item, against)) throw new ConcurrencyConflictException(item.ETag, against.ETag); }