Ejemplo n.º 1
0
        static void TestUnencryptedDetailedHistory()
        {
            // Context setup for Detailed History
            pubnub.CIPHER_KEY = "";
            int  total_msg = 10;
            long starttime = Timestamp();
            Dictionary <long, string> inputs = new Dictionary <long, string>();

            for (int i = 0; i < total_msg / 2; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg);
                long t = Timestamp();
                inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp();

            for (int i = total_msg / 2; i < total_msg; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg);
                long t = Timestamp();
                inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Timestamp();

            deliveryStatus          = false;
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "DetailedHistory")
                {
                    Console.WriteLine("\n*********** DetailedHistory Messages *********** ");
                    foreach (object msg_org in (object[])((Pubnub)sender).DetailedHistory)
                    {
                        Console.WriteLine(msg_org.ToString());
                    }
                    deliveryStatus = true;
                }
            };
            pubnub.detailedHistory(channel, total_msg);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
        }
Ejemplo n.º 2
0
        public static void DetailedHistory_Decrypted_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "enigma",
                    false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "enigma";
            string msg = "Test Message";

            deliveryStatus = false;
            pubnub.publish(channel, msg, DisplayReturnMessage);
            while (!deliveryStatus) ;

            deliveryStatus = false;
            pubnub.detailedHistory(channel, 1, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;
                Console.WriteLine("fields[0]: " + fields[0]);
                Console.WriteLine("fields[1]: " + fields[1]);
                //Assert.AreEqual(fields[0], msg);
            }
        }
Ejemplo n.º 3
0
        public void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isSecretEncryptPublished = false;
            Pubnub pubnub  = new Pubnub("demo", "demo", "key", "enigma", false);
            string channel = "my/channel";
            string message = messageForSecretEncryptPublish;

            EnqueueCallback(() => pubnub.publish <string>(channel, message, ReturnSuccessSecretEncryptPublishCodeCallback));
            EnqueueConditional(() => isSecretEncryptPubCheck);

            EnqueueCallback(() =>
            {
                if (!isSecretEncryptPublished)
                {
                    Assert.IsTrue(isSecretEncryptPublished, "Secret Encrypt Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.detailedHistory <string>(channel, -1, secretEncryptPublishTimetoken, -1, false, CaptureSecretEncryptDetailedHistoryCallback));
                    EnqueueConditional(() => isSecretEncryptDHCheck);
                    EnqueueCallback(() => Assert.IsTrue(isSecretEncryptDH, "Unable to decrypt the successful Secret key Publish"));
                }
            });

            EnqueueTestComplete();
        }
        internal static void DetailedHistoryCountDemo()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false);

            string channel = "my_channel";

            //Console.WriteLine("Detailed History Count Demo");
            //pubnub.detailedHistory(channel, 100, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History Count and reverse Demo");
            //pubnub.detailedHistory(channel, -1, -1, 100, true, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History with start and end");
            //pubnub.detailedHistory(channel, 13499635513028988, 13499836911845528, 200, true, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History with start");
            //pubnub.detailedHistory(channel, 13499635513028988, -1, 100, true, DisplayDetailedHistory);

            Console.WriteLine("Detailed History with end");
            pubnub.detailedHistory(channel, -1, 13499836911845528, 100, true, DisplayDetailedHistory);
        }
Ejemplo n.º 5
0
        public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isUnencryptPublished = false;
            Pubnub pubnub  = new Pubnub("demo", "demo", "", "", false);
            string channel = "my/channel";
            string message = messageForUnencryptPublish;

            EnqueueCallback(() => pubnub.publish <string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback));
            EnqueueConditional(() => isCheck);

            EnqueueCallback(() =>
            {
                if (!isUnencryptPublished)
                {
                    Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.detailedHistory <string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback));
                    EnqueueConditional(() => isUnencryptCheck);
                    EnqueueCallback(() => Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish"));
                }
            });

            EnqueueTestComplete();
        }
Ejemplo n.º 6
0
        public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
        {
            isEncryptObjectPublished = false;
            Pubnub pubnub  = new Pubnub("demo", "demo", "", "enigma", false);
            string channel = "my/channel";
            object message = new SecretCustomClass();

            messageObjectForEncryptPublish = JsonConvert.SerializeObject(message);

            EnqueueCallback(() => pubnub.publish <string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback));
            EnqueueConditional(() => isEncryptObjectPubCheck);

            EnqueueCallback(() =>
            {
                if (!isEncryptObjectPublished)
                {
                    Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.detailedHistory <string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback));
                    EnqueueConditional(() => isEncryptObjectDHCheck);
                    EnqueueCallback(() => Assert.IsTrue(isEncryptObjectDH, "Unable to match the successful encrypt object Publish"));
                }
            });

            EnqueueTestComplete();
        }
        /*public static void Main()
        {
            DetailedHistoryCountDemo();
            Console.ReadLine();
        }*/
        internal static void DetailedHistoryCountDemo()
        {
            Pubnub pubnub = new Pubnub(
                        "demo",
                        "demo",
                        "",
                        "",
                        false);

            string channel = "my_channel";

            //Console.WriteLine("Detailed History Count Demo");
            //pubnub.detailedHistory(channel, 100, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History Count and reverse Demo");
            //pubnub.detailedHistory(channel, -1, -1, 100, true, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History with start and end");
            //pubnub.detailedHistory(channel, 13499635513028988, 13499836911845528, 200, true, DisplayDetailedHistory);

            //Console.WriteLine("Detailed History with start");
            //pubnub.detailedHistory(channel, 13499635513028988, -1, 100, true, DisplayDetailedHistory);

            Console.WriteLine("Detailed History with end");
            pubnub.detailedHistory(channel, -1, 13499836911845528, 100, true, DisplayDetailedHistory);
        }
        public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isUnencryptPublished = false;
            Pubnub pubnub = new Pubnub("demo","demo","","",false);
            string channel = "my/channel";
            string message = messageForUnencryptPublish;

            EnqueueCallback(() => pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback));
            EnqueueConditional(() => isCheck);

            EnqueueCallback(() => 
            {
                if (!isUnencryptPublished)
                {
                    Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.detailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback));
                    EnqueueConditional(() => isUnencryptCheck);
                    EnqueueCallback(() => Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish"));
                }
            });

            EnqueueTestComplete();
        }
    public void ItShouldReturnDetailedHistory()
    {
     Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
     );
     string channel = "hello_world";

     Common cm = new Common();
     cm.deliveryStatus = false;
     cm.objResponse = null;

     //publish a test message. 
     pubnub.publish(channel, "Test message", cm.DisplayReturnMessage);
             
     while (!cm.deliveryStatus)
       ; 

     cm.deliveryStatus = false;
     cm.objResponse = null;
     pubnub.detailedHistory(channel, 1, cm.DisplayReturnMessage);
     while (!cm.deliveryStatus)
       ;

     string strResponse = "";
     if (cm.objResponse.Equals(null))
       {
        Assert.Fail("Null response");
       } else
        {
          IList<object> fields = cm.objResponse as IList<object>;
          foreach (object item in fields)
            {
             strResponse = item.ToString();
             Console.WriteLine(strResponse);

             Assert.IsNotNull(strResponse);
            }             
            if (fields [0] != null)
             {
               var myObjectArray = (from item in fields select item as object).ToArray();
               IList<object> enumerable = myObjectArray [0] as IList<object>;
               if ((enumerable != null) && (enumerable.Count > 0))
                {
                  foreach (object element in enumerable)
                    {
                     Console.WriteLine("Resp:" + element.ToString());
                    }
                }
                else
                {
                    Assert.Fail("No response");
                }
             }
        }
       }
        public void DetailHistoryCount10ReturnsRecords()
        {
            msg10Received = false;
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
                    string channel = "my/channel";

                    pubnub.detailedHistory<string>(channel, 10, DetailedHistoryCount10Callback);
                    mreMsgCount10.WaitOne(310 * 1000);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            Assert.IsTrue(msg10Received, "Detailed History Failed");
                            TestComplete();
                        });
                });
        }
Ejemplo n.º 11
0
        public static void DetailedHistory_Example()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "";
            string msg = "Test Message";

            deliveryStatus = false;
            pubnub.publish(channel, msg, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }

            deliveryStatus = false;
            pubnub.detailedHistory(channel, 10, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;

                foreach (object item in fields)
                {
                    string strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0}", strResponse));
                    Console.WriteLine(strResponse);
                }
            }
        }
Ejemplo n.º 12
0
        public static void DetailedHistory_Decrypted_Example()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "enigma",
                false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "enigma";
            string msg = "Test Message";

            deliveryStatus = false;
            pubnub.publish(channel, msg, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }

            deliveryStatus = false;
            pubnub.detailedHistory(channel, 1, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;
                Console.WriteLine("fields[0]: " + fields[0]);
                Console.WriteLine("fields[1]: " + fields[1]);
                //Assert.AreEqual(fields[0], msg);
            }
        }
Ejemplo n.º 13
0
        public static void TestEncryptedDetailedHistory()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "enigma",
                    false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "enigma";

            int total_msg = 10;
            long starttime = Timestamp(pubnub);
            Dictionary<long, string> inputs = new Dictionary<long, string>();
            for (int i = 0; i < total_msg / 2; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);
            for (int i = total_msg / 2; i < total_msg; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Timestamp(pubnub);
            while (!deliveryStatus) ;

            pubnub.detailedHistory(channel, total_msg, DisplayReturnMessage);
            deliveryStatus = false;
            while (!deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
            string strResponse = "";
            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;
                int j = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if(j<total_msg)
                        Console.WriteLine(j.ToString(), strResponse);
                    j++;
                }
            }
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
        }
Ejemplo n.º 14
0
        static public void Main()
        {
            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}", channel));
            Console.WriteLine();

            Console.WriteLine("ENTER 1 FOR Subscribe");
            Console.WriteLine("ENTER 2 FOR Publish");
            Console.WriteLine("ENTER 3 FOR Presence");
            Console.WriteLine("ENTER 4 FOR Detailed History");
            Console.WriteLine("ENTER 5 FOR Here_Now");
            Console.WriteLine("ENTER 6 FOR Unsubscribe");
            Console.WriteLine("ENTER 7 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                case "0":
                    exitFlag = true;
                    break;

                case "1":
                    Console.WriteLine("Running subscribe()");
                    pubnub.subscribe <string>(channel, DisplayReturnMessage);
                    //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                    //pubnub.subscribe(channel, DisplayReturnMessage);
                    break;

                case "2":
                    Console.WriteLine("Running publish()");
                    Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                    string publishMsg = Console.ReadLine();
                    pubnub.publish <string>(channel, publishMsg, DisplayReturnMessage);
                    break;

                case "3":
                    Console.WriteLine("Running presence()");
                    pubnub.presence <string>(channel, DisplayReturnMessage);
                    //pubnub.presence<object>(channel, DisplayReturnMessage);
                    break;

                case "4":
                    Console.WriteLine("Running detailed history()");
                    pubnub.detailedHistory <string>(channel, 100, DisplayReturnMessage);
                    //pubnub.detailedHistory<object>(channel, 100, DisplayReturnMessage);
                    break;

                case "5":
                    Console.WriteLine("Running Here_Now()");
                    pubnub.here_now <string>(channel, DisplayReturnMessage);
                    //pubnub.here_now<object>(channel, DisplayReturnMessage);
                    break;

                case "6":
                    Console.WriteLine("Running unsubscribe()");
                    pubnub.unsubscribe <string>(channel, DisplayReturnMessage);
                    //pubnub.unsubscribe<object>(channel, DisplayReturnMessage);
                    break;

                case "7":
                    Console.WriteLine("Running presence-unsubscribe()");
                    pubnub.presence_unsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "8":
                    Console.WriteLine("Running time()");
                    pubnub.time <string>(DisplayReturnMessage);
                    break;

                default:
                    Console.WriteLine("INVALID CHOICE.");
                    break;
                }
            }

            Console.WriteLine("\nPress any key to confirm exit.\n\n");
            Console.ReadLine();
        }
Ejemplo n.º 15
0
 private void History_Click(object sender, RoutedEventArgs e)
 {
     Console.WriteLine("Running detailed history()");
     pubnub.detailedHistory <string>(channel, 100, DisplayReturnMessage);
 }
Ejemplo n.º 16
0
        public static void TestEncryptedDetailedHistoryParams()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "enigma",
                false);
            // Context setup for Detailed Histor
            //pubnub.CIPHER_KEY = "enigma";
            int  total_msg = 10;
            long starttime = Timestamp(pubnub);

            for (int i = 0; i < total_msg / 2; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);

            for (int i = total_msg / 2; i < total_msg; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }


            long endtime = Timestamp(pubnub);

            deliveryStatus          = false;
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "DetailedHistory")
                {
                    Console.WriteLine("\n*********** DetailedHistory Messages *********** ");

                    /*foreach (object msg_org in (List<object>)((Pubnub)sender).DetailedHistory)
                     * {
                     *  Console.WriteLine(msg_org.ToString());
                     * }*/
                    deliveryStatus = true;
                }
            };
            Console.WriteLine("DetailedHistory with start & end");
            pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("DetailedHistory with start & reverse = true");
            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("DetailedHistory with start & reverse = false");
            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
        }
       public static void TestEncryptedDetailedHistory()
       {
          Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "enigma",
                false);
          string channel = "testchannel";
          //pubnub.CIPHER_KEY = "enigma";

          int total_msg = 10;
          Common cm = new Common();
          long starttime = cm.Timestamp(pubnub);
          cm.deliveryStatus = false;
          cm.objResponse = null;

          Dictionary<long, string> inputs = new Dictionary<long, string>();
          for (int i = 0; i < total_msg / 2; i++)
          {
             string msg = i.ToString();
             pubnub.publish(channel, msg, cm.DisplayReturnMessage);
             while (!cm.deliveryStatus) ;
             //long t = Timestamp();
             //inputs.Add(t, msg);
             Console.WriteLine("Message # " + i.ToString() + " published");
          }

          long midtime = cm.Timestamp(pubnub);
          for (int i = total_msg / 2; i < total_msg; i++)
          {
             string msg = i.ToString();
             pubnub.publish(channel, msg, cm.DisplayReturnMessage);
             while (!cm.deliveryStatus) ;
             //long t = Timestamp();
             //inputs.Add(t, msg);
             Console.WriteLine("Message # " + i.ToString() + " published");
          }

          long endtime = cm.Timestamp(pubnub);
          while (!cm.deliveryStatus) ;

          
          cm.objResponse = null;
          pubnub.detailedHistory(channel, total_msg, cm.DisplayReturnMessage);
          cm.deliveryStatus = false;
          while (!cm.deliveryStatus) ;
          Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
          string strResponse = "";
          if (cm.objResponse.Equals(null))
          {
            Assert.Fail("Null response");
          } 
          else
          {
             IList<object> fields = cm.objResponse as IList<object>;
             int j = 0;
             if (fields [0] != null)
             {
               var myObjectArray = (from item in fields select item as object).ToArray();
               IList<object> enumerable = myObjectArray [0] as IList<object>;
               if ((enumerable != null) && (enumerable.Count > 0))
                {
                  foreach (object element in enumerable)
                    {
                       strResponse = element.ToString();
                       Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                       if(j<total_msg)
                          Assert.AreEqual(j.ToString(), strResponse);
                       j++;
                    }
                }
                else
                {
                    Assert.Fail("No response");
                }
             }          
          }  
       }
        public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
        {
            isEncryptObjectPublished = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "enigma", false);
            string channel = "my/channel";
            object message = new SecretCustomClass();
            messageObjectForEncryptPublish = JsonConvert.SerializeObject(message);

            EnqueueCallback(() => pubnub.publish<string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback));
            EnqueueConditional(() => isEncryptObjectPubCheck);

            EnqueueCallback(() =>
            {
                if (!isEncryptObjectPublished)
                {
                    Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed");
                }
                else
                {
                   EnqueueCallback(() => pubnub.detailedHistory<string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback));
                   EnqueueConditional(() => isEncryptObjectDHCheck);
                   EnqueueCallback(() => Assert.IsTrue(isEncryptObjectDH, "Unable to match the successful encrypt object Publish"));
                }
            });

            EnqueueTestComplete();
        }
        public void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isSecretEncryptPublished = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "key", "enigma", false);
            string channel = "my/channel";
            string message = messageForSecretEncryptPublish;

            EnqueueCallback(() => pubnub.publish<string>(channel, message, ReturnSuccessSecretEncryptPublishCodeCallback));
            EnqueueConditional(() => isSecretEncryptPubCheck);

            EnqueueCallback(() =>
            {
                if (!isSecretEncryptPublished)
                {
                    Assert.IsTrue(isSecretEncryptPublished, "Secret Encrypt Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.detailedHistory<string>(channel, -1, secretEncryptPublishTimetoken, -1, false, CaptureSecretEncryptDetailedHistoryCallback));
                    EnqueueConditional(() => isSecretEncryptDHCheck);
                    EnqueueCallback(() => Assert.IsTrue(isSecretEncryptDH, "Unable to decrypt the successful Secret key Publish"));
                }
            });

            EnqueueTestComplete();
        }
		public static void DetailedHistory_Decrypted_Example()
		{
			Pubnub pubnub = new Pubnub(
				"demo",
				"demo",
				"",
				"enigma",
				false);
			string channel = "hello_world";
			//pubnub.CIPHER_KEY = "enigma";
			string msg = "Test Message";
			Common cm = new Common();
			
			
			cm.deliveryStatus = false;
			cm.objResponse = null;
			
			pubnub.publish(channel, msg, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			PubnubUnitTest unitTest = new PubnubUnitTest();
			unitTest.TestClassName = "WhenDetailedHistoryIsRequested";
			unitTest.TestCaseName = "DetailedHistory_Decrypted_Example";
			
			pubnub.PubnubUnitTest = unitTest;
			cm.deliveryStatus = false;
			cm.objResponse = null;
			pubnub.detailedHistory(channel, 1, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
			
			if (cm.objResponse.Equals(null))
			{
				Assert.Fail("Null response");
			} 
			else
			{
				IList<object> fields = cm.objResponse as IList<object>;
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray();
					
					IList<object> myObjectList = myObjectArray[0] as IList<object>;
					if (fields [0] != null)
					{
						Console.WriteLine("myObjectList[0]: " + myObjectList[0]);
						Assert.True(msg.Equals(myObjectList[0]));
					}
					else
					{
						Assert.Fail("NULL response");
					}
				}
			}  
		}
Ejemplo n.º 21
0
        public static void TestEncryptedDetailedHistory()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "enigma",
                false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "enigma";

            int  total_msg = 10;
            long starttime = Timestamp(pubnub);
            Dictionary <long, string> inputs = new Dictionary <long, string>();

            for (int i = 0; i < total_msg / 2; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);

            for (int i = total_msg / 2; i < total_msg; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Timestamp(pubnub);

            while (!deliveryStatus)
            {
                ;
            }



            pubnub.detailedHistory(channel, total_msg, DisplayReturnMessage);
            deliveryStatus = false;
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
            string strResponse = "";

            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;
                int            j      = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if (j < total_msg)
                    {
                        Console.WriteLine(j.ToString(), strResponse);
                    }
                    j++;
                }
            }
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
        }
Ejemplo n.º 22
0
        static public void Main()
        {
            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}", channel));
            Console.WriteLine();

            Console.WriteLine("Enable SSL? ENTER Y for Yes, else N");
            string enableSSL = Console.ReadLine();

            if (enableSSL.Trim().ToLower() == "y")
            {
                Console.WriteLine("SSL Enabled");
            }
            else
            {
                Console.WriteLine("SSL NOT Enabled");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER cipher key for encryption feature.");
            Console.WriteLine("If you don't want to avail at this time, press ENTER.");
            string cipheryKey = Console.ReadLine();

            if (cipheryKey.Trim().Length > 0)
            {
                Console.WriteLine("Cipher key provided.");
            }
            else
            {
                Console.WriteLine("No Cipher key provided");
            }
            Console.WriteLine();

            pubnub = new Pubnub("demo", "demo", "", cipheryKey,
                                (enableSSL.Trim().ToLower() == "y") ? true : false);

            Console.WriteLine("ENTER 1 FOR Subscribe");
            Console.WriteLine("ENTER 2 FOR Publish");
            Console.WriteLine("ENTER 3 FOR Presence");
            Console.WriteLine("ENTER 4 FOR Detailed History");
            Console.WriteLine("ENTER 5 FOR Here_Now");
            Console.WriteLine("ENTER 6 FOR Unsubscribe");
            Console.WriteLine("ENTER 7 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                case "0":
                    exitFlag = true;
                    break;

                case "1":
                    Console.WriteLine("Running subscribe()");
                    pubnub.subscribe <string>(channel, DisplayReturnMessage);
                    //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                    //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                    //pubnub.subscribe(channel, DisplayReturnMessage);
                    break;

                case "2":
                    Console.WriteLine("Running publish()");
                    Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                    string publishMsg = Console.ReadLine();
                    pubnub.publish <string>(channel, publishMsg, DisplayReturnMessage);
                    break;

                case "3":
                    Console.WriteLine("Running presence()");
                    pubnub.presence <string>(channel, DisplayReturnMessage);
                    //System.Threading.Tasks.Task pretask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.presence<string>(channel, DisplayReturnMessage));
                    //pubnub.presence<object>(channel, DisplayReturnMessage);
                    break;

                case "4":
                    Console.WriteLine("Running detailed history()");
                    pubnub.detailedHistory <string>(channel, 100, DisplayReturnMessage);
                    //pubnub.detailedHistory<object>(channel, 100, DisplayReturnMessage);
                    break;

                case "5":
                    Console.WriteLine("Running Here_Now()");
                    pubnub.here_now <string>(channel, DisplayReturnMessage);
                    //pubnub.here_now<object>(channel, DisplayReturnMessage);
                    break;

                case "6":
                    Console.WriteLine("Running unsubscribe()");
                    pubnub.unsubscribe <string>(channel, DisplayReturnMessage);
                    //pubnub.unsubscribe<object>(channel, DisplayReturnMessage);
                    break;

                case "7":
                    Console.WriteLine("Running presence-unsubscribe()");
                    pubnub.presence_unsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "8":
                    Console.WriteLine("Running time()");
                    pubnub.time <string>(DisplayReturnMessage);
                    break;

                default:
                    Console.WriteLine("INVALID CHOICE.");
                    break;
                }
            }

            Console.WriteLine("\nPress any key to confirm exit.\n\n");
            Console.ReadLine();
        }
        public void DetailedHistoryStartWithReverseTrue()
        {
            expectedCountAtStartTimeWithReverseTrue = 0;
            msgStartReverseTrue = false;
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
                    string channel = "my/channel";
                    startTimeWithReverseTrue = Pubnub.translateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);
                    for (int index = 0; index < 10; index++)
                    {
                        pubnub.publish<string>(channel,
                            string.Format("DetailedHistoryStartTimeWithReverseTrue {0} {1}", startTimeWithReverseTrue, index),
                            DetailedHistorySamplePublishCallback);
                        mrePublishStartReverseTrue.WaitOne(5000);
                    }

                    Thread.Sleep(5000);

                    pubnub.detailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, true);
                    mreMsgStartReverseTrue.WaitOne(310 * 1000);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            Assert.IsTrue(msgStartReverseTrue, "Detailed History with Start and Reverse True Failed");
                            TestComplete();
                        });
                });
        }
Ejemplo n.º 24
0
        public static void TestEncryptedDetailedHistoryParams()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "enigma",
                    false);
            // Context setup for Detailed Histor
            //pubnub.CIPHER_KEY = "enigma";
            int total_msg = 10;
            long starttime = Timestamp(pubnub);

            for (int i = 0; i < total_msg / 2; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);
            for (int i = total_msg / 2; i < total_msg; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Timestamp(pubnub);

            deliveryStatus = false;
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "DetailedHistory")
                {
                    Console.WriteLine("\n*********** DetailedHistory Messages *********** ");
                    /*foreach (object msg_org in (List<object>)((Pubnub)sender).DetailedHistory)
                    {
                        Console.WriteLine(msg_org.ToString());
                    }*/
                    deliveryStatus = true;
                }
            };
            Console.WriteLine("DetailedHistory with start & end");
            pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("DetailedHistory with start & reverse = true");
            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("DetailedHistory with start & reverse = false");
            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
        }
		public static void DetailedHistory_Example()
		{
			Pubnub pubnub = new Pubnub(
				"demo",
				"demo",
				"",
				"",
				false);
			string channel = "hello_world";
			//pubnub.CIPHER_KEY = "";
			string msg = "Test Message";
			Common cm = new Common();
			cm.deliveryStatus = false;
			cm.objResponse = null;
			
			pubnub.publish(channel, msg, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			
			PubnubUnitTest unitTest = new PubnubUnitTest();
			unitTest.TestClassName = "WhenDetailedHistoryIsRequested";
			unitTest.TestCaseName = "DetailHistoryCount10ReturnsRecords";
			
			pubnub.PubnubUnitTest = unitTest;
			
			cm.deliveryStatus = false;
			cm.objResponse = null;
			
			pubnub.detailedHistory(channel, 10, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
			
			if (cm.objResponse.Equals(null))
			{
				Assert.Fail("Null response");
			} 
			else
			{
				IList<object> fields = cm.objResponse as IList<object>;
				
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray();
					IList<object> enumerable = myObjectArray [0] as IList<object>;
					if ((enumerable != null) && (enumerable.Count > 0))
					{
						foreach (object element in enumerable)
						{
							string strResponse = element.ToString();
							Console.WriteLine(String.Format("resp:{0}", strResponse));
							Assert.NotNull(strResponse);
						}
					}
					else
					{
						Assert.Fail("No response");
					}
				}
			}  
		}
Ejemplo n.º 26
0
        public static void TestUnencryptedDetailedHistoryParams()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "testchannel";

            int total_msg = 10;
            long starttime = Timestamp(pubnub);

            for (int i = 0; i < total_msg / 2; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);
            for (int i = total_msg / 2; i < total_msg; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus) ;
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Timestamp(pubnub);

            deliveryStatus = false;

            Console.WriteLine("DetailedHistory with start & end");
            pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus) ;

            Console.WriteLine("DetailedHistory with start & reverse = true");
            string strResponse = "";
            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;
                int j = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if(j<total_msg/2)
                        Console.WriteLine(j.ToString(), strResponse);
                    j++;
                }
            }

            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus) ;

            Console.WriteLine("DetailedHistory with start & reverse = false");
            strResponse = "";
            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;
                int j = total_msg / 2;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if(j<total_msg)
                        Console.WriteLine(j.ToString(), strResponse);
                    j++;
                }
            }

            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
            strResponse = "";
            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;
                int j = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if(j<total_msg/2)
                        Console.WriteLine(j.ToString(), strResponse);
                    j++;
                }
            }
        }
		public static void TestUnencryptedSecretDetailedHistoryParams()
		{
			Pubnub pubnub = new Pubnub(
				"demo",
				"demo",
				"secretkey",
				"",
				false);
			string channel = "hello_world";
			
			//pubnub.CIPHER_KEY = "enigma";
			int total_msg = 10;
			Common cm = new Common();
			long starttime = cm.Timestamp(pubnub);
			cm.deliveryStatus = false;
			cm.objResponse = null;          
			
			for (int i = 0; i < total_msg / 2; i++)
			{
				cm.deliveryStatus = false;
				string msg = i.ToString();
				pubnub.publish(channel, msg, cm.DisplayReturnMessage);
				while (!cm.deliveryStatus) ;
				//long t = Timestamp();
				//inputs.Add(t, msg);
				Console.WriteLine("Message # " + i.ToString() + " published");
			}
			
			long midtime = cm.Timestamp(pubnub);
			for (int i = total_msg / 2; i < total_msg; i++)
			{
				cm.deliveryStatus = false;
				string msg = i.ToString();
				pubnub.publish(channel, msg, cm.DisplayReturnMessage);
				while (!cm.deliveryStatus) ;
				//long t = Timestamp();
				//inputs.Add(t, msg);
				Console.WriteLine("Message # " + i.ToString() + " published");
			}
			
			long endtime = cm.Timestamp(pubnub);
			
			PubnubUnitTest unitTest = new PubnubUnitTest();
			unitTest.TestClassName = "WhenDetailedHistoryIsRequested";
			unitTest.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams1";
			
			pubnub.PubnubUnitTest = unitTest;
			
			cm.deliveryStatus = false;
			cm.objResponse = null;
			Console.WriteLine("DetailedHistory with start & end");
			pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			
			Console.WriteLine("DetailedHistory with start & reverse = true");
			string strResponse = "";
			if (cm.objResponse.Equals(null))
			{
				Assert.Fail("Null response");
			} 
			else
			{
				IList<object> fields = cm.objResponse as IList<object>;
				int j = 0;
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray();
					IList<object> enumerable = myObjectArray [0] as IList<object>;
					if ((enumerable != null) && (enumerable.Count > 0))
					{
						foreach (object element in enumerable)
						{
							strResponse = element.ToString();
							Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
							if(j<total_msg/2)
								Assert.True(j.ToString().Equals(strResponse));
							j++;
						}
					}
					else
					{
						Assert.Fail("No response");
					}
				}            
			}  
			
			PubnubUnitTest unitTest2 = new PubnubUnitTest();
			unitTest2.TestClassName = "WhenDetailedHistoryIsRequested";
			unitTest2.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams2";
			
			pubnub.PubnubUnitTest = unitTest2;
			
			cm.deliveryStatus = false;
			cm.objResponse = null;
			pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			
			Console.WriteLine("DetailedHistory with start & reverse = false");
			strResponse = "";
			if (cm.objResponse.Equals(null))
			{
				Assert.Fail("Null response");
			} 
			else
			{
				IList<object> fields = cm.objResponse as IList<object>;
				int j = total_msg / 2;
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray();
					IList<object> enumerable = myObjectArray [0] as IList<object>;
					if ((enumerable != null) && (enumerable.Count > 0))
					{
						foreach (object element in enumerable)
						{
							strResponse = element.ToString();
							Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
							if(j<total_msg)
								Assert.True(j.ToString().Equals(strResponse));
							j++;
						}
					}
					else
					{
						Assert.Fail("No response");
					}
				}             
			}  
			
			
			PubnubUnitTest unitTest3 = new PubnubUnitTest();
			unitTest3.TestClassName = "WhenDetailedHistoryIsRequested";
			unitTest3.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams3";
			
			pubnub.PubnubUnitTest = unitTest3;
			
			cm.deliveryStatus = false;
			cm.objResponse = null;
			pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, cm.DisplayReturnMessage);
			while (!cm.deliveryStatus) ;
			Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
			strResponse = "";
			if (cm.objResponse.Equals(null))
			{
				Assert.Fail("Null response");
			} 
			else
			{
				IList<object> fields = cm.objResponse as IList<object>;
				int j = 0;
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray();
					IList<object> enumerable = myObjectArray [0] as IList<object>;
					if ((enumerable != null) && (enumerable.Count > 0))
					{
						foreach (object element in enumerable)
						{
							strResponse = element.ToString();
							Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
							if(j<total_msg/2)
								Assert.True(j.ToString().Equals(strResponse));
							j++;
						}
					}
					else
					{
						Assert.Fail("No response");
					}
				}             
			}  
		}
Ejemplo n.º 28
0
        public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
        {
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    isEncryptObjectPublished = false;
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "enigma", false);
                    string channel = "my/channel";
                    object message = new SecretCustomClass();
                    messageObjectForEncryptPublish = JsonConvert.SerializeObject(message);
                    

                    pubnub.publish<string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback);
                    mreEncryptObjectPub.WaitOne(310 * 1000);

                    if (!isEncryptObjectPublished)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                       {
                           Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed");
                           TestComplete();
                       });
                    }
                    else
                    {
                        pubnub.detailedHistory<string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback);
                        mreEncryptObjectDH.WaitOne(310 * 1000);
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                       {
                           Assert.IsTrue(isEncryptObjectDH, "Unable to match the successful encrypt object Publish");
                           TestComplete();
                       });
                    }
                });
        }
Ejemplo n.º 29
0
        public static void DetailedHistory_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "testchannel";
            //pubnub.CIPHER_KEY = "";
            string msg = "Test Message";
            deliveryStatus = false;
            pubnub.publish(channel, msg, DisplayReturnMessage);
            while (!deliveryStatus) ;

            deliveryStatus = false;
            pubnub.detailedHistory(channel, 10, DisplayReturnMessage);
            while (!deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (objResponse.Equals(null))
            {
              Console.WriteLine("Null response");
            }
            else
            {
                IList<object> fields = objResponse as IList<object>;

                foreach (object item in fields)
                {
                    string strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0}", strResponse));
                    Console.WriteLine(strResponse);
                }
            }
        }
Ejemplo n.º 30
0
        public static void TestUnencryptedDetailedHistoryParams()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false);
            string channel = "testchannel";

            int  total_msg = 10;
            long starttime = Timestamp(pubnub);


            for (int i = 0; i < total_msg / 2; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Timestamp(pubnub);

            for (int i = total_msg / 2; i < total_msg; i++)
            {
                deliveryStatus = false;
                string msg = i.ToString();
                pubnub.publish(channel, msg, DisplayReturnMessage);
                while (!deliveryStatus)
                {
                    ;
                }
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }


            long endtime = Timestamp(pubnub);

            deliveryStatus = false;

            Console.WriteLine("DetailedHistory with start & end");
            pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }

            Console.WriteLine("DetailedHistory with start & reverse = true");
            string strResponse = "";

            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;
                int            j      = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if (j < total_msg / 2)
                    {
                        Console.WriteLine(j.ToString(), strResponse);
                    }
                    j++;
                }
            }

            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }

            Console.WriteLine("DetailedHistory with start & reverse = false");
            strResponse = "";
            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;
                int            j      = total_msg / 2;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if (j < total_msg)
                    {
                        Console.WriteLine(j.ToString(), strResponse);
                    }
                    j++;
                }
            }


            deliveryStatus = false;
            pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
            while (!deliveryStatus)
            {
                ;
            }
            Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
            strResponse = "";
            if (objResponse.Equals(null))
            {
                Console.WriteLine("Null response");
            }
            else
            {
                IList <object> fields = objResponse as IList <object>;
                int            j      = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if (j < total_msg / 2)
                    {
                        Console.WriteLine(j.ToString(), strResponse);
                    }
                    j++;
                }
            }
        }
Ejemplo n.º 31
0
        static public void Main()
        {
            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}",channel));
            Console.WriteLine();

            Console.WriteLine("Enable SSL? ENTER Y for Yes, else N");
            string enableSSL = Console.ReadLine();
            if (enableSSL.Trim().ToLower() == "y")
            {
                Console.WriteLine("SSL Enabled");
            }
            else
            {
                Console.WriteLine("SSL NOT Enabled");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER cipher key for encryption feature.");
            Console.WriteLine("If you don't want to avail at this time, press ENTER.");
            string cipheryKey = Console.ReadLine();
            if (cipheryKey.Trim().Length > 0)
            {
                Console.WriteLine("Cipher key provided.");
            }
            else
            {
                Console.WriteLine("No Cipher key provided");
            }
            Console.WriteLine();

            pubnub = new Pubnub("demo", "demo", "", cipheryKey,
                (enableSSL.Trim().ToLower() == "y") ? true : false);

            Console.WriteLine("ENTER 1 FOR Subscribe (not implementing connectCallback)");
            Console.WriteLine("ENTER 2 FOR Subscribe (implementing connectCallback)");
            Console.WriteLine("ENTER 3 FOR Publish");
            Console.WriteLine("ENTER 4 FOR Presence");
            Console.WriteLine("ENTER 5 FOR Detailed History");
            Console.WriteLine("ENTER 6 FOR Here_Now");
            Console.WriteLine("ENTER 7 FOR Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 9 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                    case "0":
                        exitFlag = true;
                        break;
                    case "1":
                        Console.WriteLine("Running subscribe() (not implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "2":
                        Console.WriteLine("Running subscribe() (implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage, DisplayConnectStatusMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "3":
                        Console.WriteLine("Running publish()");
                        Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                        string publishMsg = Console.ReadLine();
                        double doubleData;
                        int intData;
                        if (int.TryParse(publishMsg, out intData))
                        {
                            pubnub.publish<string>(channel, intData, DisplayReturnMessage);
                        }
                        else if (double.TryParse(publishMsg, out doubleData))
                        {
                            pubnub.publish<string>(channel, doubleData, DisplayReturnMessage);
                        }
                        else
                        {
                            //check whether any numeric is sent in double quotes
                            if (publishMsg.IndexOf("\"") == 0 && publishMsg.LastIndexOf("\"") == publishMsg.Length - 1)
                            {
                                string strMsg = publishMsg.Substring(1, publishMsg.Length - 2);
                                if (int.TryParse(strMsg, out intData))
                                {
                                    pubnub.publish<string>(channel, strMsg, DisplayReturnMessage);
                                }
                                else if (double.TryParse(strMsg, out doubleData))
                                {
                                    pubnub.publish<string>(channel, strMsg, DisplayReturnMessage);
                                }
                                else
                                {
                                    pubnub.publish<string>(channel, publishMsg, DisplayReturnMessage);
                                }
                            }
                            else
                            {
                                pubnub.publish<string>(channel, publishMsg, DisplayReturnMessage);
                            }
                        }
                        break;
                    case "4":
                        Console.WriteLine("Running presence()");
                        pubnub.presence<string>(channel, DisplayReturnMessage);
                        //System.Threading.Tasks.Task pretask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.presence<string>(channel, DisplayReturnMessage));
                        //pubnub.presence<object>(channel, DisplayReturnMessage);
                        break;
                    case "5":
                        Console.WriteLine("Running detailed history()");
                        pubnub.detailedHistory<string>(channel, 100, DisplayReturnMessage);
                        //pubnub.detailedHistory<object>(channel, 100, DisplayReturnMessage);
                        break;
                    case "6":
                        Console.WriteLine("Running Here_Now()");
                        pubnub.here_now<string>(channel, DisplayReturnMessage);
                        //pubnub.here_now<object>(channel, DisplayReturnMessage);
                        break;
                    case "7":
                        Console.WriteLine("Running unsubscribe()");
                        pubnub.unsubscribe<string>(channel, DisplayReturnMessage);
                        //pubnub.unsubscribe<object>(channel, DisplayReturnMessage);
                        break;
                    case "8":
                        Console.WriteLine("Running presence-unsubscribe()");
                        pubnub.presence_unsubscribe<string>(channel, DisplayReturnMessage);
                        break;
                    case "9":
                        Console.WriteLine("Running time()");
                        pubnub.time<string>(DisplayReturnMessage);
                        break;
                    default:
                        Console.WriteLine("INVALID CHOICE.");
                        break;
                }
            }

            Console.WriteLine("\nPress any key to confirm exit.\n\n");
            Console.ReadLine();

        }
Ejemplo n.º 32
0
 public void DetailedHistory()
 {
     Display("Running Detailed History");
     pubnub.detailedHistory <string>(channel, 100, DisplayReturnMessage);
 }
Ejemplo n.º 33
0
        public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
        {
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    isUnencryptPublished = false;
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
                    string channel = "my/channel";
                    string message = messageForUnencryptPublish;

                    pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback);
                    manualEvent1.WaitOne(310 * 1000);

                    if (!isUnencryptPublished)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                       {
                           Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
                           TestComplete();
                       });
                    }
                    else
                    {
                        pubnub.detailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback);
                        mreUnencryptDH.WaitOne(310 * 1000);
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                       {
                           Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish");
                           TestComplete();
                       });
                    }
                });
        }
