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);
        }
Beispiel #2
0
        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);
        }