/// <summary> /// Saves current light level. /// </summary> /// <param name="lightLevelXmlData">Passes read xml light level object.</param> /// <param name="DeviceType">Passes device type.</param> private static void SaveCurrentLightLevel(ObixResult <XElement> lightLevelXmlData, string DeviceType) { IEnumerable <XNode> lighLevelLst = lightLevelXmlData.Result.Document.DescendantNodes(); XElement lightLevelelement = lighLevelLst.LastOrDefault() as XElement; if (lightLevelelement != null) { var deviceDetail = _dbcontext.ObixDevices.Where(y => y.object_instance == (int)DeviceEnum.LightLevel).FirstOrDefault(); if (deviceDetail == null) { var lightLevelObj = new ObixDevice { DeviceName = lightLevelelement.Attribute("displayName").Value, Unit = lightLevelelement.Attribute("unit").Value, DeviceUrl = lightLevelelement.Attribute("href").Value, Status = lightLevelelement.Attribute("status") != null?lightLevelelement.Attribute("status").Value : null, Value = lightLevelelement.Attribute("val").Value, DeviceType = DeviceType, isActive = true, DateOfEntry = DateTime.UtcNow, ValueType = lightLevelelement.Name.LocalName, object_instance = (int)DeviceEnum.LightLevel }; _dbcontext.ObixDevices.Add(lightLevelObj); _dbcontext.SaveChanges(); } else { deviceDetail.DeviceName = lightLevelelement.Attribute("displayName").Value; deviceDetail.Unit = lightLevelelement.Attribute("unit").Value; deviceDetail.DeviceUrl = lightLevelelement.Attribute("href").Value; deviceDetail.Status = lightLevelelement.Attribute("status") != null?lightLevelelement.Attribute("status").Value : null; deviceDetail.Value = lightLevelelement.Attribute("val").Value; deviceDetail.DeviceType = DeviceType; deviceDetail.isActive = true; deviceDetail.DateOfEntry = DateTime.UtcNow; deviceDetail.ValueType = lightLevelelement.Name.LocalName; deviceDetail.object_instance = (int)DeviceEnum.LightLevel; _dbcontext.Entry(deviceDetail).State = System.Data.Entity.EntityState.Modified; _dbcontext.SaveChanges(); } } }
/// <summary> /// Saves current occupancy state level detail. /// </summary> /// <param name="occupancyStateXmlData">Passes read xml ocupancy state detail.</param> /// <param name="DeviceType">Passes device type.</param> private static void SaveCurrentOccupancyState(ObixResult <XElement> occupancyStateXmlData, string DeviceType) { IEnumerable <XNode> occupancyStateLst = occupancyStateXmlData.Result.Document.DescendantNodes(); XElement occupancyStateElement = occupancyStateLst.LastOrDefault() as XElement; if (occupancyStateElement != null) { var deviceDetail = _dbcontext.ObixDevices.Where(y => y.object_instance == (int)DeviceEnum.OccupancyState).FirstOrDefault(); if (deviceDetail == null) { var occupancyStateObj = new ObixDevice { DeviceName = occupancyStateElement.Attribute("displayName").Value, DeviceUrl = occupancyStateElement.Attribute("href").Value, Value = occupancyStateElement.Attribute("val").Value, DeviceType = DeviceType, isActive = true, DateOfEntry = DateTime.UtcNow, ValueType = occupancyStateElement.Name.LocalName, object_instance = (int)DeviceEnum.OccupancyState }; _dbcontext.ObixDevices.Add(occupancyStateObj); _dbcontext.SaveChanges(); } else { deviceDetail.DeviceName = occupancyStateElement.Attribute("displayName").Value; deviceDetail.DeviceUrl = occupancyStateElement.Attribute("href").Value; deviceDetail.Value = occupancyStateElement.Attribute("val").Value; deviceDetail.DeviceType = DeviceType; deviceDetail.isActive = true; deviceDetail.DateOfEntry = DateTime.UtcNow; deviceDetail.ValueType = occupancyStateElement.Name.LocalName; deviceDetail.object_instance = (int)DeviceEnum.OccupancyState; _dbcontext.ObixDevices.Attach(deviceDetail); _dbcontext.SaveChanges(); } } }