Permalink
Browse files

New C# core code in Mono Distros in Monoforandroid, Mono-for-mac, mon…

…o-for-linux and monotouch
  • Loading branch information...
1 parent 8cc78e6 commit f661620bb8f475cfb345563b920453f828db6efe @crimsonred crimsonred committed Jan 4, 2013
Showing with 2,338 additions and 6,233 deletions.
  1. +0 −82 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/DetailedHistory_Example.cs
  2. +0 −39 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Here_Now_Example.cs
  3. +0 −74 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PresenceUnsubscribe_Example.cs
  4. +0 −157 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Presence_Example.cs
  5. +0 −213 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Example.cs
  6. +0 −796 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Example2.cs
  7. +6 −15 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.csproj
  8. BIN mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.pidb
  9. +0 −114 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Publish_Example.cs
  10. +288 −108 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub.cs
  11. +0 −2,925 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubnubBase.cs
  12. +0 −21 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubnubExtend.cs
  13. +184 −213 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub_Example.cs
  14. +0 −226 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Subscribe_Example.cs
  15. +3 −0 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/app.config
  16. +11 −10 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Messaging.userprefs
  17. BIN mono-for-linux/3.3.0.1/PubNub-Messaging/PubNubTest/PubNub-Messaging.Tests.pidb
  18. +5 −8 mono-for-linux/README.md
  19. +1 −10 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.csproj
  20. +288 −108 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub.cs
  21. +185 −213 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub_Example.cs
  22. +1 −1 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/app.config
  23. +12 −32 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Messaging.userprefs
  24. +482 −481 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNubTest/EncryptionTests.cs
  25. +8 −5 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNubTest/PubNub-Messaging.Tests.csproj
  26. +7 −10 mono-for-mac/README.md
  27. +23 −3 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/MainActivity.cs
  28. +287 −104 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Pubnub.cs
  29. +59 −47 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/Resource.designer.cs
  30. +14 −9 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/layout-large/Main.axml
  31. +17 −0 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/layout/Main.axml
  32. +2 −0 monoforandroid/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/values/Strings.xml
  33. +15 −8 monoforandroid/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.userprefs
  34. +7 −5 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.userprefs
  35. +291 −107 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging/Pubnub.cs
  36. +142 −89 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging/Pubnub_MessagingSub.cs
