コード例 #1
0
        public static ErrorHandlingPolicy NewDefaultNetworkHandlingPolicy()
        {
            ErrorHandlingPolicy res = new ErrorHandlingPolicy();

            res.ErroHandlingMode   = ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY;
            res.RetryAttempts      = 0;
            res.SleepTimeInSeconds = 0;

            return(res);
        }
 public JSONAdvancedSettingsModel()
 {
     CustomLocalTempDir = null;
     ParseDates         = false;
     NetworkErrorPolicy = new ErrorHandlingPolicy();
     NetworkErrorPolicy.ErroHandlingMode   = ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY;
     NetworkErrorPolicy.RetryAttempts      = 0;
     NetworkErrorPolicy.SleepTimeInSeconds = 0;
     HttpErrorPolicy = new Dictionary <int, ErrorHandlingPolicy>();
 }
コード例 #3
0
        /// <summary>
        /// This method returns a dictionary of ErrorHandling policies associated to some well-known http status codes.
        /// Bu default we will simply stop on errors 4xx and 5xx
        /// </summary>
        /// <returns></returns>
        public static Dictionary <int, ErrorHandlingPolicy> NewDefaultHttpHandlingPolicy()
        {
            Dictionary <int, ErrorHandlingPolicy> res = new Dictionary <int, ErrorHandlingPolicy>();

            // HTTP 400:
            ErrorHandlingPolicy p400 = new ErrorHandlingPolicy();

            p400.ErroHandlingMode   = ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY;
            p400.RetryAttempts      = 0;
            p400.SleepTimeInSeconds = 0;
            res.Add(400, p400);

            // HTTP 500:
            ErrorHandlingPolicy p500 = new ErrorHandlingPolicy();

            p500.ErroHandlingMode   = ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY;
            p500.RetryAttempts      = 0;
            p500.SleepTimeInSeconds = 0;
            res.Add(500, p500);

            return(res);
        }
コード例 #4
0
        public JSONAdvancedSettingsModel SaveToModel()
        {
            JSONAdvancedSettingsModel result = new JSONAdvancedSettingsModel();

            // Save network error policy
            ErrorHandlingPolicy networkErr = new ErrorHandlingPolicy();

            if (stopImmediatelyR.Checked)
            {
                networkErr.ErroHandlingMode = ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY;
            }
            else if (skipR.Checked)
            {
                networkErr.ErroHandlingMode = ErrorHandlingPolicy.ErrorHandling.SKIP;
            }
            else if (retryR.Checked)
            {
                networkErr.ErroHandlingMode = ErrorHandlingPolicy.ErrorHandling.RETRY;
                int res;

                if (int.TryParse(retryLabel.Text, out res))
                {
                    if (res > 0)
                    {
                        throw new ApplicationException("Please specify a positive integer value as retry attempts");
                    }
                    else
                    {
                        networkErr.RetryAttempts = res;
                    }
                }
                else
                {
                    throw new ApplicationException("Please specify a positive integer value as retry attempts");
                }

                if (int.TryParse(waitTimeLabel.Text, out res))
                {
                    if (res > 0)
                    {
                        throw new ApplicationException("Please specify a positive integer value sleep interval between failures");
                    }
                    else
                    {
                        networkErr.SleepTimeInSeconds = res;
                    }
                }
                else
                {
                    throw new ApplicationException("Please specify a positive integer value sleep interval between failures");
                }
            }
            else
            {
                throw new ApplicationException("No handling mode has been selected.");
            }

            result.NetworkErrorPolicy = networkErr;

            // Save http error policy
            Dictionary <int, ErrorHandlingPolicy> httpcodes = new Dictionary <int, ErrorHandlingPolicy>();

            if (httpErrorHandlingGv.IsCurrentCellDirty || httpErrorHandlingGv.IsCurrentRowDirty)
            {
                httpErrorHandlingGv.CurrentRow.DataGridView.EndEdit();
                httpErrorHandlingGv.EndEdit();
                CurrencyManager cm = (CurrencyManager)httpErrorHandlingGv.BindingContext[httpErrorHandlingGv.DataSource, httpErrorHandlingGv.DataMember];
                cm.EndCurrentEdit();
            }

            // Save the handling policy regarding HTTP errors
            Dictionary <int, ErrorHandlingPolicy> http_err_policy = new Dictionary <int, ErrorHandlingPolicy>();

            foreach (DataGridViewRow r in httpErrorHandlingGv.Rows)
            {
                if (r.IsNewRow)
                {
                    continue;
                }

                if (r.ErrorText != "")
                {
                    throw new ApplicationException(String.Format("Invalid HTTP error policy specified in the table. Please check row {0}", (r.Index + 1)));
                }
                else
                {
                    ErrorHandlingPolicy p = new ErrorHandlingPolicy();
                    p.ErroHandlingMode   = (ErrorHandlingPolicy.ErrorHandling)r.Cells[1].Tag;
                    p.RetryAttempts      = (int)r.Cells[2].Tag;
                    p.SleepTimeInSeconds = (int)r.Cells[3].Tag;

                    http_err_policy.Add((int)r.Cells[0].Tag, p);
                }
            }

            result.HttpErrorPolicy = http_err_policy;

            if (!string.IsNullOrEmpty(uiTempDir.Text))
            {
                result.CustomLocalTempDir = uiTempDir.Text;
            }
            else
            {
                result.CustomLocalTempDir = null;
            }

            result.ParseDates = cbParseJsonDate.Checked;

            return(result);
        }