Ejemplo n.º 1
0
        public HttpResponseMessage Destroy(int p_statetelemetry_oid)
        {
            // CAD, CEN
            StateTelemetryRESTCAD stateTelemetryRESTCAD = null;
            StateTelemetryCEN     stateTelemetryCEN     = null;

            try
            {
                SessionInitializeTransaction();


                stateTelemetryRESTCAD = new StateTelemetryRESTCAD(session);
                stateTelemetryCEN     = new StateTelemetryCEN(stateTelemetryRESTCAD);

                stateTelemetryCEN.Destroy(p_statetelemetry_oid);
                SessionCommit();
            }

            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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
        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);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            StateTelemetryRESTCAD stateTelemetryRESTCAD = null;
            StateTelemetryCEN     stateTelemetryCEN     = null;

            List <StateTelemetryEN>   stateTelemetryEN = null;
            List <StateTelemetryDTOA> returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();


                stateTelemetryRESTCAD = new StateTelemetryRESTCAD(session);
                stateTelemetryCEN     = new StateTelemetryCEN(stateTelemetryRESTCAD);

                // Data
                // TODO: paginación

                stateTelemetryEN = stateTelemetryCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (stateTelemetryEN != null)
                {
                    returnValue = new List <StateTelemetryDTOA>();
                    foreach (StateTelemetryEN entry in stateTelemetryEN)
                    {
                        returnValue.Add(StateTelemetryAssembler.Convert(entry, 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 204 - Empty
            if (returnValue == null || returnValue.Count == 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        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));
            }
        }