PageRenderTime 33ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/DetailedHistory_Example.cs

https://github.com/jhey/pubnub-api
C# | 82 lines | 60 code | 9 blank | 13 comment | 11 complexity | 0a652e96d74275515e574cf57e9dd8dc MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace PubNub_Messaging
  6. {
  7. internal static class DetailedHistory_Example
  8. {
  9. /*public static void Main()
  10. {
  11. DetailedHistoryCountDemo();
  12. Console.ReadLine();
  13. }*/
  14. internal static void DetailedHistoryCountDemo()
  15. {
  16. Pubnub pubnub = new Pubnub(
  17. "demo",
  18. "demo",
  19. "",
  20. "",
  21. false);
  22. string channel = "my_channel";
  23. //Console.WriteLine("Detailed History Count Demo");
  24. //pubnub.detailedHistory(channel, 100, DisplayDetailedHistory);
  25. //Console.WriteLine("Detailed History Count and reverse Demo");
  26. //pubnub.detailedHistory(channel, -1, -1, 100, true, DisplayDetailedHistory);
  27. //Console.WriteLine("Detailed History with start and end");
  28. //pubnub.detailedHistory(channel, 13499635513028988, 13499836911845528, 200, true, DisplayDetailedHistory);
  29. //Console.WriteLine("Detailed History with start");
  30. //pubnub.detailedHistory(channel, 13499635513028988, -1, 100, true, DisplayDetailedHistory);
  31. Console.WriteLine("Detailed History with end");
  32. pubnub.detailedHistory(channel, -1, 13499836911845528, 100, true, DisplayDetailedHistory);
  33. }
  34. static void DisplayDetailedHistory(object result)
  35. {
  36. try
  37. {
  38. IList<object> msg = result as IList<object>;
  39. if (msg != null && msg.Count > 0)
  40. {
  41. object[] history = msg[0] as object[];
  42. if (history != null && history.Length > 0)
  43. {
  44. Console.WriteLine(string.Format("Total history records = {0}", history.Length));
  45. foreach (object item in history)
  46. {
  47. if (!item.GetType().IsGenericType)
  48. {
  49. Console.WriteLine(item.ToString());
  50. }
  51. else if ((item.GetType().IsGenericType) && (item.GetType().Name == typeof(Dictionary<,>).Name))
  52. {
  53. Dictionary<string, object> itemList = (Dictionary<string, object>)item;
  54. foreach (KeyValuePair<string, object> pair in itemList)
  55. {
  56. Console.WriteLine(string.Format("Key = {0}; Value = {1}", pair.Key, pair.Value));
  57. }
  58. }
  59. else
  60. {
  61. Console.WriteLine(string.Format("Unhandled type {0}",item.ToString()));
  62. }
  63. }
  64. }
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. Console.WriteLine(ex.ToString());
  70. }
  71. }
  72. }
  73. }