예제 #1
0
        protected internal ValueNode(string value, ValueNodeType valueType)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException("Value can´t be null or empty", "value");
            }

            _value = value;
            _valueType = valueType;
        }
예제 #2
0
        protected internal ValueNode(string value, ValueNodeType valueType)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException("Value can´t be null or empty", "value");
            }

            _value     = value;
            _valueType = valueType;
        }
예제 #3
0
        protected internal ValueNode(string value, string valueType)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException("Value can´t be null or empty", "value");
            }

            if (string.IsNullOrEmpty(valueType))
            {
                throw new ArgumentException("ValueType can´t be null or empty", "valueType");
            }

            _value     = value;
            _valueType = (ValueNodeType)Enum.Parse(typeof(ValueNodeType), valueType);
        }
예제 #4
0
        protected internal ValueNode(string value, string valueType)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException("Value can´t be null or empty", "value");
            }

            if (string.IsNullOrEmpty(valueType))
            {
                throw new ArgumentException("ValueType can´t be null or empty", "valueType");
            }

            _value = value;
            _valueType = (ValueNodeType) Enum.Parse(typeof (ValueNodeType), valueType);
        }
예제 #5
0
 /// <summary>
 /// Expected null, boolean, integer, number
 /// </summary>
 /// <param name="segment"></param>
 /// <param name="valueType"></param>
 /// <param name="parentIndex"></param>
 /// <returns></returns>
 static JsonValue ParsePrimitive(Utf8String segment, ValueNodeType valueType, int parentIndex)
 {
     int i = 1;
     for (; i < segment.ByteLength; ++i)
     {
         if (Char.IsWhiteSpace((char)segment[i])
             || segment[i] == '}'
             || segment[i] == ']'
             || segment[i] == ','
             || segment[i] == ':'
             )
         {
             break;
         }
     }
     return new JsonValue(segment.Subbytes(0, i), valueType, parentIndex);
 }
예제 #6
0
        /// <summary>
        /// Expected null, boolean, integer, number
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="valueType"></param>
        /// <param name="parentIndex"></param>
        /// <returns></returns>
        static JsonTreeNode ParsePrimitive(JsonTreeNode tree, Utf8String segment, ValueNodeType valueType)
        {
            int i = 1;

            for (; i < segment.ByteLength; ++i)
            {
                if (Char.IsWhiteSpace((char)segment[i]) ||
                    segment[i] == '}' ||
                    segment[i] == ']' ||
                    segment[i] == ',' ||
                    segment[i] == ':'
                    )
                {
                    break;
                }
            }
            return(tree.AddValue(segment.Subbytes(0, i).Bytes, valueType));
        }
예제 #7
0
 protected internal CAMLValueNode(string value, ValueNodeType valueType)
     : base(value, valueType)
 {
 }
 public MsgPackValue New(ArraySegment <byte> bytes, ValueNodeType valueType, int parentIndex)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public JsonTreeNode AddValue(ArraySegment <byte> bytes, ValueNodeType valueType)
 {
     return(AddValue(default(JsonValue).New(bytes, valueType, ValueIndex)));
 }
예제 #10
0
 public virtual ValueNode CreateValueNode(string value, ValueNodeType valueType)
 {
     return(new ValueNode(value, valueType));
 }
예제 #11
0
 public void AddValue(ArraySegment <byte> bytes, ValueNodeType valueType)
 {
     m_Values.Add(default(T).New(bytes, valueType, ValueIndex));
 }
예제 #12
0
 public abstract string Evaluate(List<string> header, List<string> data, out ValueNodeType nodetype);
예제 #13
0
 public static ValueNodeBase CreateNewNode(ValueNodeType vType, XElement xml)
 {
     switch (vType)
     {
         case ValueNodeType.String:
         case ValueNodeType.Int:
         case ValueNodeType.Float:
             return new NumericalValueNode(vType, xml);
         case ValueNodeType.Date:
         case ValueNodeType.DateSpan:
             return new DateValueNode(vType, xml);
         case ValueNodeType.Field:
             return new FieldValueNode(vType, xml);
         default:
             throw new ArgumentOutOfRangeException("vType");
     }
 }
