Ejemplo n.º 1
0
        private FieldValidationResult ValidatePaths(List<Node> list, Field field)
		{
			//-- Paths
			if (this.SelectionRoots.Count > 0)
			{
				//-- Convert relative paths to absolute
				var paths = new List<string>(); //-- test equality
				var roots = new List<string>(); //-- ends with PathSeparator
				foreach (string item in this.SelectionRoots)
				{
					var handler = field.Content.ContentHandler;
					var handlerPath = RepositoryPath.Combine(RepositoryPath.GetParentPath(handler.Path), handler.Name);
					var path = "/";
					if (item.StartsWith("/"))
					{
						path = item;
					}
					else if (item == ".")
					{
						path = handlerPath;
					}
					else
					{
						path = RepositoryPath.Combine(handlerPath, item);
					}

					if (path.EndsWith(RepositoryPath.PathSeparator))
					{
						paths.Add(path.Substring(0, path.Length - 1));
						roots.Add(path);
					}
					else
					{
						paths.Add(path);
						roots.Add(String.Concat(path, RepositoryPath.PathSeparator));
					}
				}
				foreach (Node node in list)
				{
					var ok = false;
					for (int i = 0; i < paths.Count; i++)
					{
						if (node.Path == paths[i] || node.Path.StartsWith(roots[i]))
						{
							ok = true;
							break;
						}
					}
				    if (ok) 
                        continue;

				    var result = new FieldValidationResult(SelectionRootName);
				    result.AddParameter(SelectionRootName, node.Path);
				    return result;
				}
			}
			return FieldValidationResult.Successful;
		}
Ejemplo n.º 2
0
        private FieldValidationResult ValidateWithQuery(List<Node> list, NodeQuery query)
		{
            var x = query.Execute();
            List<int> idList = x.Identifiers.ToList();
			idList.Sort();
			foreach (Node node in list)
			{
				if (!idList.Contains(node.Id))
				{
					var result = new FieldValidationResult(QueryName);
					result.AddParameter("Path", node.Path);
					return result;
				}
			}
			return FieldValidationResult.Successful;
		}
Ejemplo n.º 3
0
	    private List<Node> GetNodeList(object value, out FieldValidationResult result)
		{
			result = FieldValidationResult.Successful;
            var list = new List<Node>();

            var node = value as Node;
            if (node != null)
            {
                list.Add(node);
                return list;
            }
            var enumerableNodes = value as IEnumerable<Node>;
            if (enumerableNodes != null)
            {
                return enumerableNodes.ToList();
            }
            var enumerable = value as IEnumerable;
            if (enumerable != null)
            {
                foreach (Node item in enumerable)
                    if (item != null)
                        list.Add(item);
                return list;
            }

			result = new FieldValidationResult("ReferenceValue");
			return list;
		}
Ejemplo n.º 4
0
        private FieldValidationResult ValidateTypes(List<Node> list)
		{
			List<string> allowedTypeNames = CollectExactTypeNames(this.AllowedTypes);
			foreach (Node node in list)
			{
				if (!allowedTypeNames.Contains(node.NodeType.Name))
				{
					var result = new FieldValidationResult(AllowedTypesName);
					result.AddParameter(AllowedTypesName, String.Join(", ", allowedTypeNames.ToArray()));
					result.AddParameter("Path", node.Path);
					result.AddParameter("NotAllowedType", node.NodeType.Name);
					return result;
				}
			}
			return FieldValidationResult.Successful;
		}
Ejemplo n.º 5
0
 static FieldValidationResult()
 {
     Successful = new FieldValidationResult("Successful");
 }
Ejemplo n.º 6
0
		static FieldValidationResult()
		{
			Successful = new FieldValidationResult("Successful");
		}
Ejemplo n.º 7
0
		public override FieldValidationResult ValidateData(object value, Field field)
		{
            if ((value == null) && (this.Compulsory ?? false))
                return new FieldValidationResult(CompulsoryName);

            if (value != null)
            {
                var decimalValue = Convert.ToDecimal(value);

                if (this.MinValue != null)
                {
                    if (decimalValue < (decimal) this.MinValue)
                    {
                        var result = new FieldValidationResult(MinValueName);
                        result.AddParameter(MinValueName, this.MinValue);
                        return result;
                    }
                }
                if (this.MaxValue != null)
                {
                    if (decimalValue > (decimal) this.MaxValue)
                    {
                        var result = new FieldValidationResult(MaxValueName);
                        result.AddParameter(MaxValueName, this.MaxValue);
                        return result;
                    }
                }
            }

		    return FieldValidationResult.Successful;
		}
Ejemplo n.º 8
0
		public override FieldValidationResult ValidateData(object value, Field field)
		{
            if ((value == null) && (this.Compulsory ?? false))
                return new FieldValidationResult(CompulsoryName);

            if (value != null)
            {
                if (_slotMinValue == 0)
                    this.Initialize();

                var intValue = (int)value;
                var min = this.MinValue ?? _slotMinValue;
                var max = this.MaxValue ?? _slotMaxValue;

                if (intValue < min)
                {
                    var result = new FieldValidationResult(MinValueName);
                    result.AddParameter(MinValueName, min);
                    return result;
                }

                if (intValue > max)
                {
                    var result = new FieldValidationResult(MaxValueName);
                    result.AddParameter(MaxValueName, max);
                    return result;
                }
                
            }
			return FieldValidationResult.Successful;
		}
Ejemplo n.º 9
0
		public override FieldValidationResult ValidateData(object value, Field field)
		{
            var stringValue = (string)value;

            //-- compulsory
            if (String.IsNullOrEmpty(stringValue) && (this.Compulsory ?? false))
                return new FieldValidationResult(CompulsoryName);

            stringValue = stringValue ?? "";
            if (stringValue.Length > 0)
            {
                //-- minLength
                int minLength = this.MinLength.HasValue ? this.MinLength.Value : 0;
                if (stringValue.Length < minLength)
                {
                    var result = new FieldValidationResult(MinLengthName);
                    result.AddParameter(MinLengthName, minLength);
                    return result;
                }
                //-- maxLength
                int maxLength = this.MaxLength.HasValue ? this.MaxLength.Value : Int32.MaxValue;
                if (stringValue.Length > maxLength)
                {
                    var result = new FieldValidationResult(MaxLengthName);
                    result.AddParameter(MaxLengthName, maxLength);
                    return result;
                }
            }
			return FieldValidationResult.Successful;
		}