/// <summary>
 /// Create
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Create(ConnectionModel model)
 {
     try {
         using (var e = new EntitiesModel()) {
             var connection = new Connection();
             connection.UserId = model.UserId;
             connection.Server = model.Server;
             connection.Port = model.Port;
             connection.Connected = model.Connected;
             connection.Description = model.Description;
             connection.Monitoring = model.Monitoring;
             connection.ServiceType = model.ServiceType;
             e.Add(connection);
             e.SaveChanges();
             return connection.ConnectionId;
         }
     } catch (Exception ex) {
         throw ex;
     }
 }
 /// <summary>
 /// Update
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(ConnectionModel model)
 {
     try {
         using (var e = new EntitiesModel()) {
             if (e.Connections.Where(c => c.ConnectionId == model.ConnectionId).Count() != 0) {
                 var connection = e.Connections.Where(c => c.ConnectionId == model.ConnectionId).FirstOrDefault();
                 connection.Connected = model.Connected;
                 connection.Description = model.Description;
                 connection.Port = model.Port;
                 connection.Server = model.Server;
                 connection.UserId = model.UserId;
                 connection.Monitoring = model.Monitoring;
                 connection.ServiceType = model.ServiceType;
                 e.SaveChanges();
                 return true;
             } else {
                 return false;
             }
         }
     } catch (Exception ex) {
         throw ex;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Entry Point
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="serverIp"></param>
 /// <param name="port"></param>
 public UserSocket(int userId, string description, string serverIp, int port, int connectionId)
 {
     try {
         Model = new ConnectionModel();
         GlobalObjects.UserSockets.StopMonitoringAll(userId);
         Model.Monitoring = false;
         Model.Server = serverIp;
         Model.Port = port;
         Model.UserId = userId;
         Model.Description = description;
         Model.ConnectionId = connectionId;
         Socket = new AsyncSocket();
         Socket.CouldNotConnect += Socket_CouldNotConnect;
         Socket.SocketConnected += Socket_SocketConnected;
         Socket.SocketDataArrival += Socket_SocketDataArrival;
         Socket.SocketDisconnected += Socket_SocketDisconnected;
         Socket.SocketError += Socket_SocketError;
         ConnectionsHelper.Update(Model);
     } catch (Exception ex) {
         if (ProcessError != null) {
             ProcessError(ex, "UserSocket");
         }
     }
 }