コード例 #1
0
        public void LoadModel(JSONAdvancedSettingsModel advancedSettings)
        {
            // Load network error policy
            switch (advancedSettings.NetworkErrorPolicy.ErroHandlingMode)
            {
            case ErrorHandlingPolicy.ErrorHandling.STOP_IMMEDIATELY:
                stopImmediatelyR.Checked = true;
                break;

            case ErrorHandlingPolicy.ErrorHandling.SKIP:
                skipR.Checked = true;
                break;

            case ErrorHandlingPolicy.ErrorHandling.RETRY:
                retryR.Checked     = true;
                retryLabel.Text    = "" + advancedSettings.NetworkErrorPolicy.RetryAttempts;
                waitTimeLabel.Text = "" + advancedSettings.NetworkErrorPolicy.SleepTimeInSeconds;
                break;

            default:
                throw new ApplicationException("invalid error handling policy. Please contact the developer.");
            }

            // Load the HTTP error policy
            httpErrorHandlingGv.Rows.Clear();
            foreach (var r in advancedSettings.HttpErrorPolicy)
            {
                int index = httpErrorHandlingGv.Rows.Add();
                httpErrorHandlingGv[0, index].Value = "" + r.Key;
                httpErrorHandlingGv[0, index].Tag   = r.Key;

                httpErrorHandlingGv[1, index].Value = "" + r.Value.ErroHandlingMode;
                httpErrorHandlingGv[1, index].Tag   = r.Value.ErroHandlingMode;

                httpErrorHandlingGv[2, index].Value = "" + r.Value.RetryAttempts;
                httpErrorHandlingGv[2, index].Tag   = r.Value.RetryAttempts;

                httpErrorHandlingGv[3, index].Value = "" + r.Value.SleepTimeInSeconds;
                httpErrorHandlingGv[3, index].Tag   = r.Value.SleepTimeInSeconds;
            }

            // TODO: fixme. When loading the control, if ErrorPolicy is not retry, we should lock the waittime and retry attempts.

            if (advancedSettings.CustomLocalTempDir != null)
            {
                uiTempDir.Text = advancedSettings.CustomLocalTempDir;
            }

            cbParseJsonDate.Checked = advancedSettings.ParseDates;
        }
コード例 #2
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);
        }
 public JSONSourceComponentModel()
 {
     DataSource       = new JSONDataSourceModel();
     DataMapping      = new JSONDataMappingModel();
     AdvancedSettings = new JSONAdvancedSettingsModel();
 }
        public static JSONAdvancedSettingsModel LoadFromJson(string jsonConfig)
        {
            JSONAdvancedSettingsModel res = JsonConvert.DeserializeObject <JSONAdvancedSettingsModel>(jsonConfig);

            return(res);
        }