예제 #14
0
        private string FinishEvaluation(ValueNodeType nodetype1, ValueNodeType nodetype2)
        {
            double _numerical1, _numerical2, result;
            if (string.IsNullOrWhiteSpace(Vals[0]) || !double.TryParse(Vals[0], out _numerical1))
                return null;
            if (!string.IsNullOrWhiteSpace(Vals[1]) || !double.TryParse(Vals[1], out _numerical2))
                return null;

            switch (Op)
            {
                case ValueOperand.NoOp:
                    result = _numerical1;
                    break;
                case ValueOperand.Plus:
                    result = _numerical1 + _numerical1;
                    break;
                case ValueOperand.Minus:
                    result = _numerical1 - _numerical1;
                    break;
                case ValueOperand.Times:
                    result = _numerical1*_numerical1;
                    break;
                case ValueOperand.DividedBy:
                    result = _numerical1/_numerical1;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Op");
            }
            if (NodeType == ValueNodeType.Int)
            {
                var resultInt = (int) Math.Floor(result);
                return resultInt.ToString();
            }
            return result.ToString("n");
        }
예제 #15
0
 public NumericalValueNode(ValueNodeType nodeType, XElement xml)
     : base(nodeType, xml)
 {
 }
예제 #16
0
 public MsgPackValue New(ArraySegment <byte> bytes, ValueNodeType valueType, int parentIndex)
 {
     return(new MsgPackValue(bytes, parentIndex));
 }
예제 #17
0
 public override ValueNode CreateValueNode(string value, ValueNodeType valueType)
 {
     return(new CAMLValueNode(value, valueType));
 }
 public virtual ValueNode CreateValueNode(string value, ValueNodeType valueType)
 {
     return new ValueNode(value, valueType);
 }
예제 #19
0
        public override string Evaluate(XElement data, out ValueNodeType nodetype)
        {
            nodetype = NodeType;
            if (Simple) return Vals[0];

            try
            {
                var nodetype1 = NodeType;
                var nodetype2 = NodeType;
                if (Nodes[0] != null) Vals[0] = Nodes[0].Evaluate(data, out nodetype1);
                if (Nodes[1] != null) Vals[1] = Nodes[1].Evaluate(data, out nodetype2);

                return FinishEvaluation(nodetype1, nodetype2);
            }
            catch (Exception ex)
            {
                if (BoostLog.Instance != null)
                    BoostLog.Instance.WriteEntry(EventLogEntryType.Error,
                                                                             string.Format("Error evaluating NumericalValueNode. Val1 = {0}. Val2 = {1}", Vals[0], Vals[1]),
                                                 ex);
                return null;
            }
        }
예제 #20
0
 public JsonValue(Utf8String segment, ValueNodeType valueType, int parentIndex) : this()
 {
     Segment     = segment;
     ValueType   = valueType;
     ParentIndex = parentIndex;
 }
예제 #21
0
 protected ValueNodeBase(ValueNodeType nodeType, XElement xml)
 {
     NodeType = nodeType;
     Vals = new string[2];
     Nodes = new ValueNodeBase[2];
     ParseXml(xml);
 }
예제 #22
0
 public JsonValue New(ArraySegment <byte> bytes, ValueNodeType valueType, int parentIndex)
 {
     return(new JsonValue(new Utf8String(bytes), valueType, parentIndex));
 }
예제 #23
0
 public abstract string Evaluate(XElement data, out ValueNodeType nodetype);
예제 #24
0
 public DateValueNode(ValueNodeType nodeType, XElement xml)
     : base(nodeType, xml)
 {
 }
 protected internal CAMLValueNode(string value, ValueNodeType valueType)
     : base(value, valueType)
 {
 }
