예제 #1
0
        static void Main(string[] args)
        {
            _ResetEvent = new ManualResetEvent(false);

            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine(" THE DUMMY PROGRAMMER - TEST PUSH NOTIFICATIONS CLIENT ");
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine();
            Console.WriteLine($"Insert your client ID (How do you identify yourself, 0-{int.MaxValue})");

            bool   IsValidClientID = false;
            string ClientID        = string.Empty;

            while (!IsValidClientID)
            {
                ClientID        = Console.ReadLine();
                IsValidClientID = System.Text.RegularExpressions.Regex.Match(ClientID, @"\d{1,4}").Success;
                if (!IsValidClientID)
                {
                    Console.WriteLine("Invalid client number");
                }
            }

            AuthenticationToken <int> AuthToken = new AuthenticationToken <int>(int.Parse(ClientID), DateTime.Now, DateTime.Now.AddHours(24), null);

            Console.WriteLine("Starting push notification client...");
            _PushClient = new PushClient <int>();
            _PushClient.RegisterClientStarted += _PushClient_RegisterClientStarted;
            _PushClient.RegisterClientEnded   += _PushClient_RegisterClientEnded;
            _PushClient.PushMessageReceived   += _PushClient_PushMessageReceived;
            _PushClient.ConnectionClosed      += _PushClient_ConnectionClosed;
            _PushClient.ConnectAsync(AuthToken);

            _ResetEvent.WaitOne();

            if (!_RegistrationOk)
            {
                Console.WriteLine("Press a key to exit...");
                Console.ReadKey();
                return;
            }

            while (true)
            {
                Console.WriteLine("Waiting for some push message... type EXIT to close this program");
                string Command = Console.ReadLine();

                if (Command == "EXIT")
                {
                    break;
                }
            }
        }
예제 #2
0
        public static void Connect(ClientInfo clientInfo, string application)
        {
            PushClient client = new PushClient();

            try
            {
                client.ConnectCompleted += new EventHandler <System.ComponentModel.AsyncCompletedEventArgs>(client_ConnectCompleted);
                client.ConnectAsync(clientInfo, application, 1, false);

                client.CloseAsync();
            }
            catch (Exception e)
            {
                client.Abort();
            }
            finally
            {
                client.CloseAsync();
            }
        }