public void Execute(Action operation)
        {
            ExecutionCount = 0;

            defaultRetryPolicy.Execute(() =>
            {
                doBefore(++ExecutionCount);
                operation();
            });
        }
Esempio n. 2
0
        private void buildConnection()
        {
            if (_connection == null)
            {
                _connection = _factory is null ?
                              new TransactionState(_mode, _isolationLevel, _commandTimeout, _externalConnection, _ownsConnection) :
                              new TransactionState(_factory, _mode, _isolationLevel, _commandTimeout, _ownsConnection);

                _retryPolicy.Execute(() => _connection.Open());
            }
        }
        /// <summary>
        /// Wrapper for calling a request and parsing the response if there is an error.
        /// </summary>
        /// <param name="client">The client to use for making the call.</param>
        /// <param name="retryPolicy">The retry policy to use for this request.</param>
        /// <param name="request">The details of the request to make.</param>
        /// <param name="nullOn404">Set if we should return NULL on a 404, false will cause an exception to get thrown.</param>
        /// <returns>The IRestResponse or NULL if the entity was not found.</returns>
        public static IRestResponse ExecuteRequestFor(
            this IRestClient client,
            IRetryPolicy retryPolicy,
            IRestRequest request,
            bool nullOn404)
        {
            var resource = client.BuildUri(request);

            IRestResponse response =
                retryPolicy.Execute(
                    attempt =>
            {
                s_log.Trace(m => m("REQUESTING {0}: {1}  (ATTEMPT: {2})", request.Method, resource, attempt));

                var res = client.Execute(request);

                s_log.Debug(m => m("{0} {1} - {2}", request.Method, res.StatusCode, resource));

                if (!res.StatusCode.IsSuccessCode())
                {
                    return(HandleErrorResponse(request, res, resource, nullOn404));
                }

                return(res);
            });

            return(response);
        }
        private bool EnumTheWindows(IntPtr hWnd, IntPtr lParam)
        {
            var mi = new MonitorInfoEx();

            mi.cbSize = Marshal.SizeOf(mi);

            GetMonitorInfoEx(MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY), ref mi);

            Process process = _retryPolicy.Execute(() =>
            {
                return(Process.GetProcessesByName(LeagueClientProcessName)?.FirstOrDefault());
            }, proc => proc != null && proc.MainWindowHandle != IntPtr.Zero, maxRetries: 10, delayBetweenRequest: 1000);

            if (process == null || process.MainWindowHandle == IntPtr.Zero)
            {
                throw new LeagueOfLegendsProcessException($"No League clien process found");
            }
            WINDOWPLACEMENT placement = GetPlacement(process.MainWindowHandle);

            int monitorHeight = mi.rcMonitor.Right - mi.rcMonitor.Left;
            int monitorWidth  = mi.rcMonitor.Bottom - mi.rcMonitor.Top;
            int windowHeight  = placement.rcNormalPosition.Right - placement.rcNormalPosition.Left;
            int windowWidth   = placement.rcNormalPosition.Bottom - placement.rcNormalPosition.Top;

            return(windowHeight == monitorHeight && windowWidth == monitorWidth);
        }
Esempio n. 5
0
 public void Handle(TempAlertCommand command)
 {
     _retryPolicy.Execute(() => {
         _logger.Log(command.BuildMessage());
         throw new System.Exception("Testing Exponential Retry Policy");
     });
 }
Esempio n. 6
0
 public void Handle(GenericCommand command)
 {
     _retryPolicy.Execute(() => {
         _logger.Log(command.BuildMessage());
         throw new Exception("Testing Simple Policy");
     });
 }
 public override void Open()
 {
     _retryPolicy.Execute(() =>
     {
         if (_underlyingConnection.State != ConnectionState.Open)
         {
             _underlyingConnection.Open();
         }
     });
 }
Esempio n. 8
0
        private static int CallExecuteWithFaultingAction <TException>(IRetryPolicy policy, int numberOfTimesToThrowException)
            where TException : Exception, new()
        {
            var attempts = 0;

            policy.Execute(() =>
            {
                if (attempts >= numberOfTimesToThrowException)
                {
                    return;
                }

                attempts++;

                throw new TException();
            });

            return(attempts);
        }
Esempio n. 9
0
 public override void Open()
 {
     _policy.Execute(_connection.Open);
 }
Esempio n. 10
0
 public override int Execute(string sql, object param = null, IDbTransaction transaction = null, int?timeout = default(int?), CommandType?commandType = default(CommandType?))
 {
     return(retryPolicy.Execute(() => base.Execute(sql, param, transaction, timeout, commandType)));
 }
Esempio n. 11
0
 public override void Open()
 {
     _connection.ConnectionString = ConnectionString;
     _policy.Execute(_connection.Open);
 }
Esempio n. 12
0
 public override void Cancel()
 {
     _policy.Execute(_command.Cancel);
 }
Esempio n. 13
0
 /// <inheritdoc />
 public void Execute(Action action)
 {
     _decorated.Execute(action);
     _afterExecute();
 }
Esempio n. 14
0
 public void Handle(DoorOpenCommand command)
 {
     _retryPolicy.Execute(() => { _logger.Log(command.BuildMessage()); });
 }