예제 #26
0
        public override string Evaluate(XElement data, out ValueNodeType nodetype)
        {
            nodetype = NodeType;
            if (Simple) return CheckValue(Vals[0]);

            try
            {
                //only simle date nodes can exist without nodes
                //otherwise we'd need to know the node type for each val
                if (Nodes[0] == null || Nodes[1] == null)
                    throw new Exception("All non-simple date nodes must have two sub-nodes");

                ValueNodeType nodetype1, nodetype2;
                Vals[0] = Nodes[0].Evaluate(data, out nodetype1);
                Vals[1] = Nodes[1].Evaluate(data, out nodetype2);

                return FinishEvaluation(nodetype1, nodetype2, out nodetype);
            }
            catch (Exception ex)
            {
                if (BoostLog.Instance != null)
                    BoostLog.Instance.WriteEntry(EventLogEntryType.Error,
                                                                             string.Format("Error evaluating DateValueNode. Val1 = {0}. Val2 = {1}", Vals[0], Vals[1]),
                                                                             ex);
                return null;
            }
        }
예제 #27
0
 public ListTreeNode <T> AddValue(ArraySegment <byte> bytes, ValueNodeType valueType)
 {
     return(AddValue(default(T).New(bytes, valueType, ValueIndex)));
 }
예제 #28
0
        private string FinishEvaluation(ValueNodeType nodetype1, ValueNodeType nodetype2, out ValueNodeType nodetype)
        {
            //for NoOp, just return the value of the first node
                if (Op != ValueOperand.NoOp)
                {
                    nodetype = nodetype1;
                    return Vals[0];
                }

                //Oterwise valid ops depend whether the values are dates or datespans (3 cases)
                //case 1: two dates
                if (nodetype1 == ValueNodeType.Date
                    && nodetype2 == ValueNodeType.Date)
                {
                    if (Op != ValueOperand.Minus)
                        throw new Exception(string.Format("Two dates can only be subtracted. {0} cannot be evaluated", Op.ToString()));

                    DateTime date1, date2;
                    if (!Input.TryGetDate(out date1, Vals[0], DateReversed))
                        throw new Exception(string.Format("Illegal DateTime: {0} cannot be evaluated", Vals[0]));
                    if (!Input.TryGetDate(out date2, Vals[1], DateReversed))
                        throw new Exception(string.Format("Illegal DateTime: {0} cannot be evaluated", Vals[1]));

                    var result = date1 - date2;
                    nodetype = ValueNodeType.DateSpan;
                    if (Units == ValueUnits.General) Units = ValueUnits.Minutes;
                    return Input.EncodeTimeSpan(result, Units);
                }

                //case 2: two timespans
                if (nodetype1 == ValueNodeType.DateSpan
                    && nodetype2 == ValueNodeType.DateSpan)
                {
                    TimeSpan span1, span2, result;
                    ValueUnits units1, units2;
                    if (!Input.TryGetTimeSpan(Vals[0], out span1, out units1))
                        throw new Exception(string.Format("Illegal timespan. {0} cannot be evaluated", Vals[0]));
                    if (!Input.TryGetTimeSpan(Vals[1], out span2, out units2))
                        throw new Exception(string.Format("Illegal timespan. {0} cannot be evaluated", Vals[1]));

                    switch (Op)
                    {
                        case ValueOperand.Plus:
                            result = span1 + span2;
                            break;
                        case ValueOperand.Minus:
                            result = span1 - span2;
                            break;
                        default:
                            throw new Exception(string.Format("Two time spans can only be added or subtracted. {0} cannot be evaluated",
                                                              Op.ToString()));
                    }

                    nodetype = ValueNodeType.DateSpan;
                    if (Units == ValueUnits.General) Units = units1;
                    return Input.EncodeTimeSpan(result, Units);
                }

                //case 3: one value is a timespan and the other is a date
                DateTime date;
                TimeSpan span;
                ValueUnits units;
                if (nodetype1 == ValueNodeType.DateSpan)
                {
                    if (!Input.TryGetDate(out date, Vals[0], DateReversed))
                        throw new Exception(string.Format("Illegal DateTime: {0} cannot be evaluated", Vals[0]));
                    if (!Input.TryGetTimeSpan(Vals[1], out span, out units))
                        throw new Exception(string.Format("Illegal timespan. {0} cannot be evaluated", Vals[1]));
                }
                else
                {
                    if (!Input.TryGetDate(out date, Vals[1], DateReversed))
                        throw new Exception(string.Format("Illegal DateTime: {0} cannot be evaluated", Vals[1]));
                    if (!Input.TryGetTimeSpan(Vals[0], out span, out units))
                        throw new Exception(string.Format("Illegal timespan. {0} cannot be evaluated", Vals[0]));
                }

                var subtract = false;
                switch (Op)
                {
                    case ValueOperand.Plus:
                        break;
                    case ValueOperand.Minus:
                        subtract = true;
                        break;
                    default:
                        throw new Exception(string.Format("Two time spans can only be added or subtracted. {0} cannot be evaluated",
                                                          Op.ToString()));
                }
                int val;
                switch (units)
                {
                    case ValueUnits.Days:
                        val = subtract ? span.Days : -1*span.Days;
                        date = date.AddDays(val);
                        break;
                    case ValueUnits.Hours:
                        val = subtract ? span.Hours : -1*span.Hours;
                        date = date.AddHours(val);
                        break;
                    case ValueUnits.Minutes:
                    case ValueUnits.General:
                        val = subtract ? span.Minutes : -1*span.Minutes;
                        date = date.AddMinutes(val);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                nodetype = ValueNodeType.Date;
                return date.ToString("G");
        }
        public static IJsonSchemaValidator Create(ValueNodeType valueType,
                                                  Type t = null,
                                                  BaseJsonSchemaAttribute a  = null,
                                                  ItemJsonSchemaAttribute ia = null)
        {
            switch (valueType)
            {
            case ValueNodeType.Integer:
            {
                var v = new JsonIntValidator();

                if (a != null)
                {
                    if (!double.IsNaN(a.Minimum))
                    {
                        v.Minimum = (int)a.Minimum;
                    }
                    if (a.ExclusiveMinimum)
                    {
                        v.ExclusiveMinimum = a.ExclusiveMinimum;
                    }
                    if (!double.IsNaN(a.Maximum))
                    {
                        v.Maximum = (int)a.Maximum;
                    }
                    if (a.ExclusiveMaximum)
                    {
                        v.ExclusiveMaximum = a.ExclusiveMaximum;
                    }
                    if (a.MultipleOf != 0)
                    {
                        v.MultipleOf = (int)a.MultipleOf;
                    }
                }

                return(v);
            }

            case ValueNodeType.Number:
            {
                var v = new JsonNumberValidator();
                if (a != null)
                {
                    if (!double.IsNaN(a.Minimum))
                    {
                        v.Minimum = (int)a.Minimum;
                    }
                    if (a.ExclusiveMinimum)
                    {
                        v.ExclusiveMinimum = a.ExclusiveMinimum;
                    }
                    if (!double.IsNaN(a.Maximum))
                    {
                        v.Maximum = (int)a.Maximum;
                    }
                    if (a.ExclusiveMaximum)
                    {
                        v.ExclusiveMaximum = a.ExclusiveMaximum;
                    }
                    if (a.MultipleOf != 0)
                    {
                        v.MultipleOf = (int)a.MultipleOf;
                    }
                }

                return(v);
            }

            case ValueNodeType.String:
            {
                var v = new JsonStringValidator();
                if (a != null)
                {
                    if (a.Pattern != null)
                    {
                        v.Pattern = new System.Text.RegularExpressions.Regex(a.Pattern);
                    }
                }
                return(v);
            }

            case ValueNodeType.Boolean:
                return(new JsonBoolValidator());

            case ValueNodeType.Array:
            {
                var v = new JsonArrayValidator();
                if (a != null)
                {
                    if (a.MinItems != 0)
                    {
                        v.MinItems = a.MinItems;
                    }
                    if (a.MaxItems != 0)
                    {
                        v.MaxItems = a.MaxItems;
                    }

                    if (t != null)
                    {
                        if (ia == null)
                        {
                            ia = new ItemJsonSchemaAttribute();
                        }

                        Type elementType = null;
                        if (t.IsArray)
                        {
                            elementType = t.GetElementType();
                        }
                        else if (t.GetIsGenericList())
                        {
                            elementType = t.GetGenericArguments().First();
                        }

                        if (elementType != null)
                        {
                            /*
                             * var sub = new JsonSchema
                             * {
                             *  SkipComparison = ia.SkipSchemaComparison,
                             *  Validator = Create(elementType, ia, null)
                             * };
                             */
                            var sub = JsonSchema.FromType(elementType, ia, null);
                            v.Items = sub;
                        }
                    }
                }

                return(v);
            }

            case ValueNodeType.Object:
            {
                if (t.GetIsGenericDictionary())
                {
                    var genericFactory =
                        typeof(JsonDictionaryValidator).GetMethod("Create",
                                                                  BindingFlags.Static | BindingFlags.Public);
                    var factory = genericFactory.MakeGenericMethod(t.GetGenericArguments()[1]);
                    var v       = factory.Invoke(null, null) as IJsonSchemaValidator;
                    return(v);
                }
                else
                {
                    var v = new JsonObjectValidator();
                    if (a != null)
                    {
                        if (a.MinProperties > 0)
                        {
                            v.MinProperties = a.MinProperties;
                        }

                        // props
                        foreach (var prop in GetProperties(t, a.ExportFlags))
                        {
                            v.Properties.Add(prop.Key, prop.Schema);
                            if (prop.Required)
                            {
                                v.Required.Add(prop.Key);
                            }
                            if (prop.Dependencies != null)
                            {
                                v.Dependencies.Add(prop.Key, prop.Dependencies);
                            }
                        }
                    }

                    if (ia != null)
                    {
                        var sub = new JsonSchema
                        {
                            SkipComparison = ia.SkipSchemaComparison,
                            Validator      = Create(typeof(object), ia, null)
                        };
                        v.AdditionalProperties = sub;
                    }

                    return(v);
                }
            }

            default:
                throw new NotImplementedException();
            }
        }
예제 #30
0
 //protected FieldValueNode(ValueNodeType nodeType, ValueOperand op = ValueOperand.NoOp, string val1 = null, string val2 = null, bool simple = true)
 public FieldValueNode(ValueNodeType nodeType, XElement xml)
     : base(nodeType, xml)
 {
 }
예제 #31
0
        public override string Evaluate(XElement data, out ValueNodeType nodetype)
        {
            //return node type is based on what the field evaluates to
            nodetype = ValueNodeType.String; //default is a string
            if (data == null) return null; //no data to evaluate

            try
            {
                var val = Input.GetValue(data, Name);
                if (string.IsNullOrEmpty(val)) return null; //no data matches this field

                return FinishEvaluation(val, ref nodetype);
            }
            catch (Exception ex)
            {
                if (BoostLog.Instance != null)
                    BoostLog.Instance.WriteEntry(EventLogEntryType.Error,
                                                                             string.Format("Error evaluating NumericalValueNode. Val1 = {0}. Val2 = {1}", Vals[0], Vals[1]),
                                                 ex);
                return null;
            }
        }
예제 #32
0
        private string FinishEvaluation(string val, ref ValueNodeType nodetype)
        {
            //determine node type
            DateTime testDate;
            TimeSpan testSpan;
            ValueUnits testUnits;
            int testInt;
            float testFloat;

            if (Input.TryGetDate(out testDate, val, DateReversed))
                nodetype = ValueNodeType.Date;
            else if (Input.TryGetTimeSpan(val, out testSpan, out testUnits))
                nodetype = ValueNodeType.DateSpan;
            else if (int.TryParse(val, out testInt))
                nodetype = ValueNodeType.Int;
            else if (float.TryParse(val, out testFloat))
                nodetype = ValueNodeType.Float;
            return val;
        }
 public void AddValue(ArraySegment <byte> bytes, ValueNodeType valueType)
 {
     throw new NotImplementedException();
 }
 public override ValueNode CreateValueNode(string value, ValueNodeType valueType)
 {
     return new CAMLValueNode(value, valueType);
 }