示例#1
0
 public override string ToString()
 {
     return(string.Format("{0}:{1}-p({2},{3})-r({4},{5}), {6}s",
                          DeviceEntity.roomid, DeviceEntity.ip,
                          PollingCount, LastPollingTime.ToString("mmssffff"),
                          ResponseCount, LastResponseTime.ToString("mmssffff"),
                          (DateTime.Now - LastPollingTime).TotalSeconds));
 }
示例#2
0
            /**
             * Thread that checks in regular intervals whether the Date and Time when the
             * last Client call to 'PollClientTasks' was made exceeds a certain timeout
             * limit (different for Clients connected via LAN or Remote).
             *
             * @comment The Thread is started at Class instantiation and can be stopped by
             * calling the StopClientStillAliveCheckThread method.
             *
             * @comment The check interval can be configured with the ServerSetting
             * 'Server.ClientKeepAliveCheckIntervalInSeconds'.
             *
             */
            public void ClientStillAliveCheckThread()
            {
                TimeSpan Duration;
                DateTime LastPollingTime;

                // Check whether this Thread should still execute
                while (UKeepServerAliveCheck)
                {
                    TLogging.LogAtLevel(2, "TClientStillAliveCheck (for ClientName '" + ClientName + "'): ClientStillAliveCheckThread: checking...");

                    // Get the time of the last call to TPollClientTasks.PollClientTasks
                    LastPollingTime = FClientObject.FPollClientTasks.GetLastPollingTime();

                    // Calculate time between the last call to TPollClientTasks.PollClientTasks and now
                    Duration = DateTime.Now.Subtract(LastPollingTime);

                    // Determine whether the timeout has been exceeded
                    if (Duration.TotalSeconds < UClientStillAliveTimeout)
                    {
                        // No it hasn't
                        TLogging.LogAtLevel(
                            2,
                            "TClientStillAliveCheck (for ClientName '" + ClientName +
                            "'): ClientStillAliveCheckThread: timeout hasn't been exceeded (Clients' last PollClientTasks was called " +
                            Duration.TotalSeconds.ToString() + " ago).");

                        try
                        {
                            // Sleep for some time. After that, this procedure is called again automatically.
                            TLogging.LogAtLevel(2,
                                                "TClientStillAliveCheck (for ClientName '" + ClientName + "'): ClientStillAliveCheckThread: going to sleep...");

                            Thread.Sleep(UClientStillAliveCheckInterval * 1000);

                            TLogging.LogAtLevel(12,
                                                "TClientStillAliveCheck (for ClientName '" + ClientName + "'): ClientStillAliveCheckThread: re-awakening...");
                        }
                        catch (ThreadAbortException)
                        {
                            TLogging.LogAtLevel(
                                2,
                                "TClientStillAliveCheck (for ClientName '" + ClientName +
                                "'): ClientStillAliveCheckThread: ThreadAbortException occured!!!");

                            UKeepServerAliveCheck = false;
                        }
                    }
                    else
                    {
                        TLogging.LogAtLevel(
                            1,
                            "TClientStillAliveCheck (for ClientName '" + ClientName +
                            "'): ClientStillAliveCheckThread: timeout HAS been exceeded (last PollClientTasks call: " +
                            LastPollingTime.ToString() + ") -> forcefully disconnecting the Client!");

                        /*
                         * Timeout has been exceeded, this means the Client didn't make a call
                         * to TPollClientTasks.PollClientTasks within the time that is specified
                         * in UClientStillAliveTimeout
                         */

                        /*
                         * KeepServerAliveCheck Thread should no longer run (has an effect only
                         * when this procedure is called from the ClientStillAliveCheckThread
                         * Thread itself)
                         */
                        UKeepServerAliveCheck = false;

                        // Forcefully disconnect the Client!
                        if (UTearDownAppDomain != null)
                        {
                            string CantDisconnectReason;

                            UTearDownAppDomain(FClientObject.ClientID,
                                               String.Format(StrClientFailedToContact, Duration.Hours.ToString() + ':' + Duration.Minutes.ToString() + ':' +
                                                             Duration.Seconds.ToString()), out CantDisconnectReason);
                        }
                        else
                        {
                            if (TLogging.DL >= 10)
                            {
                                TLogging.Log("TClientStillAliveCheck: FTearDownAppDomain was not assigned -> can't tear down Client's AppDomain!");
                            }
                        }
                    }
                }

                // Thread stops here and doesn't get called again automatically.
                TLogging.LogAtLevel(12, "TClientStillAliveCheck (for ClientName '" + ClientName + "'): ClientStillAliveCheckThread: Thread stopped!");
            }
