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); } }
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(); }); } }); }
/*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 static void Main() { Pubnub pubnub = new Pubnub( "demo", "demo", "", false ); string channel = "my/channel"; string message = "Pubnub API Usage Example"; pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged); Console.WriteLine("UUID -> " + pubnub.generateGUID()); pubnub.publish(channel, message); pubnub.history(channel, 10); pubnub.time(); pubnub.subscribe(channel); Console.ReadKey(); }
internal static void SubscribeDemo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "my_channel"; Console.WriteLine("Subscribe_Example"); pubnub.subscribe(channel, DisplayReturnMessage); bool userexit = false; while (!userexit) { Console.WriteLine("For Unsubscribe"); Console.WriteLine("Enter Y for UNSUBSCRIBE or ENTER X to EXIT subscribe loop"); string userinput = Console.ReadLine(); if (userinput.ToLower() == "y") { pubnub.unsubscribe(channel, DisplayReturnMessage); userexit = true; } else if (userinput.ToLower() == "x") { userexit = true; } } }
static void HereNow_Example() { Pubnub pubnub = new Pubnub( "demo", "demo", "", false); //string channel = "hello_world"; string channel = "hello_world"; pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Here_Now") { Console.WriteLine("\n********** Here Now Messages *********** "); Dictionary<string, object> _message = (Dictionary<string, object>)(((Pubnub)sender).Here_Now[0]); foreach (object uuid in (object[])_message["uuids"]) { Console.WriteLine("UUID: " + uuid.ToString()); } Console.WriteLine("Occupancy: " + _message["occupancy"].ToString()); } }; pubnub.here_now(channel); }
public void ThenPresenceShouldReturnReceivedMessage() { receivedFlag1 = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "my/channel"; pubnub.presence<string>(channel, ThenPresenceShouldReturnMessage); //since presence expects from stimulus from sub/unsub... pubnub.subscribe<string>(channel, DummyMethodForSubscribe); manualEvent1.WaitOne(2000); pubnub.unsubscribe<string>(channel, DummyMethodForUnSubscribe); manualEvent3.WaitOne(2000); manualEvent2.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedFlag1, "Presence message not received"); TestComplete(); }); }); }
public void ThenItShouldReturnTimeStamp() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGetRequestServerTime"; unitTest.TestCaseName = "ThenItShouldReturnTimeStamp"; pubnub.PubnubUnitTest = unitTest; string strResponse = ""; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.time(cm.DisplayReturnMessage); //cm.objResponse = null; while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; strResponse = fields[0].ToString(); Console.WriteLine("Resp:" + strResponse); Assert.AreNotEqual("0",strResponse); }
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 ThenItShouldReturnSuccessCodeAndInfo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; string message = "Pubnub API Usage Example"; Common cm = new Common(); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenItShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, message, cm.DisplayReturnMessage); //wait till the response is received from the server while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; string strSent = fields[1].ToString(); string strOne = fields[0].ToString(); Assert.True(("Sent").Equals(strSent)); Assert.True(("1").Equals(strOne)); }
internal static void PresenceDemo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "my_channel"; Console.WriteLine("Presence_Example"); pubnub.presence(channel, DisplayReturnMessage); bool pre_unsub = false; while (!pre_unsub) { Console.WriteLine("Enter y for Presence-Unsub; x to EXIT presence loop"); string userchoice = Console.ReadLine(); if (userchoice.ToLower() == "y") { Console.WriteLine("PresenceUnsubscribe_Example"); pubnub.presence_unsubscribe(channel, DisplayReturnMessage); pre_unsub = true; } else if (userchoice.ToLower() == "x") { pre_unsub = true; } } }
internal static void PublishDemo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "my_channel"; Console.WriteLine("Publish_Example"); bool exitFlag = false; while (!exitFlag) { Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT"); string userinput = Console.ReadLine(); if (userinput.ToLower() == "quit") { exitFlag = true; } else { pubnub.publish(channel, userinput, DisplayReturnMessage); } } }
public void NullMessage() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; string message = null; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, message, cm.DisplayReturnMessage); //wait till the response is received from the server while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; string strSent = fields[1].ToString(); string strOne = fields[0].ToString(); Assert.True(("Sent").Equals(strSent)); Assert.True(("1").Equals(strOne)); }
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 ThenItShouldReturnTimeStamp() { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); EnqueueCallback(() => pubnub.time<string>(ReturnTimeStampCallback)); EnqueueConditional(() => isTimeStamp); EnqueueCallback(() => Assert.IsTrue(timeReceived, "time() Failed")); EnqueueTestComplete(); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); /*if (ApplicationContext.Resources.Configuration.ScreenLayout = Android.Content.Res.ScreenLayout.SizeLarge) { SetContentView (Resource.Layout.Mainlarge); } else {*/ //} //Build.VERSION.Sdk SetContentView (Resource.Layout.Main); string strChannelName = Intent.GetStringExtra("Channel"); channel = strChannelName; bool bEnableSSL = Convert.ToBoolean((Intent.GetStringExtra("SslOn"))); string strCipher = (Intent.GetStringExtra("Cipher")); string strSsl= ""; if (bEnableSSL) strSsl = ", SSL"; if (!String.IsNullOrWhiteSpace (strCipher)) { strCipher = ", Cipher"; } string strHead = String.Format ("Channel: {0}{1}{2}", strChannelName, strSsl, strCipher); pubnub = new Pubnub ("demo", "demo", "", strCipher, bEnableSSL); Title = strHead; Button btnSubscribe = FindViewById<Button> (Resource.Id.btnSubscribe); btnSubscribe.Click += delegate {Subscribe();}; Button btnPresence = FindViewById<Button> (Resource.Id.btnPresence); btnPresence.Click += delegate {Presence();}; Button btnPublish = FindViewById<Button> (Resource.Id.btnPublish); btnPublish.Click += delegate {Publish();}; Button btnHereNow = FindViewById<Button> (Resource.Id.btnHereNow); btnHereNow.Click += delegate {HereNow();}; Button btnDetailedHis = FindViewById<Button> (Resource.Id.btnDetailedHis); btnDetailedHis.Click += delegate {DetailedHistory();}; Button btnTime = FindViewById<Button> (Resource.Id.btnTime); btnTime.Click += delegate {GetTime();}; Button btnUnsub = FindViewById<Button> (Resource.Id.btnUnsub); btnUnsub.Click += delegate {Unsub();}; Button btnUnsubPres = FindViewById<Button> (Resource.Id.btnUnsubPres); btnUnsubPres.Click += delegate {UnsubPresence();}; }
public PubNubNotificationMessageManager() { //Retrieve configuration values _publishKey = CloudConfigurationManager.GetSetting("PubNubPublishKey"); _subscribeKey = CloudConfigurationManager.GetSetting("PubNubSubscribeKey"); _secretKey = CloudConfigurationManager.GetSetting("PubNubSecretKey"); _channel = CloudConfigurationManager.GetSetting("PubNubMessageChannel"); _pubNubService = new Pubnub(_publishKey, _subscribeKey, _secretKey); }
public Pubnub_MessagingSub (string strChannelName, string strCipher, bool bEnableSSL) : base (UITableViewStyle.Grouped, null) { _Channel = strChannelName; _Ssl = bEnableSSL; _Cipher = strCipher; string strSsl = ""; if (_Ssl) { strSsl = ", SSL"; } string strCip = ""; if (!String.IsNullOrWhiteSpace (_Cipher)) { strCip = ", Cipher"; } string strHead = String.Format ("Ch: {0} {1} {2}", _Channel, strSsl, strCip); _pubnub = new Pubnub ("demo", "demo", "", _Cipher, _Ssl); Section secAction = new Section (); bool bIphone = true; string strHardwareVer = DeviceHardware.Version.ToString ().ToLower (); if (strHardwareVer.IndexOf ("ipad") >= 0) { bIphone = false; } Dictionary<string, RectangleF> dictRect = null; int iViewHeight = 140; if (bIphone) { dictRect = GetRectanglesForIphone(); iViewHeight = 140; } else { dictRect = GetRectanglesForIpad(); iViewHeight = 85; } secAction.HeaderView = CreateHeaderView(dictRect, iViewHeight); _secOutput = new Section("Output"); _root = new RootElement (strHead) { secAction, _secOutput }; Root = _root; _dvc = new DialogViewController (_root, true); _dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, delegate { _pubnub.EndPendingRequests (); AppDelegate.navigation.PopToRootViewController(true); }); AppDelegate.navigation.PushViewController (_dvc, true); }
public PubNubClientForm() { InitializeComponent(); _publishKey = ConfigurationManager.AppSettings["PubNubPublishKey"]; _subscribeKey = ConfigurationManager.AppSettings["PubNubSubscribeKey"]; _secretKey = ConfigurationManager.AppSettings["PubNubSecretKey"]; _pubNubService = new Pubnub(_publishKey, _subscribeKey, _secretKey); cmbUserIds.SelectedIndex = 0; }
public void IfSSLNotProvidedThenDefaultShouldBeFalse() { Pubnub pubnub = new Pubnub( "demo", "demo", "" ); string channel = "hello_world"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.AreEqual(true, pubnub.publish(channel, message, cm.DisplayReturnMessage)); }
public void ThenItShouldGenerateUniqueIdentifier() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); Assert.NotNull(pubnub.generateGUID()); }
internal static void SecureSubscribeDemo() { Pubnub pubnub = new Pubnub( "", "demo", "", "pandu", false); string channel = "my_channel"; Console.WriteLine("Secure_Subscribe_Example"); pubnub.subscribe(channel, DisplayReturnMessage); //Console.WriteLine("second channel"); //pubnub.subscribe("second_channel", DisplaySubscribeReturnMessage1); //Console.WriteLine("third channel"); //pubnub.subscribe("third_channel", DisplaySubscribeReturnMessage1); //Console.WriteLine("fourth channel"); //pubnub.subscribe("fourth_channel", DisplaySubscribeReturnMessage1); //string channelNum = ""; //do //{ // Console.WriteLine("For Unsub"); // Console.WriteLine("Enter 1 for my_channel, 2 for second_channel, 3 for third_channel, 4 for fourth channel, x for EXIT"); // channelNum = Console.ReadLine(); // if (channelNum == "1") // { // pubnub.unsubscribe(channel, DisplaySubscribeReturnMessage1); // } // else if (channelNum == "2") // { // pubnub.unsubscribe("second_channel", DisplaySubscribeReturnMessage1); // } // else if (channelNum == "3") // { // pubnub.unsubscribe("third_channel", DisplaySubscribeReturnMessage1); // } // else if (channelNum == "4") // { // pubnub.unsubscribe("fourth_channel", DisplaySubscribeReturnMessage1); // } //} while (channelNum.ToLower() != "x"); //Console.WriteLine("Please wait..."); //Console.ReadLine(); }
public void NullShouldBeTreatedAsEmpty() { Pubnub pubnub = new Pubnub( null, "demo", null, null, false ); string channel = "mychannel"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.AreEqual(false, pubnub.publish(channel, message, cm.DisplayReturnMessage)); }
public void IfHereNowIsCalledThenItShouldReturnInfo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "IfHereNowIsCalledThenItShouldReturnInfo"; pubnub.PubnubUnitTest = unitTest; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.here_now(channel, 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 lst in fields) { strResponse = lst.ToString(); Console.WriteLine("Resp:" + strResponse); Assert.IsNotEmpty(strResponse); } Dictionary<string, object> message = (Dictionary<string, object>)fields[0]; foreach(KeyValuePair<String, object> entry in message) { Console.WriteLine("value:" + entry.Value + " " + "key:" + entry.Key); } /*object[] objUuid = (object[])message["uuids"]; foreach (object obj in objUuid) { Console.WriteLine(obj.ToString()); }*/ //Assert.AreNotEqual(0, message["occupancy"]); } }
public void ThenSubscribeShouldReturnReceivedMessage() { receivedMessage = false; Pubnub pubnub = new Pubnub("demo","demo","","",false); string channel = "test"; EnqueueCallback(() => pubnub.subscribe<string>(channel, ReceivedMessageCallback)); EnqueueCallback(() => pubnub.publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback)); EnqueueConditional(() => isPublished); EnqueueConditional(() => isReceived); EnqueueCallback(() => Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed")); EnqueueTestComplete(); }
internal static void Here_Now_Demo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "my/channel"; Console.WriteLine("Here_Now_Example"); pubnub.here_now<string>(channel, DisplayReturnMessage); }
public Pubnub_MessagingSub (string strChannelName, string strCipher, bool bEnableSSL) : base (UITableViewStyle.Grouped, null) { channel = strChannelName; string strSsl = ""; if (bEnableSSL) strSsl = ", SSL"; string strCip = ""; if (!String.IsNullOrWhiteSpace (strCipher)) { strCip = ", Cipher"; } string strHead = String.Format ("Ch: {0} {1} {2}", strChannelName, strSsl, strCip); pubnub = new Pubnub ("demo", "demo", "", strCipher, bEnableSSL); Section secAction = new Section (); bool bIphone = true; string strHardwareVer = DeviceHardware.Version.ToString ().ToLower (); if (strHardwareVer.IndexOf ("ipad") >= 0) { bIphone = false; } Dictionary<string, RectangleF> dictRect = null; int iViewHeight = 100; if (bIphone) { dictRect = GetRectanglesForIphone(); iViewHeight = 100; } else { dictRect = GetRectanglesForIpad(); iViewHeight = 40; } secAction.HeaderView = CreateHeaderView(dictRect, iViewHeight); secOutput = new Section("Output"); root = new RootElement (strHead) { secAction, secOutput }; Root = root; dvc = new DialogViewController (root, true); AppDelegate.navigation.PushViewController (dvc, true); }
public void ThenItShouldReturnReceivedMessage () { Pubnub pubnub = new Pubnub ( "demo", "demo", "", "", false); string channel = "hello_world"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.subscribe (channel, cm.DisplayReturnMessage); Thread.Sleep(3000); string msg = "Test Message"; pubnub.publish (channel, msg, cm.DisplayReturnMessageDummy); //cm.deliveryStatus = false; while (!cm.deliveryStatus); if (cm.objResponse != null) { IList<object> fields = cm.objResponse as IList<object>; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray (); Console.WriteLine ("Resp:" + myObjectArray[0].ToString ()); Assert.AreEqual(msg, myObjectArray[0].ToString()); } else { Assert.Fail("No response"); } } 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(); }); }); }
public void ThenItShouldReturnHistoryMessages () { Pubnub pubnub = new Pubnub ( "demo", "demo", "", "", false ); string channel = "hello_world"; bool responseStatus = false; //publish a test message. Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish (channel, "Test message", cm.DisplayReturnMessage); List<object> lstHistory = null; pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "History") { lstHistory = ((Pubnub)sender).History; responseStatus = true; } }; pubnub.history(channel, 1); /*while (!responseStatus) ; string strResponse = ""; if (lstHistory.Equals (null)) { Assert.Fail("Null response"); } else { foreach(object lst in lstHistory) { strResponse = lst.ToString(); Console.WriteLine("resp:" + strResponse); Assert.IsNotEmpty(strResponse); } }*/ }
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(); }