View
82 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/DetailedHistory_Example.cs
@@ -1,82 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace PubNub_Messaging
-{
- internal static class DetailedHistory_Example
- {
- /*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);
- }
-
- static void DisplayDetailedHistory(object result)
- {
- try
- {
- IList<object> msg = result as IList<object>;
- if (msg != null && msg.Count > 0)
- {
- object[] history = msg[0] as object[];
- if (history != null && history.Length > 0)
- {
- Console.WriteLine(string.Format("Total history records = {0}", history.Length));
- foreach (object item in history)
- {
- if (!item.GetType().IsGenericType)
- {
- Console.WriteLine(item.ToString());
- }
- else if ((item.GetType().IsGenericType) && (item.GetType().Name == typeof(Dictionary<,>).Name))
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)item;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("Key = {0}; Value = {1}", pair.Key, pair.Value));
- }
- }
- else
- {
- Console.WriteLine(string.Format("Unhandled type {0}",item.ToString()));
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- }
- }
-}
View
39 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Here_Now_Example.cs
@@ -1,39 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace PubNub_Messaging
-{
- internal static class Here_Now_Example
- {
- /*public static void Main()
- {
- Here_Now_Demo();
- Console.ReadLine();
- }*/
-
- 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);
-
- }
-
- static void DisplayReturnMessage(string result )
- {
- Console.WriteLine(result);
- }
-
- }
-}
View
74 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PresenceUnsubscribe_Example.cs
@@ -1,74 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace PubNub_Messaging
-{
- internal class PresenceUnsubscribe_Example
- {
- internal static void PresenceUnsubscribeDemo()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false);
-
- string channel = "my_channel";
-
- Console.WriteLine("PresenceUnsubscribe_Example");
-
- pubnub.presence_unsubscribe(channel, DisplayPresenceUnpresenceReturnMessage);
-
- }
-
- static void DisplayPresenceUnpresenceReturnMessage(object result)
- {
- IList<object> message = result as IList<object>;
-
- if (message != null && message.Count >= 2)
- {
- for(int index=0; index < message.Count; index++)
- {
- Console.WriteLine(string.Format("[{0}] = {1}",index, message[index].ToString()));
- object[] msg = message[0] as object[];
- if (msg != null)
- {
- foreach (object item in msg)
- {
- if (item is Dictionary<string, object>)
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)item;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("Key = {0}; Value = {1}", pair.Key, pair.Value));
- }
- }
- else if (item is object[])
- {
- object[] itemList = (object[])item;
- foreach (string innerItem in itemList)
- {
- Console.WriteLine(innerItem.ToString());
- }
- }
- else
- {
- Console.WriteLine(item.ToString());
- }
- }
- }
- }
- Console.WriteLine(string.Format("Channel = {0}", message[2].ToString()));
-
- }
- else
- {
- Console.WriteLine("result is not List<object>");
- }
- }
-
- }
-}
View
157 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Presence_Example.cs
@@ -1,157 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace PubNub_Messaging
-{
- internal static class Presence_Example
- {
- 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;
- }
- }
-
-
- }
-
- static void DisplayReturnMessage(object result)
- {
- IList<object> message = result as IList<object>;
-
- if (message != null && message.Count >= 2)
- {
- for (int index = 0; index < message.Count; index++)
- {
- ParseObject(message[index], 1);
- }
- }
- else
- {
- Console.WriteLine("unable to parse data");
- }
- }
-
- static void ParseObject(object result, int loop)
- {
- if (result is object[])
- {
- object[] arrResult = (object[])result;
- foreach (object item in arrResult)
- {
- if (!item.GetType().IsGenericType)
- {
- if (!item.GetType().IsArray)
- {
- Console.WriteLine(item.ToString());
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- }
- else if (result.GetType().IsGenericType && (result.GetType().Name == typeof(Dictionary<,>).Name))
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)result;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("key = {0}", pair.Key));
- if (pair.Value is object[])
- {
- Console.WriteLine("value = ");
- ParseObject(pair.Value, loop);
- }
- else
- {
- Console.WriteLine(string.Format("value = {0}", pair.Value));
- }
- }
- }
-
- }
-
- //static void DisplayReturnMessage(object result)
- //{
- // IList<object> message = result as IList<object>;
-
- // if (message != null && message.Count >= 2)
- // {
- // for (int index = 0; index < message.Count; index++)
- // {
- // if (!message[index].GetType().IsGenericType)
- // {
- // if (message[index] is object[])
- // {
- // object[] itemList = (object[])message[index];
- // for (int itemIndex = 0; itemIndex < itemList.Length; itemIndex++)
- // {
- // if (!itemList[itemIndex].GetType().IsGenericType)
- // {
- // Console.WriteLine(string.Format("[{0}][{1}] = {2}", index, itemIndex, itemList[itemIndex].ToString()));
- // }
- // else if ((itemList[itemIndex].GetType().IsGenericType) && (itemList[itemIndex].GetType().Name == typeof(Dictionary<,>).Name))
- // {
- // Dictionary<string, object> subitemList = (Dictionary<string, object>)itemList[itemIndex];
- // foreach (KeyValuePair<string, object> pair in subitemList)
- // {
- // Console.WriteLine(string.Format("[{0}][{1}] = {2}", index, pair.Key, pair.Value));
- // }
- // }
- // }
- // }
- // else
- // {
- // Console.WriteLine(string.Format("[{0}] = {1}", index, message[index].ToString()));
- // }
- // }
- // else if ((message[index].GetType().IsGenericType) && (message[index].GetType().Name == typeof(Dictionary<,>).Name))
- // {
- // Dictionary<string, object> itemList = (Dictionary<string, object>)message[index];
- // foreach (KeyValuePair<string, object> pair in itemList)
- // {
- // Console.WriteLine(string.Format("[{0}][{1}] = {2}",index, pair.Key, pair.Value));
- // }
- // }
- // }
- // }
- // else
- // {
- // Console.WriteLine("result is not List<object>");
- // }
- //}
- }
-}
View
213 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Example.cs
@@ -1,213 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.ComponentModel;
-using System.Threading;
-
-namespace PubNub_Messaging
-{
- public class Pubnub_Example
- {
- static public Pubnub pubnub;
-
- static public bool deliveryStatus = false;
- static public string channel = "";
-
- 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();
-
- }
-
- static void DisplayReturnMessage(string result)
- {
- Console.WriteLine(result);
- }
-
- static void DisplayReturnMessage(object result)
- {
- IList<object> message = result as IList<object>;
-
- if (message != null && message.Count >= 1)
- {
- for (int index = 0; index < message.Count; index++)
- {
- ParseObject(message[index], 1);
- }
- }
- else
- {
- Console.WriteLine("unable to parse data");
- }
- }
-
- static void ParseObject(object result, int loop)
- {
- if (result is object[])
- {
- object[] arrResult = (object[])result;
- foreach (object item in arrResult)
- {
- if (item != null)
- {
- if (!item.GetType().IsGenericType)
- {
- if (!item.GetType().IsArray)
- {
- Console.WriteLine(item.ToString());
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- else
- {
- Console.WriteLine();
- }
- }
- }
- else if (result.GetType().IsGenericType && (result.GetType().Name == typeof(Dictionary<,>).Name))
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)result;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("key = {0}", pair.Key));
- if (pair.Value is object[])
- {
- Console.WriteLine("value = ");
- ParseObject(pair.Value, loop);
- }
- else
- {
- Console.WriteLine(string.Format("value = {0}", pair.Value));
- }
- }
- }
- else
- {
- Console.WriteLine(result.ToString());
- }
-
- }
-
- }
-}
View
796 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Example2.cs
@@ -1,796 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.ComponentModel;
-using System.Collections;
-
-namespace PubNub_Messaging
-{
- public class Pubnub_Example2
- {
- static public bool deliveryStatus = false;
- static public string channel = "testchannel";
- static public string message = "Pubnub API Usage Example - Publish";
- static public Dictionary<long, string> inputs = new Dictionary<long, string>();
- static public object objResponse = null;
-
- 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 long Timestamp (Pubnub pubnub)
- {
- deliveryStatus = false;
-
- pubnub.time(DisplayReturnMessage);
- while (!deliveryStatus) ;
- string strResponse = "";
-
- IList<object> fields = objResponse as IList<object>;
- return Convert.ToInt64(fields[0].ToString());
- }
-
- public static void TestUnencryptedHistory()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false);
- string channel = "testchannel";
- //pubnub.CIPHER_KEY = "";
-
- deliveryStatus = false;
- string message = "Pubnub API Usage Example - Publish";
-
-
- pubnub.publish(channel, message, DisplayReturnMessage);
- while (!deliveryStatus) ;
- pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
- if (e.PropertyName == "History")
- {
- Console.WriteLine("\n*********** History Messages *********** ");
- deliveryStatus = true;
- }
- };
- pubnub.history(channel, 1);
-
- deliveryStatus = false;
-
- while (!deliveryStatus) ;
- Console.WriteLine("\n*********** Publish *********** ");
- if (pubnub.History[0].Equals (null)) {
- Console.WriteLine("Null response");
- }
- else
- {
- Console.WriteLine(pubnub.History[0].ToString());
- }
- }
-
- public static void TestEncryptedHistory()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "enigma",
- false);
- string channel = "testchannel";
-
- deliveryStatus = false;
- string message = "Pubnub API Usage Example - Publish";
-
- pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == "History")
- {
- Console.WriteLine("\n*********** History Messages *********** ");
- deliveryStatus = true;
- }
- };
- deliveryStatus = false;
- pubnub.publish(channel, message, DisplayReturnMessage);
- while (!deliveryStatus) ;
-
- deliveryStatus = false;
- pubnub.history(channel, 1);
- while (!deliveryStatus) ;
- if (pubnub.History[0].Equals (null)) {
- Console.WriteLine("Null response");
- }
- else
- {
- Console.WriteLine(pubnub.History[0].ToString());
- }
- }
-
- public static void TestUnencryptedDetailedHistory()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false);
- string channel = "testchannel";
- //pubnub.CIPHER_KEY = "";
- 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++)
- {
- 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);
- while (!deliveryStatus) ;
-
- deliveryStatus = false;
- 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(strResponse);
- j++;
- }
- }
- }
-
- 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*********** ");
- }
-
- 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 BasicEncryptionDecryptionTests ()
- {
- PubnubCrypto pc = new PubnubCrypto("enigma");
-
- string enc = pc.encrypt("Pubnub Messaging API 1");
- Console.WriteLine ("Pubnub Messaging API 1 = " + enc);
- Console.WriteLine ("dec = " + pc.decrypt(enc));
-
- enc = pc.encrypt("yay!");
- Console.WriteLine ("yay = " + enc);
- Console.WriteLine ("dec = " + pc.decrypt(enc));
-
- Console.WriteLine ("Wi24KS4pcTzvyuGOHubiXg==: = " + pc.decrypt("Wi24KS4pcTzvyuGOHubiXg=="));
- Console.WriteLine ("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=: = " + pc.decrypt("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54="));
- Console.WriteLine ("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=: = " + pc.decrypt("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0="));
- Console.WriteLine ("zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF = " + pc.decrypt("zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF"));
- Console.WriteLine ("GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g= = " + pc.decrypt("GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g="));
-
- Console.WriteLine ("IDjZE9BHSjcX67RddfCYYg== = " + pc.decrypt("IDjZE9BHSjcX67RddfCYYg=="));
- Console.WriteLine ("Ns4TB41JjT2NCXaGLWSPAQ== = " + pc.decrypt("Ns4TB41JjT2NCXaGLWSPAQ=="));
-
- Console.WriteLine ("+BY5/miAA8aeuhVl4d13Kg== = " + pc.decrypt("+BY5/miAA8aeuhVl4d13Kg=="));
-
- Console.WriteLine ("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE= = " + pc.decrypt("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE="));
- Console.WriteLine ("q/xJqqN6qbiZMXYmiQC1Fw==: = " + pc.decrypt("q/xJqqN6qbiZMXYmiQC1Fw=="));
- }
-
-
- public static void Publish_Example()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false
- );
- string channel = "hello_world";
- string message = "Pubnub API Usage Example";
-
- deliveryStatus = false;
-
- pubnub.publish(channel, message, DisplayReturnMessage);
- //wait till the response is received from the server
- while (!deliveryStatus) ;
- IList<object> fields = objResponse as IList<object>;
- string strSent = fields[1].ToString();
- string strOne = fields[0].ToString();
- Console.WriteLine("Sent: " + strSent);
- Console.WriteLine("One: " + strOne);
- }
-
- 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);
- }
- }
- }
-
- 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);
- }
-
- }
-
- static void Timestamp_Example()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false
- );
-
- string strResponse = "";
- deliveryStatus = false;
-
- pubnub.time(DisplayReturnMessage);
- while (!deliveryStatus) ;
-
- IList<object> fields = objResponse as IList<object>;
- strResponse = fields[0].ToString();
- Console.WriteLine(strResponse);
- //Assert.AreNotEqual("0",strResponse);
- }
-
- public static void Subscribe_Example ()
- {
- Pubnub pubnub = new Pubnub (
- "demo",
- "demo",
- "",
- "",
- false);
- string channel = "hello_world";
-
- deliveryStatus = false;
-
- pubnub.subscribe (channel, DisplayReturnMessage);
-
- pubnub.publish (channel, "Test Message", DisplayReturnMessage);
-
- bool bStop = false;
- while (!bStop) {
- if (objResponse != null) {
- IList<object> fields = objResponse as IList<object>;
-
- if (fields [0] != null)
- {
- var myObjectArray = (from item in fields select item as object).ToArray ();
- IEnumerable enumerable = myObjectArray [0] as IEnumerable;
- if (enumerable != null) {
- foreach (object element in enumerable)
- {
- Console.WriteLine ("Resp:" + element.ToString ());
- bStop = true;
- }
- }
- }
- }
- }
- }
-
- public static void Presence_Example()
- {
- Pubnub pubnub = new Pubnub (
- "demo",
- "demo",
- "",
- "",
- false);
- string channel = "hello_world";
-
- deliveryStatus = false;
-
- pubnub.presence (channel, DisplayReturnMessage);
- Pubnub pubnub2 = new Pubnub (
- "demo",
- "demo",
- "",
- "",
- false);
-
- pubnub2.subscribe (channel, DisplayReturnMessage);
-
- bool bStop = false;
- while (!bStop) {
- if (objResponse != null) {
- IList<object> fields = objResponse as IList<object>;
-
- if (fields [0] != null)
- {
- var myObjectArray = (from item in fields select item as object).ToArray ();
- IEnumerable enumerable = myObjectArray [0] as IEnumerable;
- if (enumerable != null) {
- foreach (object element in enumerable)
- {
- Console.WriteLine ("Resp:" + element.ToString ());
- //bStop = true;
- }
- }
- }
- }
- }
-
- }
-
- public static void HereNow_Example()
- {
- Pubnub pubnub = new Pubnub(
- "demo",
- "demo",
- "",
- "",
- false
- );
- string channel = "hello_world";
-
- deliveryStatus = false;
-
- pubnub.here_now(channel, DisplayReturnMessage);
- while (!deliveryStatus) ;
-
- string strResponse = "";
- if (objResponse.Equals (null)) {
- Console.WriteLine("Null response");
- }
- else
- {
- IList<object> fields =objResponse as IList<object>;
- foreach(object lst in fields)
- {
- strResponse = lst.ToString();
- Console.WriteLine(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());
- }
- }
- }
-
- static void MessageFeeder(List<object> feed)
- {
- foreach (object message in feed)
- {
- try
- {
- Dictionary<string, object> _messageHistory = (Dictionary<string, object>)(message);
- Console.WriteLine("Key: " + _messageHistory.ElementAt(0).Key + " - Value: " + _messageHistory.ElementAt(0).Value);
- }
- catch
- {
- Console.WriteLine(message.ToString());
- }
- }
- }
-
- static void MessageFeeder(object feed)
- {
- try
- {
- Dictionary<string, object> _message = (Dictionary<string, object>)(feed);
- for (int i = 0; i < _message.Count; i ++)
- Console.WriteLine("Key: " + _message.ElementAt(i).Key + " - Value: " + _message.ElementAt(i).Value);
- }
- catch
- {
- try
- {
- List<object> _message = (List<object>)feed;
- for (int i = 0; i < _message.Count; i++)
- Console.WriteLine(_message[i].ToString());
- }
- catch
- {
- Console.WriteLine("Time: " + feed.ToString());
- }
-
- }
- }
-
- static void DisplayReturnMessage(object result)
- {
- IList<object> message = result as IList<object>;
-
- if (message != null && message.Count >= 2)
- {
- for (int index = 0; index < message.Count; index++)
- {
- ParseObject(message[index], 1);
- }
- }
- else
- {
- Console.WriteLine("unable to parse data");
- }
- deliveryStatus = true;
- objResponse = result;
- }
-
- static void ParseObject(object result, int loop)
- {
- if (result is object[])
- {
- object[] arrResult = (object[])result;
- foreach (object item in arrResult)
- {
- if (!item.GetType().IsGenericType)
- {
- if (!item.GetType().IsArray)
- {
- Console.WriteLine(item.ToString());
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- }
- else if (result.GetType().IsGenericType && (result.GetType().Name == typeof(Dictionary<,>).Name))
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)result;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("key = {0}", pair.Key));
- if (pair.Value is object[])
- {
- Console.WriteLine("value = ");
- ParseObject(pair.Value, loop);
- }
- else
- {
- Console.WriteLine(string.Format("value = {0}", pair.Value));
- }
- }
- }
- else
- {
- Console.WriteLine(result.ToString());
- }
-
- }
- }
-}
-
View
21 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.csproj
@@ -11,24 +11,24 @@
<AssemblyName>PubNub-Messaging</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
- <DebugSymbols>True</DebugSymbols>
+ <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
- <Optimize>False</Optimize>
+ <Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
- <Externalconsole>True</Externalconsole>
+ <Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
- <Optimize>True</Optimize>
+ <Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
- <Externalconsole>True</Externalconsole>
+ <Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -46,17 +46,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
- <Compile Include="PubNub-Example.cs" />
- <Compile Include="PubNub-Example2.cs" />
- <Compile Include="DetailedHistory_Example.cs" />
- <Compile Include="Here_Now_Example.cs" />
- <Compile Include="Presence_Example.cs" />
- <Compile Include="PresenceUnsubscribe_Example.cs" />
- <Compile Include="Subscribe_Example.cs" />
- <Compile Include="Publish_Example.cs" />
<Compile Include="Pubnub.cs" />
- <Compile Include="PubnubBase.cs" />
- <Compile Include="PubnubExtend.cs" />
+ <Compile Include="Pubnub_Example.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
View
BIN mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.pidb
Binary file not shown.
View
114 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Publish_Example.cs
@@ -1,114 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace PubNub_Messaging
-{
- internal static partial class Publish_Example
- {
- 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);
- }
- }
- }
-
- static void DisplayReturnMessage(object result)
- {
- IList<object> message = result as IList<object>;
-
- if (message != null && message.Count >= 2)
- {
- for (int index = 0; index < message.Count; index++)
- {
- ParseObject(message[index], 1);
- }
- }
- else
- {
- Console.WriteLine("unable to parse data");
- }
- }
-
- static void ParseObject(object result, int loop)
- {
- if (result is object[])
- {
- object[] arrResult = (object[])result;
- foreach (object item in arrResult)
- {
- if (!item.GetType().IsGenericType)
- {
- if (!item.GetType().IsArray)
- {
- Console.WriteLine(item.ToString());
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- else
- {
- ParseObject(item, loop + 1);
- }
- }
- }
- else if (result.GetType().IsGenericType && (result.GetType().Name == typeof(Dictionary<,>).Name))
- {
- Dictionary<string, object> itemList = (Dictionary<string, object>)result;
- foreach (KeyValuePair<string, object> pair in itemList)
- {
- Console.WriteLine(string.Format("key = {0}", pair.Key));
- if (pair.Value is object[])
- {
- Console.WriteLine("value = ");
- ParseObject(pair.Value, loop);
- }
- else
- {
- Console.WriteLine(string.Format("value = {0}", pair.Value));
- }
- }
- }
-
- }
-
- //static void DisplayPublishReturnMessage(object result)
- //{
- // List<object> message = result as List<object>;
-
- // if (message != null && message.Count >= 2)
- // {
- // Console.WriteLine(string.Format("[{0}, {1}, {2}]", message[0].ToString(),message[1].ToString(),message[2].ToString()));
- // }
- // else
- // {
- // Console.WriteLine("result is not List<object>");
- // }
- //}
- }
-}
View
396 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub.cs
@@ -1,4 +1,4 @@
-//Build Date: Dec 06, 2012
+//Build Date: Dec 28, 2012
#if (__MonoCS__)
#define TRACE
#endif
@@ -19,9 +19,6 @@
using System.Net.Sockets;
using System.Configuration;
using Microsoft.Win32;
-#if (SILVERLIGHT)
-using TvdP.Collections;
-#endif
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -40,8 +37,8 @@ public class Pubnub : INotifyPropertyChanged
const int PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC = 15;
const int PUBNUB_NETWORK_CHECK_RETRIES = 50;
const int PUBNUB_WEBREQUEST_RETRY_INTERVAL_IN_SEC = 10;
- const bool OVERRIDE_TCP_KEEP_ALIVE = true;
- const LoggingMethod.Level LOG_LEVEL = LoggingMethod.Level.Info;
+ bool OVERRIDE_TCP_KEEP_ALIVE = true;
+ const LoggingMethod.Level LOG_LEVEL = LoggingMethod.Level.Error;
// Common property changed event
public event PropertyChangedEventHandler PropertyChanged;
@@ -60,6 +57,7 @@ public void RaisePropertyChanged(string propertyName)
ConcurrentDictionary<string, bool> _channelInternetStatus = new ConcurrentDictionary<string, bool>();
ConcurrentDictionary<string, int> _channelInternetRetry = new ConcurrentDictionary<string, int>();
ConcurrentDictionary<string, Timer> _channelReconnectTimer = new ConcurrentDictionary<string, Timer>();
+ ConcurrentDictionary<Uri, Timer> _channelHeartbeatTimer = new ConcurrentDictionary<Uri, Timer>();
private IPubnubUnitTest _pubnubUnitTest;
public IPubnubUnitTest PubnubUnitTest
@@ -78,9 +76,6 @@ public IPubnubUnitTest PubnubUnitTest
private static bool _pubnetSystemActive = true;
- // Publish
- private ConcurrentDictionary<string, object> _publishMsg = new ConcurrentDictionary<string, object>();
-
// History of Messages
private List<object> _History = new List<object>();
public List<object> History { get { return _History; } set { _History = value; RaisePropertyChanged("History"); } }
@@ -114,18 +109,18 @@ public IPubnubUnitTest PubnubUnitTest
*/
private void init(string publish_key, string subscribe_key, string secret_key, string cipher_key, bool ssl_on)
{
-#if(MONOTOUCH || SILVERLIGHT || WINDOWS_PHONE)
+#if(MONOTOUCH || MONODROID || SILVERLIGHT || WINDOWS_PHONE)
LoggingMethod.LogLevel = LOG_LEVEL;
-#else
- string strLogLevel = ConfigurationManager.AppSettings["LogLevel"];
- int iLogLevel;
- if (!Int32.TryParse (strLogLevel, out iLogLevel))
- {
- LoggingMethod.LogLevel = LOG_LEVEL;
- }
- else
- {
- LoggingMethod.LogLevel = (LoggingMethod.Level)iLogLevel;
+#else
+ string strLogLevel = ConfigurationManager.AppSettings["PubnubMessaging.LogLevel"];
+ int iLogLevel;
+ if (!Int32.TryParse(strLogLevel, out iLogLevel))
+ {
+ LoggingMethod.LogLevel = LOG_LEVEL;
+ }
+ else
+ {
+ LoggingMethod.LogLevel = (LoggingMethod.Level)iLogLevel;
}
#endif
@@ -187,7 +182,7 @@ void reconnectNetworkCallback<T>(Object reconnectState)
switch (netState.type)
{
case ResponseType.Subscribe:
- _subscribe(netState.channel, netState.timetoken, netState.callback,netState.connectCallback, false);
+ _subscribe(netState.channel, netState.timetoken, netState.callback, netState.connectCallback, false);
break;
case ResponseType.Presence:
_presence(netState.channel, netState.timetoken, netState.callback, false);
@@ -230,7 +225,7 @@ void reconnectNetworkCallback<T>(Object reconnectState)
private void initiatePowerModeCheck()
{
-#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH)
+#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH && !MONODROID)
try
{
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
@@ -244,7 +239,7 @@ private void initiatePowerModeCheck()
#endif
}
-#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH)
+#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH && !MONODROID)
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode == PowerModes.Suspend)
@@ -290,6 +285,7 @@ private void TerminatePendingWebRequest(RequestState state)
{
if (state != null && state.request != null)
{
+ TerminateHeartbeatTimer(state.request.RequestUri);
state.request.Abort();
LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminatePendingWebRequest {1}", DateTime.Now.ToString(), state.request.RequestUri.ToString()), LoggingMethod.LevelInfo);
@@ -309,9 +305,20 @@ private void TerminatePendingWebRequest(RequestState state)
RequestState currReq = _channelRequest[key];
if (currReq.request != null)
{
- currReq.request.Abort();
- LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminatePendingWebRequest {1}", DateTime.Now.ToString(), currReq.request.RequestUri.ToString()), LoggingMethod.LevelInfo);
-
+ if (currReq.type == ResponseType.Subscribe)
+ {
+ unsubscribe<string>(currReq.channel, null);
+ }
+ else if (currReq.type == ResponseType.Presence)
+ {
+ presence_unsubscribe<string>(currReq.channel.Replace("-pnpres", ""), null);
+ }
+ else
+ {
+ TerminateHeartbeatTimer(currReq.request.RequestUri);
+ currReq.request.Abort();
+ LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminatePendingWebRequest {1}", DateTime.Now.ToString(), currReq.request.RequestUri.ToString()), LoggingMethod.LevelInfo);
+ }
bool removeKey = _channelRequest.TryRemove(key, out currReq);
if (!removeKey)
{
@@ -322,7 +329,7 @@ private void TerminatePendingWebRequest(RequestState state)
}
}
-#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH)
+#if (!SILVERLIGHT && !WINDOWS_PHONE && !MONOTOUCH && !MONODROID)
~Pubnub()
{
//detach
@@ -561,41 +568,28 @@ private List<object> decodeDecryptLoop(List<object> message)
* @param String channel name.
* @param Procedure function callback
*/
- public void subscribe(string channel, Action<object> usercallback)
+ public void subscribe(string channel, Action<object> userCallback)
+ {
+ subscribe<object>(channel, userCallback);
+ }
+
+ public void subscribe(string channel, Action<object> userCallback, Action<object> connectCallback)
{
- subscribe<object>(channel, usercallback);
+ subscribe<object>(channel, userCallback, connectCallback);
}
- public void subscribe<T>(string channel, Action<T> usercallback)
+ public void subscribe<T>(string channel, Action<T> userCallback)
{
if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
{
throw new ArgumentException("Missing Channel");
}
- if (usercallback == null)
+ if (userCallback == null)
{
throw new ArgumentException("Missing Callback");
}
- LoggingMethod.WriteToLog(string.Format("DateTime {0}, requested subscribe for channel={1}", DateTime.Now.ToString(), channel), LoggingMethod.LevelInfo);
-
- if (_channelSubscription.ContainsKey(channel))
- {
- List<object> result = new List<object>();
- string jsonString = "[0, \"Already subscribed\"]";
- result = (List<object>)JsonConvert.DeserializeObject<List<object>>(jsonString);
- result.Add(channel);
- LoggingMethod.WriteToLog(string.Format("DateTime {0}, JSON subscribe response={1}", DateTime.Now.ToString(), jsonString), LoggingMethod.LevelInfo);
- goToCallback<T>(result, usercallback);
- }
- else
- {
- object subMsg = _subscribeMsg.TryRemove(channel, out subMsg); //Clear the dictionary received for last sub msg
- _channelSubscription.GetOrAdd(channel, 0);
- resetInternetCheckSettings(channel);
- _subscribe<T>(channel, 0, usercallback, null, false); // connectCallback = null
- }
-
+ subscribeInit<T>(channel, userCallback, null);
}
public void subscribe<T>(string channel, Action<T> userCallback, Action<T> connectCallback)
@@ -613,7 +607,12 @@ public void subscribe<T>(string channel, Action<T> userCallback, Action<T> conne
throw new ArgumentException("Missing connectCallback");
}
- LoggingMethod.WriteToLog(string.Format("DateTime {0}, requested subscribe with connectCallback for channel={1}", DateTime.Now.ToString(), channel), LoggingMethod.LevelInfo);
+ subscribeInit<T>(channel, userCallback, connectCallback);
+ }
+
+ private void subscribeInit<T>(string channel, Action<T> userCallback, Action<T> connectCallback)
+ {
+ LoggingMethod.WriteToLog(string.Format("DateTime {0}, requested subscribe for channel={1}", DateTime.Now.ToString(), channel), LoggingMethod.LevelInfo);
if (_channelSubscription.ContainsKey(channel))
{
@@ -629,7 +628,7 @@ public void subscribe<T>(string channel, Action<T> userCallback, Action<T> conne
object subMsg = _subscribeMsg.TryRemove(channel, out subMsg); //Clear the dictionary received for last sub msg
_channelSubscription.GetOrAdd(channel, 0);
resetInternetCheckSettings(channel);
- _subscribe<T>(channel, 0, userCallback, connectCallback, false);
+ _subscribe<T>(channel, 0, userCallback, connectCallback, false);
}
}
@@ -673,15 +672,6 @@ void OnPubnubWebRequestTimeout(object state, bool timeout)
{
LoggingMethod.WriteToLog(string.Format("DateTime: {0}, OnPubnubWebRequestTimeout: client request timeout reached. However state is unknown", DateTime.Now.ToString()), LoggingMethod.LevelError);
}
-
- if (OVERRIDE_TCP_KEEP_ALIVE)
- {
- //reset heart beat time because http request already timedout
- heartBeatTimer.Change(
- (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000,
- (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000);
- LoggingMethod.WriteToLog(string.Format("DateTime: {0}, OnPubnubWebRequestTimeout: resetting the heartbeat timeout", DateTime.Now.ToString()), LoggingMethod.LevelInfo);
- }
}
}
@@ -692,12 +682,12 @@ void OnPubnubHeartBeatTimeoutCallback(Object heartbeatState)
RequestState currentState = heartbeatState as RequestState;
if (currentState != null)
{
- bool networkConnection = ClientNetworkStatus.checkInternetStatus(_pubnetSystemActive);
-
if (_channelInternetStatus.ContainsKey(currentState.channel)
&& (currentState.type == ResponseType.Subscribe || currentState.type == ResponseType.Presence)
&& OVERRIDE_TCP_KEEP_ALIVE)
{
+ bool networkConnection = ClientNetworkStatus.checkInternetStatus(_pubnetSystemActive);
+
_channelInternetStatus[currentState.channel] = networkConnection;
LoggingMethod.WriteToLog(string.Format("DateTime: {0}, OnPubnubHeartBeatTimeoutCallback - Internet connection = {1}", DateTime.Now.ToString(), networkConnection), LoggingMethod.LevelVerbose);
@@ -713,7 +703,6 @@ void OnPubnubHeartBeatTimeoutCallback(Object heartbeatState)
}
-
/// <summary>
/// Check the response of the REST API and call for re-subscribe
/// </summary>
@@ -743,7 +732,7 @@ private void subscribeInternalCallback<T>(object subscribeResult, Action<T> user
if (message != null && message.Count >= 3)
{
- _subscribe<T>(channelName, (object)message[1], usercallback, connectCallback, false);
+ _subscribe<T>(channelName, (object)message[1], usercallback, connectCallback, false);
}
}
@@ -807,9 +796,10 @@ public void unsubscribe<T>(string channel, Action<T> usercallback)
if (_channelRequest.ContainsKey(channel))
{
PubnubWebRequest storedRequest = _channelRequest[channel].request;
+ TerminateHeartbeatTimer(storedRequest.RequestUri);
storedRequest.Abort();
}
- object subMsg =_subscribeMsg.TryRemove(channel, out subMsg); //Clear the dictionary received for last sub msg
+ object subMsg = _subscribeMsg.TryRemove(channel, out subMsg); //Clear the dictionary received for last sub msg
jsonString = string.Format("[1, \"Unsubscribed from {0}\"]", channel);
}
@@ -849,7 +839,7 @@ public void unsubscribe<T>(string channel, Action<T> usercallback)
* @param Procedure function callback
* @param String timetoken.
*/
- private void _subscribe<T>(string channel, object timetoken, Action<T> userCallback,Action<T> connectCallback, bool reconnect)
+ private void _subscribe<T>(string channel, object timetoken, Action<T> userCallback, Action<T> connectCallback, bool reconnect)
{
//Exit if the channel is unsubscribed
if (!_channelSubscription.ContainsKey(channel))
@@ -897,7 +887,7 @@ private void _subscribe<T>(string channel, object timetoken, Action<T> userCallb
catch (Exception ex)
{
LoggingMethod.WriteToLog(string.Format("DateTime {0} method:_subscribe \n channel={1} \n timetoken={2} \n Exception Details={3}", DateTime.Now.ToString(), channel, timetoken.ToString(), ex.ToString()), LoggingMethod.LevelError);
- this._subscribe<T>(channel, timetoken, userCallback, connectCallback, false);
+ this._subscribe<T>(channel, timetoken, userCallback, connectCallback, false);
}
}
/**
@@ -908,19 +898,19 @@ private void _subscribe<T>(string channel, object timetoken, Action<T> userCallb
* @param String channel name. (+"pnpres")
* @param Procedure function callback
*/
- public void presence(string channel, Action<object> usercallback)
+ public void presence(string channel, Action<object> userCallback)
{
- presence<object>(channel, usercallback);
+ presence<object>(channel, userCallback);
}
- public void presence<T>(string channel, Action<T> usercallback)
+ public void presence<T>(string channel, Action<T> userCallback)
{
if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
{
throw new ArgumentException("Missing Channel");
}
- if (usercallback == null)
+ if (userCallback == null)
{
throw new ArgumentException("Missing Callback");
}
@@ -935,13 +925,13 @@ public void presence<T>(string channel, Action<T> usercallback)
result = (List<object>)JsonConvert.DeserializeObject<List<object>>(jsonString);
result.Add(channel.Replace("-pnpres", ""));
LoggingMethod.WriteToLog(string.Format("DateTime {0}, JSON presence response={1}", DateTime.Now.ToString(), jsonString), LoggingMethod.LevelInfo);
- goToCallback<T>(result, usercallback);
+ goToCallback<T>(result, userCallback);
}
else
{
_channelPresence.GetOrAdd(channel, 0);
resetInternetCheckSettings(channel);
- this._presence<T>(channel, 0, usercallback, false);
+ this._presence<T>(channel, 0, userCallback, false);
}
}
@@ -952,7 +942,7 @@ public void presence<T>(string channel, Action<T> usercallback)
* @param Procedure function callback
* @param String timetoken.
*/
- private void _presence<T>(string channel, object timetoken, Action<T> usercallback, bool reconnect)
+ private void _presence<T>(string channel, object timetoken, Action<T> userCallback, bool reconnect)
{
//Exit if the channel is unsubscribed
if (!_channelPresence.ContainsKey(channel))
@@ -967,7 +957,7 @@ private void _presence<T>(string channel, object timetoken, Action<T> usercallba
if (_channelInternetRetry.ContainsKey(channel) && (_channelInternetRetry[channel] >= PUBNUB_NETWORK_CHECK_RETRIES))
{
LoggingMethod.WriteToLog(string.Format("DateTime {0}, Presence channel={1} - No internet connection. MAXed retries for internet ", DateTime.Now.ToString(), channel), LoggingMethod.LevelInfo);
- presenceExceptionHandler<T>(channel, usercallback, true);
+ presenceExceptionHandler<T>(channel, userCallback, true);
return;
}
@@ -978,7 +968,7 @@ private void _presence<T>(string channel, object timetoken, Action<T> usercallba
ReconnectState<T> netState = new ReconnectState<T>();
netState.channel = channel;
netState.type = ResponseType.Presence;
- netState.callback = usercallback;
+ netState.callback = userCallback;
netState.timetoken = timetoken;
reconnectNetwork<T>(netState);
@@ -993,21 +983,21 @@ private void _presence<T>(string channel, object timetoken, Action<T> usercallba
Uri request = buildPresenceRequest(channel, timetoken);
// Wait for message
- _urlRequest<T>(request, channel, ResponseType.Presence, usercallback, null, reconnect); // connectCallback = null
+ _urlRequest<T>(request, channel, ResponseType.Presence, userCallback, null, reconnect); // connectCallback = null
}
catch (Exception ex)
{
LoggingMethod.WriteToLog(string.Format("method:_presence \n channel={0} \n timetoken={1} \n Exception Details={2}", channel, timetoken.ToString(), ex.ToString()), LoggingMethod.LevelError);
- this._presence<T>(channel, timetoken, usercallback, false);
+ this._presence<T>(channel, timetoken, userCallback, false);
}
}
- public void presence_unsubscribe(string channel, Action<object> usercallback)
+ public void presence_unsubscribe(string channel, Action<object> userCallback)
{
- presence_unsubscribe<object>(channel, usercallback);
+ presence_unsubscribe<object>(channel, userCallback);
}
- public void presence_unsubscribe<T>(string channel, Action<T> usercallback)
+ public void presence_unsubscribe<T>(string channel, Action<T> userCallback)
{
if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
{
@@ -1032,8 +1022,10 @@ public void presence_unsubscribe<T>(string channel, Action<T> usercallback)
if (_channelRequest.ContainsKey(channel))
{
PubnubWebRequest storedRequest = _channelRequest[channel].request;
+ TerminateHeartbeatTimer(storedRequest.RequestUri);
storedRequest.Abort();
}
+ object presenceMsg = _presenceMsg.TryRemove(channel, out presenceMsg); //Clear the dictionary received for last presence msg
jsonString = string.Format("[1, \"Presence-Unsubscribed from {0}\"]", channel.Replace("-pnpres", ""));
}
else
@@ -1046,7 +1038,7 @@ public void presence_unsubscribe<T>(string channel, Action<T> usercallback)
result.Add(channel.Replace("-pnpres", ""));
LoggingMethod.WriteToLog(string.Format("DateTime {0}, JSON presence-unsubscribe response={1}", DateTime.Now.ToString(), jsonString), LoggingMethod.LevelInfo);
- goToCallback<T>(result, usercallback);
+ goToCallback<T>(result, userCallback);
}
else
{
@@ -1055,16 +1047,16 @@ public void presence_unsubscribe<T>(string channel, Action<T> usercallback)
result = (List<object>)JsonConvert.DeserializeObject<List<object>>(jsonString);
result.Add(channel.Replace("-pnpres", ""));
LoggingMethod.WriteToLog(string.Format("DateTime {0}, JSON presence-unsubscribe response={1}", DateTime.Now.ToString(), jsonString), LoggingMethod.LevelInfo);
- goToCallback<T>(result, usercallback);
+ goToCallback<T>(result, userCallback);
}
}
- public bool here_now(string channel, Action<object> usercallback)
+ public bool here_now(string channel, Action<object> userCallback)
{
- return here_now<object>(channel, usercallback);
+ return here_now<object>(channel, userCallback);
}
- public bool here_now<T>(string channel, Action<T> usercallback)
+ public bool here_now<T>(string channel, Action<T> userCallback)
{
if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
{
@@ -1073,7 +1065,7 @@ public bool here_now<T>(string channel, Action<T> usercallback)
Uri request = buildHereNowRequest(channel);
- return _urlRequest<T>(request, channel, ResponseType.Here_Now, usercallback, null, false); // connectCallback = null
+ return _urlRequest<T>(request, channel, ResponseType.Here_Now, userCallback, null, false); // connectCallback = null
}
@@ -1084,16 +1076,16 @@ public bool here_now<T>(string channel, Action<T> usercallback)
*
* @return object timestamp.
*/
- public bool time(Action<object> usercallback)
+ public bool time(Action<object> userCallback)
{
- return time<object>(usercallback);
+ return time<object>(userCallback);
}
- public bool time<T>(Action<T> usercallback)
+ public bool time<T>(Action<T> userCallback)
{
Uri request = buildTimeRequest();
- return _urlRequest<T>(request, "", ResponseType.Time, usercallback, null, false); // connectCallback = null
+ return _urlRequest<T>(request, "", ResponseType.Time, userCallback, null, false); // connectCallback = null
}
/**
@@ -1210,6 +1202,7 @@ private bool _urlRequest<T>(Uri requestUri, string channelName, ResponseType typ
heartBeatTimer = new System.Threading.Timer(
new TimerCallback(OnPubnubHeartBeatTimeoutCallback), pubnubRequestState, 0,
(-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? Timeout.Infinite : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000);
+ _channelHeartbeatTimer.AddOrUpdate(requestUri, heartBeatTimer, (key, oldState) => heartBeatTimer);
}
else
{
@@ -1240,14 +1233,11 @@ private bool _urlRequest<T>(Uri requestUri, string channelName, ResponseType typ
}
// Deserialize the result
string jsonString = streamReader.ReadToEnd();
- Console.WriteLine (jsonString);
streamReader.Close();
if (OVERRIDE_TCP_KEEP_ALIVE)
{
- heartBeatTimer.Change(
- (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000,
- (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000);
+ TerminateHeartbeatTimer(requestUri);
}
LoggingMethod.WriteToLog(string.Format("DateTime {0}, JSON for channel={1} ({2}) ={3}", DateTime.Now.ToString(), channelName, type.ToString(), jsonString), LoggingMethod.LevelInfo);
@@ -1284,7 +1274,13 @@ private bool _urlRequest<T>(Uri requestUri, string channelName, ResponseType typ
{
LoggingMethod.WriteToLog(string.Format("DateTime {0}, WebException: {1} for URL: {2}", DateTime.Now.ToString(), webEx.ToString(), requestUri.ToString()), LoggingMethod.LevelError);
+ if (OVERRIDE_TCP_KEEP_ALIVE)
+ {
+ TerminateHeartbeatTimer(requestUri);
+ }
+
RequestState state = (RequestState)asynchronousResult.AsyncState;
+
if (state.response != null)
{
state.response.Close();
@@ -1353,11 +1349,95 @@ private bool _urlRequest<T>(Uri requestUri, string channelName, ResponseType typ
}
}
+ private void TerminateHeartbeatTimer()
+ {
+ TerminateHeartbeatTimer(null);
+ }
+
+ private void TerminateHeartbeatTimer(Uri requestUri)
+ {
+ if (requestUri != null)
+ {
+ if (_channelHeartbeatTimer.ContainsKey(requestUri))
+ {
+ Timer requestHeatbeatTimer = _channelHeartbeatTimer[requestUri];
+ requestHeatbeatTimer.Change(
+ (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000,
+ (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000);
+ requestHeatbeatTimer.Dispose();
+ Timer removedTimer = null;
+ bool removed = _channelHeartbeatTimer.TryRemove(requestUri, out removedTimer);
+ if (!removed)
+ {
+ LoggingMethod.WriteToLog(string.Format("DateTime {0} Unable to remove heartbeat reference from collection for {1}", DateTime.Now.ToString(), requestUri.ToString()), LoggingMethod.LevelInfo);
+ }
+ }
+ }
+ else
+ {
+ ConcurrentDictionary<Uri, Timer> timerCollection = _channelHeartbeatTimer;
+ ICollection<Uri> keyCol = timerCollection.Keys;
+ foreach (Uri key in keyCol)
+ {
+ Timer currTimer = _channelHeartbeatTimer[key];
+ currTimer.Dispose();
+ Timer removedTimer = null;
+ bool removed = _channelHeartbeatTimer.TryRemove(key, out removedTimer);
+ if (!removed)
+ {
+ LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminateHeartbeatTimer(null) - Unable to remove heartbeat reference from collection for {1}", DateTime.Now.ToString(), key.ToString()), LoggingMethod.LevelInfo);
+ }
+ }
+ }
+ }
+
+ private void TerminateReconnectTimer()
+ {
+ TerminateReconnectTimer(null);
+ }
+
+ private void TerminateReconnectTimer(string channelName)
+ {
+ if (channelName != null)
+ {
+ if (_channelReconnectTimer.ContainsKey(channelName))
+ {
+ Timer channelReconnectTimer = _channelReconnectTimer[channelName];
+ channelReconnectTimer.Change(
+ (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000,
+ (-1 == PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC) ? -1 : PUBNUB_NETWORK_TCP_CHECK_INTERVAL_IN_SEC * 1000);
+ channelReconnectTimer.Dispose();
+ Timer removedTimer = null;
+ bool removed = _channelReconnectTimer.TryRemove(channelName, out removedTimer);
+ if (!removed)
+ {
+ LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminateReconnectTimer - Unable to remove reconnect timer reference from collection for {1}", DateTime.Now.ToString(), channelName), LoggingMethod.LevelInfo);
+ }
+ }
+ }
+ else
+ {
+ ConcurrentDictionary<string, Timer> reconnectCollection = _channelReconnectTimer;
+ ICollection<string> keyCol = reconnectCollection.Keys;
+ foreach (string key in keyCol)
+ {
+ Timer currTimer = _channelReconnectTimer[key];
+ currTimer.Dispose();
+ Timer removedTimer = null;
+ bool removed = _channelReconnectTimer.TryRemove(key, out removedTimer);
+ if (!removed)
+ {
+ LoggingMethod.WriteToLog(string.Format("DateTime {0} TerminateReconnectTimer(null) - Unable to remove reconnect timer reference from collection for {1}", DateTime.Now.ToString(), key.ToString()), LoggingMethod.LevelInfo);
+ }
+ }
+ }
+ }
+
private void responseToConnectCallback<T>(List<object> result, ResponseType type, string channelName, Action<T> connectCallback)
{
//Check callback exists and make sure previous timetoken = 0
- if (connectCallback != null
- && _channelSubscription.ContainsKey(channelName)
+ if (connectCallback != null
+ && _channelSubscription.ContainsKey(channelName)
&& _channelSubscription[channelName].Equals(0))
{
switch (type)
@@ -1585,7 +1665,7 @@ private void urlRequestCommonExceptionHandler<T>(ResponseType type, string chann
}
}
- private void responseToUserCallback<T>(List<object> result, ResponseType type, string channelName, Action<T> usercallback) //where T: class//, new()
+ private void responseToUserCallback<T>(List<object> result, ResponseType type, string channelName, Action<T> usercallback)
{
switch (type)
{
@@ -1836,7 +1916,6 @@ private List<object> WrapResultBasedOnResponseType(ResponseType type, string jso
{
case ResponseType.Publish:
result.Add(channelName);
- _publishMsg.AddOrUpdate(channelName, result, (key, oldValue) => result);
break;
case ResponseType.History:
if (this.CIPHER_KEY.Length > 0)
@@ -1965,13 +2044,21 @@ private string getChannelName(List<string> url_components, ResponseType type)
return channelName;
}
- // Serialize the given object into JSON string
+ /// <summary>
+ /// Serialize the given object into JSON string
+ /// </summary>
+ /// <param name="objectToSerialize"></param>
+ /// <returns></returns>
public static string SerializeToJsonString(object objectToSerialize)
{
return JsonConvert.SerializeObject(objectToSerialize);
}
- // Deserialize JSON string into List of Objects
+ /// <summary>
+ /// Deserialize JSON string into List of Objects
+ /// </summary>
+ /// <param name="jsonString"></param>
+ /// <returns></returns>
public static List<object> DeserializeToListOfObject(string jsonString)
{
return JsonConvert.DeserializeObject<List<object>>(jsonString);
@@ -2010,6 +2097,7 @@ private bool isUnsafe(char ch)
return " ~`!@#$%^&*()+=[]\\{}|;':\",./<>?".IndexOf(ch) >= 0;
}
+
public Guid generateGUID()
{
return Guid.NewGuid();
@@ -2025,19 +2113,36 @@ private static string md5(string text)
return hexaHash;
}
+ /// <summary>
+ /// Convert the UTC/GMT DateTime to Unix Nano Seconds format
+ /// </summary>
+ /// <param name="dotNetUTCDateTime"></param>
+ /// <returns></returns>
public static long translateDateTimeToPubnubUnixNanoSeconds(DateTime dotNetUTCDateTime)
{
TimeSpan ts = dotNetUTCDateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long timestamp = Convert.ToInt64(ts.TotalSeconds) * 10000000;
return timestamp;
}
+ /// <summary>
+ /// Convert the Unix Nano Seconds format time to UTC/GMT DateTime
+ /// </summary>
+ /// <param name="unixNanoSecondTime"></param>
+ /// <returns></returns>
public static DateTime translatePubnubUnixNanoSecondsToDateTime(long unixNanoSecondTime)
{
double timestamp = unixNanoSecondTime / 10000000;
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp);
return dt;
}
+
+ public void EndPendingRequests()
+ {
+ TerminatePendingWebRequest();
+ TerminateHeartbeatTimer();
+ TerminateReconnectTimer();
+ }
}
/// <summary>
@@ -2115,7 +2220,7 @@ static public MD5 Create()
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
+ } ;
#endregion
#region F, G, H and I are basic MD5 functions.
@@ -2634,7 +2739,7 @@ private static string ComputeHash(string input, HashAlgorithm algorithm)
private string GetEncryptionKey()
{
//Compute Hash using the SHA256
-#if (SILVERLIGHT || WINDOWS_PHONE || MONOTOUCH)
+#if (SILVERLIGHT || WINDOWS_PHONE || MONOTOUCH || MONODROID)
string strKeySHA256HashRaw = ComputeHash(this.CIPHER_KEY, new System.Security.Cryptography.SHA256Managed());
#else
string strKeySHA256HashRaw = ComputeHash(this.CIPHER_KEY, new SHA256CryptoServiceProvider());
@@ -2706,8 +2811,9 @@ private string EncryptOrDecrypt(bool type, string plainStr)