// Modify default (Update all attributes of the class)

        public void ModifyDefault(IMPropertyEN iMProperty)
        {
            try
            {
                SessionInitializeTransaction();
                IMPropertyEN iMPropertyEN = (IMPropertyEN)session.Load(typeof(IMPropertyEN), iMProperty.Id);

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

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


            finally
            {
                SessionClose();
            }
        }
        public IMPropertyEN ReadOIDDefault(int id
                                           )
        {
            IMPropertyEN iMPropertyEN = null;

            try
            {
                SessionInitializeTransaction();
                iMPropertyEN = (IMPropertyEN)session.Get(typeof(IMPropertyEN), id);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }

            return(iMPropertyEN);
        }
Exemple #3
0
        public IMPropertyEN ReadOID(int id
                                    )
        {
            IMPropertyEN iMPropertyEN = null;

            iMPropertyEN = _IIMPropertyCAD.ReadOID(id);
            return(iMPropertyEN);
        }
Exemple #4
0
        public void Modify(int p_IMProperty_OID, string p_name, MoSIoTGenNHibernate.Enumerated.MosIoT.DataTypeEnum p_type, bool p_isOID, bool p_isWritable, string p_description, string p_value)
        {
            IMPropertyEN iMPropertyEN = null;

            //Initialized IMPropertyEN
            iMPropertyEN             = new IMPropertyEN();
            iMPropertyEN.Id          = p_IMProperty_OID;
            iMPropertyEN.Name        = p_name;
            iMPropertyEN.Type        = p_type;
            iMPropertyEN.IsOID       = p_isOID;
            iMPropertyEN.IsWritable  = p_isWritable;
            iMPropertyEN.Description = p_description;
            iMPropertyEN.Value       = p_value;
            //Call to IMPropertyCAD

            _IIMPropertyCAD.Modify(iMPropertyEN);
        }
        public static IMPropertyDTOA Convert(EntityAttributesEN en, NHibernate.ISession session = null)
        {
            IMPropertyDTOA    dto = null;
            IMPropertyRESTCAD iMPropertyRESTCAD = null;
            IMPropertyCEN     iMPropertyCEN     = null;
            IMPropertyCP      iMPropertyCP      = null;

            if (en != null)
            {
                dto = new IMPropertyDTOA();
                iMPropertyRESTCAD = new IMPropertyRESTCAD(session);
                iMPropertyCEN     = new IMPropertyCEN(iMPropertyRESTCAD);
                iMPropertyCP      = new IMPropertyCP(session);


                IMPropertyEN enHijo = iMPropertyRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Type = en.Type;


                dto.Value = en.Value;


                //
                // TravesalLink

                /* Rol: IMProperty o--> Property */
                dto.ValueProperty = PropertyAssembler.Convert((PropertyEN)enHijo.Property, session);


                //
                // Service
            }

            return(dto);
        }
        public void Modify(IMPropertyEN iMProperty)
        {
            try
            {
                SessionInitializeTransaction();
                IMPropertyEN iMPropertyEN = (IMPropertyEN)session.Load(typeof(IMPropertyEN), iMProperty.Id);

                iMPropertyEN.Name = iMProperty.Name;


                iMPropertyEN.Type = iMProperty.Type;


                iMPropertyEN.IsOID = iMProperty.IsOID;


                iMPropertyEN.IsWritable = iMProperty.IsWritable;


                iMPropertyEN.Description = iMProperty.Description;


                iMPropertyEN.Value = iMProperty.Value;

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

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


            finally
            {
                SessionClose();
            }
        }
Exemple #7
0
        public int New_(string p_name, MoSIoTGenNHibernate.Enumerated.MosIoT.DataTypeEnum p_type, bool p_isOID, bool p_isWritable, string p_description, int p_entity, string p_value, int p_property)
        {
            IMPropertyEN iMPropertyEN = null;
            int          oid;

            //Initialized IMPropertyEN
            iMPropertyEN      = new IMPropertyEN();
            iMPropertyEN.Name = p_name;

            iMPropertyEN.Type = p_type;

            iMPropertyEN.IsOID = p_isOID;

            iMPropertyEN.IsWritable = p_isWritable;

            iMPropertyEN.Description = p_description;


            if (p_entity != -1)
            {
                // El argumento p_entity -> Property entity es oid = false
                // Lista de oids id
                iMPropertyEN.Entity    = new MoSIoTGenNHibernate.EN.MosIoT.EntityEN();
                iMPropertyEN.Entity.Id = p_entity;
            }

            iMPropertyEN.Value = p_value;


            if (p_property != -1)
            {
                // El argumento p_property -> Property property es oid = false
                // Lista de oids id
                iMPropertyEN.Property    = new MoSIoTGenNHibernate.EN.MosIoT.PropertyEN();
                iMPropertyEN.Property.Id = p_property;
            }

            //Call to IMPropertyCAD

            oid = _IIMPropertyCAD.New_(iMPropertyEN);
            return(oid);
        }
        public int New_(IMPropertyEN iMProperty)
        {
            try
            {
                SessionInitializeTransaction();
                if (iMProperty.Entity != null)
                {
                    // Argumento OID y no colección.
                    iMProperty.Entity = (MoSIoTGenNHibernate.EN.MosIoT.EntityEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.EntityEN), iMProperty.Entity.Id);

                    iMProperty.Entity.Attributes
                    .Add(iMProperty);
                }
                if (iMProperty.Property != null)
                {
                    // Argumento OID y no colección.
                    iMProperty.Property = (MoSIoTGenNHibernate.EN.MosIoT.PropertyEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.PropertyEN), iMProperty.Property.Id);
                }

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

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


            finally
            {
                SessionClose();
            }

            return(iMProperty.Id);
        }
        public HttpResponseMessage ReadOID(int idIMProperty)
        {
            // CAD, CEN, EN, returnValue
            IMPropertyRESTCAD iMPropertyRESTCAD = null;
            IMPropertyCEN     iMPropertyCEN     = null;
            IMPropertyEN      iMPropertyEN      = null;
            IMPropertyDTOA    returnValue       = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMPropertyRESTCAD = new IMPropertyRESTCAD(session);
                iMPropertyCEN     = new IMPropertyCEN(iMPropertyRESTCAD);

                // Data
                iMPropertyEN = iMPropertyCEN.ReadOID(idIMProperty);

                // Convert return
                if (iMPropertyEN != null)
                {
                    returnValue = IMPropertyAssembler.Convert(iMPropertyEN, 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));
            }
        }
        public static IMPropertyEN Convert(IMPropertyDTO dto)
        {
            IMPropertyEN newinstance = null;

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



                    if (dto.Property_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IPropertyCAD propertyCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PropertyCAD();

                        newinstance.Property = propertyCAD.ReadOIDDefault(dto.Property_oid);
                    }
                    newinstance.Id    = dto.Id;
                    newinstance.Name  = dto.Name;
                    newinstance.Type  = dto.Type;
                    newinstance.IsOID = dto.IsOID;
                    if (dto.TargetAssociation_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD();

                        newinstance.TargetAssociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>();
                        foreach (int entry in dto.TargetAssociation_oid)
                        {
                            newinstance.TargetAssociation.Add(associationCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.OriginAsociation_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD();

                        newinstance.OriginAsociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>();
                        foreach (int entry in dto.OriginAsociation_oid)
                        {
                            newinstance.OriginAsociation.Add(associationCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.AssociationType = dto.AssociationType;
                    newinstance.IsWritable      = dto.IsWritable;
                    newinstance.Description     = dto.Description;
                    if (dto.Entity_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD();

                        newinstance.Entity = entityCAD.ReadOIDDefault(dto.Entity_oid);
                    }
                    if (dto.Trigger_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IRecipeTriggerCAD recipeTriggerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeTriggerCAD();

                        newinstance.Trigger = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeTriggerEN>();
                        foreach (int entry in dto.Trigger_oid)
                        {
                            newinstance.Trigger.Add(recipeTriggerCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.Register_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IRegisterCAD registerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RegisterCAD();

                        newinstance.Register = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RegisterEN>();
                        foreach (int entry in dto.Register_oid)
                        {
                            newinstance.Register.Add(registerCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.Value = dto.Value;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }