Exemple #1
0
        public IResult Validate(object target)
        {
            IResult result = null;

            foreach (IValidationTask task in this._tasks)
            {
                if (null == result)
                {
                    result = task.Validate(target);
                }
                else
                {
                    result.Concatenate(task.Validate(target));
                }
                if (!result.IsSuccessful())
                {
                    this._failTask = task;
                    break;
                }
            }
            return(result);
        }
        public override IResult Parse(object source)
        {
            if (null == source)
            {
                throw new ArgumentNullException("source");
            }
            ContainerWebPart webPart = source as ContainerWebPart;

            if (null == webPart)
            {
                throw new ArgumentException("source is not an ContainerWebPart");
            }
            IConfiguration config = webPart.Configuration;

            if (null == config)
            {
                throw new ArgumentException("missing configuration");
            }
            IValidationManager validationManager = webPart.ValidationManager;

            if (null == validationManager)
            {
                throw new ArgumentException("missing validation manager");
            }
            base.Parse(source);
            if (config.Sections.ContainsKey("Template"))
            {
                IConfigurationSection templateConfig = config.GetConfigurationSectionReference("Template");
                webPart.TemplateConfig = templateConfig;
            }
            else
            {
                webPart.TemplateConfig = config.NewConfigurationSectionInstance("Template");
            }
            if (config.Sections.ContainsKey("Validation"))
            {
                foreach (IConfigurationElement element in config.Sections["Validation"].Elements.Values)
                {
                    IValidationTask task = validationManager.NewValidationTaskInstance();
                    if (element.Attributes.ContainsKey("target"))
                    {
                        task.Target = element.GetAttributeReference("target").Value;
                    }
                    if (element.Attributes.ContainsKey("member"))
                    {
                        task.Member = element.GetAttributeReference("member").Value.ToString();
                    }
                    foreach (IConfigurationElement handlerElement in element.Elements.Values)
                    {
                        if (handlerElement.Attributes.ContainsKey("handlerKey"))
                        {
                            string             handlerKey = handlerElement.GetAttributeReference("handlerKey").Value.ToString();
                            IValidationHandler handler    = validationManager.Handler(handlerKey);
                            if ("expression" == handlerKey)
                            {
                                IExpressionHandler expressionHandler           = handler as IExpressionHandler;
                                IEnumerator <IConfigurationElement> enumerator = handlerElement.Elements.Values.GetEnumerator();
                                if (enumerator.MoveNext())
                                {
                                    IConfigurationElement expressionElement = enumerator.Current;
                                    expressionHandler.Expression = (validationManager.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression);
                                    if (null == expressionHandler.Expression)
                                    {
                                        throw new InvalidOperationException("Token is not an IExpression");
                                    }
                                    expressionHandler.Expression.Make(expressionElement, validationManager.ExpressionsManager);
                                }
                            }
                            task.Handlers.Add(handler);
                        }
                    }
                    validationManager.RegisterTask(task);
                }
            }
            if (config.Sections.ContainsKey("Checks"))
            {
                foreach (IConfigurationElement element in config.Sections["Checks"].Elements.Values)
                {
                    if (element.Attributes.ContainsKey("command"))
                    {
                        string command = element.GetAttributeReference("command").Value.ToString();
                        webPart.Checks.Add(command, new List <Container.CheckDefinition>());
                        foreach (IConfigurationElement checkElement in element.Elements.Values)
                        {
                            Container.CheckDefinition check = new Container.CheckDefinition();

                            if (checkElement.Attributes.ContainsKey("error"))
                            {
                                check.Error = checkElement.GetAttributeReference("error").Value.ToString();
                            }

                            if (checkElement.Attributes.ContainsKey("milestone"))
                            {
                                check.Milestone = checkElement.GetAttributeReference("milestone").Value.ToString();
                            }

                            IEnumerator <IConfigurationElement> enumerator = checkElement.Elements.Values.GetEnumerator();
                            if (enumerator.MoveNext())
                            {
                                IConfigurationElement expressionElement = enumerator.Current;
                                IExpression           expression        = webPart.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression;
                                if (null == expression)
                                {
                                    throw new InvalidOperationException("Token is not an IExpression");
                                }

                                expression.Make(expressionElement, webPart.ExpressionsManager);
                                check.Expression = expression;
                            }
                            webPart.Checks[command].Add(check);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #3
0
 public IResult Validate(object target)
 {
     IResult result = null;
     foreach (IValidationTask task in this._tasks)
     {
         if (null == result)
         {
             result = task.Validate(target);
         }
         else
         {
             result.Concatenate(task.Validate(target));
         }
         if (!result.IsSuccessful())
         {
             this._failTask = task;
             break;
         }
     }
     return result;
 }
Exemple #4
0
 public void RegisterTask(IValidationTask task)
 {
     this._tasks.Add(task);
 }
Exemple #5
0
 public void RegisterTask(IValidationTask task)
 {
     this._tasks.Add(task);
 }