public static DeviceStatusType ParseStatusString(string status) { DeviceStatusType statusToReturn = DeviceStatusType.Undefined; if (string.IsNullOrWhiteSpace(status)) { // We didn't get back any status information from the device, like // indicating that the UPS is gone. return(statusToReturn); } var tokens = status.Split(' '); foreach (string token in tokens) { DeviceStatusInfo statusInfo = statusInfos.FirstOrDefault( s => s.Identifiers.Contains(token, StringComparer.OrdinalIgnoreCase)); // s => string.Equals(s.Identifier, token, StringComparison.OrdinalIgnoreCase)); if (statusInfo == null) { throw new Exception($"The status {token} is not defined"); } statusToReturn |= statusInfo.StatusType; } return(statusToReturn); }
public static List <string> GetStatusDisplayName(this DeviceStatusType status) { List <string> result = new List <string>(); foreach (Constants.Device.DeviceStatusInfo info in Constants.Device.statusInfos) { if (status.HasFlag(info.StatusType)) { result.Add(info.DisplayName); } } return(result); }
public static DeviceSeverityType GetStatusSeverity(DeviceStatusType status) { DeviceSeverityType severity = DeviceSeverityType.OK; foreach (DeviceStatusInfo deviceStatusInfo in statusInfos) { if (status.HasFlag(deviceStatusInfo.StatusType) && deviceStatusInfo.Severity > severity) { severity = deviceStatusInfo.Severity; } } return(severity); }
private static bool IsStatusTransition( UpsStatusChangeData changeData, DeviceStatusType status, bool requirePreviousState) { if (!requirePreviousState) { return(changeData.UpsContext.State.Status.HasFlag(status) && (changeData.PreviousState == null || !changeData.PreviousState.Status.HasFlag(status))); } if (changeData.PreviousState == null) { return(false); } return(changeData.UpsContext.State.Status.HasFlag(status) && !changeData.PreviousState.Status.HasFlag(status)); }
private void Process(List<string> data) { /* 1 ECoS2 1 ProtocolVersion[0.2] 1 ApplicationVersion[3.7.0] 1 HardwareVersion[2.0] 1 status[STOP] */ string pattern = ID + @"\s(?<Parameter>[^\[]*)" + @"(\[(?<Value>[^\]]*)\])*"; Regex r = new Regex(pattern, RegexOptions.IgnoreCase); foreach (string str in data) { string param = r.Match(str).Groups["Parameter"].Value; string val = r.Match(str).Groups["Value"].Value; if (string.IsNullOrEmpty(val)) Name = param; else { switch (param.ToUpper()) { case "PROTOCOLVERSION": ProtocolVersion = val; break; case "APPLICATIONVERSION": ApplicationVersion = val; break; case "HARDWAREVERSION": HardwareVersion = val; break; case "STATUS": switch (val.ToUpper()) { case "STOP": Status = DeviceStatusType.Stop; break; case "GO": Status = DeviceStatusType.Go; break; case "SHUTDOWN": Status = DeviceStatusType.Shutdown; break; default: Status = DeviceStatusType.Stop; break; } break; } } } }
public DeviceResponseResult GetDeviceStatus(DeviceStatusType statusType) { throw new NotImplementedException(); }
public DeviceResponseResult GetDeviceStatus(DeviceStatusType statusType) { return DeviceResponseResult; }