Permalink
Browse files

Custom UUID

  • Loading branch information...
1 parent 64b45fb commit cafcb2d9fba784df0c6e3accaab57805f37cc6f0 @crimsonred crimsonred committed Mar 6, 2013
Showing with 698 additions and 178 deletions.
  1. +25 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/Andr.Unit-master/Andr.Unit/PubnubUnitTest.cs
  2. +43 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/Andr.Unit-master/Andr.Unit/WhenAClientIsPresented.cs
  3. +5 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/LaunchScreen.cs
  4. +37 −3 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Pubnub.cs
  5. +100 −94 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/Resource.designer.cs
  6. +17 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/layout-large/Launch.axml
  7. +17 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/layout/Launch.axml
  8. +1 −0 mono-for-android/3.3.0.1/Pubnub-Messaging/PubNub_Messaging/Resources/values/Strings.xml
  9. +10 −6 mono-for-android/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.userprefs
  10. BIN mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/PubNub-Messaging.pidb
  11. +37 −3 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub.cs
  12. +15 −0 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub_Example.cs
  13. +5 −3 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Console/app.config
  14. +6 −7 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNub-Messaging.userprefs
  15. BIN mono-for-linux/3.3.0.1/PubNub-Messaging/PubNubTest/PubNub-Messaging.Tests.pidb
  16. +42 −17 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNubTest/PubnubUnitTest.cs
  17. +43 −0 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNubTest/WhenAClientIsPresented.cs
  18. +6 −3 mono-for-linux/3.3.0.1/PubNub-Messaging/PubNubTest/app.config
  19. +37 −3 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/Pubnub.cs
  20. +15 −0 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/PubnubExample.cs
  21. +5 −3 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Console/app.config
  22. +11 −7 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNub-Messaging.userprefs
  23. +42 −17 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNubTest/PubnubUnitTest.cs
  24. +43 −0 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNubTest/WhenAClientIsPresented.cs
  25. +5 −3 mono-for-mac/3.3.0.1/PubNub-Messaging/PubNubTest/app.config
  26. +26 −1 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.Tests/PubnubUnitTest.cs
  27. +43 −0 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.Tests/WhenAClientIsPresented.cs
  28. +2 −5 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging.userprefs
  29. +37 −3 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging/Pubnub.cs
  30. +23 −0 monotouch/3.3.0.1/Pubnub-Messaging/Pubnub-Messaging/Pubnub_MessagingMain.cs
