Exemplo n.º 1
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     using (var db = new SOFTWAREEntities())
     {
         var ip = db.REMOTE_INFO.Where(m => m.IPAddress == IpAddress).FirstOrDefault();
         if (ip != null)
         {
             ip.IsOnline = false;
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 2
0
        private void Timer_Tick(object Sender, EventArgs e)
        {
            if (CommonFunc.Utils.PingHost("172.28.10.8"))
            {
                timer.Stop();
                try
                {
                    Common.RegisterInStartup(true, Application.ExecutablePath);
                    IpAddress = CommonFunc.Utils.GetLocalIPAddress();
                    string hostname = Environment.MachineName;
                    createSession();
                    Connect(currentSession);
                    var textConnectionString = getConnectionString(currentSession,
                                                                   "Test", "Group", "", 5);
                    using (var db = new SOFTWAREEntities())
                    {
                        var ip = db.REMOTE_INFO.Where(m => m.ComputerName == hostname).FirstOrDefault();

                        if (ip != null)
                        {
                            ip.IPAddress    = IpAddress;
                            ip.UpdateTime   = DateTime.Now;
                            ip.Connection   = textConnectionString;
                            ip.ComputerName = hostname;
                            ip.IsOnline     = true;
                            db.SaveChanges();
                        }
                        else
                        {
                            ip = new REMOTE_INFO()
                            {
                                IPAddress    = IpAddress,
                                Connection   = textConnectionString,
                                UpdateTime   = DateTime.Now,
                                ComputerName = hostname,
                                IsOnline     = true
                            };
                            db.REMOTE_INFO.Add(ip);
                            db.SaveChanges();
                        }
                        Port = ip.Id;
                        StartConnection();
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 3
0
 private void Timer_Tick(object Sender, EventArgs e)
 {
     lblTick.Text = i.ToString();
     i++;
     using (var db = new SOFTWAREEntities())
     {
         var ip = db.REMOTE_INFO.Where(m => m.IPAddress == txtIpAddress.Text.Trim()).OrderByDescending(m => m.UpdateTime).FirstOrDefault();
         if (ip != null && !string.IsNullOrEmpty(ip.Connection))
         {
             var form = new Form1(ip.Connection);
             form.Show();
             timer.Stop();
             i = 1;
         }
     };
 }