コード例 #1
0
// Modify default (Update all attributes of the class)

        public void ModifyDefault(IoTScenarioEN ioTScenario)
        {
            try
            {
                SessionInitializeTransaction();
                IoTScenarioEN ioTScenarioEN = (IoTScenarioEN)session.Load(typeof(IoTScenarioEN), ioTScenario.Id);

                ioTScenarioEN.Name = ioTScenario.Name;



                ioTScenarioEN.Description = ioTScenario.Description;

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

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


            finally
            {
                SessionClose();
            }
        }
コード例 #2
0
        public IoTScenarioEN ReadOIDDefault(int id
                                            )
        {
            IoTScenarioEN ioTScenarioEN = null;

            try
            {
                SessionInitializeTransaction();
                ioTScenarioEN = (IoTScenarioEN)session.Get(typeof(IoTScenarioEN), id);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }

            return(ioTScenarioEN);
        }
コード例 #3
0
        public void Destroy(int id
                            )
        {
            try
            {
                SessionInitializeTransaction();
                IoTScenarioEN ioTScenarioEN = (IoTScenarioEN)session.Load(typeof(IoTScenarioEN), id);
                session.Delete(ioTScenarioEN);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }
        }
コード例 #4
0
        public int New_(IoTScenarioEN ioTScenario)
        {
            try
            {
                SessionInitializeTransaction();

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

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


            finally
            {
                SessionClose();
            }

            return(ioTScenario.Id);
        }
コード例 #5
0
        public IoTScenarioEN ReadOID(int id
                                     )
        {
            IoTScenarioEN ioTScenarioEN = null;

            ioTScenarioEN = _IIoTScenarioCAD.ReadOID(id);
            return(ioTScenarioEN);
        }
コード例 #6
0
        public static IoTScenarioEN Convert(IoTScenarioDTO dto)
        {
            IoTScenarioEN newinstance = null;

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



                    newinstance.Id   = dto.Id;
                    newinstance.Name = dto.Name;

                    if (dto.Entity != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD();

                        newinstance.Entity = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.EntityEN>();
                        foreach (EntityDTO entry in dto.Entity)
                        {
                            newinstance.Entity.Add(EntityAssemblerDTO.Convert(entry));
                        }
                    }

                    if (dto.Recipes != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IRecipeCAD recipeCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeCAD();

                        newinstance.Recipes = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeEN>();
                        foreach (RecipeDTO entry in dto.Recipes)
                        {
                            newinstance.Recipes.Add(RecipeAssemblerDTO.Convert(entry));
                        }
                    }

                    if (dto.Association != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD();

                        newinstance.Association = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>();
                        foreach (AssociationDTO entry in dto.Association)
                        {
                            newinstance.Association.Add(AssociationAssemblerDTO.Convert(entry));
                        }
                    }
                    newinstance.Description = dto.Description;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
コード例 #7
0
        public void Modify(int p_IoTScenario_OID, string p_name, string p_description)
        {
            IoTScenarioEN ioTScenarioEN = null;

            //Initialized IoTScenarioEN
            ioTScenarioEN             = new IoTScenarioEN();
            ioTScenarioEN.Id          = p_IoTScenario_OID;
            ioTScenarioEN.Name        = p_name;
            ioTScenarioEN.Description = p_description;
            //Call to IoTScenarioCAD

            _IIoTScenarioCAD.Modify(ioTScenarioEN);
        }
コード例 #8
0
        public int New_(string p_name, string p_description)
        {
            IoTScenarioEN ioTScenarioEN = null;
            int           oid;

            //Initialized IoTScenarioEN
            ioTScenarioEN      = new IoTScenarioEN();
            ioTScenarioEN.Name = p_name;

            ioTScenarioEN.Description = p_description;

            //Call to IoTScenarioCAD

            oid = _IIoTScenarioCAD.New_(ioTScenarioEN);
            return(oid);
        }
コード例 #9
0
        public static IoTScenarioDTOA Convert(IoTScenarioEN en, NHibernate.ISession session = null)
        {
            IoTScenarioDTOA    dto = null;
            IoTScenarioRESTCAD ioTScenarioRESTCAD = null;
            IoTScenarioCEN     ioTScenarioCEN     = null;
            IoTScenarioCP      ioTScenarioCP      = null;

            if (en != null)
            {
                dto = new IoTScenarioDTOA();
                ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session);
                ioTScenarioCEN     = new IoTScenarioCEN(ioTScenarioRESTCAD);
                ioTScenarioCP      = new IoTScenarioCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
コード例 #10
0
        public HttpResponseMessage Entities(int idIoTScenario)
        {
            // CAD, EN
            IoTScenarioRESTCAD ioTScenarioRESTCAD = null;
            IoTScenarioEN      ioTScenarioEN      = null;

            // returnValue
            List <EntityEN>   en          = null;
            List <EntityDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session);

                // Exists IoTScenario
                ioTScenarioEN = ioTScenarioRESTCAD.ReadOIDDefault(idIoTScenario);
                if (ioTScenarioEN == null)
                {
                    throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "IoTScenario#" + idIoTScenario + " not found"));
                }

                // Rol
                // TODO: paginación


                en = ioTScenarioRESTCAD.Entities(idIoTScenario).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new List <EntityDTOA>();
                    foreach (EntityEN entry in en)
                    {
                        returnValue.Add(EntityAssembler.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));
            }
        }
コード例 #11
0
        public HttpResponseMessage ReadOID(int idIoTScenario)
        {
            // CAD, CEN, EN, returnValue
            IoTScenarioRESTCAD ioTScenarioRESTCAD = null;
            IoTScenarioCEN     ioTScenarioCEN     = null;
            IoTScenarioEN      ioTScenarioEN      = null;
            IoTScenarioDTOA    returnValue        = null;

            try
            {
                SessionInitializeWithoutTransaction();


                ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session);
                ioTScenarioCEN     = new IoTScenarioCEN(ioTScenarioRESTCAD);

                // Data
                ioTScenarioEN = ioTScenarioCEN.ReadOID(idIoTScenario);

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