public IHttpActionResult EditFormData(string id, [FromBody] IoTDeviceModels.Update iotDevice) { JavaScriptSerializer js = new JavaScriptSerializer(); string logForm = "Form : " + js.Serialize(iotDevice); string logAPI = "[Put] " + Request.RequestUri.ToString(); if (!ModelState.IsValid || iotDevice == null) { Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm); return(BadRequest("Invalid data")); } try { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); iotDeviceModel.updateIoTDevice(id, iotDevice); return(Ok("Success")); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); logMessage.AppendLine(logForm); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public IHttpActionResult UpdateDesiredProperty(string deviceId, [FromBody] IoTDeviceModels.Update_Desired desired) { JavaScriptSerializer js = new JavaScriptSerializer(); string logForm = "Form : " + js.Serialize(desired); string logAPI = "[Put] " + Request.RequestUri.ToString(); if (!ModelState.IsValid) { return(BadRequest()); } try { JObject desiredProperty = JObject.Parse(desired.DeviceTwinsDesired); IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); iotDeviceModel.updateIoTDeviceDesired(deviceId, desiredProperty); return(Ok()); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public IHttpActionResult AddFormData([FromBody] IoTDeviceModels.Add iotDevice) { string logForm = "Form : " + Startup._jsSerializer.Serialize(iotDevice); string logAPI = "[Post] " + Request.RequestUri.ToString(); if (!ModelState.IsValid || iotDevice == null) { Startup._sfAppLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm); return(BadRequest("Invalid data")); } try { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); iotDeviceModel.addIoTDevice(iotDevice); return(Ok()); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); logMessage.AppendLine(logForm); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public async System.Threading.Tasks.Task <IHttpActionResult> SendC2DMessageAsync(string iotDeviceId) { try { int companyId = GetCompanyIdFromToken(); if (!General.IsIoTDeviceUnderCompany(iotDeviceId, companyId)) { return(Unauthorized()); } string payload = await Request.Content.ReadAsStringAsync(); //Retrieve IoTHub Connection String IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); IoTHubModels iotHubModel = new IoTHubModels(); string IoTHubAlias = iotDeviceModel.getIoTDeviceById(iotDeviceId).IoTHubAlias; string IoTHubConnectionString = iotHubModel.getIoTHubById(IoTHubAlias).P_IoTHubConnectionString; //Send out Cloud to Device Message ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(IoTHubConnectionString); var commandMessage = new Message(Encoding.ASCII.GetBytes(payload)); await serviceClient.SendAsync(iotDeviceId, commandMessage); return(Ok()); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); string logAPI = "[Put] " + Request.RequestUri.ToString(); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError(ex)); } }
public IHttpActionResult GetIoTDeciceById(string id) { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); try { return(Ok(iotDeviceModel.getIoTDeviceById(id))); } catch { return(NotFound()); } }
public IHttpActionResult GetAllMessageTemplateByDeviceId(string deviceId) { IoTDeviceModels iotDeviceModels = new IoTDeviceModels(); IoTDeviceMessageCatalogModels iotDMCModels = new IoTDeviceMessageCatalogModels(); MessageCatalogModels msgCatalogModels = new MessageCatalogModels(); List <object> objectList = new List <object>(); var msgCatalogs = iotDMCModels.GetAllMessageCatalogByIoTDeviceId(deviceId); foreach (var msgCatalog in msgCatalogs) { objectList.Add(msgCatalogModels.GetMessageCatalogTemplate(msgCatalog.MessageCatalogId, deviceId)); } return(Ok(objectList)); }
public IHttpActionResult Delete(string id) { try { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); iotDeviceModel.deleteIoTDevice(id); return(Ok("Success")); } catch (Exception ex) { string logAPI = "[Delete] " + Request.RequestUri.ToString(); StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError()); } }
public IHttpActionResult GetIoTDeviceById(string iotDeviceId) { try { int companyId = GetCompanyIdFromToken(); if (!General.IsIoTDeviceUnderCompany(iotDeviceId, companyId)) { return(Unauthorized()); } IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); return(Ok(iotDeviceModel.getIoTDeviceByIdReadonly(iotDeviceId))); } catch (Exception ex) { StringBuilder logMessage = LogUtility.BuildExceptionMessage(ex); string logAPI = "[Get] " + Request.RequestUri.ToString(); Startup._sfAppLogger.Error(logAPI + logMessage); return(InternalServerError()); } }
public IHttpActionResult GetAllIoTDeciceByFactoryId(int factoryId) { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); return(Ok(iotDeviceModel.GetAllIoTDeviceByFactoryId(factoryId))); }
public IHttpActionResult GetAllIoTDeciceByCompanyId(int companyId) { IoTDeviceModels iotDeviceModel = new IoTDeviceModels(); return(Ok(iotDeviceModel.GetAllIoTDeviceByCompanyId(companyId))); }