示例#3
0
            /**
             * Thread that checks in regular intervals whether the Date and Time when the
             * last Client call to 'PollClientTasks' was made exceeds a certain timeout
             * limit (different for Clients connected via LAN or Remote).
             *
             * @comment The Thread is started at Class instantiation and can be stopped by
             * calling the StopClientStillAliveCheckThread method.
             *
             * @comment The check interval can be configured with the ServerSetting
             * 'Server.ClientKeepAliveCheckIntervalInSeconds'.
             *
             */
            public void ClientStillAliveCheckThread()
            {
                TimeSpan Duration;
                DateTime LastPollingTime;

                // Check whether this Thread should still execute
                while (UKeepServerAliveCheck)
                {
                    if (TLogging.DL >= 10)
                    {
                        Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: checking...", DateTime.Now);
                    }

                    // Get the time of the last call to TPollClientTasks.PollClientTasks
                    LastPollingTime = TPollClientTasks.GetLastPollingTime();

                    // Calculate time between the last call to TPollClientTasks.PollClientTasks and now
                    Duration = DateTime.Now.Subtract(LastPollingTime);

                    // Determine whether the timeout has been exceeded
                    if (Duration.TotalSeconds < UClientStillAliveTimeout)
                    {
                        // No it hasn't
                        if (TLogging.DL >= 10)
                        {
                            Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: timeout hasn't been exceeded.", DateTime.Now);
                        }

                        try
                        {
                            // Sleep for some time. After that, this procedure is called again automatically.
                            if (TLogging.DL >= 10)
                            {
                                Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: going to sleep...", DateTime.Now);
                            }

                            Thread.Sleep(UClientStillAliveCheckInterval * 1000);

                            if (TLogging.DL >= 10)
                            {
                                Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: re-awakening...", DateTime.Now);
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            if (TLogging.DL >= 10)
                            {
                                Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: ThreadAbortException occured!!!",
                                                  DateTime.Now);
                            }

                            UKeepServerAliveCheck = false;
                        }
                    }
                    else
                    {
                        if (TLogging.DL >= 5)
                        {
                            Console.WriteLine(
                                "{0} TClientStillAliveCheck: ClientStillAliveCheckThread: timeout HAS been exceeded (last PollClientTasks call: " +
                                LastPollingTime.ToString() + ") -> SignalTearDownAppDomain!",
                                DateTime.Now);
                        }

                        /*
                         * Timeout has been exceeded, this means the Client didn't make a call
                         * to TPollClientTasks.PollClientTasks within the time that is specified
                         * in UClientStillAliveTimeout
                         */

                        /*
                         * KeepServerAliveCheck Thread should no longer run (has an effect only
                         * when this procedure is called from the ClientStillAliveCheckThread
                         * Thread itself)
                         */
                        UKeepServerAliveCheck = false;

                        if (UTearDownAppDomain != null)
                        {
                            UTearDownAppDomain(UTearDownAppDomainToken,
                                               String.Format(StrClientFailedToContact, Duration.Hours.ToString() + ':' + Duration.Minutes.ToString() + ':' +
                                                             Duration.Seconds.ToString()));
                        }
                        else
                        {
                            if (TLogging.DL >= 10)
                            {
                                Console.WriteLine(
                                    "{0} TClientStillAliveCheck: FTearDownAppDomain was not assigned -> can't tear down Client's AppDomain!",
                                    DateTime.Now);
                            }
                        }
                    }
                }

                // Thread stops here and doesn't get called again automatically.
                if (TLogging.DL >= 10)
                {
                    Console.WriteLine("{0} TClientStillAliveCheck: ClientStillAliveCheckThread: Thread stopped!", DateTime.Now);
                }
            }