public static StateTelemetryDTOA Convert(SpecificTelemetryEN en, NHibernate.ISession session = null) { StateTelemetryDTOA dto = null; StateTelemetryRESTCAD stateTelemetryRESTCAD = null; StateTelemetryCEN stateTelemetryCEN = null; StateTelemetryCP stateTelemetryCP = null; if (en != null) { dto = new StateTelemetryDTOA(); stateTelemetryRESTCAD = new StateTelemetryRESTCAD(session); stateTelemetryCEN = new StateTelemetryCEN(stateTelemetryRESTCAD); stateTelemetryCP = new StateTelemetryCP(session); StateTelemetryEN enHijo = stateTelemetryRESTCAD.ReadOIDDefault(en.Id); // // Attributes dto.Id = en.Id; // // TravesalLink /* Rol: StateTelemetry o--> StateDevice */ dto.States = null; List <StateDeviceEN> States = stateTelemetryRESTCAD.States(en.Id).ToList(); if (States != null) { dto.States = new List <StateDeviceDTOA>(); foreach (StateDeviceEN entry in States) { dto.States.Add(StateDeviceAssembler.Convert(entry, session)); } } // // Service } return(dto); }
public HttpResponseMessage New_([FromBody] StateTelemetryDTO dto) { // CAD, CEN, returnValue, returnOID StateTelemetryRESTCAD stateTelemetryRESTCAD = null; StateTelemetryCEN stateTelemetryCEN = null; StateTelemetryDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); stateTelemetryRESTCAD = new StateTelemetryRESTCAD(session); stateTelemetryCEN = new StateTelemetryCEN(stateTelemetryRESTCAD); // Create returnOID = stateTelemetryCEN.New_( //Atributo OID: p_telemetry // attr.estaRelacionado: true dto.Telemetry_oid // association role , dto.Name //Atributo Primitivo: p_name ); SessionCommit(); // Convert return returnValue = StateTelemetryAssembler.Convert(stateTelemetryRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 201 - Created response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue); // Location Header /* * Dictionary<string, object> routeValues = new Dictionary<string, object>(); * * // TODO: y rolPaths * routeValues.Add("id", returnOID); * * uri = Url.Link("GetOIDStateTelemetry", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage ReadOID(int idStateTelemetry) { // CAD, CEN, EN, returnValue StateTelemetryRESTCAD stateTelemetryRESTCAD = null; StateTelemetryCEN stateTelemetryCEN = null; StateTelemetryEN stateTelemetryEN = null; StateTelemetryDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); stateTelemetryRESTCAD = new StateTelemetryRESTCAD(session); stateTelemetryCEN = new StateTelemetryCEN(stateTelemetryRESTCAD); // Data stateTelemetryEN = stateTelemetryCEN.ReadOID(idStateTelemetry); // Convert return if (stateTelemetryEN != null) { returnValue = StateTelemetryAssembler.Convert(stateTelemetryEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }