public int New_(int p_deviceTemplate, string p_name, bool p_isSynchronous, MoSIoTGenNHibernate.Enumerated.MosIoT.OperationTypeEnum p_type, string p_description) { CommandEN commandEN = null; int oid; //Initialized CommandEN commandEN = new CommandEN(); if (p_deviceTemplate != -1) { // El argumento p_deviceTemplate -> Property deviceTemplate es oid = false // Lista de oids id commandEN.DeviceTemplate = new MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN(); commandEN.DeviceTemplate.Id = p_deviceTemplate; } commandEN.Name = p_name; commandEN.IsSynchronous = p_isSynchronous; commandEN.Type = p_type; commandEN.Description = p_description; //Call to CommandCAD oid = _ICommandCAD.New_(commandEN); return(oid); }
public CommandEN ReadOIDDefault(int id ) { CommandEN commandEN = null; try { SessionInitializeTransaction(); commandEN = (CommandEN)session.Get(typeof(CommandEN), id); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in CommandCAD.", ex); } finally { SessionClose(); } return(commandEN); }
public void Destroy(int id ) { try { SessionInitializeTransaction(); CommandEN commandEN = (CommandEN)session.Load(typeof(CommandEN), id); session.Delete(commandEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in CommandCAD.", ex); } finally { SessionClose(); } }
public int New_(CommandEN command) { try { SessionInitializeTransaction(); if (command.DeviceTemplate != null) { // Argumento OID y no colección. command.DeviceTemplate = (MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.DeviceTemplateEN), command.DeviceTemplate.Id); command.DeviceTemplate.Command .Add(command); } session.Save(command); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in CommandCAD.", ex); } finally { SessionClose(); } return(command.Id); }
public CommandEN ReadOID(int id ) { CommandEN commandEN = null; commandEN = _ICommandCAD.ReadOID(id); return(commandEN); }
public void Modify(int p_Command_OID, string p_name, bool p_isSynchronous, MoSIoTGenNHibernate.Enumerated.MosIoT.OperationTypeEnum p_type, string p_description) { CommandEN commandEN = null; //Initialized CommandEN commandEN = new CommandEN(); commandEN.Id = p_Command_OID; commandEN.Name = p_name; commandEN.IsSynchronous = p_isSynchronous; commandEN.Type = p_type; commandEN.Description = p_description; //Call to CommandCAD _ICommandCAD.Modify(commandEN); }
public static CommandDTOA Convert(CommandEN en, NHibernate.ISession session = null) { CommandDTOA dto = null; CommandRESTCAD commandRESTCAD = null; CommandCEN commandCEN = null; CommandCP commandCP = null; if (en != null) { dto = new CommandDTOA(); commandRESTCAD = new CommandRESTCAD(session); commandCEN = new CommandCEN(commandRESTCAD); commandCP = new CommandCP(session); // // Attributes dto.Id = en.Id; dto.Name = en.Name; dto.IsSynchronous = en.IsSynchronous; dto.Type = en.Type; dto.Description = en.Description; // // TravesalLink // // Service } return(dto); }
public static CommandEN Convert(CommandDTO dto) { CommandEN newinstance = null; try { if (dto != null) { newinstance = new CommandEN(); if (dto.DeviceTemplate_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IDeviceTemplateCAD deviceTemplateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DeviceTemplateCAD(); newinstance.DeviceTemplate = deviceTemplateCAD.ReadOIDDefault(dto.DeviceTemplate_oid); } newinstance.Id = dto.Id; newinstance.Name = dto.Name; newinstance.IsSynchronous = dto.IsSynchronous; if (dto.Telemetries_oid != null) { MoSIoTGenNHibernate.CAD.MosIoT.IEventTelemetryCAD eventTelemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EventTelemetryCAD(); newinstance.Telemetries = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.EventTelemetryEN>(); foreach (int entry in dto.Telemetries_oid) { newinstance.Telemetries.Add(eventTelemetryCAD.ReadOIDDefault(entry)); } } newinstance.Type = dto.Type; newinstance.Description = dto.Description; } } catch (Exception ex) { throw ex; } return(newinstance); }
// Modify default (Update all attributes of the class) public void ModifyDefault(CommandEN command) { try { SessionInitializeTransaction(); CommandEN commandEN = (CommandEN)session.Load(typeof(CommandEN), command.Id); commandEN.Name = command.Name; commandEN.IsSynchronous = command.IsSynchronous; commandEN.Type = command.Type; commandEN.Description = command.Description; session.Update(commandEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in CommandCAD.", ex); } finally { SessionClose(); } }
public CommandEN ValueCommand(int id) { CommandEN result = null; try { SessionInitializeTransaction(); String sql = @"select self.Command FROM IMCommandEN self " + "where self.Id = :p_Id"; IQuery query = session.CreateQuery(sql).SetParameter("p_Id", id); result = query.UniqueResult <CommandEN>(); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is MoSIoTGenNHibernate.Exceptions.ModelException) { throw ex; } throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in IMCommandRESTCAD.", ex); } finally { SessionClose(); } return(result); }
public HttpResponseMessage ReadOID(int idCommand) { // CAD, CEN, EN, returnValue CommandRESTCAD commandRESTCAD = null; CommandCEN commandCEN = null; CommandEN commandEN = null; CommandDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); commandRESTCAD = new CommandRESTCAD(session); commandCEN = new CommandCEN(commandRESTCAD); // Data commandEN = commandCEN.ReadOID(idCommand); // Convert return if (commandEN != null) { returnValue = CommandAssembler.Convert(commandEN, 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)); } }