コード例 #1
0
 public EventValueDescription(string name, EventValueType type, ValueType valueType)
 {
     this.Name           = name;
     this.EventValueType = type;
     this.ValueType      = valueType;
     this.ValueType.CheckType(this.EventValueType);
 }
コード例 #2
0
 public static void CheckType(this ValueType vt, EventValueType type)
 {
     if (((type != EventValueType.INT) && (type != EventValueType.LONG)) && (vt != ValueType.NOT_APPLICABLE))
     {
         throw new ArgumentException(string.Format("{0} doesn't support type {1}", type, vt));
     }
 }
コード例 #3
0
        private string GetValueAsString(object data, int valueIndex, bool recursive)
        {
            EventValueType type = this.GetType(data);

            switch (type)
            {
            case EventValueType.INT:
            case EventValueType.LONG:
            case EventValueType.STRING:
                return(data.ToString());

            case EventValueType.LIST:
            {
                if (!recursive)
                {
                    throw new InvalidCastException("getValueAsString() doesn't support EventValueType.TREE");
                }
                object[] objArray = (object[])data;
                if ((valueIndex < 0) || (valueIndex >= objArray.Length))
                {
                    break;
                }
                return(this.GetValueAsString(objArray[valueIndex], valueIndex, false));
            }
            }
            throw new InvalidCastException("getValueAsString() unsupported type:" + type);
        }
コード例 #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            if (EventType.Equals(EventType.Inactive))
            {
                if (EventValueType != EventValueType.Empty)
                {
                    results.Add(new ValidationResult($"The EventValueType must be Empty for EventType.{EventType}", new string[] { "EventValueType" }));
                }

                if (EventFrequency != EventFrequency.EveryMinute)
                {
                    results.Add(new ValidationResult($"The EventFrequency must be EveryMinute for EventType.{EventType}", new string[] { "EventFrequency" }));
                }

                if (!BoschIoTSuiteApiConnector.gateways.Select(gateway => gateway.thingId).ToList().Contains(Variable))
                {
                    results.Add(new ValidationResult($"The Variable must be a valid Bosch IoT Things ThingId", new string[] { "Variable" }));
                }
            }

            if (EventType.Equals(EventType.Threshold))
            {
                if (EventValueType.Equals(EventValueType.Empty))
                {
                    results.Add(new ValidationResult($"The EventValueType must not be {EventValueType} for EventType.{EventType}", new string[] { "EventValueType" }));
                }

                if (EventFrequency != EventFrequency.Never)
                {
                    results.Add(new ValidationResult($"The EventFrequency must be Never for EventType.{EventType}", new string[] { "EventFrequency" }));
                }

                if (!BoschIoTSuiteApiConnector.gateways.Select(gateway => gateway.attributes.configuration.devices).Select(devices => devices.Where(device => device.deviceId.Equals(Variable))).First().Any())
                {
                    results.Add(new ValidationResult($"The Variable must be a valid Bosch IoT Things device", new string[] { "Variable" }));
                }
            }

            if (EventType.Equals(EventType.Algorithm))
            {
                if (EventValueType != EventValueType.Empty)
                {
                    results.Add(new ValidationResult($"The EventValueType must be Empty for EventType.{EventType}", new string[] { "EventValueType" }));
                }

                if (EventFrequency == EventFrequency.Never | EventFrequency == EventFrequency.EveryMinute)
                {
                    results.Add(new ValidationResult($"The EventFrequency must not be {EventFrequency} for EventType.{EventType}", new string[] { "EventFrequency" }));
                }

                if (!BoschIoTSuiteApiConnector.gateways.Select(gateway => gateway.attributes.configuration.devices).Select(devices => devices.Where(device => device.deviceId.Equals(Variable))).First().Any())
                {
                    results.Add(new ValidationResult($"The Variable must be a valid Bosch IoT Things device", new string[] { "Variable" }));
                }
            }

            return(results);
        }
コード例 #5
0
        private EventValueDescription[] ProcessDescription(string description)
        {
            string[] strArray = Regex.Split(description, @"\s*,\s*", RegexOptions.Compiled);
            List <EventValueDescription> list = new List <EventValueDescription>();

            foreach (string str in strArray)
            {
                Match match = this.PATTERN_DESCRIPTION.Match(str);
                if (match.Success)
                {
                    try
                    {
                        string         name = match.Groups[1].Value;
                        EventValueType type = (EventValueType)int.Parse(match.Groups[2].Value);
                        string         str3 = match.Groups[3].Value;
                        if (!string.IsNullOrEmpty(str3))
                        {
                            ValueType valueType = (ValueType)int.Parse(str3.Substring(1));
                            list.Add(new EventValueDescription(name, type, valueType));
                        }
                        else
                        {
                            list.Add(new EventValueDescription(name, type));
                        }
                    }
                    catch (FormatException)
                    {
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (list.Count != 0)
            {
                return(list.ToArray());
            }
            return(null);
        }
コード例 #6
0
 public EventValueDescription(string name, EventValueType type)
 {
     this.Name           = name;
     this.EventValueType = type;
     this.ValueType      = ((this.EventValueType == EventValueType.INT) || (this.EventValueType == EventValueType.LONG)) ? ValueType.BYTES : ValueType.NOT_APPLICABLE;
 }