internal void OnCheckModelValidity(object sender, EventArgs e)
        {
            ValidationController controller = this.CurrentData.ValidationController;
            ValidationCategory   category   = ValidationCategory.Menu;

            bool isValid = controller.Validate(this.CurrentData.Store, category);

            bool errorsOccurred = false;

            foreach (ValidationMessage message in controller.ValidationMessages)
            {
                if (message.Type == ViolationType.Error)
                {
                    errorsOccurred = true;
                    break;
                }
            }

            if (errorsOccurred)
            {
                System.Windows.Forms.MessageBox.Show("Cannot generate XML from model: There were validation errors!", "Model Invalidity", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram = this.CurrentView.CurrentDiagram;
                ISpySoft.FeatureModelLanguage.Designer.Custom.XmlFileGenerator xmlFileGenerator = new ISpySoft.FeatureModelLanguage.Designer.Custom.XmlFileGenerator();
                xmlFileGenerator.GenerateXmlFile(diagram);
            }
        } // OnCheckModelValidity
Exemplo n.º 2
0
 public ValidationError(string message, ValidationCategory category, ILineInfo lineInfo = null, ErrorLevel errorLevel = ErrorLevel.ERROR)
 {
     Message  = EnsureArg.IsNotNullOrWhiteSpace(message, nameof(message));
     Level    = errorLevel;
     Category = category;
     LineInfo = lineInfo;
 }
Exemplo n.º 3
0
 internal static string ToSerializedValue(this ValidationCategory value)
 {
     switch (value)
     {
     case ValidationCategory.JobCreationValidation:
         return("JobCreationValidation");
     }
     return(null);
 }
        /// <summary>
        /// Handler for validating the model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void OnMenuValidate(object sender, EventArgs e)
        {
            if (this.CurrentData != null && this.CurrentData.Store != null)
            {
                ValidationCategory category = ValidationCategory.Menu;
#if DEBUG
                category |= ValidationCategory.Debug;
#endif
                this.CurrentData.ValidationController.Validate(this.CurrentData.Store, category);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// After the document is opened, validation the model.
        /// </summary>
        /// <param name="e">Event Args.</param>
        protected override void OnDocumentLoaded(EventArgs e)
        {
            base.OnDocumentLoaded(e);

            // Validate the document
            ValidationCategory category = ValidationCategory.Open;

#if DEBUG
            category |= ValidationCategory.Debug;
#endif
            this.ValidationController.Validate(this.Store, category);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Validate the model before the file is saved.
        /// </summary>
        /// <param name="fileName"></param>
        protected override void Save(string fileName)
        {
            DialogResult       result   = DialogResult.Yes;
            ValidationCategory category = ValidationCategory.Save;

#if DEBUG
            category |= ValidationCategory.Debug;
#endif
            if (!this.ValidationController.Validate(this.Store, category))
            {
                result = PackageUtility.ShowMessageBox(this.ServiceProvider, Designer_Resource.SaveValidationFailed, VsShell.OLEMSGBUTTON.OLEMSGBUTTON_YESNO, VsShell.OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, VsShell.OLEMSGICON.OLEMSGICON_WARNING);
            }

            if (result == DialogResult.Yes)
            {
                // Save the model now!
                base.Save(fileName);
            }
            else
            {                   // Throw E_ABORT so that VS shell knows that the save operation is canceled.
                throw new System.Runtime.InteropServices.COMException(Designer_Resource.SaveOperationCancelled, Microsoft.VisualStudio.VSConstants.E_ABORT);
            }
        }
Exemplo n.º 7
0
        public static void CaptureWarning(this IResult validationResult, string warning, ValidationCategory category, ILineInfo lineInfo)
        {
            EnsureArg.IsNotNull(validationResult, nameof(validationResult));
            EnsureArg.IsNotNullOrWhiteSpace(warning, nameof(warning));

            validationResult.Exceptions.Add(new ValidationError(warning, category, lineInfo, ErrorLevel.WARN));
        }
Exemplo n.º 8
0
        public static void CaptureException(this IResult validationResult, Exception exception, ValidationCategory category)
        {
            EnsureArg.IsNotNull(validationResult, nameof(validationResult));
            EnsureArg.IsNotNull(exception, nameof(exception));

            if (exception is IExceptionWithLineInfo exceptionWithLineInfo)
            {
                validationResult.Exceptions.Add(new ValidationError(exception.JoinInnerMessages(), category, exceptionWithLineInfo.GetLineInfo));
            }
            else
            {
                validationResult.Exceptions.Add(new ValidationError(exception.JoinInnerMessages(), category));
            }
        }
Exemplo n.º 9
0
        public static void CaptureError(this IResult validationResult, string message, ErrorLevel errorLevel, ValidationCategory category, ILineInfo lineInfo)
        {
            EnsureArg.IsNotNull(validationResult, nameof(validationResult));
            EnsureArg.IsNotNullOrWhiteSpace(message, nameof(message));

            validationResult.Exceptions.Add(new ValidationError(message, category, lineInfo, errorLevel));
        }
Exemplo n.º 10
0
 public void AddRule(string propertyName, string errorMessage, Func<object, bool> invalidWhen, ValidationCategory category)
 {
     _rules.Add(new LambdaValidationRule() { ErrorMessage = errorMessage, Properties = new[] { propertyName }, ValidateCallback = () => !invalidWhen(null), Category = category });
 }
Exemplo n.º 11
0
 private static void CaptureTemplateErrors <TTemplateContext>(TemplateResult templateResult, TemplateContext <TTemplateContext> templateContext, ValidationCategory validationCategory)
     where TTemplateContext : class
 {
     foreach (var templateError in templateContext.Errors)
     {
         templateResult.CaptureError(templateError.Message, ErrorLevel.ERROR, validationCategory, templateError.LineInfo);
     }
 }