public int New_(int p_telemetry, string p_name, int p_latitude, int p_longitude, int p_altitude)
        {
            LocationTelemetryEN locationTelemetryEN = null;
            int oid;

            //Initialized LocationTelemetryEN
            locationTelemetryEN = new LocationTelemetryEN();

            if (p_telemetry != -1)
            {
                // El argumento p_telemetry -> Property telemetry es oid = false
                // Lista de oids id
                locationTelemetryEN.Telemetry    = new MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN();
                locationTelemetryEN.Telemetry.Id = p_telemetry;
            }

            locationTelemetryEN.Name = p_name;

            locationTelemetryEN.Latitude = p_latitude;

            locationTelemetryEN.Longitude = p_longitude;

            locationTelemetryEN.Altitude = p_altitude;

            //Call to LocationTelemetryCAD

            oid = _ILocationTelemetryCAD.New_(locationTelemetryEN);
            return(oid);
        }
        public LocationTelemetryEN ReadOIDDefault(int id
                                                  )
        {
            LocationTelemetryEN locationTelemetryEN = null;

            try
            {
                SessionInitializeTransaction();
                locationTelemetryEN = (LocationTelemetryEN)session.Get(typeof(LocationTelemetryEN), id);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in LocationTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(locationTelemetryEN);
        }
// Modify default (Update all attributes of the class)

        public void ModifyDefault(LocationTelemetryEN locationTelemetry)
        {
            try
            {
                SessionInitializeTransaction();
                LocationTelemetryEN locationTelemetryEN = (LocationTelemetryEN)session.Load(typeof(LocationTelemetryEN), locationTelemetry.Id);

                locationTelemetryEN.Latitude = locationTelemetry.Latitude;


                locationTelemetryEN.Longitude = locationTelemetry.Longitude;


                locationTelemetryEN.Altitude = locationTelemetry.Altitude;

                session.Update(locationTelemetryEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in LocationTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public void Destroy(int id
                            )
        {
            try
            {
                SessionInitializeTransaction();
                LocationTelemetryEN locationTelemetryEN = (LocationTelemetryEN)session.Load(typeof(LocationTelemetryEN), id);
                session.Delete(locationTelemetryEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in LocationTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public int New_(LocationTelemetryEN locationTelemetry)
        {
            try
            {
                SessionInitializeTransaction();
                if (locationTelemetry.Telemetry != null)
                {
                    // Argumento OID y no colección.
                    locationTelemetry.Telemetry = (MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN), locationTelemetry.Telemetry.Id);

                    locationTelemetry.Telemetry.TypeTelemetry
                        = locationTelemetry;
                }

                session.Save(locationTelemetry);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in LocationTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(locationTelemetry.Id);
        }
示例#6
0
        public static LocationTelemetryEN Convert(LocationTelemetryDTO dto)
        {
            LocationTelemetryEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new LocationTelemetryEN();



                    newinstance.Latitude  = dto.Latitude;
                    newinstance.Longitude = dto.Longitude;
                    newinstance.Altitude  = dto.Altitude;
                    if (dto.Telemetry_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ITelemetryCAD telemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TelemetryCAD();

                        newinstance.Telemetry = telemetryCAD.ReadOIDDefault(dto.Telemetry_oid);
                    }
                    newinstance.Id   = dto.Id;
                    newinstance.Name = dto.Name;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
        public LocationTelemetryEN ReadOID(int id
                                           )
        {
            LocationTelemetryEN locationTelemetryEN = null;

            locationTelemetryEN = _ILocationTelemetryCAD.ReadOID(id);
            return(locationTelemetryEN);
        }
示例#8
0
        public static LocationTelemetryDTOA Convert(SpecificTelemetryEN en, NHibernate.ISession session = null)
        {
            LocationTelemetryDTOA    dto = null;
            LocationTelemetryRESTCAD locationTelemetryRESTCAD = null;
            LocationTelemetryCEN     locationTelemetryCEN     = null;
            LocationTelemetryCP      locationTelemetryCP      = null;

            if (en != null)
            {
                dto = new LocationTelemetryDTOA();
                locationTelemetryRESTCAD = new LocationTelemetryRESTCAD(session);
                locationTelemetryCEN     = new LocationTelemetryCEN(locationTelemetryRESTCAD);
                locationTelemetryCP      = new LocationTelemetryCP(session);


                LocationTelemetryEN enHijo = locationTelemetryRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                if (enHijo != null)
                {
                    dto.Latitude = enHijo.Latitude;
                }


                if (enHijo != null)
                {
                    dto.Longitude = enHijo.Longitude;
                }


                if (enHijo != null)
                {
                    dto.Altitude = enHijo.Altitude;
                }


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
        public void Modify(int p_LocationTelemetry_OID, string p_name, int p_latitude, int p_longitude, int p_altitude)
        {
            LocationTelemetryEN locationTelemetryEN = null;

            //Initialized LocationTelemetryEN
            locationTelemetryEN           = new LocationTelemetryEN();
            locationTelemetryEN.Id        = p_LocationTelemetry_OID;
            locationTelemetryEN.Name      = p_name;
            locationTelemetryEN.Latitude  = p_latitude;
            locationTelemetryEN.Longitude = p_longitude;
            locationTelemetryEN.Altitude  = p_altitude;
            //Call to LocationTelemetryCAD

            _ILocationTelemetryCAD.Modify(locationTelemetryEN);
        }
        public LocationTelemetryEN Location(int id)
        {
            LocationTelemetryEN result = null;

            try
            {
                SessionInitializeTransaction();


                String sql = @"select self.TypeTelemetry FROM TelemetryEN self " +
                             "where self.Id = :p_Id";
                IQuery query = session.CreateQuery(sql).SetParameter("p_Id", id);



                result = query.UniqueResult <LocationTelemetryEN>();

                SessionCommit();
            }

            catch (Exception ex)
            {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in TelemetryRESTCAD.", ex);
            }

            finally
            {
                SessionClose();
            }

            return(result);
        }
        public HttpResponseMessage ReadOID(int idLocationTelemetry)
        {
            // CAD, CEN, EN, returnValue
            LocationTelemetryRESTCAD locationTelemetryRESTCAD = null;
            LocationTelemetryCEN     locationTelemetryCEN     = null;
            LocationTelemetryEN      locationTelemetryEN      = null;
            LocationTelemetryDTOA    returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                locationTelemetryRESTCAD = new LocationTelemetryRESTCAD(session);
                locationTelemetryCEN     = new LocationTelemetryCEN(locationTelemetryRESTCAD);

                // Data
                locationTelemetryEN = locationTelemetryCEN.ReadOID(idLocationTelemetry);

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