コード例 #1
0
        public static DeviceDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            DeviceDTOA    dto           = null;
            DeviceRESTCAD deviceRESTCAD = null;
            DeviceCEN     deviceCEN     = null;
            DeviceCP      deviceCP      = null;

            if (en != null)
            {
                dto           = new DeviceDTOA();
                deviceRESTCAD = new DeviceRESTCAD(session);
                deviceCEN     = new DeviceCEN(deviceRESTCAD);
                deviceCP      = new DeviceCP(session);


                DeviceEN enHijo = deviceRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

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


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


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


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


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


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


                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: Device o--> DeviceTemplate */
                dto.DeviceTemplate = DeviceTemplateAssembler.Convert((DeviceTemplateEN)enHijo.DeviceTemplate, session);


                //
                // Service
            }

            return(dto);
        }
コード例 #2
0
        public HttpResponseMessage New_([FromBody] DeviceDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            DeviceRESTCAD deviceRESTCAD = null;
            DeviceCEN     deviceCEN     = null;
            DeviceDTOA    returnValue   = null;
            int           returnOID     = -1;

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

            try
            {
                SessionInitializeTransaction();


                deviceRESTCAD = new DeviceRESTCAD(session);
                deviceCEN     = new DeviceCEN(deviceRESTCAD);

                // Create
                returnOID = deviceCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    ,
                    //Atributo OID: p_scenario
                    // attr.estaRelacionado: true
                    dto.Scenario_oid                     // association role

                    , dto.Description                    //Atributo Primitivo: p_description
                    , dto.DeviceSwitch                   //Atributo Primitivo: p_deviceSwitch
                    , dto.Tag                            //Atributo Primitivo: p_tag
                    , dto.IsSimulated                    //Atributo Primitivo: p_isSimulated
                    , dto.SerialNumber                   //Atributo Primitivo: p_serialNumber
                    , dto.FirmVersion                    //Atributo Primitivo: p_firmVersion
                    , dto.Trademark                      //Atributo Primitivo: p_trademark
                    ,
                    //Atributo OID: p_deviceTemplate
                    // attr.estaRelacionado: true
                    dto.DeviceTemplate_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
コード例 #3
0
        public HttpResponseMessage Modify(int idDevice, [FromBody] DeviceDTO dto)
        {
            // CAD, CEN, returnValue
            DeviceRESTCAD deviceRESTCAD = null;
            DeviceCEN     deviceCEN     = null;
            DeviceDTOA    returnValue   = null;

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

            try
            {
                SessionInitializeTransaction();


                deviceRESTCAD = new DeviceRESTCAD(session);
                deviceCEN     = new DeviceCEN(deviceRESTCAD);

                // Modify
                deviceCEN.Modify(idDevice,
                                 dto.Name
                                 ,
                                 dto.Description
                                 ,
                                 dto.DeviceSwitch
                                 ,
                                 dto.Tag
                                 ,
                                 dto.IsSimulated
                                 ,
                                 dto.SerialNumber
                                 ,
                                 dto.FirmVersion
                                 ,
                                 dto.Trademark
                                 );

                // Return modified object
                returnValue = DeviceAssembler.Convert(deviceRESTCAD.ReadOIDDefault(idDevice), 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);
            }
        }
コード例 #4
0
        public HttpResponseMessage ReadOID(int idDevice)
        {
            // CAD, CEN, EN, returnValue
            DeviceRESTCAD deviceRESTCAD = null;
            DeviceCEN     deviceCEN     = null;
            DeviceEN      deviceEN      = null;
            DeviceDTOA    returnValue   = null;

            try
            {
                SessionInitializeWithoutTransaction();


                deviceRESTCAD = new DeviceRESTCAD(session);
                deviceCEN     = new DeviceCEN(deviceRESTCAD);

                // Data
                deviceEN = deviceCEN.ReadOID(idDevice);

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