예제 #1
0
        public HttpResponseMessage Destroy(int p_imtelemetry_oid)
        {
            // CAD, CEN
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;

            try
            {
                SessionInitializeTransaction();


                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);

                iMTelemetryCEN.Destroy(p_imtelemetry_oid);
                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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
        public static IMTelemetryDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            IMTelemetryDTOA    dto = null;
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;
            IMTelemetryCP      iMTelemetryCP      = null;

            if (en != null)
            {
                dto = new IMTelemetryDTOA();
                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);
                iMTelemetryCP      = new IMTelemetryCP(session);


                IMTelemetryEN enHijo = iMTelemetryRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: IMTelemetry o--> Telemetry */
                dto.Telemetry = TelemetryAssembler.Convert((TelemetryEN)enHijo.Telemetry, session);


                //
                // Service
            }

            return(dto);
        }
예제 #3
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;

            List <IMTelemetryEN>   iMTelemetryEN = null;
            List <IMTelemetryDTOA> returnValue   = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);

                // Data
                // TODO: paginación

                iMTelemetryEN = iMTelemetryCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (iMTelemetryEN != null)
                {
                    returnValue = new List <IMTelemetryDTOA>();
                    foreach (IMTelemetryEN entry in iMTelemetryEN)
                    {
                        returnValue.Add(IMTelemetryAssembler.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));
            }
        }
예제 #4
0
        public HttpResponseMessage Modify(int idIMTelemetry, [FromBody] IMTelemetryDTO dto)
        {
            // CAD, CEN, returnValue
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;
            IMTelemetryDTOA    returnValue        = null;

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

            try
            {
                SessionInitializeTransaction();


                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);

                // Modify
                iMTelemetryCEN.Modify(idIMTelemetry,
                                      dto.Name
                                      ,
                                      dto.Description
                                      );

                // Return modified object
                returnValue = IMTelemetryAssembler.Convert(iMTelemetryRESTCAD.ReadOIDDefault(idIMTelemetry), 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);
            }
        }
예제 #5
0
        public HttpResponseMessage New_([FromBody] IMTelemetryDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;
            IMTelemetryDTOA    returnValue        = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);

                // Create
                returnOID = iMTelemetryCEN.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
                    ,
                    //Atributo OID: p_telemetry
                    // attr.estaRelacionado: true
                    dto.Telemetry_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
예제 #6
0
        public HttpResponseMessage ReadOID(int idIMTelemetry)
        {
            // CAD, CEN, EN, returnValue
            IMTelemetryRESTCAD iMTelemetryRESTCAD = null;
            IMTelemetryCEN     iMTelemetryCEN     = null;
            IMTelemetryEN      iMTelemetryEN      = null;
            IMTelemetryDTOA    returnValue        = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMTelemetryRESTCAD = new IMTelemetryRESTCAD(session);
                iMTelemetryCEN     = new IMTelemetryCEN(iMTelemetryRESTCAD);

                // Data
                iMTelemetryEN = iMTelemetryCEN.ReadOID(idIMTelemetry);

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