diff --git a/csharp.net/PubNub-Messaging.Tests/PubnubUnitTest.cs b/csharp.net/PubNub-Messaging.Tests/PubnubUnitTest.cs index e31306120..bdf839bc0 100644 --- a/csharp.net/PubNub-Messaging.Tests/PubnubUnitTest.cs +++ b/csharp.net/PubNub-Messaging.Tests/PubnubUnitTest.cs @@ -197,14 +197,17 @@ public bool EnableStubTest data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D//%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A/%22%20zxcvbnm%2C/%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD123%22%7D%2C%7B%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD456%22%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //FOR WP7. Difference where there is ./ data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD123%22%7D%2C%7B%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD456%22%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"Welcome to the world of Pubnub for Publish and Subscribe. Hah!\"},\"SampleXml\":[{\"Name\":{\"First\":\"John\",\"Middle\":\"P.\",\"Last\":\"Doe\"},\"Address\":{\"Street\":\"123 Duck Street\",\"City\":\"New City\",\"State\":\"New York\",\"Country\":\"United States\"},\"ID\":\"ABCD123\"},{\"Name\":{\"First\":\"Peter\",\"Middle\":\"Z.\",\"Last\":\"Smith\"},\"Address\":{\"Street\":\"12 Hollow Street\",\"City\":\"Philadelphia\",\"State\":\"Pennsylvania\",\"Country\":\"United States\"},\"ID\":\"ABCD456\"}]}],13735400879163600,13735400879163600]"); +#elif (__MonoCS__) + data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"This is a demo message\"}}],13735400879163600,13735400879163600]"); //For mono + data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22This%20is%20a%20demo%20message%22%7D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //Mono #else -#if USE_JSONFX - data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"Welcome to the world of Pubnub for Publish and Subscribe. Hah!\"},\"SampleXml\":[{\"ID\":\"ABCD123\",\"Name\":{\"First\":\"John\",\"Middle\":\"P.\",\"Last\":\"Doe\"},\"Address\":{\"Street\":\"123 Duck Street\",\"City\":\"New City\",\"State\":\"New York\",\"Country\":\"United States\"}},{\"ID\":\"ABCD456\",\"Name\":{\"First\":\"Peter\",\"Middle\":\"Z.\",\"Last\":\"Smith\"},\"Address\":{\"Street\":\"12 Hollow Street\",\"City\":\"Philadelphia\",\"State\":\"Pennsylvania\",\"Country\":\"United States\"}}]}],13735400879163600,13735400879163600]"); //JsonFX - data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22ID%22%3A%22ABCD123%22%2C%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%7D%2C%7B%22ID%22%3A%22ABCD456%22%2C%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //JsonFx -#else - data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"Welcome to the world of Pubnub for Publish and Subscribe. Hah!\"},\"SampleXml\":[{\"Name\":{\"First\":\"John\",\"Middle\":\"P.\",\"Last\":\"Doe\"},\"Address\":{\"Street\":\"123 Duck Street\",\"City\":\"New City\",\"State\":\"New York\",\"Country\":\"United States\"},\"ID\":\"ABCD123\"},{\"Name\":{\"First\":\"Peter\",\"Middle\":\"Z.\",\"Last\":\"Smith\"},\"Address\":{\"Street\":\"12 Hollow Street\",\"City\":\"Philadelphia\",\"State\":\"Pennsylvania\",\"Country\":\"United States\"},\"ID\":\"ABCD456\"}]}],13735400879163600,13735400879163600]"); //Newton Json.NET - data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD123%22%7D%2C%7B%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD456%22%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //Newton Json.NET -#endif + #if USE_JSONFX + data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"Welcome to the world of Pubnub for Publish and Subscribe. Hah!\"},\"SampleXml\":[{\"ID\":\"ABCD123\",\"Name\":{\"First\":\"John\",\"Middle\":\"P.\",\"Last\":\"Doe\"},\"Address\":{\"Street\":\"123 Duck Street\",\"City\":\"New City\",\"State\":\"New York\",\"Country\":\"United States\"}},{\"ID\":\"ABCD456\",\"Name\":{\"First\":\"Peter\",\"Middle\":\"Z.\",\"Last\":\"Smith\"},\"Address\":{\"Street\":\"12 Hollow Street\",\"City\":\"Philadelphia\",\"State\":\"Pennsylvania\",\"Country\":\"United States\"}}]}],13735400879163600,13735400879163600]"); //JsonFX + data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22ID%22%3A%22ABCD123%22%2C%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%7D%2C%7B%22ID%22%3A%22ABCD456%22%2C%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //JsonFx + #else + data.Add("/v2/history/sub-key/demo-36/channel/hello_my_channel", "[[{\"VersionID\":3.4,\"Timetoken\":\"13601488652764619\",\"OperationName\":\"Publish\",\"Channels\":[\"ch1\"],\"DemoMessage\":{\"DefaultMessage\":\"~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\\\ {}| asdfghjkl;' :\\\" zxcvbnm,./ <>? \"},\"CustomMessage\":{\"DefaultMessage\":\"Welcome to the world of Pubnub for Publish and Subscribe. Hah!\"},\"SampleXml\":[{\"Name\":{\"First\":\"John\",\"Middle\":\"P.\",\"Last\":\"Doe\"},\"Address\":{\"Street\":\"123 Duck Street\",\"City\":\"New City\",\"State\":\"New York\",\"Country\":\"United States\"},\"ID\":\"ABCD123\"},{\"Name\":{\"First\":\"Peter\",\"Middle\":\"Z.\",\"Last\":\"Smith\"},\"Address\":{\"Street\":\"12 Hollow Street\",\"City\":\"Philadelphia\",\"State\":\"Pennsylvania\",\"Country\":\"United States\"},\"ID\":\"ABCD456\"}]}],13735400879163600,13735400879163600]"); //Newton Json.NET + data.Add("/publish/demo-36/demo-36/0/hello_my_channel/0/%7B%22VersionID%22%3A3.4%2C%22Timetoken%22%3A%2213601488652764619%22%2C%22OperationName%22%3A%22Publish%22%2C%22Channels%22%3A%5B%22ch1%22%5D%2C%22DemoMessage%22%3A%7B%22DefaultMessage%22%3A%22%7E%21%40%23%24%25%5E%26%2A%28%29_%2B%20%601234567890-%3D%20qwertyuiop%5B%5D%5C%5C%20%7B%7D%7C%20asdfghjkl%3B%27%20%3A%5C%22%20zxcvbnm%2C.%2F%20%3C%3E%3F%20%22%7D%2C%22CustomMessage%22%3A%7B%22DefaultMessage%22%3A%22Welcome%20to%20the%20world%20of%20Pubnub%20for%20Publish%20and%20Subscribe.%20Hah%21%22%7D%2C%22SampleXml%22%3A%5B%7B%22Name%22%3A%7B%22First%22%3A%22John%22%2C%22Middle%22%3A%22P.%22%2C%22Last%22%3A%22Doe%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%22123%20Duck%20Street%22%2C%22City%22%3A%22New%20City%22%2C%22State%22%3A%22New%20York%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD123%22%7D%2C%7B%22Name%22%3A%7B%22First%22%3A%22Peter%22%2C%22Middle%22%3A%22Z.%22%2C%22Last%22%3A%22Smith%22%7D%2C%22Address%22%3A%7B%22Street%22%3A%2212%20Hollow%20Street%22%2C%22City%22%3A%22Philadelphia%22%2C%22State%22%3A%22Pennsylvania%22%2C%22Country%22%3A%22United%20States%22%7D%2C%22ID%22%3A%22ABCD456%22%7D%5D%7D", "[1,\"Sent\",\"13602210467298480\"]"); //Newton Json.NET + #endif #endif return data; } diff --git a/csharp.net/PubNub-Messaging/PubnubCore.cs b/csharp.net/PubNub-Messaging/PubnubCore.cs index 5466dc540..5bdaab004 100644 --- a/csharp.net/PubNub-Messaging/PubnubCore.cs +++ b/csharp.net/PubNub-Messaging/PubnubCore.cs @@ -1,4 +1,4 @@ -//Build Date: March 24, 2015 +//Build Date: May 11, 2015 #region "Header" #if (UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_ANDROID || UNITY_IOS) #define USE_JSONFX_UNITY_IOS @@ -1027,6 +1027,43 @@ private void RemoveChannelDictionary(RequestState state) } } + private void RemoveChannelCallback(string channel, ResponseType type) + { + string[] arrChannels = channel.Split(','); + if (arrChannels != null && arrChannels.Length > 0) + { + foreach (string arrChannel in arrChannels) + { + PubnubChannelCallbackKey callbackKey = new PubnubChannelCallbackKey(); + callbackKey.Channel = arrChannel; + switch (type) + { + case ResponseType.Unsubscribe: + callbackKey.Type = ResponseType.Subscribe; + break; + case ResponseType.PresenceUnsubscribe: + callbackKey.Type = ResponseType.Presence; + break; + default: + callbackKey.Type = ResponseType.Time; //overriding the default + break; + } + + if (channelCallbacks.Count > 0 && channelCallbacks.ContainsKey(callbackKey)) + { + PubnubChannelCallback currentPubnubCallback = channelCallbacks[callbackKey] as PubnubChannelCallback; + if (currentPubnubCallback != null) + { + currentPubnubCallback.Callback = null; + currentPubnubCallback.ConnectCallback = null; + } + } + + } + } + + } + private void RemoveChannelCallback() { ICollection channelCollection = channelCallbacks.Keys; @@ -1043,6 +1080,43 @@ private void RemoveChannelCallback() } } + private void RemoveChannelGroupCallback(string channelGroup, ResponseType type) + { + string[] arrChannelGroups = channelGroup.Split(','); + if (arrChannelGroups != null && arrChannelGroups.Length > 0) + { + foreach (string arrChannelGroup in arrChannelGroups) + { + PubnubChannelGroupCallbackKey callbackKey = new PubnubChannelGroupCallbackKey(); + callbackKey.ChannelGroup = arrChannelGroup; + switch (type) + { + case ResponseType.Unsubscribe: + callbackKey.Type = ResponseType.Subscribe; + break; + case ResponseType.PresenceUnsubscribe: + callbackKey.Type = ResponseType.Presence; + break; + default: + callbackKey.Type = ResponseType.Time; //overriding the default + break; + } + + if (channelGroupCallbacks.Count > 0 && channelGroupCallbacks.ContainsKey(callbackKey)) + { + PubnubChannelGroupCallback currentPubnubCallback = channelGroupCallbacks[callbackKey] as PubnubChannelGroupCallback; + if (currentPubnubCallback != null) + { + currentPubnubCallback.Callback = null; + currentPubnubCallback.ConnectCallback = null; + } + } + + } + } + + } + private void RemoveChannelGroupCallback() { ICollection channelGroupCollection = channelGroupCallbacks.Keys; @@ -3165,8 +3239,15 @@ private void MultiChannelUnSubscribeInit (ResponseType type, string channel, if (_channelRequest.ContainsKey(multiChannelName)) { - LoggingMethod.WriteToLog (string.Format ("DateTime {0}, Aborting previous subscribe/presence requests having channel(s)={1}; channelgroup(s)={2}", DateTime.Now.ToString (), multiChannelName, multiChannelGroupName), LoggingMethod.LevelInfo); - PubnubWebRequest webRequest = _channelRequest[multiChannelName]; + string[] arrValidChannels = validChannels.ToArray(); + RemoveChannelCallback(string.Join(",", arrValidChannels), type); + + string[] arrValidChannelGroups = validChannels.ToArray(); + RemoveChannelGroupCallback(string.Join(",", arrValidChannelGroups), type); + + LoggingMethod.WriteToLog(string.Format("DateTime {0}, Aborting previous subscribe/presence requests having channel(s)={1}; channelgroup(s)={2}", DateTime.Now.ToString(), multiChannelName, multiChannelGroupName), LoggingMethod.LevelInfo); + + PubnubWebRequest webRequest = _channelRequest[multiChannelName]; _channelRequest[multiChannelName] = null; if (webRequest != null) { @@ -4973,7 +5054,9 @@ private void ResponseToConnectCallback (List result, ResponseType typ PubnubChannelGroupCallback currentPubnubCallback = channelGroupCallbacks[callbackKey] as PubnubChannelGroupCallback; if (currentPubnubCallback != null && currentPubnubCallback.ConnectCallback != null) { - GoToCallback(connectResult, currentPubnubCallback.ConnectCallback); + Action targetCallback = currentPubnubCallback.ConnectCallback; + currentPubnubCallback.ConnectCallback = null; + GoToCallback(connectResult, targetCallback); } } break; @@ -4991,7 +5074,9 @@ private void ResponseToConnectCallback (List result, ResponseType typ PubnubChannelGroupCallback currentPubnubCallback = channelGroupCallbacks[pCallbackKey] as PubnubChannelGroupCallback; if (currentPubnubCallback != null && currentPubnubCallback.ConnectCallback != null) { - GoToCallback(connectResult, currentPubnubCallback.ConnectCallback); + Action targetCallback = currentPubnubCallback.ConnectCallback; + currentPubnubCallback.ConnectCallback = null; + GoToCallback(connectResult, targetCallback); } } break; @@ -7247,36 +7332,49 @@ public object DeserializeToObject (string jsonString) public class NewtonsoftJsonDotNet : IJsonPluggableLibrary { #region IJsonPlugableLibrary methods implementation + private bool IsValidJson(string jsonString) + { + bool ret = false; + try + { + JObject.Parse(jsonString); + ret = true; + } + catch { } + return ret; + } public bool IsArrayCompatible (string jsonString) { bool ret = false; - JsonTextReader reader = new JsonTextReader (new StringReader (jsonString)); - while (reader.Read ()) { - if (reader.LineNumber == 1 && reader.LinePosition == 1 && reader.TokenType == JsonToken.StartArray) { - ret = true; - break; - } else { - break; - } - } - + if (IsValidJson(jsonString)){ + JsonTextReader reader = new JsonTextReader(new StringReader(jsonString)); + while (reader.Read()){ + if (reader.LineNumber == 1 && reader.LinePosition == 1 && reader.TokenType == JsonToken.StartArray){ + ret = true; + break; + } else { + break; + } + } + } return ret; } public bool IsDictionaryCompatible (string jsonString) { bool ret = false; - JsonTextReader reader = new JsonTextReader (new StringReader (jsonString)); - while (reader.Read ()) { - if (reader.LineNumber == 1 && reader.LinePosition == 1 && reader.TokenType == JsonToken.StartObject) { - ret = true; - break; - } else { - break; - } - } - + if (IsValidJson(jsonString)){ + JsonTextReader reader = new JsonTextReader(new StringReader(jsonString)); + while (reader.Read()){ + if (reader.LineNumber == 1 && reader.LinePosition == 1 && reader.TokenType == JsonToken.StartObject){ + ret = true; + break; + } else { + break; + } + } + } return ret; } @@ -7435,10 +7533,18 @@ private static object ConvertJTokenToDictionary(JToken token) if (jsonObject != null) { var jsonDict = new Dictionary(); - (from childToken in token - where childToken is JProperty select childToken as JProperty) - .ToList() - .ForEach(property => jsonDict.Add(property.Name, ConvertJTokenToDictionary(property.Value))); + List propertyList = (from childToken in token + where childToken is JProperty + select childToken as JProperty).ToList(); + foreach (JProperty property in propertyList) + { + jsonDict.Add(property.Name, ConvertJTokenToDictionary(property.Value)); + } + + //(from childToken in token + // where childToken is JProperty select childToken as JProperty) + // .ToList() + // .ForEach(property => jsonDict.Add(property.Name, ConvertJTokenToDictionary(property.Value))); return jsonDict; }