Exemplo n.º 1
0
        /// <summary>Generates a feature.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <returns>The feature.</returns>
        public static Property GenerateFeature(Type type, string name)
        {
            Property p;
            if (type == typeof(string))
                p = new StringProperty();
            else if (type == typeof(DateTime))
                p = new DateTimeProperty();
            else if (type.GetInterfaces().Contains(typeof(IEnumerable)))
                throw new InvalidOperationException(
                    string.Format("Property {0} needs to be labeled as an EnumerableFeature", name));
            else
                p = new Property();


            p.Discrete = type.BaseType == typeof(Enum) ||
                         type == typeof(bool) ||
                         type == typeof(string) ||
                         type == typeof(char) ||
                         type == typeof(DateTime);

            p.Type = type;
            p.Name = name;

            return p;
        }
Exemplo n.º 2
0
        public override void Write(JsonWriter writer, object value)
        {
            base.Write(writer, value);
            var p = (DateTimeProperty)value;

            writer.WriteFirstArrayProperty("Features", DateTimeProperty.GetColumns(p.Features));
        }
Exemplo n.º 3
0
        public override object Read(JsonReader reader)
        {
            var p = (DateTimeProperty)base.Read(reader);

            var features = reader.ReadArrayProperty().Value
                           .Select(o => (string)o)
                           .ToArray();

            p.Features = DateTimeProperty.GetFeatures(features);

            return(p);
        }
Exemplo n.º 4
0
        public void DateTime_Property_Save_And_Load()
        {
            DateTimeProperty p =
                new DateTimeProperty(DateTimeFeature.DayOfWeek |
                                     DateTimeFeature.Second |
                                     DateTimeFeature.Minute);
            p.Name = "MyProp";
            p.Discrete = false;
            p.Start = 5;

            Serialize(p);
            var property = Deserialize<DateTimeProperty>();
            Assert.Equal(p, property);
        }
Exemplo n.º 5
0
        /// <summary>Adds DateTime property to descriptor with previously chained name.</summary>
        /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception>
        /// <param name="features">
        ///     Which date features to use (can pipe: DateTimeFeature.Year |
        ///     DateTimeFeature.DayOfWeek)
        /// </param>
        /// <returns>descriptor with added property.</returns>
        public Descriptor AsDateTime(DateTimeFeature features)
        {
            if (this._label)
            {
                throw new DescriptorException("Cannot use a DateTime property as a label");
            }

            var p = new DateTimeProperty(features)
            {
                Discrete = true, Name = this._name
            };

            this.AddProperty(p);
            return(this._descriptor);
        }
Exemplo n.º 6
0
        /// <summary>Adds DateTime property to descriptor with previously chained name.</summary>
        /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception>
        /// <param name="portion">Which date portions to use (can pipe: DateTimeFeature.Year |
        /// DateTimeFeature.DayOfWeek)</param>
        /// <returns>descriptor with added property.</returns>
        public Descriptor AsDateTime(DatePortion portion)
        {
            if (_label)
            {
                throw new DescriptorException("Cannot use an DateTime property as a label");
            }

            var p = new DateTimeProperty(portion)
            {
                Discrete = true,
                Name     = _name
            };

            AddProperty(p);
            return(_descriptor);
        }
Exemplo n.º 7
0
        public void DateTime_Property_Save_And_Load()
        {
            DateTimeProperty p = new DateTimeProperty(DateTimeFeature.DayOfWeek | DateTimeFeature.Second | DateTimeFeature.Minute);
            p.Name = "MyProp";
            p.Discrete = false;
            p.Start = 5;

            Serialize(p);

            var po = Deserialize<DateTimeProperty>();

            Assert.AreEqual(p.Name, po.Name);
            Assert.AreEqual(p.Type, po.Type);
            Assert.AreEqual(p.Discrete, po.Discrete);
            Assert.AreEqual(p.Start, po.Start);
            Assert.AreEqual(p.Features, po.Features);
            Assert.AreEqual(p.Length, po.Length);
        }
Exemplo n.º 8
0
 /// <summary>Constructor.</summary>
 /// <param name="portion">The portion.</param>
 public DateFeatureAttribute(DatePortion portion)
 {
     dp = new DateTimeProperty(portion);
 }
Exemplo n.º 9
0
 /// <summary>Constructor.</summary>
 /// <param name="features">The features.</param>
 public DateFeatureAttribute(DateTimeFeature features)
 {
     dp = new DateTimeProperty(features);
 }
Exemplo n.º 10
0
        /// <summary>Adds DateTime property to descriptor with previously chained name.</summary>
        /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception>
        /// <param name="portion">Which date portions to use (can pipe: DateTimeFeature.Year |
        /// DateTimeFeature.DayOfWeek)</param>
        /// <returns>descriptor with added property.</returns>
        public Descriptor AsDateTime(DatePortion portion)
        {
            if (_label)
                throw new DescriptorException("Cannot use an DateTime property as a label");

            var p = new DateTimeProperty(portion)
            {
                Discrete = true,
                Name = _name
            };

            AddProperty(p);
            return _descriptor;
        }
Exemplo n.º 11
0
 public DateFeatureAttribute(DatePortion portion)
 {
     dp = new DateTimeProperty(portion);
 }
Exemplo n.º 12
0
 public DateFeatureAttribute(DateTimeFeature features)
 {
     dp = new DateTimeProperty(features);
 }
Exemplo n.º 13
0
        /// <summary>Adds DateTime property to descriptor with previously chained name.</summary>
        /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception>
        /// <param name="features">
        ///     Which date features to use (can pipe: DateTimeFeature.Year |
        ///     DateTimeFeature.DayOfWeek)
        /// </param>
        /// <returns>descriptor with added property.</returns>
        public Descriptor AsDateTime(DateTimeFeature features)
        {
            if (this._label)
            {
                throw new DescriptorException("Cannot use a DateTime property as a label");
            }

            var p = new DateTimeProperty(features) { Discrete = true, Name = this._name };

            this.AddProperty(p);
            return this._descriptor;
        }