public DeviceTemplateEN ReadOIDDefault(int id ) { DeviceTemplateEN deviceTemplateEN = null; try { SessionInitializeTransaction(); deviceTemplateEN = (DeviceTemplateEN)session.Get(typeof(DeviceTemplateEN), id); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in DeviceTemplateCAD.", ex); } finally { SessionClose(); } return(deviceTemplateEN); }
// Modify default (Update all attributes of the class) public void ModifyDefault(DeviceTemplateEN deviceTemplate) { try { SessionInitializeTransaction(); DeviceTemplateEN deviceTemplateEN = (DeviceTemplateEN)session.Load(typeof(DeviceTemplateEN), deviceTemplate.Id); deviceTemplateEN.Name = deviceTemplate.Name; deviceTemplateEN.Type = deviceTemplate.Type; deviceTemplateEN.IsEdge = deviceTemplate.IsEdge; session.Update(deviceTemplateEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in DeviceTemplateCAD.", ex); } finally { SessionClose(); } }
public void Destroy(int id ) { try { SessionInitializeTransaction(); DeviceTemplateEN deviceTemplateEN = (DeviceTemplateEN)session.Load(typeof(DeviceTemplateEN), id); session.Delete(deviceTemplateEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in DeviceTemplateCAD.", ex); } finally { SessionClose(); } }
public int New_(DeviceTemplateEN deviceTemplate) { try { SessionInitializeTransaction(); session.Save(deviceTemplate); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in DeviceTemplateCAD.", ex); } finally { SessionClose(); } return(deviceTemplate.Id); }
public DeviceTemplateEN ReadOID(int id ) { DeviceTemplateEN deviceTemplateEN = null; deviceTemplateEN = _IDeviceTemplateCAD.ReadOID(id); return(deviceTemplateEN); }
public static DeviceTemplateEN Convert(DeviceTemplateDTO dto) { DeviceTemplateEN newinstance = null; try { if (dto != null) { newinstance = new DeviceTemplateEN(); newinstance.Id = dto.Id; newinstance.Name = dto.Name; if (dto.Property != null) { MoSIoTGenNHibernate.CAD.MosIoT.IPropertyCAD propertyCAD = new MoSIoTGenNHibernate.CAD.MosIoT.PropertyCAD(); newinstance.Property = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.PropertyEN>(); foreach (PropertyDTO entry in dto.Property) { newinstance.Property.Add(PropertyAssemblerDTO.Convert(entry)); } } if (dto.Command != null) { MoSIoTGenNHibernate.CAD.MosIoT.ICommandCAD commandCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CommandCAD(); newinstance.Command = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.CommandEN>(); foreach (CommandDTO entry in dto.Command) { newinstance.Command.Add(CommandAssemblerDTO.Convert(entry)); } } if (dto.Telemetry != null) { MoSIoTGenNHibernate.CAD.MosIoT.ITelemetryCAD telemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TelemetryCAD(); newinstance.Telemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN>(); foreach (TelemetryDTO entry in dto.Telemetry) { newinstance.Telemetry.Add(TelemetryAssemblerDTO.Convert(entry)); } } newinstance.Type = dto.Type; newinstance.IsEdge = dto.IsEdge; } } catch (Exception ex) { throw ex; } return(newinstance); }
public void Modify(int p_DeviceTemplate_OID, string p_name, MoSIoTGenNHibernate.Enumerated.MosIoT.DeviceTypeEnum p_type, bool p_isEdge) { DeviceTemplateEN deviceTemplateEN = null; //Initialized DeviceTemplateEN deviceTemplateEN = new DeviceTemplateEN(); deviceTemplateEN.Id = p_DeviceTemplate_OID; deviceTemplateEN.Name = p_name; deviceTemplateEN.Type = p_type; deviceTemplateEN.IsEdge = p_isEdge; //Call to DeviceTemplateCAD _IDeviceTemplateCAD.Modify(deviceTemplateEN); }
public int New_(string p_name, MoSIoTGenNHibernate.Enumerated.MosIoT.DeviceTypeEnum p_type, bool p_isEdge) { DeviceTemplateEN deviceTemplateEN = null; int oid; //Initialized DeviceTemplateEN deviceTemplateEN = new DeviceTemplateEN(); deviceTemplateEN.Name = p_name; deviceTemplateEN.Type = p_type; deviceTemplateEN.IsEdge = p_isEdge; //Call to DeviceTemplateCAD oid = _IDeviceTemplateCAD.New_(deviceTemplateEN); return(oid); }
public DeviceTemplateEN DeviceTemplate(int id) { DeviceTemplateEN result = null; try { SessionInitializeTransaction(); String sql = @"select self.DeviceTemplate FROM DeviceEN self " + "where self.Id = :p_Id"; IQuery query = session.CreateQuery(sql).SetParameter("p_Id", id); result = query.UniqueResult <DeviceTemplateEN>(); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in DeviceRESTCAD.", ex); } finally { SessionClose(); } return(result); }
public static DeviceTemplateDTOA Convert(DeviceTemplateEN en, NHibernate.ISession session = null) { DeviceTemplateDTOA dto = null; DeviceTemplateRESTCAD deviceTemplateRESTCAD = null; DeviceTemplateCEN deviceTemplateCEN = null; DeviceTemplateCP deviceTemplateCP = null; if (en != null) { dto = new DeviceTemplateDTOA(); deviceTemplateRESTCAD = new DeviceTemplateRESTCAD(session); deviceTemplateCEN = new DeviceTemplateCEN(deviceTemplateRESTCAD); deviceTemplateCP = new DeviceTemplateCP(session); // // Attributes dto.Id = en.Id; dto.Name = en.Name; dto.Type = en.Type; dto.IsEdge = en.IsEdge; // // TravesalLink /* Rol: DeviceTemplate o--> Property */ dto.Properties = null; List <PropertyEN> Properties = deviceTemplateRESTCAD.Properties(en.Id).ToList(); if (Properties != null) { dto.Properties = new List <PropertyDTOA>(); foreach (PropertyEN entry in Properties) { dto.Properties.Add(PropertyAssembler.Convert(entry, session)); } } /* Rol: DeviceTemplate o--> Command */ dto.Commands = null; List <CommandEN> Commands = deviceTemplateRESTCAD.Commands(en.Id).ToList(); if (Commands != null) { dto.Commands = new List <CommandDTOA>(); foreach (CommandEN entry in Commands) { dto.Commands.Add(CommandAssembler.Convert(entry, session)); } } /* Rol: DeviceTemplate o--> Telemetry */ dto.Telemetries = null; List <TelemetryEN> Telemetries = deviceTemplateRESTCAD.Telemetries(en.Id).ToList(); if (Telemetries != null) { dto.Telemetries = new List <TelemetryDTOA>(); foreach (TelemetryEN entry in Telemetries) { dto.Telemetries.Add(TelemetryAssembler.Convert(entry, session)); } } // // Service } return(dto); }
public HttpResponseMessage ReadOID(int idDeviceTemplate) { // CAD, CEN, EN, returnValue DeviceTemplateRESTCAD deviceTemplateRESTCAD = null; DeviceTemplateCEN deviceTemplateCEN = null; DeviceTemplateEN deviceTemplateEN = null; DeviceTemplateDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); deviceTemplateRESTCAD = new DeviceTemplateRESTCAD(session); deviceTemplateCEN = new DeviceTemplateCEN(deviceTemplateRESTCAD); // Data deviceTemplateEN = deviceTemplateCEN.ReadOID(idDeviceTemplate); // Convert return if (deviceTemplateEN != null) { returnValue = DeviceTemplateAssembler.Convert(deviceTemplateEN, 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)); } }