public HashSetCommand(string key, string field, T value, OptimisticConcurrency concurrency = OptimisticConcurrency.None) : base(concurrency == OptimisticConcurrency.None ? CommandNames.HSet : CommandNames.HSetNX, key.ToValue(), field.ToValue(), value.ToValue()) { if (concurrency == OptimisticConcurrency.IfExists) { throw new NotSupportedException(); } }
public void modifyCustomer(KundeDto kundeDto) { WriteActualMethod(); Kunde kunde = DtoConverter.ConvertToEntity(kundeDto); KundeManager kundeManager = new KundeManager(); try { kundeManager.modifyCustomer(kunde); } catch (OptimisticConcurrencyException <Kunde> e) { OptimisticConcurrency <KundeDto> fault = new OptimisticConcurrency <KundeDto>(); fault.Result = false; fault.Message = e.Message; fault.Description = "Occurrency Exception!"; throw new FaultException <OptimisticConcurrency <KundeDto> >(fault); } }
public void modifyCar(AutoDto autoDto) { WriteActualMethod(); Auto auto = DtoConverter.ConvertToEntity(autoDto); AutoManager autoManager = new AutoManager(); try { autoManager.modifyCar(auto); } catch (OptimisticConcurrencyException <Auto> e) { OptimisticConcurrency <AutoDto> fault = new OptimisticConcurrency <AutoDto>(); fault.Result = false; fault.Message = e.Message; fault.Description = "Occurrency Exception!"; throw new FaultException <OptimisticConcurrency <AutoDto> >(fault); } }
public void modifyRerservation(ReservationDto reservationDto) { WriteActualMethod(); Reservation reservation = DtoConverter.ConvertToEntity(reservationDto); ReservationManager reservationManager = new ReservationManager(); try { reservationManager.modifyReservation(reservation); } catch (OptimisticConcurrencyException <Reservation> e) { OptimisticConcurrency <ReservationDto> fault = new OptimisticConcurrency <ReservationDto>(); fault.Result = false; fault.Message = e.Message; fault.Description = "Occurrency Exception!"; throw new FaultException <OptimisticConcurrency <ReservationDto> >(fault); } }
protected async Task <SaveResult> SaveAsync(DataConflictPolicy policy) { bool saveFailed; do { saveFailed = false; try { int result = await this.context.SaveChangesAsync(); return(new SaveResult { AlteredObjectsCount = result }); } catch (DbUpdateConcurrencyException exception) { if (policy == DataConflictPolicy.NoPolicy) { throw new DalException(DalErrorType.BaseServiceDataConflictWithNoPolicy, "Data conflict (Optimistic concurrency)"); } saveFailed = true; DataConflictInfo info = OptimisticConcurrency.ApplyPolicy(policy, exception); if (info != null) { throw new DataConflictException(DalErrorType.BaseServiceDataConflictWithAskClientPolicy, info); } } catch (Exception exception) { exception.HandleException(); } } while (saveFailed); return(null); }
public static ValueTask <bool> Set <T>(this IRedisCommands redis, string key, T value, OptimisticConcurrency concurrency) { return(redis.Set(key, value, null, concurrency)); }
public async ValueTask <bool> HashSet <T>(string key, string field, T value, OptimisticConcurrency concurrency = OptimisticConcurrency.None) { return(await Execute(new HashSetCommand <T>(key, field, value, concurrency))); }
public async ValueTask <bool> Set <T>(string key, T value, TimeSpan?expiration = null, OptimisticConcurrency concurrency = OptimisticConcurrency.None) { return(await Execute(new SetCommand <T>(key, value, expiration, concurrency))); }
private static RedisObject[] PrepareParams(string key, T value, TimeSpan?expiration = null, OptimisticConcurrency concurrency = OptimisticConcurrency.None) { var paramCount = 2; if (expiration != null) { paramCount += 2; } if (concurrency != OptimisticConcurrency.None) { ++paramCount; } var @params = new RedisObject[paramCount]; @params[0] = key.ToValue(); @params[1] = value.ToValue(); var paramIndex = 2; if (expiration != null) { @params[paramIndex++] = CommandSwitches.PX; @params[paramIndex++] = ((int)expiration.Value.TotalMilliseconds).ToValue(); } switch (concurrency) { case OptimisticConcurrency.IfNotExists: @params[paramIndex] = CommandSwitches.NX; break; case OptimisticConcurrency.IfExists: @params[paramIndex] = CommandSwitches.XX; break; } return(@params); }
public SetCommand(string key, T value, TimeSpan?expiration = null, OptimisticConcurrency concurrency = default) : base(CommandNames.Set, PrepareParams(key, value, expiration, concurrency)) { }