public EventValueDescription(string name, EventValueType type, ValueType valueType) { this.Name = name; this.EventValueType = type; this.ValueType = valueType; this.ValueType.CheckType(this.EventValueType); }
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)); } }
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); }
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); }
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); }
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; }