private void RetryOrStopIfNecessary(HttpStatusCode statusCode)
        {
            if (!IsRunning || ((int)statusCode >= 200 && (int)statusCode <= 299))
            {
                return;
            }

            Log.To.ChangeTracker.I(Tag, "{0} got a bad status code ({1}), analyzing...", this, statusCode);
            var resolution = ExceptionResolver.Solve(statusCode, new ExceptionResolverOptions {
                Continuous = Continuous
            });

            switch (resolution.Resolution)
            {
            case ErrorResolution.RetryLater:
                if (resolution.ResolutionFlags.HasFlag(ErrorResolutionFlags.OutOfRetries))
                {
                    Log.To.ChangeTracker.I(Tag, "{0} out of retries", this);
                }

                Log.To.ChangeTracker.I(Tag, "{0} will retry later...", this);
                _workExecutor.StartNew(Stop, ErrorResolution.RetryLater);
                break;

            case ErrorResolution.Stop:
                Log.To.ChangeTracker.I(Tag, "{0} cannot recover, stopping...", this);
                _workExecutor.StartNew(Stop, ErrorResolution.Stop);
                break;

            default:
                break;
            }
        }
        private bool RetryIfFailedPost(Exception e)
        {
            if (!_usePost)
            {
                return(false);
            }

            var statusCode = ExceptionResolver.GetStatusCode(e);

            return(RetryIfFailedPost(statusCode));
        }
        private void RetryOrStopIfNecessary(Exception e)
        {
            if (!IsRunning)
            {
                return;
            }

            if (e != null)
            {
                Log.To.ChangeTracker.I(Tag, "{0} got an exception, analyzing...", this);
            }

            var resolution = ExceptionResolver.Solve(e, new ExceptionResolverOptions {
                Continuous = Continuous
            });

            switch (resolution.Resolution)
            {
            case ErrorResolution.RetryLater:
                Error = Misc.Flatten(e).FirstOrDefault();
                if (resolution.ResolutionFlags.HasFlag(ErrorResolutionFlags.OutOfRetries))
                {
                    Log.To.ChangeTracker.I(Tag, "{0} out of retries", this);
                }

                Log.To.ChangeTracker.I(Tag, "{0} will retry later...", this);
                _workExecutor.StartNew(Stop, ErrorResolution.RetryLater);
                break;

            case ErrorResolution.RetryNow:
                Log.To.ChangeTracker.V(Tag, "{0} no error detected, continuing...", this);
                PerformRetry(false);
                break;

            case ErrorResolution.GoOffline:
                Error = Misc.Flatten(e).FirstOrDefault();
                Log.To.ChangeTracker.I(Tag, "{0} signaling to go offline...", this);
                _workExecutor.StartNew(Stop, ErrorResolution.GoOffline);
                break;

            case ErrorResolution.Stop:
                Error = Misc.Flatten(e).FirstOrDefault();
                if (Error != null)
                {
                    Log.To.ChangeTracker.I(Tag, "{0} cannot recover, stopping...", this);
                }

                _workExecutor.StartNew(Stop, ErrorResolution.Stop);
                break;
            }
        }