Example #1
0
        static void Main()
        {
            ServerOpt so = new ServerOpt();

            Client = new InformerClient();

            Client.OnMessage += Console.WriteLine;

            Client.OnAuthed += () =>
            {
                Console.WriteLine("Authed...");
                new Thread(SendOnlineUpdates).Start();
            };

            ScsClient = ScsServiceClientBuilder.CreateClient <IInformerService>
                            (new ScsTcpEndPoint(so.serverip, so.informerPort), Client);

            ScsClient.Timeout = ScsClient.ConnectTimeout = 2500;

            ScsClient.Connected += (sender, args) =>
            {
                Console.WriteLine("Connected...");
                ScsClient.ServiceProxy.Auth(so.sercurityKey);
            };

            while (true)
            {
                try
                {
                    if (ScsClient.CommunicationState == CommunicationStates.Disconnected)
                    {
                        ScsClient.Connect();
                    }

                    while (ScsClient.CommunicationState == CommunicationStates.Connected)
                    {
                        Thread.Sleep(1000);
                    }
                }
                catch
                {
                }

                SendUpdate(); //Offline
            }
        }
Example #2
0
        private static void SendUpdate(string status = "offline")
        {
            ServerOpt so = new ServerOpt();

            if (_lastStatus == status)
            {
                Console.WriteLine("### Last server status equals current!");
                if (status == "0" || status == "1")
                {
                    var AjaxQueryFormat = string.Format("{0}?server={1}&status=updateonline&userson={2}",
                                                        so.webApiUrl, so.server,
                                                        ScsClient.ServiceProxy.GetOnlineList().Count.ToString(CultureInfo.InvariantCulture)
                                                        );
                    var request = WebRequest.Create(AjaxQueryFormat);
                    request.Timeout = 5000;
                    using (request.GetResponse())
                    {
                        Console.WriteLine("Online Users: " + ScsClient.ServiceProxy.GetOnlineList().Count.ToString(CultureInfo.InvariantCulture));
                    }
                }
                return;
            }

            Console.WriteLine("### Try update status to {0}", status);

            try
            {
                var AjaxQueryFormat = so.webApiUrl + "?server={0}&status={1}";
                var request         = WebRequest.Create(string.Format(AjaxQueryFormat, so.server, status));
                request.Timeout = 5000;
                using (request.GetResponse())
                {
                    //Nothing
                }

                Console.WriteLine("### Status succesfuly updated.");
                _lastStatus = status;
            }
            catch
            {
                Console.WriteLine("### Status update failed.");
            }
        }
Example #3
0
        static void Main()
        {
            ServerOpt so = new ServerOpt();

            Client = new InformerClient();

            Client.OnMessage += Console.WriteLine;

            Client.OnAuthed += () =>
                {
                    Console.WriteLine("Authed...");
                    new Thread(SendOnlineUpdates).Start();
                };

            ScsClient = ScsServiceClientBuilder.CreateClient<IInformerService>
                (new ScsTcpEndPoint(so.serverip, so.informerPort), Client);

            ScsClient.Timeout = ScsClient.ConnectTimeout = 2500;

            ScsClient.Connected += (sender, args) =>
                {
                    Console.WriteLine("Connected...");
                    ScsClient.ServiceProxy.Auth(so.sercurityKey);
                };

            while (true)
            {
                try
                {
                    if (ScsClient.CommunicationState == CommunicationStates.Disconnected)
                        ScsClient.Connect();

                    while (ScsClient.CommunicationState == CommunicationStates.Connected)
                        Thread.Sleep(1000);
                }
                catch
                {
                }

                SendUpdate(); //Offline
            }
        }
Example #4
0
        private static void SendUpdate(string status = "offline")
        {
            ServerOpt so = new ServerOpt();

            if (_lastStatus == status)
            {
                Console.WriteLine("### Last server status equals current!");
                if (status == "0" || status == "1")
                {
                    var AjaxQueryFormat = string.Format("{0}?server={1}&status=updateonline&userson={2}",
                            so.webApiUrl, so.server,
                            ScsClient.ServiceProxy.GetOnlineList().Count.ToString(CultureInfo.InvariantCulture)
                        );
                    var request = WebRequest.Create(AjaxQueryFormat);
                    request.Timeout = 5000;
                    using (request.GetResponse())
                    {
                        Console.WriteLine("Online Users: " + ScsClient.ServiceProxy.GetOnlineList().Count.ToString(CultureInfo.InvariantCulture));
                    }
                }
                return;
            }

            Console.WriteLine("### Try update status to {0}", status);

            try
            {
                var AjaxQueryFormat = so.webApiUrl+"?server={0}&status={1}";
                var request = WebRequest.Create(string.Format(AjaxQueryFormat, so.server, status));
                request.Timeout = 5000;
                using (request.GetResponse())
                {
                    //Nothing
                }

                Console.WriteLine("### Status succesfuly updated.");
                _lastStatus = status;
            }
            catch
            {
                Console.WriteLine("### Status update failed.");
            }
        }