예제 #1
0
 public static Entity.UnlockResponse FromProto(this UnlockResponse response)
 {
     return(new Entity.UnlockResponse()
     {
         Header = response.Header.FromProto(),
     });
 }
예제 #2
0
        /// <summary>
        /// UnlockAsync takes a key returned by Lock and releases the hold on lock. The
        /// next Lock caller waiting for the lock will then be woken up and given
        /// ownership of the lock.
        /// </summary>
        /// <param name="request">The request to send to the server</param>
        /// <returns></returns>
        public async Task <UnlockResponse> UnlockAsync(UnlockRequest request, Metadata headers = null)
        {
            UnlockResponse response   = new UnlockResponse();
            bool           success    = false;
            int            retryCount = 0;

            while (!success)
            {
                try
                {
                    response = await _balancer.GetConnection().lockClient.UnlockAsync(request, headers);

                    success = true;
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable)
                {
                    retryCount++;
                    if (retryCount >= _balancer._numNodes)
                    {
                        throw ex;
                    }
                }
            }
            return(response);
        }
예제 #3
0
        public UnlockResponse Unlock(UnlockRequest request)
        {
            UnlockResponse response = new UnlockResponse();

            response.Errors = new List <BusinessRule>();

            User user = _repository
                        .FindBy(request.UserId);

            if (user != null)
            {
                try
                {
                    user.Status = 1;
                    _repository.Save(user);
                    _uow.Commit();

                    response.Result = true;
                }
                catch (Exception ex)
                {
                    response.Errors.Add(new BusinessRule("Error", ex.Message));
                    response.Result = false;
                }
            }
            else
            {
                response.Result = false;
            }

            return(response);
        }
예제 #4
0
        /// <summary>
        /// UnlockAsync takes a key returned by Lock and releases the hold on lock. The
        /// next Lock caller waiting for the lock will then be woken up and given
        /// ownership of the lock.
        /// </summary>
        /// <param name="request">The request to send to the server</param>
        /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
        /// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>The response received from the server.</returns>
        public async Task <UnlockResponse> UnlockAsync(UnlockRequest request, Grpc.Core.Metadata headers = null,
                                                       DateTime?deadline = null, CancellationToken cancellationToken = default)
        {
            UnlockResponse response   = new UnlockResponse();
            bool           success    = false;
            int            retryCount = 0;

            while (!success)
            {
                try
                {
                    response = await _balancer.GetConnection().lockClient
                               .UnlockAsync(request, headers, deadline, cancellationToken);

                    success = true;
                }
                catch (RpcException ex) when(ex.StatusCode == StatusCode.Unavailable)
                {
                    retryCount++;
                    if (retryCount >= _balancer._numNodes)
                    {
                        throw;
                    }
                }
            }

            return(response);
        }
예제 #5
0
        public bool UnlockDataFromUser()
        {
            // Truongnx: test performance
            // return true;

            // Kiểm tra kết nối, server, service trước khi request
            Common.Utilities.IsRequestAllow(ApplicationConstant.SystemService.UtilitiesService.layGiaTri());

            //Khởi tạo và gán các giá trị cho request
            UnlockRequest  request  = Common.Utilities.PrepareRequest(new UnlockRequest());
            UnlockResponse response = new UnlockResponse();

            // Lấy kết quả trả về
            response = Client.UnlockDataFromUser(request);

            // Kiểm tra kết quả trả về
            Common.Utilities.ValidResponse(request, response);

            //return response.ListUnlockedId.ToList();
            if (response.ResponseStatus == ApplicationConstant.ResponseStatus.THANH_CONG)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
        public UnlockResponse UnLock(ByteSequence lockKey)
        {
            V3Lockpb.UnlockRequest request = new V3Lockpb.UnlockRequest();
            request.Key = lockKey.GetByteString();
            var            rsp      = lockClient.Unlock(request);
            UnlockResponse response = new UnlockResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //       stub.Unlock(request),
            //       new FunctionResponse<V3Lockpb.UnlockRequest, UnlockResponse>(),
            //       Util.IsRetriable
            //);
        }
예제 #7
0
        public ActionResult Modal(string Id)
        {
            SecurityController security = new SecurityController();

            if (!string.IsNullOrEmpty(Id) && security.IsAuthorized())
            {
                Item item = Dbs.Db.GetItem(Id);

                if (item != null && security.IsUnlockable(item))
                {
                    UnlockResponse response = new UnlockResponse();
                    response.Id = item.ID.ToString();
                    return(View("/~/Views/Modal.cshtml", response));
                }
            }

            return(new EmptyResult());
        }
예제 #8
0
        public bool UnlockData(DatabaseConstant.Module module,
                               DatabaseConstant.Function function,
                               DatabaseConstant.Table table,
                               DatabaseConstant.Action action,
                               List <int> listLockedId)
        {
            // Truongnx: test performance
            //return true;

            // Kiểm tra kết nối, server, service trước khi request
            Common.Utilities.IsRequestAllow(ApplicationConstant.SystemService.UtilitiesService.layGiaTri());

            //Khởi tạo và gán các giá trị cho request
            UnlockRequest  request  = Common.Utilities.PrepareRequest(new UnlockRequest());
            UnlockResponse response = new UnlockResponse();

            request.Module     = module;
            request.Function   = function;
            request.Table      = table;
            request.Action     = action;
            request.ListLockId = listLockedId.ToArray();

            // Lấy kết quả trả về
            response = Client.UnlockData(request);

            // Kiểm tra kết quả trả về
            Common.Utilities.ValidResponse(request, response);

            //return response.ListUnlockedId.ToList();
            if (response.ResponseStatus == ApplicationConstant.ResponseStatus.THANH_CONG)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }