public static bool SetConfiguration(string key, string identifier, string value) { Configuration retConfig = null; if (!string.IsNullOrEmpty(identifier)) { retConfig = ORM.Select <Configuration> ("Configuration", string.Format("Key = '{0}' AND Identifier = '{1}'", key, identifier)).FirstOrDefault(); } else { retConfig = ORM.Select <Configuration> ("Configuration", string.Format("Key = '{0}' AND Identifier = NULL", key)).FirstOrDefault(); } if (retConfig == null) { retConfig = new Configuration() { Key = key, Identifier = identifier, Created = DateTime.Now }; } retConfig.Value = value; return(ORM.Update <Configuration> ("Configuration", retConfig)); }
public override EditMapJSONResponse GetResponse(Dictionary <string, string[]> requestAttributes) { string mapIDstr = string.Empty; try { if (requestAttributes.ContainsKey("ID")) { mapIDstr = requestAttributes ["ID"] [0].Trim().ToUpper(); var map = ORM.Select <DeviceMap>("DeviceMap", string.Format("ID = '{0}'", mapIDstr)).FirstOrDefault(); if (map == null) { throw new KeyNotFoundException(string.Format("The map with an ID of {0} does not exist in the database.", mapIDstr)); } foreach (string key in requestAttributes.Keys) { switch (key.Trim().ToUpper()) { case "NAME": map.Name = requestAttributes[key][0]; break; case "DEVICEKEY": map.DeviceKey = requestAttributes[key][0]; break; case "DEVICETYPE": map.DeviceTypeEnum = (DeviceType)Enum.Parse(typeof(DeviceType), requestAttributes[key][0]); break; case "CREATED": map.Created = new DateTimeStamp(DateTime.Parse(requestAttributes[key][0])); break; case "PARENTMAPID": map.ParentMapID = (int)int.Parse(requestAttributes[key][0]); break; } } bool success = ORM.Update <DeviceMap>("DeviceMap", map); return(new EditMapJSONResponse(map, success)); } } catch (Exception ex) { if (string.IsNullOrEmpty(mapIDstr)) { mapIDstr = "NULL"; } LogWriter.WriteLog(string.Format("An error was encountered while attempting to update the map. ID:{0}", mapIDstr), ex); } return(new EditMapJSONResponse(null, false)); }
public bool LogValue(IConvertible Value, DateTime logTimeStamp) { DeviceLog log = new DeviceLog(); log.DeviceMapID = this.ID; log.TimeStamp = new DateTimeStamp(logTimeStamp); log.Value = Value.ToString(); return(ORM.Update <DeviceLog> ("DeviceLog", log)); }
public static DeviceMap Create(string deviceKey, DeviceType type) { var match = ORM.Select <DeviceMap> ("DeviceMap", string.Format("DeviceKey = '{0}' and DeviceType = ", deviceKey, (int)type)).FirstOrDefault(); if (match != null) { return(match); } else { match = new DeviceMap(); match.Created = DateTimeStamp.Now; match.DeviceKey = deviceKey; match.DeviceTypeEnum = type; match.Name = deviceKey; ORM.Update <DeviceMap> ("DeviceMap", match); match = ORM.Select <DeviceMap> ("DeviceMap", string.Format("DeviceKey = '{0}' and DeviceType = ", deviceKey, (int)type)).FirstOrDefault(); return(match); } }