Esempio n. 1
0
        private static void ExecuteMonitor(object state)
        {
            List <Session> ToDispose = new List <Session>();
            List <Session> ToStop    = new List <Session>();

            lock (mSessions)
            {
                lock (mSessionsToStop)
                {
                    foreach (uint SessionId in mSessionsToStop)
                    {
                        if (mSessions.ContainsKey(SessionId))
                        {
                            ToStop.Add(mSessions[SessionId]);
                        }
                    }

                    mSessionsToStop.Clear();
                }

                foreach (Session Session in mSessions.Values)
                {
                    if (ToStop.Contains(Session))
                    {
                        continue;
                    }

                    if (Session.Stopped)
                    {
                        if (Session.TimeStopped > 15)
                        {
                            ToDispose.Add(Session);
                        }

                        continue;
                    }

                    if (Session.LastReceived == DateTime.MinValue)
                    {
                        Session.TryAcknowledge();
                    }

                    if ((DateTime.Now - Session.LastReceived).TotalMinutes > 10)
                    {
                        Session.MAuthProcessed     = false;
                        Session.AuthMessageCounter = 0;
                        Session.TryAcknowledge();
                    }
                }

                // Adicionado pela Laila
                DateTime timeinit = DateTime.Now;
                foreach (Session Session in mSessions.Values)
                {
                    foreach (Radio Radio in Session.Channel.Radios)
                    {
                        if (((DateTime.Now - Radio.TimeStamp).TotalMinutes > 10) && (Radio.CommStatus == 1))
                        {
                            Core.GetRadioManager().SetCommStatus(Radio.SerialNumber, 0);
                            Radio.CommStatus = 0;
                        }
                    }
                }
                if ((DateTime.Now - timeinit).TotalMilliseconds > 10)
                {
                    Console.WriteLine(String.Concat("Tempo Gasto: ", Convert.ToString((DateTime.Now - timeinit).TotalMilliseconds)));
                }
            }

            foreach (Session SessionDispose in ToDispose)
            {
                SessionDispose.Dispose();

                lock (mSessions)
                {
                    if (mSessions.ContainsKey(SessionDispose.Id))
                    {
                        mSessions.Remove(SessionDispose.Id);
                    }
                }
            }
        }
Esempio n. 2
0
        private static void ExecuteMonitor(object state)
        {
            List <Session> ToDispose = new List <Session>();
            List <Session> ToStop    = new List <Session>();

            lock (mSessions)
            {
                lock (mSessionsToStop)
                {
                    foreach (uint SessionId in mSessionsToStop)
                    {
                        if (mSessions.ContainsKey(SessionId))
                        {
                            ToStop.Add(mSessions[SessionId]);
                        }
                    }

                    mSessionsToStop.Clear();
                }

                foreach (Session Session in mSessions.Values)
                {
                    if (ToStop.Contains(Session))
                    {
                        continue;
                    }

                    if (Session.Stopped)
                    {
                        if (Session.TimeStopped > 15)
                        {
                            ToDispose.Add(Session);
                        }

                        continue;
                    }
                }
            }

            if (ToStop.Count > 0)
            {
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    foreach (Session SessionStop in ToStop)
                    {
                        SessionStop.Stop(MySqlClient);
                    }
                }
            }

            foreach (Session SessionDispose in ToDispose)
            {
                SessionDispose.Dispose();

                lock (mSessions)
                {
                    if (mSessions.ContainsKey(SessionDispose.Id))
                    {
                        mSessions.Remove(SessionDispose.Id);
                    }
                }
            }
        }
Esempio n. 3
0
        private static void ExecuteMonitor(object state)
        {
            List <Session> ToDispose = new List <Session>();
            List <Session> ToStop    = new List <Session>();

            lock (mSessions)
            {
                lock (mSessionsToStop)
                {
                    foreach (uint SessionId in mSessionsToStop)
                    {
                        if (mSessions.ContainsKey(SessionId))
                        {
                            ToStop.Add(mSessions[SessionId]);
                        }
                    }

                    mSessionsToStop.Clear();
                }

                foreach (Session Session in mSessions.Values)
                {
                    if (ToStop.Contains(Session))
                    {
                        continue;
                    }

                    if (Session.Stopped)
                    {
                        if (Session.TimeStopped > 15)
                        {
                            ToDispose.Add(Session);
                        }

                        continue;
                    }

                    if (Session.LastReceived == DateTime.MinValue)
                    {
                        Session.TryAcknowledge();
                    }

                    if ((Session.LastReceived - DateTime.Now).TotalMinutes > 10)
                    {
                        Session.MAuthProcessed     = false;
                        Session.AuthMessageCounter = 0;
                        Session.TryAcknowledge();
                    }
                }
            }

            foreach (Session SessionDispose in ToDispose)
            {
                SessionDispose.Dispose();

                lock (mSessions)
                {
                    if (mSessions.ContainsKey(SessionDispose.Id))
                    {
                        mSessions.Remove(SessionDispose.Id);
                    }
                }
            }
        }
Esempio n. 4
0
        private static void ExecuteMonitor()
        {
            try
            {
                while (Program.Alive)
                {
                    List <Session> ToDispose = new List <Session>();
                    List <Session> ToStop    = new List <Session>();

                    lock (mSessions)
                    {
                        lock (mSessionsToStop)
                        {
                            foreach (uint SessionId in mSessionsToStop)
                            {
                                if (mSessions.ContainsKey(SessionId))
                                {
                                    ToStop.Add(mSessions[SessionId]);
                                }
                            }

                            mSessionsToStop.Clear();
                        }

                        foreach (Session Session in mSessions.Values)
                        {
                            if (ToStop.Contains(Session))
                            {
                                continue;
                            }

                            if (Session.Stopped)
                            {
                                if (Session.TimeStopped > 15)
                                {
                                    ToDispose.Add(Session);
                                }

                                continue;
                            }
                        }
                    }

                    if (ToStop.Count > 0)
                    {
                        using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                        {
                            foreach (Session SessionStop in ToStop)
                            {
                                SessionStop.Stop(MySqlClient);
                            }
                        }
                    }

                    foreach (Session SessionDispose in ToDispose)
                    {
                        SessionDispose.Dispose();

                        lock (mSessions)
                        {
                            if (mSessions.ContainsKey(SessionDispose.Id))
                            {
                                mSessions.Remove(SessionDispose.Id);
                            }
                        }
                    }

                    Thread.Sleep(100);
                }
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
        }