Beispiel #1
0
        /// <summary>
        /// Performs any pre-save validation logic. The base implementation performs
        /// a <see cref="ResourceValidatorSet"/> validation (non-casccading) on the
        /// edited resource before attempting a save into the session repository
        /// (triggering any errors relating to invalid XML content). Override this
        /// method if the base implementation just described does not cover your
        /// validation needs.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnBeforeSave(object sender, CancelEventArgs e)
        {
            //We've been editing an in-memory model of the session copy
            //so we need to save this model back to the session copy before Save()
            //commits the changes back to the original resource
            _svc.UpdateResourceContent(GetXmlContent());
            try
            {
                var validate = PropertyService.Get(ConfigProperties.ValidateOnSave, true);
                if (this.IsDirty && validate)
                {
                    BusyWaitDelegate del = () =>
                    {
                        var errors = new List <ValidationIssue>(ValidateEditedResource()).ToArray();
                        return(errors);
                    };

                    BusyWaitDialog.Run(Strings.PrgPreSaveValidation, del, (result, ex) =>
                    {
                        if (ex != null)
                        {
                            throw ex;
                        }

                        ValidationIssue[] errors = result as ValidationIssue[];
                        if (errors.Length > 0)
                        {
                            MessageService.ShowError(Strings.FixErrorsBeforeSaving);
                            ValidationResultsDialog diag = new ValidationResultsDialog(this.Resource.ResourceID, errors, OpenAffectedResource);
                            diag.ShowDialog(Workbench.Instance);
                            e.Cancel = true;
                        }
                        else
                        {
                            e.Cancel = false;
                        }
                    });
                }
                else
                {
                    LoggingService.Info("Skipping validation on save"); //NOXLATE
                    e.Cancel = false;
                }
            }
            catch (Exception ex)
            {
                ErrorDialog.Show(ex);
                e.Cancel = true;
            }
        }
Beispiel #2
0
        static void CollectAndDisplayIssues(ValidationIssue[] issues)
        {
            if (issues != null)
            {
                if (issues.Length > 0)
                {
                    //Sigh! LINQ would've made this code so simple...

                    var sort = new Dictionary <string, List <ValidationIssue> >();
                    foreach (var issue in issues)
                    {
                        string resId = issue.Resource.ResourceID;
                        if (!sort.ContainsKey(resId))
                        {
                            sort[resId] = new List <ValidationIssue>();
                        }

                        sort[resId].Add(issue);
                    }

                    var groupedIssues = new List <KeyValuePair <string, ValidationIssue[]> >();
                    foreach (var kvp in sort)
                    {
                        groupedIssues.Add(
                            new KeyValuePair <string, ValidationIssue[]>(
                                kvp.Key,
                                kvp.Value.ToArray()));
                    }

                    var resDlg = new ValidationResultsDialog(groupedIssues);
                    resDlg.Show();
                }
                else
                {
                    MessageService.ShowMessage("No validation issues found");
                }
            }
        }
        protected static void CollectAndDisplayIssues(ValidationIssue[] issues)
        {
            if (issues != null)
            {
                if (issues.Length > 0)
                {
                    //Sigh! LINQ would've made this code so simple...

                    var sort = new Dictionary<string, List<ValidationIssue>>();
                    foreach (var issue in issues)
                    {
                        string resId = issue.Resource.ResourceID;
                        if (!sort.ContainsKey(resId))
                            sort[resId] = new List<ValidationIssue>();

                        sort[resId].Add(issue);
                    }

                    var groupedIssues = new List<KeyValuePair<string, ValidationIssue[]>>();
                    foreach (var kvp in sort)
                    {
                        groupedIssues.Add(
                            new KeyValuePair<string, ValidationIssue[]>(
                                kvp.Key,
                                kvp.Value.ToArray()));
                    }

                    var resDlg = new ValidationResultsDialog(groupedIssues, OpenAffectedResource);
                    resDlg.Show();
                }
                else
                {
                    MessageService.ShowMessage(Strings.ValidationNoIssues);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Performs any pre-save validation logic. The base implementation performs
        /// a <see cref="ResourceValidatorSet"/> validation (non-casccading) on the 
        /// edited resource before attempting a save into the session repository 
        /// (triggering any errors relating to invalid XML content). Override this
        /// method if the base implementation just described does not cover your 
        /// validation needs.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnBeforeSave(object sender, CancelEventArgs e) 
        {
            //We've been editing an in-memory model of the session copy
            //so we need to save this model back to the session copy before Save()
            //commits the changes back to the original resource
            _svc.UpdateResourceContent(GetXmlContent());
            try
            {
                var validate = PropertyService.Get(ConfigProperties.ValidateOnSave, true);
                if (this.IsDirty && validate)
                {
                    BusyWaitDelegate del = () => 
                    {
                        var errors = new List<ValidationIssue>(ValidateEditedResource()).ToArray();
                        return errors;
                    };
                    
                    BusyWaitDialog.Run(Strings.PrgPreSaveValidation, del, (result, ex) => {
                        if (ex != null)
                            throw ex;

                        ValidationIssue[] errors = result as ValidationIssue[];
                        if (errors.Length > 0)
                        {
                            MessageService.ShowError(Strings.FixErrorsBeforeSaving);
                            ValidationResultsDialog diag = new ValidationResultsDialog(this.Resource.ResourceID, errors, OpenAffectedResource);
                            diag.ShowDialog(Workbench.Instance);
                            e.Cancel = true;
                        }
                        else
                        {
                            e.Cancel = false;
                        }               
                    });
                }
                else
                {
                    LoggingService.Info("Skipping validation on save"); //NOXLATE
                    e.Cancel = false;
                }
            }
            catch (Exception ex)
            {
                ErrorDialog.Show(ex);
                e.Cancel = true;
            }
        }