Ejemplo n.º 34
0
        static public void Main()
        {
            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}", channel));
            Console.WriteLine();

            Console.WriteLine("Enable SSL? ENTER Y for Yes, else N");
            string enableSSL = Console.ReadLine();

            if (enableSSL.Trim().ToLower() == "y")
            {
                Console.WriteLine("SSL Enabled");
            }
            else
            {
                Console.WriteLine("SSL NOT Enabled");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER cipher key for encryption feature.");
            Console.WriteLine("If you don't want to avail at this time, press ENTER.");
            string cipheryKey = Console.ReadLine();

            if (cipheryKey.Trim().Length > 0)
            {
                Console.WriteLine("Cipher key provided.");
            }
            else
            {
                Console.WriteLine("No Cipher key provided");
            }
            Console.WriteLine();

            pubnub = new Pubnub("demo", "demo", "", cipheryKey,
                                (enableSSL.Trim().ToLower() == "y") ? true : false);

            Console.WriteLine("ENTER 1 FOR Subscribe (not implementing connectCallback)");
            Console.WriteLine("ENTER 2 FOR Subscribe (implementing connectCallback)");
            Console.WriteLine("ENTER 3 FOR Publish");
            Console.WriteLine("ENTER 4 FOR Presence");
            Console.WriteLine("ENTER 5 FOR Detailed History");
            Console.WriteLine("ENTER 6 FOR Here_Now");
            Console.WriteLine("ENTER 7 FOR Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 9 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                case "0":
                    exitFlag = true;
                    pubnub.EndPendingRequests();
                    break;

                case "1":
                    Console.WriteLine("Running subscribe() (not implementing connectCallback)");
                    pubnub.subscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "2":
                    Console.WriteLine("Running subscribe() (implementing connectCallback)");
                    pubnub.subscribe <string>(channel, DisplayReturnMessage, DisplayConnectStatusMessage);
                    break;

                case "3":
                    Console.WriteLine("Running publish()");
                    Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                    string publishMsg = Console.ReadLine();
                    double doubleData;
                    int    intData;
                    if (int.TryParse(publishMsg, out intData))                     //capture numeric data
                    {
                        pubnub.publish <string>(channel, intData, DisplayReturnMessage);
                    }
                    else if (double.TryParse(publishMsg, out doubleData))                     //capture numeric data
                    {
                        pubnub.publish <string>(channel, doubleData, DisplayReturnMessage);
                    }
                    else
                    {
                        //check whether any numeric is sent in double quotes
                        if (publishMsg.IndexOf("\"") == 0 && publishMsg.LastIndexOf("\"") == publishMsg.Length - 1)
                        {
                            string strMsg = publishMsg.Substring(1, publishMsg.Length - 2);
                            if (int.TryParse(strMsg, out intData))
                            {
                                pubnub.publish <string>(channel, strMsg, DisplayReturnMessage);
                            }
                            else if (double.TryParse(strMsg, out doubleData))
                            {
                                pubnub.publish <string>(channel, strMsg, DisplayReturnMessage);
                            }
                            else
                            {
                                pubnub.publish <string>(channel, publishMsg, DisplayReturnMessage);
                            }
                        }
                        else
                        {
                            pubnub.publish <string>(channel, publishMsg, DisplayReturnMessage);
                        }
                    }
                    break;

                case "4":
                    Console.WriteLine("Running presence()");
                    pubnub.presence <string>(channel, DisplayReturnMessage);
                    break;

                case "5":
                    Console.WriteLine("Running detailed history()");
                    pubnub.detailedHistory <string>(channel, 100, DisplayReturnMessage);
                    break;

                case "6":
                    Console.WriteLine("Running Here_Now()");
                    pubnub.here_now <string>(channel, DisplayReturnMessage);
                    break;

                case "7":
                    Console.WriteLine("Running unsubscribe()");
                    pubnub.unsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "8":
                    Console.WriteLine("Running presence-unsubscribe()");
                    pubnub.presence_unsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "9":
                    Console.WriteLine("Running time()");
                    pubnub.time <string>(DisplayReturnMessage);
                    break;

                default:
                    Console.WriteLine("INVALID CHOICE.");
                    break;
                }
            }

            Console.WriteLine("\nPress any key to exit.\n\n");
            Console.ReadLine();
        }