コード例 #1
0
 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();
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public static ValueTask <bool> Set <T>(this IRedisCommands redis, string key, T value, OptimisticConcurrency concurrency)
 {
     return(redis.Set(key, value, null, concurrency));
 }
コード例 #7
0
 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)));
 }
コード例 #8
0
 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)));
 }
コード例 #9
0
        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);
        }
コード例 #10
0
 public SetCommand(string key, T value, TimeSpan?expiration = null, OptimisticConcurrency concurrency = default)
     : base(CommandNames.Set, PrepareParams(key, value, expiration, concurrency))
 {
 }