Ejemplo n.º 1
0
        public static EventTelemetryDTOA Convert(SpecificTelemetryEN en, NHibernate.ISession session = null)
        {
            EventTelemetryDTOA    dto = null;
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryCP      eventTelemetryCP      = null;

            if (en != null)
            {
                dto = new EventTelemetryDTOA();
                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);
                eventTelemetryCP      = new EventTelemetryCP(session);


                EventTelemetryEN enHijo = eventTelemetryRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

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


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage New_([FromBody] EventTelemetryDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryDTOA    returnValue           = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Create
                returnOID = eventTelemetryCEN.New_(

                    //Atributo OID: p_telemetry
                    // attr.estaRelacionado: true
                    dto.Telemetry_oid                     // association role

                    , dto.Name                            //Atributo Primitivo: p_name
                    , dto.Severity                        //Atributo Primitivo: p_severity
                    );
                SessionCommit();

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

            return(response);
        }
        public HttpResponseMessage Modify(int idEventTelemetry, [FromBody] EventTelemetryDTO dto)
        {
            // CAD, CEN, returnValue
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryDTOA    returnValue           = null;

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

            try
            {
                SessionInitializeTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Modify
                eventTelemetryCEN.Modify(idEventTelemetry,
                                         dto.Name
                                         ,
                                         dto.Severity
                                         );

                // Return modified object
                returnValue = EventTelemetryAssembler.Convert(eventTelemetryRESTCAD.ReadOIDDefault(idEventTelemetry), 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);
            }
        }
        public HttpResponseMessage ReadOID(int idEventTelemetry)
        {
            // CAD, CEN, EN, returnValue
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryEN      eventTelemetryEN      = null;
            EventTelemetryDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Data
                eventTelemetryEN = eventTelemetryCEN.ReadOID(idEventTelemetry);

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