public static TelemetryDTOA Convert(TelemetryEN en, NHibernate.ISession session = null)
        {
            TelemetryDTOA    dto = null;
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;
            TelemetryCP      telemetryCP      = null;

            if (en != null)
            {
                dto = new TelemetryDTOA();
                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);
                telemetryCP      = new TelemetryCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Frecuency = en.Frecuency;


                dto.Schema = en.Schema;


                dto.Unit = en.Unit;


                dto.Name = en.Name;


                dto.Type = en.Type;


                //
                // TravesalLink

                /* Rol: Telemetry o--> SensorTelemetry */
                dto.Sensor = SensorTelemetryAssembler.Convert((SpecificTelemetryEN)en.TypeTelemetry, session);

                /* Rol: Telemetry o--> StateTelemetry */
                dto.State = StateTelemetryAssembler.Convert((SpecificTelemetryEN)en.TypeTelemetry, session);

                /* Rol: Telemetry o--> LocationTelemetry */
                dto.Location = LocationTelemetryAssembler.Convert((SpecificTelemetryEN)en.TypeTelemetry, session);

                /* Rol: Telemetry o--> EventTelemetry */
                dto.Event_ = EventTelemetryAssembler.Convert((SpecificTelemetryEN)en.TypeTelemetry, session);


                //
                // Service
            }

            return(dto);
        }
Exemple #2
0
        public HttpResponseMessage AsignarSpecific(int p_telemetry_oid, int p_typetelemetry_oid)
        {
            // CAD, CEN, returnValue
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;

            try
            {
                SessionInitializeTransaction();


                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);

                // Relationer
                telemetryCEN.AsignarSpecific(p_telemetry_oid, p_typetelemetry_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 200 - OK
            return(this.Request.CreateResponse(HttpStatusCode.OK));
        }
Exemple #3
0
        public static TelemetryDTOA Convert(TelemetryEN en, NHibernate.ISession session = null)
        {
            TelemetryDTOA    dto = null;
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;
            TelemetryCP      telemetryCP      = null;

            if (en != null)
            {
                dto = new TelemetryDTOA();
                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);
                telemetryCP      = new TelemetryCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Frecuency = en.Frecuency;


                dto.Schema = en.Schema;


                dto.Unit = en.Unit;


                dto.Name = en.Name;


                dto.Type = en.Type;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
Exemple #4
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;

            List <TelemetryEN>   telemetryEN = null;
            List <TelemetryDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);

                // Data
                // TODO: paginación

                telemetryEN = telemetryCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (telemetryEN != null)
                {
                    returnValue = new List <TelemetryDTOA>();
                    foreach (TelemetryEN entry in telemetryEN)
                    {
                        returnValue.Add(TelemetryAssembler.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));
            }
        }
Exemple #5
0
        public HttpResponseMessage Modify(int idTelemetry, [FromBody] TelemetryDTO dto)
        {
            // CAD, CEN, returnValue
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;
            TelemetryDTOA    returnValue      = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);

                // Modify
                telemetryCEN.Modify(idTelemetry,
                                    dto.Frecuency
                                    ,
                                    dto.Schema
                                    ,
                                    dto.Unit
                                    ,
                                    dto.Name
                                    ,
                                    dto.Type
                                    );

                // Return modified object
                returnValue = TelemetryAssembler.Convert(telemetryRESTCAD.ReadOIDDefault(idTelemetry), session);

                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 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
Exemple #6
0
        public HttpResponseMessage New_([FromBody] TelemetryDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;
            TelemetryDTOA    returnValue      = null;
            int returnOID = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);

                // Create
                returnOID = telemetryCEN.New_(

                    //Atributo OID: p_deviceTemplate
                    // attr.estaRelacionado: true
                    dto.DeviceTemplate_oid                     // association role

                    , dto.Frecuency                            //Atributo Primitivo: p_frecuency
                    , dto.Schema                               //Atributo Primitivo: p_schema
                    , dto.Unit                                 //Atributo Primitivo: p_unit
                    , dto.Name                                 //Atributo Primitivo: p_name
                    , dto.Type                                 //Atributo Primitivo: p_type
                    );
                SessionCommit();

                // Convert return
                returnValue = TelemetryAssembler.Convert(telemetryRESTCAD.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("GetOIDTelemetry", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
Exemple #7
0
        public HttpResponseMessage ReadOID(int idTelemetry)
        {
            // CAD, CEN, EN, returnValue
            TelemetryRESTCAD telemetryRESTCAD = null;
            TelemetryCEN     telemetryCEN     = null;
            TelemetryEN      telemetryEN      = null;
            TelemetryDTOA    returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();


                telemetryRESTCAD = new TelemetryRESTCAD(session);
                telemetryCEN     = new TelemetryCEN(telemetryRESTCAD);

                // Data
                telemetryEN = telemetryCEN.ReadOID(idTelemetry);

                // Convert return
                if (telemetryEN != null)
                {
                    returnValue = TelemetryAssembler.Convert(telemetryEN, 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));
            }
        }