@@ -320,6 +320,28 @@ public bool EnableStubTest
return data;
}
+ private Dictionary<string, string> LoadWhenAClientIsPresentedThenPresenceShouldReturnCustomUUID()
+ {
+ Dictionary<string, string> data = new Dictionary<string, string>();
+#if ((!__MonoCS__) && (!SILVERLIGHT) && (!WINDOWS_PHONE))
+ data.Add("/subscribe/demo/hello_world-pnpres/0/0", "[[],\"13559007117760880\"]");
+ data.Add("/subscribe/demo/testChannel/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"CustomSessionUUIDTest\", \"occupancy\": 1}],\"13559011560379628\"]");
+ data.Add("/subscribe/demo/hello_world-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
+ data.Add("/subscribe/demo/hello_world/0/0", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/hello_world/0/13559006802662768", "[[\"f7wNXpx8Ys8pVJNR5ZHT9g==\"],\"13559014566792816\"]");
+ data.Add("/subscribe/demo/hello_world/0/13559014566792816", "[[],\"13559014566792816\"]");
+#else
+ data.Add("/subscribe/demo/hello_world-pnpres/0/0", "[[],\"13559007117760880\"]");
+ data.Add("/subscribe/demo/hello_world-pnpres/0/13559007117760880", "[[{\"action\": \"join\", \"timestamp\": 1355929955, \"uuid\": \"CustomSessionUUIDTest\", \"occupancy\": 1}],\"13559011560379628\"]");
+ data.Add("/subscribe/demo/hello_world-pnpres/0/13559011560379628", "[[],\"13559011560379628\"]");
+ data.Add("/subscribe/demo/hello_world/0/0", "[[],\"13559006802662768\"]");
+ data.Add("/subscribe/demo/hello_world/0/13559006802662768", "[[\"demo test for stubs\"],\"13559014566792816\"]");
+ data.Add("/subscribe/demo/hello_world/0/13559014566792816", "[[],\"13559014566792816\"]");
+#endif
+ data.Add("/v2/presence/sub_key/demo/channel/hello_world/leave", "{\"action\": \"leave\"}");
+ return data;
+ }
+
public string GetStubResponse(Uri request)
{
Dictionary<string,string> responseDictionary = null;
@@ -341,6 +363,9 @@ public string GetStubResponse(Uri request)
case "IfHereNowIsCalledThenItShouldReturnInfo":
responseDictionary = LoadWhenAClientIsPresentedIfHereNowIsCalledThenItShouldReturnInfo();
break;
+ case "ThenPresenceShouldReturnCustomUUID":
+ responseDictionary = LoadWhenAClientIsPresentedThenPresenceShouldReturnCustomUUID();
+ break;
default:
break;
}
@@ -132,6 +132,49 @@ public void IfHereNowIsCalledWithCipherThenItShouldReturnInfo()
ParseResponse(common.Response);
}
+
+ [Test]
+ public void ThenPresenceShouldReturnCustomUUID()
+ {
+ Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
+
+ Common common = new Common();
+ common.DeliveryStatus = false;
+ common.Response = null;
+
+ pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnCustomUUID");;
+ pubnub.SessionUUID = "CustomSessionUUIDTest";
+
+ string channel = "hello_world";
+
+ pubnub.Presence(channel, common.DisplayReturnMessage);
+
+ pubnub.Subscribe(channel, common.DisplayReturnMessageDummy);
+
+ while (!common.DeliveryStatus) ;
+
+ string response = "";
+ if (common.Response.Equals (null)) {
+ Assert.Fail("Null response");
+ }
+ else
+ {
+ IList<object> responseFields = common.Response as IList<object>;
+ if(responseFields != null)
+ {
+ foreach (object item in responseFields)
+ {
+ response = item.ToString();
+ Console.WriteLine("Response:" + response);
+ }
+ Assert.True((responseFields[0].ToString()).Contains(pubnub.SessionUUID));
+ }
+ else
+ {
+ Assert.Fail("null response");
+ }
+ }
+ }
}
}
@@ -210,6 +210,7 @@ void LaunchClick (object sender, EventArgs e)
ToggleButton tbSsl = FindViewById<ToggleButton> (Resource.Id.tbSsl);
EditText txtCipher = FindViewById<EditText> (Resource.Id.txtCipher);
+ EditText txtCustomUuid = FindViewById<EditText> (Resource.Id.txtCustomUuid);
var mainActivity = new Intent(this, typeof(MainActivity));
@@ -226,6 +227,10 @@ void LaunchClick (object sender, EventArgs e)
mainActivity.PutExtra("Cipher", txtCipher.Text.Trim());
pubnub = new Pubnub ("demo", "demo", "", txtCipher.Text.Trim(), tbSsl.Checked);
+ if(!String.IsNullOrWhiteSpace (txtCustomUuid.Text.Trim()))
+ {
+ pubnub.SessionUUID = txtCustomUuid.Text.Trim();
+ }
bool errorFree = true;
@@ -1,4 +1,4 @@
-//Build Date: Jan 08, 2013
+//Build Date: Jan 15, 2013
#if (__MonoCS__)
#define TRACE
#endif
@@ -129,6 +129,18 @@ public PubnubProxy Proxy
private string sessionUUID = "";
private string parameters = "";
+ public string SessionUUID
+ {
+ get
+ {
+ return sessionUUID;
+ }
+ set
+ {
+ sessionUUID = value;
+ }
+ }
+
/**
* Pubnub instance initialization function
*
@@ -159,8 +171,8 @@ private void Init(string publishKey, string subscribeKey, string secretKey, stri
this.secretKey = secretKey;
this.cipherKey = cipherKey;
this.ssl = sslOn;
- if (this.sessionUUID == "")
- this.sessionUUID = Guid.NewGuid().ToString();
+
+ VerifyOrSetSessionUUID();
// SSL is ON?
if (this.ssl)
@@ -1136,6 +1148,7 @@ private bool ProcessRequest(List<string> urlComponents, ResponseType type)
url.Append(EncodeUricomponent(url_bit, type));
}
+ VerifyOrSetSessionUUID();
if (type == ResponseType.Presence || type == ResponseType.Subscribe)
{
url.Append("?uuid=");
@@ -1184,6 +1197,14 @@ private bool ProcessRequest(List<string> urlComponents, ResponseType type)
}
}
+ private void VerifyOrSetSessionUUID()
+ {
+ if (string.IsNullOrEmpty(this.sessionUUID) || string.IsNullOrEmpty(this.sessionUUID.Trim()))
+ {
+ this.sessionUUID = Guid.NewGuid().ToString();
+ }
+ }
+
/// <summary>
/// Http Get Request process
/// </summary>
@@ -1653,6 +1674,7 @@ private Uri BuildRestApiRequest<T>(List<string> urlComponents, ResponseType type
url.Append(EncodeUricomponent(urlBit, type));
}
+ VerifyOrSetSessionUUID();
if (type == ResponseType.Presence || type == ResponseType.Subscribe || type == ResponseType.Leave)
{
url.Append("?uuid=");
@@ -1662,6 +1684,18 @@ private Uri BuildRestApiRequest<T>(List<string> urlComponents, ResponseType type
if (type == ResponseType.DetailedHistory)
url.Append(parameters);
+#if (WINDOWS_PHONE)
+ if (type == ResponseType.Presence || type == ResponseType.Subscribe || type == ResponseType.Leave || type == ResponseType.DetailedHistory)
+ {
+ url.Append("&nocache=");
+ url.Append(Guid.NewGuid().ToString());
+ }
+ else
+ {
+ url.Append("?nocache=");
+ url.Append(Guid.NewGuid().ToString());
+ }
+#endif
Uri requestUri = new Uri(url.ToString());
Oops, something went wrong.

0 comments on commit cafcb2d

Please sign in to comment.