PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/jhey/pubnub-api
C# | 796 lines | 667 code | 98 blank | 31 comment | 87 complexity | 84b139cab718e3afe3eb3d54eef0c743 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. using System.ComponentModel;
  6. using System.Collections;
  7. namespace PubNub_Messaging
  8. {
  9. public class Pubnub_Example2
  10. {
  11. static public bool deliveryStatus = false;
  12. static public string channel = "testchannel";
  13. static public string message = "Pubnub API Usage Example - Publish";
  14. static public Dictionary<long, string> inputs = new Dictionary<long, string>();
  15. static public object objResponse = null;
  16. public static void TestEncryptedDetailedHistoryParams()
  17. {
  18. Pubnub pubnub = new Pubnub(
  19. "demo",
  20. "demo",
  21. "",
  22. "enigma",
  23. false);
  24. // Context setup for Detailed Histor
  25. //pubnub.CIPHER_KEY = "enigma";
  26. int total_msg = 10;
  27. long starttime = Timestamp(pubnub);
  28. for (int i = 0; i < total_msg / 2; i++)
  29. {
  30. deliveryStatus = false;
  31. string msg = i.ToString();
  32. pubnub.publish(channel, msg, DisplayReturnMessage);
  33. while (!deliveryStatus) ;
  34. //long t = Timestamp();
  35. //inputs.Add(t, msg);
  36. Console.WriteLine("Message # " + i.ToString() + " published");
  37. }
  38. long midtime = Timestamp(pubnub);
  39. for (int i = total_msg / 2; i < total_msg; i++)
  40. {
  41. deliveryStatus = false;
  42. string msg = i.ToString();
  43. pubnub.publish(channel, msg, DisplayReturnMessage);
  44. while (!deliveryStatus) ;
  45. //long t = Timestamp();
  46. //inputs.Add(t, msg);
  47. Console.WriteLine("Message # " + i.ToString() + " published");
  48. }
  49. long endtime = Timestamp(pubnub);
  50. deliveryStatus = false;
  51. pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
  52. {
  53. if (e.PropertyName == "DetailedHistory")
  54. {
  55. Console.WriteLine("\n*********** DetailedHistory Messages *********** ");
  56. /*foreach (object msg_org in (List<object>)((Pubnub)sender).DetailedHistory)
  57. {
  58. Console.WriteLine(msg_org.ToString());
  59. }*/
  60. deliveryStatus = true;
  61. }
  62. };
  63. Console.WriteLine("DetailedHistory with start & end");
  64. pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
  65. while (!deliveryStatus) ;
  66. Console.WriteLine("DetailedHistory with start & reverse = true");
  67. deliveryStatus = false;
  68. pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
  69. while (!deliveryStatus) ;
  70. Console.WriteLine("DetailedHistory with start & reverse = false");
  71. deliveryStatus = false;
  72. pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
  73. while (!deliveryStatus) ;
  74. Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
  75. }
  76. public static long Timestamp (Pubnub pubnub)
  77. {
  78. deliveryStatus = false;
  79. pubnub.time(DisplayReturnMessage);
  80. while (!deliveryStatus) ;
  81. string strResponse = "";
  82. IList<object> fields = objResponse as IList<object>;
  83. return Convert.ToInt64(fields[0].ToString());
  84. }
  85. public static void TestUnencryptedHistory()
  86. {
  87. Pubnub pubnub = new Pubnub(
  88. "demo",
  89. "demo",
  90. "",
  91. "",
  92. false);
  93. string channel = "testchannel";
  94. //pubnub.CIPHER_KEY = "";
  95. deliveryStatus = false;
  96. string message = "Pubnub API Usage Example - Publish";
  97. pubnub.publish(channel, message, DisplayReturnMessage);
  98. while (!deliveryStatus) ;
  99. pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
  100. if (e.PropertyName == "History")
  101. {
  102. Console.WriteLine("\n*********** History Messages *********** ");
  103. deliveryStatus = true;
  104. }
  105. };
  106. pubnub.history(channel, 1);
  107. deliveryStatus = false;
  108. while (!deliveryStatus) ;
  109. Console.WriteLine("\n*********** Publish *********** ");
  110. if (pubnub.History[0].Equals (null)) {
  111. Console.WriteLine("Null response");
  112. }
  113. else
  114. {
  115. Console.WriteLine(pubnub.History[0].ToString());
  116. }
  117. }
  118. public static void TestEncryptedHistory()
  119. {
  120. Pubnub pubnub = new Pubnub(
  121. "demo",
  122. "demo",
  123. "",
  124. "enigma",
  125. false);
  126. string channel = "testchannel";
  127. deliveryStatus = false;
  128. string message = "Pubnub API Usage Example - Publish";
  129. pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
  130. {
  131. if (e.PropertyName == "History")
  132. {
  133. Console.WriteLine("\n*********** History Messages *********** ");
  134. deliveryStatus = true;
  135. }
  136. };
  137. deliveryStatus = false;
  138. pubnub.publish(channel, message, DisplayReturnMessage);
  139. while (!deliveryStatus) ;
  140. deliveryStatus = false;
  141. pubnub.history(channel, 1);
  142. while (!deliveryStatus) ;
  143. if (pubnub.History[0].Equals (null)) {
  144. Console.WriteLine("Null response");
  145. }
  146. else
  147. {
  148. Console.WriteLine(pubnub.History[0].ToString());
  149. }
  150. }
  151. public static void TestUnencryptedDetailedHistory()
  152. {
  153. Pubnub pubnub = new Pubnub(
  154. "demo",
  155. "demo",
  156. "",
  157. "",
  158. false);
  159. string channel = "testchannel";
  160. //pubnub.CIPHER_KEY = "";
  161. int total_msg = 10;
  162. long starttime = Timestamp(pubnub);
  163. Dictionary<long, string> inputs = new Dictionary<long,string>();
  164. for (int i = 0; i < total_msg / 2; i++)
  165. {
  166. deliveryStatus = false;
  167. string msg = i.ToString();
  168. pubnub.publish(channel, msg, DisplayReturnMessage);
  169. while (!deliveryStatus) ;
  170. //long t = Timestamp();
  171. //inputs.Add(t, msg);
  172. Console.WriteLine("Message # " + i.ToString() + " published");
  173. }
  174. long midtime = Timestamp(pubnub);
  175. for (int i = total_msg / 2; i < total_msg; i++)
  176. {
  177. deliveryStatus = false;
  178. string msg = i.ToString();
  179. pubnub.publish(channel, msg, DisplayReturnMessage);
  180. while (!deliveryStatus) ;
  181. //long t = Timestamp();
  182. //inputs.Add(t, msg);
  183. Console.WriteLine("Message # " + i.ToString() + " published");
  184. }
  185. long endtime = Timestamp(pubnub);
  186. while (!deliveryStatus) ;
  187. deliveryStatus = false;
  188. pubnub.detailedHistory(channel, total_msg, DisplayReturnMessage);
  189. deliveryStatus = false;
  190. while (!deliveryStatus) ;
  191. Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
  192. string strResponse = "";
  193. if (objResponse.Equals(null))
  194. {
  195. Console.WriteLine("Null response");
  196. }
  197. else
  198. {
  199. IList<object> fields =objResponse as IList<object>;
  200. int j = 0;
  201. foreach (object item in fields)
  202. {
  203. strResponse = item.ToString();
  204. Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
  205. if(j<total_msg)
  206. Console.WriteLine(strResponse);
  207. j++;
  208. }
  209. }
  210. }
  211. public static void TestEncryptedDetailedHistory()
  212. {
  213. Pubnub pubnub = new Pubnub(
  214. "demo",
  215. "demo",
  216. "",
  217. "enigma",
  218. false);
  219. string channel = "testchannel";
  220. //pubnub.CIPHER_KEY = "enigma";
  221. int total_msg = 10;
  222. long starttime = Timestamp(pubnub);
  223. Dictionary<long, string> inputs = new Dictionary<long, string>();
  224. for (int i = 0; i < total_msg / 2; i++)
  225. {
  226. string msg = i.ToString();
  227. pubnub.publish(channel, msg, DisplayReturnMessage);
  228. while (!deliveryStatus) ;
  229. //long t = Timestamp();
  230. //inputs.Add(t, msg);
  231. Console.WriteLine("Message # " + i.ToString() + " published");
  232. }
  233. long midtime = Timestamp(pubnub);
  234. for (int i = total_msg / 2; i < total_msg; i++)
  235. {
  236. string msg = i.ToString();
  237. pubnub.publish(channel, msg, DisplayReturnMessage);
  238. while (!deliveryStatus) ;
  239. //long t = Timestamp();
  240. //inputs.Add(t, msg);
  241. Console.WriteLine("Message # " + i.ToString() + " published");
  242. }
  243. long endtime = Timestamp(pubnub);
  244. while (!deliveryStatus) ;
  245. pubnub.detailedHistory(channel, total_msg, DisplayReturnMessage);
  246. deliveryStatus = false;
  247. while (!deliveryStatus) ;
  248. Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
  249. string strResponse = "";
  250. if (objResponse.Equals(null))
  251. {
  252. Console.WriteLine("Null response");
  253. }
  254. else
  255. {
  256. IList<object> fields = objResponse as IList<object>;
  257. int j = 0;
  258. foreach (object item in fields)
  259. {
  260. strResponse = item.ToString();
  261. Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
  262. if(j<total_msg)
  263. Console.WriteLine(j.ToString(), strResponse);
  264. j++;
  265. }
  266. }
  267. Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
  268. }
  269. public static void TestUnencryptedDetailedHistoryParams()
  270. {
  271. Pubnub pubnub = new Pubnub(
  272. "demo",
  273. "demo",
  274. "",
  275. "",
  276. false);
  277. string channel = "testchannel";
  278. int total_msg = 10;
  279. long starttime = Timestamp(pubnub);
  280. for (int i = 0; i < total_msg / 2; i++)
  281. {
  282. deliveryStatus = false;
  283. string msg = i.ToString();
  284. pubnub.publish(channel, msg, DisplayReturnMessage);
  285. while (!deliveryStatus) ;
  286. //long t = Timestamp();
  287. //inputs.Add(t, msg);
  288. Console.WriteLine("Message # " + i.ToString() + " published");
  289. }
  290. long midtime = Timestamp(pubnub);
  291. for (int i = total_msg / 2; i < total_msg; i++)
  292. {
  293. deliveryStatus = false;
  294. string msg = i.ToString();
  295. pubnub.publish(channel, msg, DisplayReturnMessage);
  296. while (!deliveryStatus) ;
  297. //long t = Timestamp();
  298. //inputs.Add(t, msg);
  299. Console.WriteLine("Message # " + i.ToString() + " published");
  300. }
  301. long endtime = Timestamp(pubnub);
  302. deliveryStatus = false;
  303. Console.WriteLine("DetailedHistory with start & end");
  304. pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, DisplayReturnMessage);
  305. while (!deliveryStatus) ;
  306. Console.WriteLine("DetailedHistory with start & reverse = true");
  307. string strResponse = "";
  308. if (objResponse.Equals(null))
  309. {
  310. Console.WriteLine("Null response");
  311. }
  312. else
  313. {
  314. IList<object> fields = objResponse as IList<object>;
  315. int j = 0;
  316. foreach (object item in fields)
  317. {
  318. strResponse = item.ToString();
  319. Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
  320. if(j<total_msg/2)
  321. Console.WriteLine(j.ToString(), strResponse);
  322. j++;
  323. }
  324. }
  325. deliveryStatus = false;
  326. pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, DisplayReturnMessage);
  327. while (!deliveryStatus) ;
  328. Console.WriteLine("DetailedHistory with start & reverse = false");
  329. strResponse = "";
  330. if (objResponse.Equals(null))
  331. {
  332. Console.WriteLine("Null response");
  333. }
  334. else
  335. {
  336. IList<object> fields = objResponse as IList<object>;
  337. int j = total_msg / 2;
  338. foreach (object item in fields)
  339. {
  340. strResponse = item.ToString();
  341. Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
  342. if(j<total_msg)
  343. Console.WriteLine(j.ToString(), strResponse);
  344. j++;
  345. }
  346. }
  347. deliveryStatus = false;
  348. pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, DisplayReturnMessage);
  349. while (!deliveryStatus) ;
  350. Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");
  351. strResponse = "";
  352. if (objResponse.Equals(null))
  353. {
  354. Console.WriteLine("Null response");
  355. }
  356. else
  357. {
  358. IList<object> fields = objResponse as IList<object>;
  359. int j = 0;
  360. foreach (object item in fields)
  361. {
  362. strResponse = item.ToString();
  363. Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
  364. if(j<total_msg/2)
  365. Console.WriteLine(j.ToString(), strResponse);
  366. j++;
  367. }
  368. }
  369. }
  370. public static void BasicEncryptionDecryptionTests ()
  371. {
  372. PubnubCrypto pc = new PubnubCrypto("enigma");
  373. string enc = pc.encrypt("Pubnub Messaging API 1");
  374. Console.WriteLine ("Pubnub Messaging API 1 = " + enc);
  375. Console.WriteLine ("dec = " + pc.decrypt(enc));
  376. enc = pc.encrypt("yay!");
  377. Console.WriteLine ("yay = " + enc);
  378. Console.WriteLine ("dec = " + pc.decrypt(enc));
  379. Console.WriteLine ("Wi24KS4pcTzvyuGOHubiXg==: = " + pc.decrypt("Wi24KS4pcTzvyuGOHubiXg=="));
  380. Console.WriteLine ("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=: = " + pc.decrypt("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54="));
  381. Console.WriteLine ("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=: = " + pc.decrypt("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0="));
  382. Console.WriteLine ("zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF = " + pc.decrypt("zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF"));
  383. Console.WriteLine ("GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g= = " + pc.decrypt("GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g="));
  384. Console.WriteLine ("IDjZE9BHSjcX67RddfCYYg== = " + pc.decrypt("IDjZE9BHSjcX67RddfCYYg=="));
  385. Console.WriteLine ("Ns4TB41JjT2NCXaGLWSPAQ== = " + pc.decrypt("Ns4TB41JjT2NCXaGLWSPAQ=="));
  386. Console.WriteLine ("+BY5/miAA8aeuhVl4d13Kg== = " + pc.decrypt("+BY5/miAA8aeuhVl4d13Kg=="));
  387. Console.WriteLine ("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE= = " + pc.decrypt("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE="));
  388. Console.WriteLine ("q/xJqqN6qbiZMXYmiQC1Fw==: = " + pc.decrypt("q/xJqqN6qbiZMXYmiQC1Fw=="));
  389. }
  390. public static void Publish_Example()
  391. {
  392. Pubnub pubnub = new Pubnub(
  393. "demo",
  394. "demo",
  395. "",
  396. "",
  397. false
  398. );
  399. string channel = "hello_world";
  400. string message = "Pubnub API Usage Example";
  401. deliveryStatus = false;
  402. pubnub.publish(channel, message, DisplayReturnMessage);
  403. //wait till the response is received from the server
  404. while (!deliveryStatus) ;
  405. IList<object> fields = objResponse as IList<object>;
  406. string strSent = fields[1].ToString();
  407. string strOne = fields[0].ToString();
  408. Console.WriteLine("Sent: " + strSent);
  409. Console.WriteLine("One: " + strOne);
  410. }
  411. public static void DetailedHistory_Example()
  412. {
  413. Pubnub pubnub = new Pubnub(
  414. "demo",
  415. "demo",
  416. "",
  417. "",
  418. false);
  419. string channel = "testchannel";
  420. //pubnub.CIPHER_KEY = "";
  421. string msg = "Test Message";
  422. deliveryStatus = false;
  423. pubnub.publish(channel, msg, DisplayReturnMessage);
  424. while (!deliveryStatus) ;
  425. deliveryStatus = false;
  426. pubnub.detailedHistory(channel, 10, DisplayReturnMessage);
  427. while (!deliveryStatus) ;
  428. Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
  429. if (objResponse.Equals(null))
  430. {
  431. Console.WriteLine("Null response");
  432. }
  433. else
  434. {
  435. IList<object> fields = objResponse as IList<object>;
  436. foreach (object item in fields)
  437. {
  438. string strResponse = item.ToString();
  439. Console.WriteLine(String.Format("resp:{0}", strResponse));
  440. Console.WriteLine(strResponse);
  441. }
  442. }
  443. }
  444. public static void DetailedHistory_Decrypted_Example()
  445. {
  446. Pubnub pubnub = new Pubnub(
  447. "demo",
  448. "demo",
  449. "",
  450. "enigma",
  451. false);
  452. string channel = "testchannel";
  453. //pubnub.CIPHER_KEY = "enigma";
  454. string msg = "Test Message";
  455. deliveryStatus = false;
  456. pubnub.publish(channel, msg, DisplayReturnMessage);
  457. while (!deliveryStatus) ;
  458. deliveryStatus = false;
  459. pubnub.detailedHistory(channel, 1, DisplayReturnMessage);
  460. while (!deliveryStatus) ;
  461. Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
  462. if (objResponse.Equals(null))
  463. {
  464. Console.WriteLine("Null response");
  465. }
  466. else
  467. {
  468. IList<object> fields = objResponse as IList<object>;
  469. Console.WriteLine("fields[0]: " + fields[0]);
  470. Console.WriteLine("fields[1]: " + fields[1]);
  471. //Assert.AreEqual(fields[0], msg);
  472. }
  473. }
  474. static void Timestamp_Example()
  475. {
  476. Pubnub pubnub = new Pubnub(
  477. "demo",
  478. "demo",
  479. "",
  480. "",
  481. false
  482. );
  483. string strResponse = "";
  484. deliveryStatus = false;
  485. pubnub.time(DisplayReturnMessage);
  486. while (!deliveryStatus) ;
  487. IList<object> fields = objResponse as IList<object>;
  488. strResponse = fields[0].ToString();
  489. Console.WriteLine(strResponse);
  490. //Assert.AreNotEqual("0",strResponse);
  491. }
  492. public static void Subscribe_Example ()
  493. {
  494. Pubnub pubnub = new Pubnub (
  495. "demo",
  496. "demo",
  497. "",
  498. "",
  499. false);
  500. string channel = "hello_world";
  501. deliveryStatus = false;
  502. pubnub.subscribe (channel, DisplayReturnMessage);
  503. pubnub.publish (channel, "Test Message", DisplayReturnMessage);
  504. bool bStop = false;
  505. while (!bStop) {
  506. if (objResponse != null) {
  507. IList<object> fields = objResponse as IList<object>;
  508. if (fields [0] != null)
  509. {
  510. var myObjectArray = (from item in fields select item as object).ToArray ();
  511. IEnumerable enumerable = myObjectArray [0] as IEnumerable;
  512. if (enumerable != null) {
  513. foreach (object element in enumerable)
  514. {
  515. Console.WriteLine ("Resp:" + element.ToString ());
  516. bStop = true;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. }
  523. public static void Presence_Example()
  524. {
  525. Pubnub pubnub = new Pubnub (
  526. "demo",
  527. "demo",
  528. "",
  529. "",
  530. false);
  531. string channel = "hello_world";
  532. deliveryStatus = false;
  533. pubnub.presence (channel, DisplayReturnMessage);
  534. Pubnub pubnub2 = new Pubnub (
  535. "demo",
  536. "demo",
  537. "",
  538. "",
  539. false);
  540. pubnub2.subscribe (channel, DisplayReturnMessage);
  541. bool bStop = false;
  542. while (!bStop) {
  543. if (objResponse != null) {
  544. IList<object> fields = objResponse as IList<object>;
  545. if (fields [0] != null)
  546. {
  547. var myObjectArray = (from item in fields select item as object).ToArray ();
  548. IEnumerable enumerable = myObjectArray [0] as IEnumerable;
  549. if (enumerable != null) {
  550. foreach (object element in enumerable)
  551. {
  552. Console.WriteLine ("Resp:" + element.ToString ());
  553. //bStop = true;
  554. }
  555. }
  556. }
  557. }
  558. }
  559. }
  560. public static void HereNow_Example()
  561. {
  562. Pubnub pubnub = new Pubnub(
  563. "demo",
  564. "demo",
  565. "",
  566. "",
  567. false
  568. );
  569. string channel = "hello_world";
  570. deliveryStatus = false;
  571. pubnub.here_now(channel, DisplayReturnMessage);
  572. while (!deliveryStatus) ;
  573. string strResponse = "";
  574. if (objResponse.Equals (null)) {
  575. Console.WriteLine("Null response");
  576. }
  577. else
  578. {
  579. IList<object> fields =objResponse as IList<object>;
  580. foreach(object lst in fields)
  581. {
  582. strResponse = lst.ToString();
  583. Console.WriteLine(strResponse);
  584. }
  585. Dictionary<string, object> message = (Dictionary<string, object>)fields[0];
  586. foreach(KeyValuePair<String, object> entry in message)
  587. {
  588. Console.WriteLine("value:" + entry.Value + " " + "key:" + entry.Key);
  589. }
  590. object[] objUuid = (object[])message["uuids"];
  591. foreach (object obj in objUuid)
  592. {
  593. Console.WriteLine(obj.ToString());
  594. }
  595. }
  596. }
  597. static void MessageFeeder(List<object> feed)
  598. {
  599. foreach (object message in feed)
  600. {
  601. try
  602. {
  603. Dictionary<string, object> _messageHistory = (Dictionary<string, object>)(message);
  604. Console.WriteLine("Key: " + _messageHistory.ElementAt(0).Key + " - Value: " + _messageHistory.ElementAt(0).Value);
  605. }
  606. catch
  607. {
  608. Console.WriteLine(message.ToString());
  609. }
  610. }
  611. }
  612. static void MessageFeeder(object feed)
  613. {
  614. try
  615. {
  616. Dictionary<string, object> _message = (Dictionary<string, object>)(feed);
  617. for (int i = 0; i < _message.Count; i ++)
  618. Console.WriteLine("Key: " + _message.ElementAt(i).Key + " - Value: " + _message.ElementAt(i).Value);
  619. }
  620. catch
  621. {
  622. try
  623. {
  624. List<object> _message = (List<object>)feed;
  625. for (int i = 0; i < _message.Count; i++)
  626. Console.WriteLine(_message[i].ToString());
  627. }
  628. catch
  629. {
  630. Console.WriteLine("Time: " + feed.ToString());
  631. }
  632. }
  633. }
  634. static void DisplayReturnMessage(object result)
  635. {
  636. IList<object> message = result as IList<object>;
  637. if (message != null && message.Count >= 2)
  638. {
  639. for (int index = 0; index < message.Count; index++)
  640. {
  641. ParseObject(message[index], 1);
  642. }
  643. }
  644. else
  645. {
  646. Console.WriteLine("unable to parse data");
  647. }
  648. deliveryStatus = true;
  649. objResponse = result;
  650. }
  651. static void ParseObject(object result, int loop)
  652. {
  653. if (result is object[])
  654. {
  655. object[] arrResult = (object[])result;
  656. foreach (object item in arrResult)
  657. {
  658. if (!item.GetType().IsGenericType)
  659. {
  660. if (!item.GetType().IsArray)
  661. {
  662. Console.WriteLine(item.ToString());
  663. }
  664. else
  665. {
  666. ParseObject(item, loop + 1);
  667. }
  668. }
  669. else
  670. {
  671. ParseObject(item, loop + 1);
  672. }
  673. }
  674. }
  675. else if (result.GetType().IsGenericType && (result.GetType().Name == typeof(Dictionary<,>).Name))
  676. {
  677. Dictionary<string, object> itemList = (Dictionary<string, object>)result;
  678. foreach (KeyValuePair<string, object> pair in itemList)
  679. {
  680. Console.WriteLine(string.Format("key = {0}", pair.Key));
  681. if (pair.Value is object[])
  682. {
  683. Console.WriteLine("value = ");
  684. ParseObject(pair.Value, loop);
  685. }
  686. else
  687. {
  688. Console.WriteLine(string.Format("value = {0}", pair.Value));
  689. }
  690. }
  691. }
  692. else
  693. {
  694. Console.WriteLine(result.ToString());
  695. }
  696. }
  697. }
  698. }