public void Destroy(int id
                            )
        {
            try
            {
                SessionInitializeTransaction();
                PropertyEN propertyEN = (PropertyEN)session.Load(typeof(PropertyEN), id);
                session.Delete(propertyEN);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }
        }
        public PropertyEN ReadOIDDefault(int id
                                         )
        {
            PropertyEN propertyEN = null;

            try
            {
                SessionInitializeTransaction();
                propertyEN = (PropertyEN)session.Get(typeof(PropertyEN), id);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }

            return(propertyEN);
        }
        public int New_(PropertyEN property)
        {
            try
            {
                SessionInitializeTransaction();
                if (property.DeviceTemplate != null)
                {
                    // Argumento OID y no colección.
                    property.DeviceTemplate = (MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN), property.DeviceTemplate.Id);

                    property.DeviceTemplate.Property
                    .Add(property);
                }

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

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


            finally
            {
                SessionClose();
            }

            return(property.Id);
        }
        public void Modify(PropertyEN property)
        {
            try
            {
                SessionInitializeTransaction();
                PropertyEN propertyEN = (PropertyEN)session.Load(typeof(PropertyEN), property.Id);

                propertyEN.Name = property.Name;


                propertyEN.IsWritable = property.IsWritable;


                propertyEN.IsCloudable = property.IsCloudable;

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

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


            finally
            {
                SessionClose();
            }
        }
示例#5
0
        public int New_(int p_deviceTemplate, string p_name, bool p_isWritable, bool p_isCloudable)
        {
            PropertyEN propertyEN = null;
            int        oid;

            //Initialized PropertyEN
            propertyEN = new PropertyEN();

            if (p_deviceTemplate != -1)
            {
                // El argumento p_deviceTemplate -> Property deviceTemplate es oid = false
                // Lista de oids id
                propertyEN.DeviceTemplate    = new MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN();
                propertyEN.DeviceTemplate.Id = p_deviceTemplate;
            }

            propertyEN.Name = p_name;

            propertyEN.IsWritable = p_isWritable;

            propertyEN.IsCloudable = p_isCloudable;

            //Call to PropertyCAD

            oid = _IPropertyCAD.New_(propertyEN);
            return(oid);
        }
示例#6
0
        public PropertyEN ReadOID(int id
                                  )
        {
            PropertyEN propertyEN = null;

            propertyEN = _IPropertyCAD.ReadOID(id);
            return(propertyEN);
        }
示例#7
0
        public void Modify(int p_Property_OID, string p_name, bool p_isWritable, bool p_isCloudable)
        {
            PropertyEN propertyEN = null;

            //Initialized PropertyEN
            propertyEN             = new PropertyEN();
            propertyEN.Id          = p_Property_OID;
            propertyEN.Name        = p_name;
            propertyEN.IsWritable  = p_isWritable;
            propertyEN.IsCloudable = p_isCloudable;
            //Call to PropertyCAD

            _IPropertyCAD.Modify(propertyEN);
        }
示例#8
0
        public static PropertyEN Convert(PropertyDTO dto)
        {
            PropertyEN newinstance = null;

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



                    if (dto.DeviceTemplate_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IDeviceTemplateCAD deviceTemplateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DeviceTemplateCAD();

                        newinstance.DeviceTemplate = deviceTemplateCAD.ReadOIDDefault(dto.DeviceTemplate_oid);
                    }
                    newinstance.Id          = dto.Id;
                    newinstance.Name        = dto.Name;
                    newinstance.IsWritable  = dto.IsWritable;
                    newinstance.IsCloudable = dto.IsCloudable;
                    if (dto.Telemetry_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ITelemetryCAD telemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TelemetryCAD();

                        newinstance.Telemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN>();
                        foreach (int entry in dto.Telemetry_oid)
                        {
                            newinstance.Telemetry.Add(telemetryCAD.ReadOIDDefault(entry));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
示例#9
0
        public static PropertyDTOA Convert(PropertyEN en, NHibernate.ISession session = null)
        {
            PropertyDTOA    dto             = null;
            PropertyRESTCAD propertyRESTCAD = null;
            PropertyCEN     propertyCEN     = null;
            PropertyCP      propertyCP      = null;

            if (en != null)
            {
                dto             = new PropertyDTOA();
                propertyRESTCAD = new PropertyRESTCAD(session);
                propertyCEN     = new PropertyCEN(propertyRESTCAD);
                propertyCP      = new PropertyCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.IsWritable = en.IsWritable;


                dto.IsCloudable = en.IsCloudable;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
示例#10
0
        public PropertyEN ValueProperty(int id)
        {
            PropertyEN result = null;

            try
            {
                SessionInitializeTransaction();


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



                result = query.UniqueResult <PropertyEN>();

                SessionCommit();
            }

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

            finally
            {
                SessionClose();
            }

            return(result);
        }
示例#11
0
        public HttpResponseMessage ReadOID(int idProperty)
        {
            // CAD, CEN, EN, returnValue
            PropertyRESTCAD propertyRESTCAD = null;
            PropertyCEN     propertyCEN     = null;
            PropertyEN      propertyEN      = null;
            PropertyDTOA    returnValue     = null;

            try
            {
                SessionInitializeWithoutTransaction();


                propertyRESTCAD = new PropertyRESTCAD(session);
                propertyCEN     = new PropertyCEN(propertyRESTCAD);

                // Data
                propertyEN = propertyCEN.ReadOID(idProperty);

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