diff --git a/.pubnub.yml b/.pubnub.yml index 22e8b5a07..fba2a8153 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,13 @@ name: c-sharp -version: "6.20.0" +version: "6.20.1" schema: 1 scm: github.com/pubnub/c-sharp changelog: + - date: 2024-05-09 + version: v6.20.1 + changes: + - type: bug + text: "Fixes issue of Unity SDK not being able to have a fully independent IJsonPluggableLibrary implementation because of direct nu-get Newtonsoft usage in C# SDK (Unity has it's own version that works with IL2CPP builds)." - date: 2024-04-18 version: v6.20.0 changes: @@ -783,7 +788,7 @@ features: - QUERY-PARAM supported-platforms: - - version: Pubnub 'C#' 6.20.0 + version: Pubnub 'C#' 6.20.1 platforms: - Windows 10 and up - Windows Server 2008 and up @@ -793,7 +798,7 @@ supported-platforms: - .Net Framework 4.5 - .Net Framework 4.6.1+ - - version: PubnubPCL 'C#' 6.20.0 + version: PubnubPCL 'C#' 6.20.1 platforms: - Xamarin.Android - Xamarin.iOS @@ -813,7 +818,7 @@ supported-platforms: - .Net Core - .Net 6.0 - - version: PubnubUWP 'C#' 6.20.0 + version: PubnubUWP 'C#' 6.20.1 platforms: - Windows Phone 10 - Universal Windows Apps @@ -837,7 +842,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: Pubnub - location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.1.0 requires: - name: ".Net" @@ -1120,7 +1125,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: PubNubPCL - location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.1.0 requires: - name: ".Net Core" @@ -1479,7 +1484,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: PubnubUWP - location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.20.1.0 requires: - name: "Universal Windows Platform Development" diff --git a/CHANGELOG b/CHANGELOG index fca743687..aecab45e3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v6.20.1 - May 09 2024 +----------------------------- +- Fixed: fixes issue of Unity SDK not being able to have a fully independent IJsonPluggableLibrary implementation because of direct nu-get Newtonsoft usage in C# SDK (Unity has it's own version that works with IL2CPP builds). + v6.20.0 - April 18 2024 ----------------------------- - Added: added event engine implementation for subscribe and presence operation. diff --git a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs index f60425703..4142c946d 100644 --- a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs +++ b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs @@ -127,7 +127,7 @@ private void Subscribe(string[] channels, string[] channelGroups, SubscriptionCu } else { var subscribeManager = new SubscribeManager2(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, pubnubTokenMgr, PubnubInstance); var eventEmitter = new EventEmitter(config, SubscribeListenerList, jsonLibrary, pubnubTokenMgr, pubnubLog, PubnubInstance); - subscribeEventEngine = subscribeEventEngineFactory.InitializeEventEngine(instanceId, PubnubInstance, config, subscribeManager, eventEmitter, StatusEmitter); + subscribeEventEngine = subscribeEventEngineFactory.InitializeEventEngine(instanceId, PubnubInstance, config, subscribeManager, eventEmitter, jsonLibrary, StatusEmitter); subscribeEventEngine.OnStateTransition += SubscribeEventEngine_OnStateTransition; subscribeEventEngine.OnEventQueued += SubscribeEventEngine_OnEventQueued; subscribeEventEngine.OnEffectDispatch += SubscribeEventEngine_OnEffectDispatch; diff --git a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs index 0edb4f90a..d6c809293 100644 --- a/src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs +++ b/src/Api/PubnubApi/EndPoint/PubSub/SubscribeManager2.cs @@ -114,7 +114,7 @@ public async Task> HandshakeRequest(PNOperati if (!string.IsNullOrEmpty(responseTuple.Item1) && responseTuple.Item2 == null) { PNStatus status = new PNStatus(null, PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectedCategory, channels, channelGroups); - HandshakeResponse handshakeResponse = JsonConvert.DeserializeObject(responseTuple.Item1); + HandshakeResponse handshakeResponse = jsonLibrary.DeserializeToObject(responseTuple.Item1); return new Tuple(handshakeResponse, status); } @@ -170,7 +170,7 @@ internal async Task, PNStatus>> ReceiveRequest receiveResponse = JsonConvert.DeserializeObject>(responseTuple.Item1); + ReceivingResponse receiveResponse = jsonLibrary.DeserializeToObject>(responseTuple.Item1); return new Tuple, PNStatus>(receiveResponse, status); } else if (responseTuple.Item2 != null) @@ -550,6 +550,10 @@ private PNStatus GetStatusIfError(RequestState asyncRequestState, string j status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(type, category, asyncRequestState, statusCode, new PNException(jsonString)); } } + else if (deserializeStatus.ContainsKey("message") && statusCode != 200) { + PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, deserializeStatus["message"].ToString()); + status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(type, category, asyncRequestState, statusCode, new PNException(jsonString)); + } } else if (jsonString.ToLowerInvariant().TrimStart().IndexOf("(object e) Timetoken = pnFileResult.Timetoken, Publisher = pnFileResult.Publisher, }; - Dictionary pnMsgObjDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(pnFileResult.Message); + Dictionary pnMsgObjDic = jsonLibrary.ConvertToDictionaryObject(pnFileResult.Message); if (pnMsgObjDic != null && pnMsgObjDic.Count > 0) { if (pnMsgObjDic.ContainsKey("message") && pnMsgObjDic["message"] != null) { fileMessage.Message = pnMsgObjDic["message"]; } if (pnMsgObjDic.ContainsKey("file")) { - Dictionary fileObjDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(pnMsgObjDic["file"]); + Dictionary fileObjDic = jsonLibrary.ConvertToDictionaryObject(pnMsgObjDic["file"]); if (fileObjDic != null && fileObjDic.ContainsKey("id") && fileObjDic.ContainsKey("name")) { fileMessage.File = new PNFile { Id = fileObjDic["id"].ToString(), Name = fileObjDic["name"].ToString() }; diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitMessagesHandler.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitMessagesHandler.cs index dd68568d0..a5f7a23d6 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitMessagesHandler.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitMessagesHandler.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using PubnubApi.EventEngine.Common; using PubnubApi.EventEngine.Core; using PubnubApi.EventEngine.Subscribe.Invocations; @@ -14,18 +12,18 @@ public class EmitMessagesHandler : EffectHandler { private readonly Dictionary channelTypeMap; private readonly Dictionary channelGroupTypeMap; - private readonly JsonSerializer serializer; + private readonly IJsonPluggableLibrary jsonPluggableLibrary; private readonly EventEmitter eventEmitter; public EmitMessagesHandler(EventEmitter eventEmitter, - JsonSerializer serializer, + IJsonPluggableLibrary jsonPluggableLibrary, Dictionary channelTypeMap = null, Dictionary channelGroupTypeMap = null) { this.eventEmitter = eventEmitter; this.channelTypeMap = channelTypeMap; this.channelGroupTypeMap = channelGroupTypeMap; - this.serializer = serializer; + this.jsonPluggableLibrary = jsonPluggableLibrary; } public async override Task Run(EmitMessagesInvocation invocation) @@ -45,17 +43,14 @@ public async override Task Run(EmitMessagesInvocation invocation) private object DeserializePayload(string key, object rawMessage) { try { - if (rawMessage is JObject message) { - Type t; - if ((channelTypeMap is not null && channelTypeMap.TryGetValue(key, out t) || - channelGroupTypeMap is not null && channelGroupTypeMap.TryGetValue(key, out t)) && - t != typeof(string)) { - return message.ToObject(t, serializer); - } else { - return message.ToString(Formatting.None); - } + Type t; + if ((channelTypeMap is not null && channelTypeMap.TryGetValue(key, out t) || + channelGroupTypeMap is not null && channelGroupTypeMap.TryGetValue(key, out t)) && + t != typeof(string)) + { + return jsonPluggableLibrary.DeserializeToObject(rawMessage, t); } else { - return rawMessage; + return rawMessage.ToString(); } } catch (Exception) { return rawMessage; diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs index 5867c2782..5b49f0039 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; using System.Linq; using PubnubApi.EventEngine.Subscribe.Common; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; using PubnubApi.EventEngine.Subscribe.Events; using PubnubApi.EventEngine.Common; @@ -17,11 +15,7 @@ public class SubscribeEventEngine : Engine private SubscribeManager2 subscribeManager; private readonly Dictionary channelTypeMap = new Dictionary(); private readonly Dictionary channelGroupTypeMap = new Dictionary(); - - private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings() - { Formatting = Formatting.None, DateParseHandling = DateParseHandling.None }; - private static readonly JsonSerializer Serializer = JsonSerializer.Create(SerializerSettings); - + private readonly IJsonPluggableLibrary jsonPluggableLibrary; public string[] Channels { get; set; } = new string[] {}; public string[] Channelgroups { get; set; } = new string[] {}; @@ -30,9 +24,11 @@ internal SubscribeEventEngine(Pubnub pubnubInstance, PNConfiguration pubnubConfiguration, SubscribeManager2 subscribeManager, EventEmitter eventEmitter, + IJsonPluggableLibrary jsonPluggableLibrary, Action statusListener = null) { this.subscribeManager = subscribeManager; + this.jsonPluggableLibrary = jsonPluggableLibrary; var handshakeHandler = new Effects.HandshakeEffectHandler(subscribeManager, EventQueue); var handshakeReconnectHandler = new Effects.HandshakeReconnectEffectHandler(pubnubConfiguration, EventQueue, handshakeHandler); @@ -49,7 +45,7 @@ internal SubscribeEventEngine(Pubnub pubnubInstance, dispatcher.Register(receiveReconnectHandler); dispatcher.Register(receiveReconnectHandler); - var emitMessageHandler = new Effects.EmitMessagesHandler(eventEmitter, Serializer, channelTypeMap, channelGroupTypeMap); + var emitMessageHandler = new Effects.EmitMessagesHandler(eventEmitter, jsonPluggableLibrary, channelTypeMap, channelGroupTypeMap); dispatcher.Register(emitMessageHandler); var emitStatusHandler = new Effects.EmitStatusEffectHandler(pubnubInstance, statusListener); diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngineFactory.cs b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngineFactory.cs index 31397ddfc..7c51dd158 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngineFactory.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngineFactory.cs @@ -28,10 +28,11 @@ internal SubscribeEventEngine InitializeEventEngine(string instanceId, PNConfiguration pubnubConfiguration, SubscribeManager2 subscribeManager, EventEmitter eventEmitter, + IJsonPluggableLibrary jsonPluggableLibrary, Action statusListener = null) { - var subscribeEventEngine = new SubscribeEventEngine(pubnubInstance, pubnubConfiguration: pubnubConfiguration, subscribeManager,eventEmitter, statusListener); + var subscribeEventEngine = new SubscribeEventEngine(pubnubInstance, pubnubConfiguration: pubnubConfiguration, subscribeManager,eventEmitter, jsonPluggableLibrary, statusListener); if (engineInstances.TryAdd(instanceId, subscribeEventEngine)) { return subscribeEventEngine; } diff --git a/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs b/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs index cf4c6ad25..0e6a2b70d 100644 --- a/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs +++ b/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; namespace PubnubApi { @@ -17,7 +19,9 @@ public interface IJsonPluggableLibrary T DeserializeToObject(string jsonString); T DeserializeToObject(List listObject); - + + object DeserializeToObject(object rawObject, Type type); + Dictionary DeserializeToDictionaryOfObject(string jsonString); Dictionary ConvertToDictionaryObject(object localContainer); diff --git a/src/Api/PubnubApi/JsonDataParse/DeserializeToInternalObjectUtility.cs b/src/Api/PubnubApi/JsonDataParse/DeserializeToInternalObjectUtility.cs new file mode 100644 index 000000000..73d215306 --- /dev/null +++ b/src/Api/PubnubApi/JsonDataParse/DeserializeToInternalObjectUtility.cs @@ -0,0 +1,1006 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace PubnubApi +{ + public static class DeserializeToInternalObjectUtility + { + public static T DeserializeToInternalObject(IJsonPluggableLibrary jsonPlug, List listObject) + { + T ret = default(T); + + if (listObject == null) + { + return ret; + } + + if (typeof(T) == typeof(PNAccessManagerGrantResult)) + { + #region "PNAccessManagerGrantResult" + + PNAccessManagerGrantResult result = PNAccessManagerGrantJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerGrantResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNAccessManagerTokenResult)) + { + #region "PNAccessManagerTokenResult" + + PNAccessManagerTokenResult result = PNGrantTokenJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerTokenResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNAccessManagerRevokeTokenResult)) + { + #region "PNAccessManagerRevokeTokenResult" + + PNAccessManagerRevokeTokenResult result = PNRevokeTokenJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerRevokeTokenResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNAccessManagerAuditResult)) + { + #region "PNAccessManagerAuditResult" + + Dictionary auditDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNAccessManagerAuditResult ack = null; + + if (auditDicObj != null) + { + ack = new PNAccessManagerAuditResult(); + + if (auditDicObj.ContainsKey("payload")) + { + Dictionary auditAckPayloadDic = + jsonPlug.ConvertToDictionaryObject(auditDicObj["payload"]); + if (auditAckPayloadDic != null && auditAckPayloadDic.Count > 0) + { + if (auditAckPayloadDic.ContainsKey("level")) + { + ack.Level = auditAckPayloadDic["level"].ToString(); + } + + if (auditAckPayloadDic.ContainsKey("subscribe_key")) + { + ack.SubscribeKey = auditAckPayloadDic["subscribe_key"].ToString(); + } + + if (auditAckPayloadDic.ContainsKey("channel")) + { + ack.Channel = auditAckPayloadDic["channel"].ToString(); + } + + if (auditAckPayloadDic.ContainsKey("channel-group")) + { + ack.ChannelGroup = auditAckPayloadDic["channel-group"].ToString(); + } + + if (auditAckPayloadDic.ContainsKey("auths")) + { + Dictionary auditAckAuthListDic = + jsonPlug.ConvertToDictionaryObject(auditAckPayloadDic["auths"]); + if (auditAckAuthListDic != null && auditAckAuthListDic.Count > 0) + { + ack.AuthKeys = new Dictionary(); + + foreach (string authKey in auditAckAuthListDic.Keys) + { + Dictionary authDataDic = + jsonPlug.ConvertToDictionaryObject(auditAckAuthListDic[authKey]); + if (authDataDic != null && authDataDic.Count > 0) + { + PNAccessManagerKeyData authData = new PNAccessManagerKeyData(); + authData.ReadEnabled = authDataDic["r"].ToString() == "1"; + authData.WriteEnabled = authDataDic["w"].ToString() == "1"; + authData.ManageEnabled = authDataDic.ContainsKey("m") + ? authDataDic["m"].ToString() == "1" + : false; + authData.DeleteEnabled = authDataDic.ContainsKey("d") + ? authDataDic["d"].ToString() == "1" + : false; + + ack.AuthKeys.Add(authKey, authData); + } + } + } + } + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNAccessManagerAuditResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPublishResult)) + { + #region "PNPublishResult" + + PNPublishResult result = null; + if (listObject.Count >= 2) + { + long publishTimetoken; + var _ = Int64.TryParse(listObject[2].ToString(), out publishTimetoken); + result = new PNPublishResult + { + Timetoken = publishTimetoken + }; + } + + ret = (T)Convert.ChangeType(result, typeof(PNPublishResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPresenceEventResult)) + { + #region "PNPresenceEventResult" + + Dictionary presenceDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNPresenceEventResult ack = null; + + if (presenceDicObj != null) + { + ack = new PNPresenceEventResult(); + ack.Event = presenceDicObj["action"].ToString(); + long presenceTimeStamp; + if (Int64.TryParse(presenceDicObj["timestamp"].ToString(), out presenceTimeStamp)) + { + ack.Timestamp = presenceTimeStamp; + } + + if (presenceDicObj.ContainsKey("uuid")) + { + ack.Uuid = presenceDicObj["uuid"].ToString(); + } + + int presenceOccupany; + if (Int32.TryParse(presenceDicObj["occupancy"].ToString(), out presenceOccupany)) + { + ack.Occupancy = presenceOccupany; + } + + if (presenceDicObj.ContainsKey("data")) + { + Dictionary stateDic = presenceDicObj["data"] as Dictionary; + if (stateDic != null) + { + ack.State = stateDic; + } + } + + long presenceTimetoken; + if (Int64.TryParse(listObject[2].ToString(), out presenceTimetoken)) + { + ack.Timetoken = presenceTimetoken; + } + + ack.Channel = (listObject.Count == 6) ? listObject[5].ToString() : listObject[4].ToString(); + ack.Channel = ack.Channel.Replace("-pnpres", ""); + + if (listObject.Count == 6) + { + ack.Subscription = listObject[4].ToString(); + ack.Subscription = ack.Subscription.Replace("-pnpres", ""); + } + + if (listObject[1] != null) + { + ack.UserMetadata = listObject[1]; + } + + if (ack.Event != null && ack.Event.ToLowerInvariant() == "interval") + { + if (presenceDicObj.ContainsKey("join")) + { + List joinDeltaList = presenceDicObj["join"] as List; + if (joinDeltaList != null && joinDeltaList.Count > 0) + { + ack.Join = joinDeltaList.Select(x => x.ToString()).ToArray(); + } + } + + if (presenceDicObj.ContainsKey("timeout")) + { + List timeoutDeltaList = presenceDicObj["timeout"] as List; + if (timeoutDeltaList != null && timeoutDeltaList.Count > 0) + { + ack.Timeout = timeoutDeltaList.Select(x => x.ToString()).ToArray(); + } + } + + if (presenceDicObj.ContainsKey("leave")) + { + List leaveDeltaList = presenceDicObj["leave"] as List; + if (leaveDeltaList != null && leaveDeltaList.Count > 0) + { + ack.Leave = leaveDeltaList.Select(x => x.ToString()).ToArray(); + } + } + + if (presenceDicObj.ContainsKey("here_now_refresh")) + { + string hereNowRefreshStr = presenceDicObj["here_now_refresh"].ToString(); + if (!string.IsNullOrEmpty(hereNowRefreshStr)) + { + bool boolHereNowRefresh = false; + if (Boolean.TryParse(hereNowRefreshStr, out boolHereNowRefresh)) + { + ack.HereNowRefresh = boolHereNowRefresh; + } + } + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNPresenceEventResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNHistoryResult)) + { + #region "PNHistoryResult" + + PNHistoryResult result = PNHistoryJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNHistoryResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNFetchHistoryResult)) + { + #region "PNFetchHistoryResult" + + PNFetchHistoryResult result = PNFetchHistoryJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNFetchHistoryResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNDeleteMessageResult)) + { + #region "PNDeleteMessageResult" + + PNDeleteMessageResult ack = new PNDeleteMessageResult(); + ret = (T)Convert.ChangeType(ack, typeof(PNDeleteMessageResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNMessageCountResult)) + { + #region "PNMessageCountResult" + + PNMessageCountResult ack = null; + Dictionary messageCouuntContainerDicObj = + jsonPlug.ConvertToDictionaryObject(listObject[0]); + if (messageCouuntContainerDicObj != null && messageCouuntContainerDicObj.ContainsKey("channels")) + { + ack = new PNMessageCountResult(); + Dictionary messageCountDic = + jsonPlug.ConvertToDictionaryObject(messageCouuntContainerDicObj["channels"]); + if (messageCountDic != null) + { + ack.Channels = new Dictionary(); + foreach (string channel in messageCountDic.Keys) + { + long msgCount = 0; + if (Int64.TryParse(messageCountDic[channel].ToString(), out msgCount)) + { + ack.Channels.Add(channel, msgCount); + } + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNMessageCountResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNHereNowResult)) + { + #region "PNHereNowResult" + + Dictionary herenowDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNHereNowResult hereNowResult = null; + + if (herenowDicObj != null) + { + hereNowResult = new PNHereNowResult(); + + string hereNowChannelName = listObject[1].ToString(); + + if (herenowDicObj.ContainsKey("payload")) + { + Dictionary hereNowPayloadDic = + jsonPlug.ConvertToDictionaryObject(herenowDicObj["payload"]); + if (hereNowPayloadDic != null && hereNowPayloadDic.Count > 0) + { + int hereNowTotalOccupancy; + int hereNowTotalChannel; + if (Int32.TryParse(hereNowPayloadDic["total_occupancy"].ToString(), + out hereNowTotalOccupancy)) + { + hereNowResult.TotalOccupancy = hereNowTotalOccupancy; + } + + if (Int32.TryParse(hereNowPayloadDic["total_channels"].ToString(), out hereNowTotalChannel)) + { + hereNowResult.TotalChannels = hereNowTotalChannel; + } + + if (hereNowPayloadDic.ContainsKey("channels")) + { + Dictionary hereNowChannelListDic = + jsonPlug.ConvertToDictionaryObject(hereNowPayloadDic["channels"]); + if (hereNowChannelListDic != null && hereNowChannelListDic.Count > 0) + { + foreach (string channel in hereNowChannelListDic.Keys) + { + Dictionary hereNowChannelItemDic = + jsonPlug.ConvertToDictionaryObject(hereNowChannelListDic[channel]); + if (hereNowChannelItemDic != null && hereNowChannelItemDic.Count > 0) + { + PNHereNowChannelData channelData = new PNHereNowChannelData(); + channelData.ChannelName = channel; + int hereNowOccupancy; + if (Int32.TryParse(hereNowChannelItemDic["occupancy"].ToString(), + out hereNowOccupancy)) + { + channelData.Occupancy = hereNowOccupancy; + } + + if (hereNowChannelItemDic.ContainsKey("uuids")) + { + object[] hereNowChannelUuidList = + jsonPlug.ConvertToObjectArray(hereNowChannelItemDic["uuids"]); + if (hereNowChannelUuidList != null && hereNowChannelUuidList.Length > 0) + { + List uuidDataList = + new List(); + + for (int index = 0; index < hereNowChannelUuidList.Length; index++) + { + if (hereNowChannelUuidList[index].GetType() == typeof(string)) + { + PNHereNowOccupantData uuidData = + new PNHereNowOccupantData(); + uuidData.Uuid = hereNowChannelUuidList[index].ToString(); + uuidDataList.Add(uuidData); + } + else + { + Dictionary hereNowChannelItemUuidsDic = + jsonPlug.ConvertToDictionaryObject( + hereNowChannelUuidList[index]); + if (hereNowChannelItemUuidsDic != null && + hereNowChannelItemUuidsDic.Count > 0) + { + PNHereNowOccupantData uuidData = + new PNHereNowOccupantData(); + uuidData.Uuid = hereNowChannelItemUuidsDic["uuid"] + .ToString(); + if (hereNowChannelItemUuidsDic.ContainsKey("state")) + { + uuidData.State = + jsonPlug.ConvertToDictionaryObject( + hereNowChannelItemUuidsDic["state"]); + } + + uuidDataList.Add(uuidData); + } + } + } + + channelData.Occupants = uuidDataList; + } + } + + hereNowResult.Channels.Add(channel, channelData); + } + } + } + } + } + } + else if (herenowDicObj.ContainsKey("occupancy")) + { + int hereNowTotalOccupancy; + if (Int32.TryParse(herenowDicObj["occupancy"].ToString(), out hereNowTotalOccupancy)) + { + hereNowResult.TotalOccupancy = hereNowTotalOccupancy; + } + + hereNowResult.Channels = new Dictionary(); + if (herenowDicObj.ContainsKey("uuids")) + { + object[] uuidArray = jsonPlug.ConvertToObjectArray(herenowDicObj["uuids"]); + if (uuidArray != null && uuidArray.Length > 0) + { + List uuidDataList = new List(); + for (int index = 0; index < uuidArray.Length; index++) + { + Dictionary hereNowChannelItemUuidsDic = + jsonPlug.ConvertToDictionaryObject(uuidArray[index]); + if (hereNowChannelItemUuidsDic != null && hereNowChannelItemUuidsDic.Count > 0) + { + PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); + uuidData.Uuid = hereNowChannelItemUuidsDic["uuid"].ToString(); + if (hereNowChannelItemUuidsDic.ContainsKey("state")) + { + uuidData.State = + jsonPlug.ConvertToDictionaryObject(hereNowChannelItemUuidsDic["state"]); + } + + uuidDataList.Add(uuidData); + } + else + { + PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); + uuidData.Uuid = uuidArray[index].ToString(); + uuidDataList.Add(uuidData); + } + } + + PNHereNowChannelData channelData = new PNHereNowChannelData(); + channelData.ChannelName = hereNowChannelName; + channelData.Occupants = uuidDataList; + channelData.Occupancy = hereNowResult.TotalOccupancy; + + hereNowResult.Channels.Add(hereNowChannelName, channelData); + hereNowResult.TotalChannels = hereNowResult.Channels.Count; + } + } + else + { + string channels = listObject[1].ToString(); + string[] arrChannel = channels.Split(','); + int totalChannels = 0; + foreach (string channel in arrChannel) + { + PNHereNowChannelData channelData = new PNHereNowChannelData(); + channelData.Occupancy = 1; + hereNowResult.Channels.Add(channel, channelData); + totalChannels++; + } + + hereNowResult.TotalChannels = totalChannels; + } + } + } + + ret = (T)Convert.ChangeType(hereNowResult, typeof(PNHereNowResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNWhereNowResult)) + { + #region "WhereNowAck" + + Dictionary wherenowDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNWhereNowResult ack = null; + + if (wherenowDicObj != null) + { + ack = new PNWhereNowResult(); + + if (wherenowDicObj.ContainsKey("payload")) + { + Dictionary whereNowPayloadDic = + jsonPlug.ConvertToDictionaryObject(wherenowDicObj["payload"]); + if (whereNowPayloadDic != null && whereNowPayloadDic.Count > 0) + { + if (whereNowPayloadDic.ContainsKey("channels")) + { + object[] whereNowChannelList = + jsonPlug.ConvertToObjectArray(whereNowPayloadDic["channels"]); + if (whereNowChannelList != null && whereNowChannelList.Length >= 0) + { + List channelList = new List(); + foreach (string channel in whereNowChannelList) + { + channelList.Add(channel); + } + + ack.Channels = channelList; + } + } + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNWhereNowResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNSetStateResult)) + { + #region "SetUserStateAck" + + Dictionary setUserStatewDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNSetStateResult ack = null; + + if (setUserStatewDicObj != null) + { + ack = new PNSetStateResult(); + + ack.State = new Dictionary(); + + if (setUserStatewDicObj.ContainsKey("payload")) + { + Dictionary setStateDic = + jsonPlug.ConvertToDictionaryObject(setUserStatewDicObj["payload"]); + if (setStateDic != null) + { + ack.State = setStateDic; + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNSetStateResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetStateResult)) + { + #region "PNGetStateResult" + + Dictionary getUserStatewDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNGetStateResult ack = null; + + if (getUserStatewDicObj != null) + { + ack = new PNGetStateResult(); + + ack.StateByUUID = new Dictionary(); + + if (getUserStatewDicObj.ContainsKey("payload")) + { + Dictionary getStateDic = + jsonPlug.ConvertToDictionaryObject(getUserStatewDicObj["payload"]); + if (getStateDic != null) + { + ack.StateByUUID = getStateDic; + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNGetStateResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelGroupsAllChannelsResult)) + { + #region "PNChannelGroupsAllChannelsResult" + + Dictionary getCgChannelsDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNChannelGroupsAllChannelsResult ack = null; + + if (getCgChannelsDicObj != null) + { + ack = new PNChannelGroupsAllChannelsResult(); + Dictionary getCgChannelPayloadDic = + jsonPlug.ConvertToDictionaryObject(getCgChannelsDicObj["payload"]); + if (getCgChannelPayloadDic != null && getCgChannelPayloadDic.Count > 0) + { + ack.ChannelGroup = getCgChannelPayloadDic["group"].ToString(); + object[] channelGroupChPayloadChannels = + jsonPlug.ConvertToObjectArray(getCgChannelPayloadDic["channels"]); + if (channelGroupChPayloadChannels != null && channelGroupChPayloadChannels.Length > 0) + { + List channelList = new List(); + for (int index = 0; index < channelGroupChPayloadChannels.Length; index++) + { + channelList.Add(channelGroupChPayloadChannels[index].ToString()); + } + + ack.Channels = channelList; + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsAllChannelsResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelGroupsListAllResult)) + { + #region "PNChannelGroupsListAllResult" + + Dictionary getAllCgDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNChannelGroupsListAllResult ack = null; + + if (getAllCgDicObj != null) + { + ack = new PNChannelGroupsListAllResult(); + + Dictionary getAllCgPayloadDic = + jsonPlug.ConvertToDictionaryObject(getAllCgDicObj["payload"]); + if (getAllCgPayloadDic != null && getAllCgPayloadDic.Count > 0) + { + object[] channelGroupAllCgPayloadChannels = + jsonPlug.ConvertToObjectArray(getAllCgPayloadDic["groups"]); + if (channelGroupAllCgPayloadChannels != null && channelGroupAllCgPayloadChannels.Length > 0) + { + List allCgList = new List(); + for (int index = 0; index < channelGroupAllCgPayloadChannels.Length; index++) + { + allCgList.Add(channelGroupAllCgPayloadChannels[index].ToString()); + } + + ack.Groups = allCgList; + } + } + } + + ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsListAllResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelGroupsAddChannelResult)) + { + #region "AddChannelToChannelGroupAck" + + Dictionary addChToCgDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNChannelGroupsAddChannelResult ack = null; + + if (addChToCgDicObj != null) + { + ack = new PNChannelGroupsAddChannelResult(); + } + + ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsAddChannelResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelGroupsRemoveChannelResult)) + { + #region "PNChannelGroupsRemoveChannelResult" + + Dictionary removeChFromCgDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNChannelGroupsRemoveChannelResult ack = null; + + int statusCode = 0; + + if (removeChFromCgDicObj != null) + { + ack = new PNChannelGroupsRemoveChannelResult(); + + if (int.TryParse(removeChFromCgDicObj["status"].ToString(), out statusCode)) + { + ack.Status = statusCode; + } + + ack.Message = removeChFromCgDicObj["message"].ToString(); + ack.Service = removeChFromCgDicObj["service"].ToString(); + + ack.Error = Convert.ToBoolean(removeChFromCgDicObj["error"].ToString(), + CultureInfo.InvariantCulture); + + ack.ChannelGroup = listObject[1].ToString(); + } + + ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsRemoveChannelResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelGroupsDeleteGroupResult)) + { + #region "PNChannelGroupsDeleteGroupResult" + + Dictionary removeCgDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + + PNChannelGroupsDeleteGroupResult ack = null; + + int statusCode = 0; + + if (removeCgDicObj != null) + { + ack = new PNChannelGroupsDeleteGroupResult(); + + if (int.TryParse(removeCgDicObj["status"].ToString(), out statusCode)) + { + ack.Status = statusCode; + } + + ack.Service = removeCgDicObj["service"].ToString(); + ack.Message = removeCgDicObj["message"].ToString(); + + ack.Error = Convert.ToBoolean(removeCgDicObj["error"].ToString(), CultureInfo.InvariantCulture); + } + + ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsDeleteGroupResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNTimeResult)) + { + #region "PNTimeResult" + + Int64 timetoken = 0; + + var _ = Int64.TryParse(listObject[0].ToString(), out timetoken); + + PNTimeResult result = new PNTimeResult + { + Timetoken = timetoken + }; + + ret = (T)Convert.ChangeType(result, typeof(PNTimeResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPushAddChannelResult)) + { + #region "PNPushAddChannelResult" + + PNPushAddChannelResult result = new PNPushAddChannelResult(); + + ret = (T)Convert.ChangeType(result, typeof(PNPushAddChannelResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPushListProvisionsResult)) + { + #region "PNPushListProvisionsResult" + + PNPushListProvisionsResult result = new PNPushListProvisionsResult(); + result.Channels = listObject.OfType().Where(s => s.Trim() != "").ToList(); + + ret = (T)Convert.ChangeType(result, typeof(PNPushListProvisionsResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPushRemoveChannelResult)) + { + #region "PNPushRemoveChannelResult" + + PNPushRemoveChannelResult result = new PNPushRemoveChannelResult(); + + ret = (T)Convert.ChangeType(result, typeof(PNPushRemoveChannelResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPushRemoveAllChannelsResult)) + { + #region "PNPushRemoveAllChannelsResult" + + PNPushRemoveAllChannelsResult result = new PNPushRemoveAllChannelsResult(); + + ret = (T)Convert.ChangeType(result, typeof(PNPushRemoveAllChannelsResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNHeartbeatResult)) + { + #region "PNHeartbeatResult" + + Dictionary heartbeatDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); + PNHeartbeatResult result = null; + + if (heartbeatDicObj != null && heartbeatDicObj.ContainsKey("status")) + { + result = new PNHeartbeatResult(); + + int statusCode; + if (int.TryParse(heartbeatDicObj["status"].ToString(), out statusCode)) + { + result.Status = statusCode; + } + + if (heartbeatDicObj.ContainsKey("message")) + { + result.Message = heartbeatDicObj["message"].ToString(); + } + } + + ret = (T)Convert.ChangeType(result, typeof(PNHeartbeatResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNSetUuidMetadataResult)) + { + #region "PNSetUuidMetadataResult" + + PNSetUuidMetadataResult result = PNSetUuidMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNSetUuidMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNRemoveUuidMetadataResult)) + { + #region "PNDeleteUuidMetadataResult" + + PNRemoveUuidMetadataResult ack = new PNRemoveUuidMetadataResult(); + ret = (T)Convert.ChangeType(ack, typeof(PNRemoveUuidMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetAllUuidMetadataResult)) + { + #region "PNGetAllUuidMetadataResult" + + PNGetAllUuidMetadataResult result = PNGetAllUuidMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGetAllUuidMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetUuidMetadataResult)) + { + #region "PNGetUuidMetadataResult" + + PNGetUuidMetadataResult result = PNGetUuidMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGetUuidMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNSetChannelMetadataResult)) + { + #region "PNSetChannelMetadataResult" + + PNSetChannelMetadataResult result = PNSetChannelMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNSetChannelMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNRemoveChannelMetadataResult)) + { + #region "PNDeleteUserResult" + + PNRemoveChannelMetadataResult ack = new PNRemoveChannelMetadataResult(); + ret = (T)Convert.ChangeType(ack, typeof(PNRemoveChannelMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetAllChannelMetadataResult)) + { + #region "PNGetSpacesResult" + + PNGetAllChannelMetadataResult result = PNGetAllChannelMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGetAllChannelMetadataResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetChannelMetadataResult)) + { + #region "PNGetSpaceResult" + + PNGetChannelMetadataResult result = PNGetChannelMetadataJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGetChannelMetadataResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNMembershipsResult)) + { + #region "PNMembershipsResult" + + PNMembershipsResult result = PNMembershipsJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNMembershipsResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNChannelMembersResult)) + { + #region "PNChannelMembersResult" + + PNChannelMembersResult result = PNChannelMembersJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNChannelMembersResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNObjectEventResult)) + { + #region "PNObjectEventResult" + + PNObjectEventResult result = PNObjectEventJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNObjectEventResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNMessageActionEventResult)) + { + #region "PNMessageActionEventResult" + + PNMessageActionEventResult result = PNMessageActionEventJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNMessageActionEventResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNAddMessageActionResult)) + { + #region "PNAddMessageActionResult" + + PNAddMessageActionResult result = PNAddMessageActionJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNAddMessageActionResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNRemoveMessageActionResult)) + { + #region "PNRemoveMessageActionResult" + + PNRemoveMessageActionResult result = PNRemoveMessageActionJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNRemoveMessageActionResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGetMessageActionsResult)) + { + #region "PNGetMessageActionsResult" + + PNGetMessageActionsResult result = PNGetMessageActionsJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGetMessageActionsResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNGenerateFileUploadUrlResult)) + { + #region "PNGenerateFileUploadUrlResult" + + PNGenerateFileUploadUrlResult result = PNGenerateFileUploadUrlDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNGenerateFileUploadUrlResult), + CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNPublishFileMessageResult)) + { + #region "PNPublishFileMessageResult" + + PNPublishFileMessageResult result = PNPublishFileMessageJsonDataParse.GetObject(listObject); + ret = (T)Convert.ChangeType(result, typeof(PNPublishFileMessageResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNListFilesResult)) + { + #region "PNListFilesResult" + + PNListFilesResult result = PNListFilesJsonDataParse.GetObject(jsonPlug, listObject); + ret = (T)Convert.ChangeType(result, typeof(PNListFilesResult), CultureInfo.InvariantCulture); + + #endregion + } + else if (typeof(T) == typeof(PNDeleteFileResult)) + { + #region "PNDeleteFileResult" + + PNDeleteFileResult ack = new PNDeleteFileResult(); + ret = (T)Convert.ChangeType(ack, typeof(PNDeleteFileResult), CultureInfo.InvariantCulture); + + #endregion + } + else + { + System.Diagnostics.Debug.WriteLine("DeserializeToObject(list) => NO MATCH"); + try + { + ret = (T)(object)listObject; + } + catch + { + /* ignore */ + } + } + + return ret; + } + } +} \ No newline at end of file diff --git a/src/Api/PubnubApi/JsonDataParse/JsonDataParseInternalUtil.cs b/src/Api/PubnubApi/JsonDataParse/JsonDataParseInternalUtil.cs deleted file mode 100644 index c5298c3c6..000000000 --- a/src/Api/PubnubApi/JsonDataParse/JsonDataParseInternalUtil.cs +++ /dev/null @@ -1,255 +0,0 @@ -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace PubnubApi -{ - internal static class JsonDataParseInternalUtil - { - public static Dictionary ConvertToDictionaryObject(object localContainer) - { - Dictionary ret = null; - - try - { - if (localContainer != null) - { - if (localContainer.GetType().ToString() == "Newtonsoft.Json.Linq.JObject") - { - ret = new Dictionary(); - - IDictionary jsonDictionary = localContainer as JObject; - if (jsonDictionary != null) - { - foreach (KeyValuePair pair in jsonDictionary) - { - JToken token = pair.Value; - ret.Add(pair.Key, ConvertJTokenToObject(token)); - } - } - } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.Dictionary`2[System.String,System.Object]") - { - ret = new Dictionary(); - Dictionary dictionary = localContainer as Dictionary; - foreach (string key in dictionary.Keys) - { - ret.Add(key, dictionary[key]); - } - } - else if (localContainer.GetType().ToString() == "Newtonsoft.Json.Linq.JProperty") - { - ret = new Dictionary(); - - JProperty jsonProp = localContainer as JProperty; - if (jsonProp != null) - { - string propName = jsonProp.Name; - ret.Add(propName, ConvertJTokenToObject(jsonProp.Value)); - } - } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.List`1[System.Object]") - { - List localList = localContainer as List; - if (localList != null && localList.Count > 0) - { - if (localList[0].GetType() == typeof(KeyValuePair)) - { - ret = new Dictionary(); - foreach (object item in localList) - { - if (item is KeyValuePair kvpItem) - { - ret.Add(kvpItem.Key, kvpItem.Value); - } - else - { - ret = null; - break; - } - } - } - else if (localList[0].GetType() == typeof(Dictionary)) - { - ret = new Dictionary(); - foreach (object item in localList) - { - if (item is Dictionary dicItem) - { - if (dicItem.Count > 0 && dicItem.ContainsKey("key") && dicItem.ContainsKey("value")) - { - ret.Add(dicItem["key"].ToString(), dicItem["value"]); - } - } - else - { - ret = null; - break; - } - } - } - } - } - } - } - catch { /* ignore */ } - - return ret; - - } - - public static object[] ConvertToObjectArray(object localContainer) - { - object[] ret = null; - - try - { - if (localContainer.GetType().ToString() == "Newtonsoft.Json.Linq.JArray") - { - JArray jarrayResult = localContainer as JArray; - List objectContainer = jarrayResult.ToObject>(); - if (objectContainer != null && objectContainer.Count > 0) - { - for (int index = 0; index < objectContainer.Count; index++) - { - if (objectContainer[index].GetType().ToString() == "Newtonsoft.Json.Linq.JArray") - { - JArray internalItem = objectContainer[index] as JArray; - objectContainer[index] = internalItem.Select(item => (object)item).ToArray(); - } - } - ret = objectContainer.ToArray(); - } - } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.List`1[System.Object]") - { - List listResult = localContainer as List; - ret = listResult.ToArray(); - } - } - catch { /* ignore */ } - - return ret; - } - - private static object ConvertJTokenToObject(JToken token) - { - if (token == null) - { - return null; - } - - var jsonValue = token as JValue; - if (jsonValue != null) - { - return jsonValue.Value; - } - - var jsonContainer = token as JArray; - if (jsonContainer != null) - { - List jsonList = new List(); - foreach (JToken arrayItem in jsonContainer) - { - jsonList.Add(ConvertJTokenToObject(arrayItem)); - } - return jsonList; - } - - IDictionary jsonObject = token as JObject; - if (jsonObject != null) - { - var jsonDict = new Dictionary(); - List propertyList = (from childToken in token - where childToken is JProperty - select childToken as JProperty).ToList(); - foreach (JProperty property in propertyList) - { - jsonDict.Add(property.Name, ConvertJTokenToObject(property.Value)); - } - - return jsonDict; - } - - return null; - } - - public static List> ConvertToKeyValuePairList(object localContainer) - { - List> ret = null; - - try - { - if (localContainer != null) - { - if (localContainer.GetType().ToString() == "Newtonsoft.Json.Linq.JObject") - { - ret = new List>(); - - IDictionary jsonDictionary = localContainer as JObject; - if (jsonDictionary != null) - { - foreach (KeyValuePair pair in jsonDictionary) - { - JToken token = pair.Value; - ret.Add(new KeyValuePair(pair.Key,ConvertJTokenToObject(token))); - } - } - } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.Dictionary`2[System.String,System.Object]") - { - ret = new List>(); - Dictionary dictionary = localContainer as Dictionary; - foreach (string key in dictionary.Keys) - { - ret.Add(new KeyValuePair(key, dictionary[key])); - } - } - else if (localContainer.GetType().ToString() == "Newtonsoft.Json.Linq.JProperty") - { - ret = new List>(); - - JProperty jsonProp = localContainer as JProperty; - if (jsonProp != null) - { - string propName = jsonProp.Name; - ret.Add(new KeyValuePair(propName, ConvertJTokenToObject(jsonProp.Value))); - } - } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.List`1[System.Object]") - { - List localList = localContainer as List; - if (localList != null) - { - if (localList.Count > 0 && (localList[0] is Dictionary)) - { - ret = new List>(); - foreach (object item in localList) - { - if (item is Dictionary kvpItem) - { - if (kvpItem.Count > 0 && kvpItem.ContainsKey("key") && kvpItem.ContainsKey("value")) - { - ret.Add(new KeyValuePair(kvpItem["key"].ToString(), kvpItem["value"].ToString())); - } - } - else - { - ret = null; - break; - } - } - } - } - } - } - } - catch { /* ignore */ } - - return ret; - - } - } -} \ No newline at end of file diff --git a/src/Api/PubnubApi/JsonDataParse/PNAccessManagerGrantJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNAccessManagerGrantJsonDataParse.cs index 3d0cceb7f..ee9fb1d59 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNAccessManagerGrantJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNAccessManagerGrantJsonDataParse.cs @@ -1,17 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNAccessManagerGrantJsonDataParse { - internal static PNAccessManagerGrantResult GetObject(List listObject) + internal static PNAccessManagerGrantResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNAccessManagerGrantResult ack = null; - Dictionary grantDictObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]); + Dictionary grantDictObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); if (grantDictObj != null) { @@ -19,7 +17,7 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) if (grantDictObj.ContainsKey("payload")) { - Dictionary grantAckPayloadDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantDictObj["payload"]); + Dictionary grantAckPayloadDict = jsonPlug.ConvertToDictionaryObject(grantDictObj["payload"]); if (grantAckPayloadDict != null && grantAckPayloadDict.Count > 0) { if (grantAckPayloadDict.ContainsKey("level")) @@ -51,24 +49,24 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { ack.Channels = new Dictionary>(); - Dictionary grantAckChannelListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["channels"]); + Dictionary grantAckChannelListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["channels"]); if (grantAckChannelListDict != null && grantAckChannelListDict.Count > 0) { foreach (string channel in grantAckChannelListDict.Keys) { - Dictionary grantAckChannelDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelListDict[channel]); + Dictionary grantAckChannelDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelListDict[channel]); if (grantAckChannelDataDict != null && grantAckChannelDataDict.Count > 0) { if (grantAckChannelDataDict.ContainsKey("auths")) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckChannelAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelDataDict["auths"]); + Dictionary grantAckChannelAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelDataDict["auths"]); if (grantAckChannelAuthListDict != null && grantAckChannelAuthListDict.Count > 0) { foreach (string authKey in grantAckChannelAuthListDict.Keys) { - Dictionary grantAckChannelAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); + Dictionary grantAckChannelAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); if (grantAckChannelAuthDataDict != null && grantAckChannelAuthDataDict.Count > 0) { @@ -94,13 +92,13 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckChannelAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); + Dictionary grantAckChannelAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); if (grantAckChannelAuthListDict != null && grantAckChannelAuthListDict.Count > 0) { foreach (string authKey in grantAckChannelAuthListDict.Keys) { - Dictionary grantAckChannelAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); + Dictionary grantAckChannelAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); if (grantAckChannelAuthDataDict != null && grantAckChannelAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckChannelAuthDataDict); @@ -118,24 +116,24 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { ack.ChannelGroups = new Dictionary>(); - Dictionary grantAckCgListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["channel-groups"]); + Dictionary grantAckCgListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["channel-groups"]); if (grantAckCgListDict != null && grantAckCgListDict.Count > 0) { foreach (string channelgroup in grantAckCgListDict.Keys) { - Dictionary grantAckCgDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckCgListDict[channelgroup]); + Dictionary grantAckCgDataDict = jsonPlug.ConvertToDictionaryObject(grantAckCgListDict[channelgroup]); if (grantAckCgDataDict != null && grantAckCgDataDict.Count > 0) { if (grantAckCgDataDict.ContainsKey("auths")) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckCgAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckCgDataDict["auths"]); + Dictionary grantAckCgAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckCgDataDict["auths"]); if (grantAckCgAuthListDict != null && grantAckCgAuthListDict.Count > 0) { foreach (string authKey in grantAckCgAuthListDict.Keys) { - Dictionary grantAckCgAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckCgAuthListDict[authKey]); + Dictionary grantAckCgAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckCgAuthListDict[authKey]); if (grantAckCgAuthDataDict != null && grantAckCgAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckCgAuthDataDict); @@ -157,13 +155,13 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckChannelAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); + Dictionary grantAckChannelAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); if (grantAckChannelAuthListDict != null && grantAckChannelAuthListDict.Count > 0) { foreach (string authKey in grantAckChannelAuthListDict.Keys) { - Dictionary grantAckChannelAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); + Dictionary grantAckChannelAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); if (grantAckChannelAuthDataDict != null && grantAckChannelAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckChannelAuthDataDict); @@ -187,13 +185,13 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckChannelAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); + Dictionary grantAckChannelAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); if (grantAckChannelAuthListDict != null && grantAckChannelAuthListDict.Count > 0) { foreach (string authKey in grantAckChannelAuthListDict.Keys) { - Dictionary grantAckChannelAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); + Dictionary grantAckChannelAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); if (grantAckChannelAuthDataDict != null && grantAckChannelAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckChannelAuthDataDict); @@ -211,24 +209,24 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { ack.Uuids = new Dictionary>(); - Dictionary grantAckCgListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["uuids"]); + Dictionary grantAckCgListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["uuids"]); if (grantAckCgListDict != null && grantAckCgListDict.Count > 0) { foreach (string uuid in grantAckCgListDict.Keys) { - Dictionary grantAckUuidDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckCgListDict[uuid]); + Dictionary grantAckUuidDataDict = jsonPlug.ConvertToDictionaryObject(grantAckCgListDict[uuid]); if (grantAckUuidDataDict != null && grantAckUuidDataDict.Count > 0) { if (grantAckUuidDataDict.ContainsKey("auths")) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckUuidAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckUuidDataDict["auths"]); + Dictionary grantAckUuidAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckUuidDataDict["auths"]); if (grantAckUuidAuthListDict != null && grantAckUuidAuthListDict.Count > 0) { foreach (string authKey in grantAckUuidAuthListDict.Keys) { - Dictionary grantAckUuidAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckUuidAuthListDict[authKey]); + Dictionary grantAckUuidAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckUuidAuthListDict[authKey]); if (grantAckUuidAuthDataDict != null && grantAckUuidAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckUuidAuthDataDict); @@ -250,13 +248,13 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckUuidAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); + Dictionary grantAckUuidAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); if (grantAckUuidAuthListDict != null && grantAckUuidAuthListDict.Count > 0) { foreach (string authKey in grantAckUuidAuthListDict.Keys) { - Dictionary grantAckUuidAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckUuidAuthListDict[authKey]); + Dictionary grantAckUuidAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckUuidAuthListDict[authKey]); if (grantAckUuidAuthDataDict != null && grantAckUuidAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckUuidAuthDataDict); @@ -280,13 +278,13 @@ internal static PNAccessManagerGrantResult GetObject(List listObject) { Dictionary authKeyDataDict = new Dictionary(); - Dictionary grantAckChannelAuthListDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); + Dictionary grantAckChannelAuthListDict = jsonPlug.ConvertToDictionaryObject(grantAckPayloadDict["auths"]); if (grantAckChannelAuthListDict != null && grantAckChannelAuthListDict.Count > 0) { foreach (string authKey in grantAckChannelAuthListDict.Keys) { - Dictionary grantAckChannelAuthDataDict = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); + Dictionary grantAckChannelAuthDataDict = jsonPlug.ConvertToDictionaryObject(grantAckChannelAuthListDict[authKey]); if (grantAckChannelAuthDataDict != null && grantAckChannelAuthDataDict.Count > 0) { PNAccessManagerKeyData authData = GetAccessManagerKeyData(grantAckChannelAuthDataDict); diff --git a/src/Api/PubnubApi/JsonDataParse/PNAddMessageActionJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNAddMessageActionJsonDataParse.cs index 8fb8ea039..a62383209 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNAddMessageActionJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNAddMessageActionJsonDataParse.cs @@ -1,21 +1,19 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNAddMessageActionJsonDataParse { - internal static PNAddMessageActionResult GetObject(List listObject) + internal static PNAddMessageActionResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { - Dictionary addMsgActionDicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]); + Dictionary addMsgActionDicObj = jsonPlug.ConvertToDictionaryObject(listObject[1]); PNAddMessageActionResult result = null; if (addMsgActionDicObj != null && addMsgActionDicObj.ContainsKey("data")) { result = new PNAddMessageActionResult(); - Dictionary addMsgActionDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(addMsgActionDicObj["data"]); + Dictionary addMsgActionDataDic = jsonPlug.ConvertToDictionaryObject(addMsgActionDicObj["data"]); if (addMsgActionDataDic != null && addMsgActionDataDic.Count > 0) { long messageTimetoken; diff --git a/src/Api/PubnubApi/JsonDataParse/PNChannelMembersJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNChannelMembersJsonDataParse.cs index aeda8deb0..8e60e44e4 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNChannelMembersJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNChannelMembersJsonDataParse.cs @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNChannelMembersJsonDataParse { - internal static PNChannelMembersResult GetObject(List listObject) + internal static PNChannelMembersResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNChannelMembersResult result = null; for (int listIndex = 0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -23,12 +21,12 @@ internal static PNChannelMembersResult GetObject(List listObject) { result.ChannelMembers = new List(); - object[] userArray = JsonDataParseInternalUtil.ConvertToObjectArray(dicObj["data"]); + object[] userArray = jsonPlug.ConvertToObjectArray(dicObj["data"]); if (userArray != null && userArray.Length > 0) { for (int index = 0; index < userArray.Length; index++) { - Dictionary getMbrItemDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(userArray[index]); + Dictionary getMbrItemDataDic = jsonPlug.ConvertToDictionaryObject(userArray[index]); if (getMbrItemDataDic != null && getMbrItemDataDic.Count > 0) { var mbrItem = new PNChannelMembersItemResult @@ -37,11 +35,11 @@ internal static PNChannelMembersResult GetObject(List listObject) }; if (getMbrItemDataDic.ContainsKey("custom")) { - mbrItem.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMbrItemDataDic["custom"]); + mbrItem.Custom = jsonPlug.ConvertToDictionaryObject(getMbrItemDataDic["custom"]); } if (getMbrItemDataDic.ContainsKey("uuid")) { - Dictionary uuidMetadataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMbrItemDataDic["uuid"]); + Dictionary uuidMetadataDic = jsonPlug.ConvertToDictionaryObject(getMbrItemDataDic["uuid"]); if (uuidMetadataDic != null && uuidMetadataDic.Count > 0) { var uuidMetadataResult = new PNUuidMetadataResult @@ -52,7 +50,7 @@ internal static PNChannelMembersResult GetObject(List listObject) ProfileUrl = (uuidMetadataDic.ContainsKey("profileUrl") && uuidMetadataDic["profileUrl"] != null) ? uuidMetadataDic["profileUrl"].ToString() : "", Email = (uuidMetadataDic.ContainsKey("email") && uuidMetadataDic["email"] != null) ? uuidMetadataDic["email"].ToString() : "", Updated = (uuidMetadataDic.ContainsKey("updated") && uuidMetadataDic["updated"] != null) ? uuidMetadataDic["updated"].ToString() : "", - Custom = (uuidMetadataDic.ContainsKey("custom") && uuidMetadataDic["custom"] != null) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(uuidMetadataDic["custom"]) : null + Custom = (uuidMetadataDic.ContainsKey("custom") && uuidMetadataDic["custom"] != null) ? jsonPlug.ConvertToDictionaryObject(uuidMetadataDic["custom"]) : null }; mbrItem.UuidMetadata = uuidMetadataResult; } diff --git a/src/Api/PubnubApi/JsonDataParse/PNFetchHistoryJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNFetchHistoryJsonDataParse.cs index 0f1c8040c..b17da3cfb 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNFetchHistoryJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNFetchHistoryJsonDataParse.cs @@ -1,13 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNFetchHistoryJsonDataParse { - internal static PNFetchHistoryResult GetObject(List listObject) + internal static PNFetchHistoryResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNFetchHistoryResult ack = new PNFetchHistoryResult(); @@ -28,10 +26,10 @@ internal static PNFetchHistoryResult GetObject(List listObject) { string channel = channelKVP.Key; List resultList = new List(); - object[] channelValArray = channelKVP.Value != null ? JsonDataParseInternalUtil.ConvertToObjectArray(channelKVP.Value) : new object[0]; + object[] channelValArray = channelKVP.Value != null ? jsonPlug.ConvertToObjectArray(channelKVP.Value) : new object[0]; foreach (object msgContainerObj in channelValArray) { - Dictionary messagesContainer = JsonDataParseInternalUtil.ConvertToDictionaryObject(msgContainerObj); + Dictionary messagesContainer = jsonPlug.ConvertToDictionaryObject(msgContainerObj); if (messagesContainer != null) { PNHistoryItemResult result = new PNHistoryItemResult(); diff --git a/src/Api/PubnubApi/JsonDataParse/PNGenerateFileUploadUrlDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGenerateFileUploadUrlDataParse.cs index 15721faa3..0637142d5 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGenerateFileUploadUrlDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGenerateFileUploadUrlDataParse.cs @@ -1,18 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNGenerateFileUploadUrlDataParse { - internal static PNGenerateFileUploadUrlResult GetObject(List listObject) + internal static PNGenerateFileUploadUrlResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNGenerateFileUploadUrlResult result = null; for (int listIndex = 0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -21,7 +18,7 @@ internal static PNGenerateFileUploadUrlResult GetObject(List listObject) } if (dicObj.ContainsKey("data") && dicObj["data"] != null) { - Dictionary generateFileUploadUrlDicData = JsonDataParseInternalUtil.ConvertToDictionaryObject(dicObj["data"]); + Dictionary generateFileUploadUrlDicData = jsonPlug.ConvertToDictionaryObject(dicObj["data"]); if (generateFileUploadUrlDicData != null && generateFileUploadUrlDicData.Count > 0) { result.FileId = generateFileUploadUrlDicData.ContainsKey("id") && generateFileUploadUrlDicData["id"] != null ? generateFileUploadUrlDicData["id"].ToString() : null; @@ -31,7 +28,7 @@ internal static PNGenerateFileUploadUrlResult GetObject(List listObject) } else if (dicObj.ContainsKey("file_upload_request") && dicObj["file_upload_request"] != null) { - Dictionary generateFileUploadUrlDicUploadReq = JsonDataParseInternalUtil.ConvertToDictionaryObject(dicObj["file_upload_request"]); + Dictionary generateFileUploadUrlDicUploadReq = jsonPlug.ConvertToDictionaryObject(dicObj["file_upload_request"]); if (generateFileUploadUrlDicUploadReq != null && generateFileUploadUrlDicUploadReq.Count > 0) { result.FileUploadRequest = new PNGenerateFileUploadUrlData @@ -39,7 +36,7 @@ internal static PNGenerateFileUploadUrlResult GetObject(List listObject) Url = generateFileUploadUrlDicUploadReq.ContainsKey("url") && generateFileUploadUrlDicUploadReq["url"] != null ? generateFileUploadUrlDicUploadReq["url"].ToString() : null, Method = generateFileUploadUrlDicUploadReq.ContainsKey("method") && generateFileUploadUrlDicUploadReq["method"] != null ? generateFileUploadUrlDicUploadReq["method"].ToString() : null, ExpirationDate = generateFileUploadUrlDicUploadReq.ContainsKey("expiration_date") && generateFileUploadUrlDicUploadReq["expiration_date"] != null ? generateFileUploadUrlDicUploadReq["expiration_date"].ToString() : null, - FormFields = generateFileUploadUrlDicUploadReq.ContainsKey("form_fields") && generateFileUploadUrlDicUploadReq["form_fields"] != null ? JsonDataParseInternalUtil.ConvertToDictionaryObject(generateFileUploadUrlDicUploadReq["form_fields"]) : null + FormFields = generateFileUploadUrlDicUploadReq.ContainsKey("form_fields") && generateFileUploadUrlDicUploadReq["form_fields"] != null ? jsonPlug.ConvertToDictionaryObject(generateFileUploadUrlDicUploadReq["form_fields"]) : null }; } } diff --git a/src/Api/PubnubApi/JsonDataParse/PNGetAllChannelMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGetAllChannelMetadataJsonDataParse.cs index 070de03ff..fa5806bee 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGetAllChannelMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGetAllChannelMetadataJsonDataParse.cs @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNGetAllChannelMetadataJsonDataParse { - internal static PNGetAllChannelMetadataResult GetObject(List listObject) + internal static PNGetAllChannelMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNGetAllChannelMetadataResult result = null; for (int listIndex = 0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -23,7 +21,7 @@ internal static PNGetAllChannelMetadataResult GetObject(List listObject) { result.Channels = new List(); - Dictionary getChMetadataDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(dicObj["data"]); + Dictionary getChMetadataDataDic = jsonPlug.ConvertToDictionaryObject(dicObj["data"]); if (getChMetadataDataDic != null && getChMetadataDataDic.Count > 0) { var chMetadata = new PNChannelMetadataResult @@ -35,18 +33,18 @@ internal static PNGetAllChannelMetadataResult GetObject(List listObject) }; if (getChMetadataDataDic.ContainsKey("custom")) { - chMetadata.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getChMetadataDataDic["custom"]); + chMetadata.Custom = jsonPlug.ConvertToDictionaryObject(getChMetadataDataDic["custom"]); } result.Channels.Add(chMetadata); } else { - object[] chMetadataDataArray = JsonDataParseInternalUtil.ConvertToObjectArray(dicObj["data"]); + object[] chMetadataDataArray = jsonPlug.ConvertToObjectArray(dicObj["data"]); if (chMetadataDataArray != null && chMetadataDataArray.Length > 0) { for (int index = 0; index < chMetadataDataArray.Length; index++) { - Dictionary chMetadataDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(chMetadataDataArray[index]); + Dictionary chMetadataDataDic = jsonPlug.ConvertToDictionaryObject(chMetadataDataArray[index]); if (chMetadataDataDic != null && chMetadataDataDic.Count > 0) { var chMetadataData = new PNChannelMetadataResult @@ -59,7 +57,7 @@ internal static PNGetAllChannelMetadataResult GetObject(List listObject) if (chMetadataDataDic.ContainsKey("custom")) { - chMetadataData.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(chMetadataDataDic["custom"]); + chMetadataData.Custom = jsonPlug.ConvertToDictionaryObject(chMetadataDataDic["custom"]); } result.Channels.Add(chMetadataData); } diff --git a/src/Api/PubnubApi/JsonDataParse/PNGetAllUuidMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGetAllUuidMetadataJsonDataParse.cs index 9e8158b79..248f8d3d6 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGetAllUuidMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGetAllUuidMetadataJsonDataParse.cs @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNGetAllUuidMetadataJsonDataParse { - internal static PNGetAllUuidMetadataResult GetObject(List listObject) + internal static PNGetAllUuidMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNGetAllUuidMetadataResult result = null; for (int listIndex=0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -23,7 +21,7 @@ internal static PNGetAllUuidMetadataResult GetObject(List listObject) { result.Uuids = new List(); - Dictionary getUserDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(dicObj["data"]); + Dictionary getUserDataDic = jsonPlug.ConvertToDictionaryObject(dicObj["data"]); if (getUserDataDic != null && getUserDataDic.Count > 0) { var uuidMetaData = new PNUuidMetadataResult @@ -37,18 +35,18 @@ internal static PNGetAllUuidMetadataResult GetObject(List listObject) }; if (getUserDataDic.ContainsKey("custom")) { - uuidMetaData.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getUserDataDic["custom"]); + uuidMetaData.Custom = jsonPlug.ConvertToDictionaryObject(getUserDataDic["custom"]); } result.Uuids.Add(uuidMetaData); } else { - object[] userDataArray = JsonDataParseInternalUtil.ConvertToObjectArray(dicObj["data"]); + object[] userDataArray = jsonPlug.ConvertToObjectArray(dicObj["data"]); if (userDataArray != null && userDataArray.Length > 0) { for (int index = 0; index < userDataArray.Length; index++) { - Dictionary userDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(userDataArray[index]); + Dictionary userDataDic = jsonPlug.ConvertToDictionaryObject(userDataArray[index]); if (userDataDic != null && userDataDic.Count > 0) { var uuidMetadata = new PNUuidMetadataResult @@ -63,7 +61,7 @@ internal static PNGetAllUuidMetadataResult GetObject(List listObject) if (userDataDic.ContainsKey("custom")) { - uuidMetadata.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(userDataDic["custom"]); + uuidMetadata.Custom = jsonPlug.ConvertToDictionaryObject(userDataDic["custom"]); } result.Uuids.Add(uuidMetadata); } diff --git a/src/Api/PubnubApi/JsonDataParse/PNGetChannelMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGetChannelMetadataJsonDataParse.cs index dda41147b..ef3677b63 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGetChannelMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGetChannelMetadataJsonDataParse.cs @@ -1,21 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNGetChannelMetadataJsonDataParse { - internal static PNGetChannelMetadataResult GetObject(List listObject) + internal static PNGetChannelMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNGetChannelMetadataResult result = null; - Dictionary getChMetadataDicObj = (listObject != null && listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; + Dictionary getChMetadataDicObj = (listObject != null && listObject.Count >= 2) ? jsonPlug.ConvertToDictionaryObject(listObject[1]) : null; if (getChMetadataDicObj != null && getChMetadataDicObj.ContainsKey("data")) { result = new PNGetChannelMetadataResult(); - Dictionary getChMetadataDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getChMetadataDicObj["data"]); + Dictionary getChMetadataDataDic = jsonPlug.ConvertToDictionaryObject(getChMetadataDicObj["data"]); if (getChMetadataDataDic != null && getChMetadataDataDic.Count > 0) { var chMetadata = new PNGetChannelMetadataResult @@ -27,7 +24,7 @@ internal static PNGetChannelMetadataResult GetObject(List listObject) }; if (getChMetadataDataDic.ContainsKey("custom")) { - chMetadata.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getChMetadataDataDic["custom"]); + chMetadata.Custom = jsonPlug.ConvertToDictionaryObject(getChMetadataDataDic["custom"]); } result = chMetadata; } diff --git a/src/Api/PubnubApi/JsonDataParse/PNGetMessageActionsJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGetMessageActionsJsonDataParse.cs index 719e723d0..29219936f 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGetMessageActionsJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGetMessageActionsJsonDataParse.cs @@ -1,28 +1,26 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNGetMessageActionsJsonDataParse { - internal static PNGetMessageActionsResult GetObject(List listObject) + internal static PNGetMessageActionsResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { - Dictionary getMsgActionsDicObj = (listObject != null && listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; + Dictionary getMsgActionsDicObj = (listObject != null && listObject.Count >= 2) ? jsonPlug.ConvertToDictionaryObject(listObject[1]) : null; PNGetMessageActionsResult result = null; if (getMsgActionsDicObj != null && getMsgActionsDicObj.ContainsKey("data")) { result = new PNGetMessageActionsResult(); - object[] getMsgActionsDataList = JsonDataParseInternalUtil.ConvertToObjectArray(getMsgActionsDicObj["data"]); + object[] getMsgActionsDataList = jsonPlug.ConvertToObjectArray(getMsgActionsDicObj["data"]); if (getMsgActionsDataList != null && getMsgActionsDataList.Length > 0) { result.MessageActions = new List(); foreach (object getMsgActionObj in getMsgActionsDataList) { - Dictionary getMsgActionItemDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMsgActionObj); + Dictionary getMsgActionItemDic = jsonPlug.ConvertToDictionaryObject(getMsgActionObj); if (getMsgActionItemDic != null && getMsgActionItemDic.Count > 0) { PNMessageActionItem actionItem = new PNMessageActionItem(); @@ -54,7 +52,7 @@ internal static PNGetMessageActionsResult GetObject(List listObject) if (getMsgActionsDicObj.ContainsKey("more")) { - Dictionary getMsgActionsMoreDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMsgActionsDicObj["more"]); + Dictionary getMsgActionsMoreDic = jsonPlug.ConvertToDictionaryObject(getMsgActionsDicObj["more"]); if (getMsgActionsMoreDic != null && getMsgActionsMoreDic.Count > 0) { result.More = new PNGetMessageActionsResult.MoreInfo(); diff --git a/src/Api/PubnubApi/JsonDataParse/PNGetUuidMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGetUuidMetadataJsonDataParse.cs index 700b5cada..f543bb188 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGetUuidMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGetUuidMetadataJsonDataParse.cs @@ -1,21 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNGetUuidMetadataJsonDataParse { - internal static PNGetUuidMetadataResult GetObject(List listObject) + internal static PNGetUuidMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNGetUuidMetadataResult result = null; - Dictionary getUserDicObj = (listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; + Dictionary getUserDicObj = (listObject.Count >= 2) ? jsonPlug.ConvertToDictionaryObject(listObject[1]) : null; if (getUserDicObj != null && getUserDicObj.ContainsKey("data")) { result = new PNGetUuidMetadataResult(); - Dictionary userDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getUserDicObj["data"]); + Dictionary userDataDic = jsonPlug.ConvertToDictionaryObject(getUserDicObj["data"]); if (userDataDic != null && userDataDic.Count > 0) { var usrData = new PNGetUuidMetadataResult @@ -30,7 +27,7 @@ internal static PNGetUuidMetadataResult GetObject(List listObject) if (userDataDic.ContainsKey("custom")) { - usrData.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(userDataDic["custom"]); + usrData.Custom = jsonPlug.ConvertToDictionaryObject(userDataDic["custom"]); } result = usrData; } diff --git a/src/Api/PubnubApi/JsonDataParse/PNGrantTokenJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNGrantTokenJsonDataParse.cs index fd04662a9..3e64eedd4 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNGrantTokenJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNGrantTokenJsonDataParse.cs @@ -1,21 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNGrantTokenJsonDataParse { - internal static PNAccessManagerTokenResult GetObject(List listObject) + internal static PNAccessManagerTokenResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNAccessManagerTokenResult result = null; - Dictionary grantDicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]); + Dictionary grantDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); if (grantDicObj != null && grantDicObj.ContainsKey("data")) { result = new PNAccessManagerTokenResult(); - Dictionary grantDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(grantDicObj["data"]); + Dictionary grantDataDic = jsonPlug.ConvertToDictionaryObject(grantDicObj["data"]); if (grantDataDic != null && grantDataDic.ContainsKey("token")) { result.Token = grantDataDic["token"].ToString(); diff --git a/src/Api/PubnubApi/JsonDataParse/PNHistoryJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNHistoryJsonDataParse.cs index 7746682f9..4ef70c315 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNHistoryJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNHistoryJsonDataParse.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNHistoryJsonDataParse { - internal static PNHistoryResult GetObject(List listObject) + internal static PNHistoryResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNHistoryResult ack = new PNHistoryResult(); if (listObject == null || listObject.Count == 0) @@ -40,7 +39,7 @@ internal static PNHistoryResult GetObject(List listObject) foreach (var message in messagesContainer) { PNHistoryItemResult result = new PNHistoryItemResult(); - Dictionary dicMessageTimetoken = JsonDataParseInternalUtil.ConvertToDictionaryObject(message); + Dictionary dicMessageTimetoken = jsonPlug.ConvertToDictionaryObject(message); if (dicMessageTimetoken != null) { if (dicMessageTimetoken.ContainsKey("message") && diff --git a/src/Api/PubnubApi/JsonDataParse/PNListFilesJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNListFilesJsonDataParse.cs index 3eae42606..7979ded39 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNListFilesJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNListFilesJsonDataParse.cs @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNListFilesJsonDataParse { - internal static PNListFilesResult GetObject(List listObject) + internal static PNListFilesResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNListFilesResult result = null; for (int listIndex = 0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -21,13 +19,13 @@ internal static PNListFilesResult GetObject(List listObject) } if (dicObj.ContainsKey("data") && dicObj["data"] != null) { - object[] fileDataArray = JsonDataParseInternalUtil.ConvertToObjectArray(dicObj["data"]); + object[] fileDataArray = jsonPlug.ConvertToObjectArray(dicObj["data"]); if (fileDataArray != null && fileDataArray.Length > 0) { result.FilesList = new List(); for (int index = 0; index < fileDataArray.Length; index++) { - Dictionary getFileDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(fileDataArray[index]); + Dictionary getFileDataDic = jsonPlug.ConvertToDictionaryObject(fileDataArray[index]); if (getFileDataDic != null && getFileDataDic.Count > 0) { int fileSize; diff --git a/src/Api/PubnubApi/JsonDataParse/PNMembershipsJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNMembershipsJsonDataParse.cs index fda417c79..6ef03e78c 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNMembershipsJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNMembershipsJsonDataParse.cs @@ -1,18 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNMembershipsJsonDataParse { - internal static PNMembershipsResult GetObject(List listObject) + internal static PNMembershipsResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNMembershipsResult result = null; for (int listIndex = 0; listIndex < listObject.Count; listIndex++) { - Dictionary dicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[listIndex]); + Dictionary dicObj = jsonPlug.ConvertToDictionaryObject(listObject[listIndex]); if (dicObj != null && dicObj.Count > 0) { if (result == null) @@ -23,12 +21,12 @@ internal static PNMembershipsResult GetObject(List listObject) { result.Memberships = new List(); - object[] channelMetadataArray = JsonDataParseInternalUtil.ConvertToObjectArray(dicObj["data"]); + object[] channelMetadataArray = jsonPlug.ConvertToObjectArray(dicObj["data"]); if (channelMetadataArray != null && channelMetadataArray.Length > 0) { for (int index = 0; index < channelMetadataArray.Length; index++) { - Dictionary getMbrshipItemDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(channelMetadataArray[index]); + Dictionary getMbrshipItemDataDic = jsonPlug.ConvertToDictionaryObject(channelMetadataArray[index]); if (getMbrshipItemDataDic != null && getMbrshipItemDataDic.Count > 0) { var mbrshipItem = new PNMembershipsItemResult @@ -37,11 +35,11 @@ internal static PNMembershipsResult GetObject(List listObject) }; if (getMbrshipItemDataDic.ContainsKey("custom")) { - mbrshipItem.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMbrshipItemDataDic["custom"]); + mbrshipItem.Custom = jsonPlug.ConvertToDictionaryObject(getMbrshipItemDataDic["custom"]); } if (getMbrshipItemDataDic.ContainsKey("channel")) { - Dictionary channelMetadataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(getMbrshipItemDataDic["channel"]); + Dictionary channelMetadataDic = jsonPlug.ConvertToDictionaryObject(getMbrshipItemDataDic["channel"]); if (channelMetadataDic != null && channelMetadataDic.Count > 0) { var channelMetadataResult = new PNChannelMetadataResult @@ -50,7 +48,7 @@ internal static PNMembershipsResult GetObject(List listObject) Name = (channelMetadataDic.ContainsKey("name") && channelMetadataDic["name"] != null) ? channelMetadataDic["name"].ToString() : null, Description = (channelMetadataDic.ContainsKey("description") && channelMetadataDic["description"] != null) ? channelMetadataDic["description"].ToString() : null, Updated = (channelMetadataDic.ContainsKey("updated") && channelMetadataDic["updated"] != null) ? channelMetadataDic["updated"].ToString() : null, - Custom = (channelMetadataDic.ContainsKey("custom") && channelMetadataDic["custom"] != null) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(channelMetadataDic["custom"]) : null + Custom = (channelMetadataDic.ContainsKey("custom") && channelMetadataDic["custom"] != null) ? jsonPlug.ConvertToDictionaryObject(channelMetadataDic["custom"]) : null }; mbrshipItem.ChannelMetadata = channelMetadataResult; } diff --git a/src/Api/PubnubApi/JsonDataParse/PNMessageActionEventJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNMessageActionEventJsonDataParse.cs index b59d4eda1..0c5bddcd3 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNMessageActionEventJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNMessageActionEventJsonDataParse.cs @@ -1,17 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNMessageActionEventJsonDataParse { - internal static PNMessageActionEventResult GetObject(List listObject) + internal static PNMessageActionEventResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNMessageActionEventResult result = null; - Dictionary msgActionEventDicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]); + Dictionary msgActionEventDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); if (msgActionEventDicObj != null) { result = new PNMessageActionEventResult(); diff --git a/src/Api/PubnubApi/JsonDataParse/PNObjectEventJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNObjectEventJsonDataParse.cs index fa3c0ebc9..548b3acc7 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNObjectEventJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNObjectEventJsonDataParse.cs @@ -1,17 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { internal static class PNObjectEventJsonDataParse { - internal static PNObjectEventResult GetObject(List listObject) + internal static PNObjectEventResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNObjectEventResult result = null; - Dictionary objectEventDicObj = (listObject != null && listObject.Count > 0) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]) : null; + Dictionary objectEventDicObj = (listObject != null && listObject.Count > 0) ? jsonPlug.ConvertToDictionaryObject(listObject[0]) : null; if (objectEventDicObj != null) { if (result == null) @@ -52,7 +50,7 @@ internal static PNObjectEventResult GetObject(List listObject) ExternalId = (dataDic.ContainsKey("externalId") && dataDic["externalId"] != null) ? dataDic["externalId"].ToString() : null, ProfileUrl = (dataDic.ContainsKey("profileUrl") && dataDic["profileUrl"] != null) ? dataDic["profileUrl"].ToString() : null, Email = (dataDic.ContainsKey("email") && dataDic["email"] != null) ? dataDic["email"].ToString() : null, - Custom = (dataDic.ContainsKey("custom") && dataDic["custom"] != null) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(dataDic["custom"]) : null, + Custom = (dataDic.ContainsKey("custom") && dataDic["custom"] != null) ? jsonPlug.ConvertToDictionaryObject(dataDic["custom"]) : null, Updated = (dataDic.ContainsKey("updated") && dataDic["updated"] != null) ? dataDic["updated"].ToString() : null }; } @@ -63,7 +61,7 @@ internal static PNObjectEventResult GetObject(List listObject) Channel = dataDic["id"] != null ? dataDic["id"].ToString() : null, Name = (dataDic.ContainsKey("name") && dataDic["name"] != null) ? dataDic["name"].ToString() : null, Description = (dataDic.ContainsKey("description") && dataDic["description"] != null) ? dataDic["description"].ToString() : null, - Custom = (dataDic.ContainsKey("custom") && dataDic["custom"] != null) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(dataDic["custom"]) : null, + Custom = (dataDic.ContainsKey("custom") && dataDic["custom"] != null) ? jsonPlug.ConvertToDictionaryObject(dataDic["custom"]) : null, Updated = (dataDic.ContainsKey("updated") && dataDic["updated"] != null) ? dataDic["updated"].ToString() : null }; } diff --git a/src/Api/PubnubApi/JsonDataParse/PNPublishFileMessageJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNPublishFileMessageJsonDataParse.cs index 562529933..fc72707af 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNPublishFileMessageJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNPublishFileMessageJsonDataParse.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace PubnubApi { diff --git a/src/Api/PubnubApi/JsonDataParse/PNRemoveMessageActionJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNRemoveMessageActionJsonDataParse.cs index f16fa184b..9a2a4c96f 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNRemoveMessageActionJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNRemoveMessageActionJsonDataParse.cs @@ -1,15 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNRemoveMessageActionJsonDataParse { - internal static PNRemoveMessageActionResult GetObject(List listObject) + internal static PNRemoveMessageActionResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { - Dictionary removeMsgActionDicObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]); + Dictionary removeMsgActionDicObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); PNRemoveMessageActionResult result = null; if (removeMsgActionDicObj != null && removeMsgActionDicObj.ContainsKey("status")) { diff --git a/src/Api/PubnubApi/JsonDataParse/PNRevokeTokenJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNRevokeTokenJsonDataParse.cs index e189b42cf..874bacb4a 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNRevokeTokenJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNRevokeTokenJsonDataParse.cs @@ -1,17 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNRevokeTokenJsonDataParse { - internal static PNAccessManagerRevokeTokenResult GetObject(List listObject) + internal static PNAccessManagerRevokeTokenResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { PNAccessManagerRevokeTokenResult result = null; - Dictionary revokeTokenDictObj = JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[0]); + Dictionary revokeTokenDictObj = jsonPlug.ConvertToDictionaryObject(listObject[0]); if (revokeTokenDictObj != null && revokeTokenDictObj.ContainsKey("data")) { result = new PNAccessManagerRevokeTokenResult(); diff --git a/src/Api/PubnubApi/JsonDataParse/PNSetChannelMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNSetChannelMetadataJsonDataParse.cs index 2bff997f3..69e5f777f 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNSetChannelMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNSetChannelMetadataJsonDataParse.cs @@ -1,21 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNSetChannelMetadataJsonDataParse { - internal static PNSetChannelMetadataResult GetObject(List listObject) + internal static PNSetChannelMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { - Dictionary setChannelMetadataDicObj = (listObject != null && listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; + Dictionary setChannelMetadataDicObj = (listObject != null && listObject.Count >= 2) ? jsonPlug.ConvertToDictionaryObject(listObject[1]) : null; PNSetChannelMetadataResult result = null; if (setChannelMetadataDicObj != null && setChannelMetadataDicObj.ContainsKey("data")) { result = new PNSetChannelMetadataResult(); - Dictionary getSetChMetadataDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(setChannelMetadataDicObj["data"]); + Dictionary getSetChMetadataDataDic = jsonPlug.ConvertToDictionaryObject(setChannelMetadataDicObj["data"]); if (getSetChMetadataDataDic != null && getSetChMetadataDataDic.Count > 0) { result.Channel = getSetChMetadataDataDic.ContainsKey("id") && getSetChMetadataDataDic["id"] != null ? getSetChMetadataDataDic["id"].ToString() : null; @@ -24,7 +21,7 @@ internal static PNSetChannelMetadataResult GetObject(List listObject) result.Updated = getSetChMetadataDataDic.ContainsKey("updated") && getSetChMetadataDataDic["updated"] != null ? getSetChMetadataDataDic["updated"].ToString() : null; if (getSetChMetadataDataDic.ContainsKey("custom")) { - result.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getSetChMetadataDataDic["custom"]); + result.Custom = jsonPlug.ConvertToDictionaryObject(getSetChMetadataDataDic["custom"]); } } } diff --git a/src/Api/PubnubApi/JsonDataParse/PNSetUuidMetadataJsonDataParse.cs b/src/Api/PubnubApi/JsonDataParse/PNSetUuidMetadataJsonDataParse.cs index d3cfad8af..9f5f39bd2 100644 --- a/src/Api/PubnubApi/JsonDataParse/PNSetUuidMetadataJsonDataParse.cs +++ b/src/Api/PubnubApi/JsonDataParse/PNSetUuidMetadataJsonDataParse.cs @@ -1,21 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace PubnubApi { internal static class PNSetUuidMetadataJsonDataParse { - internal static PNSetUuidMetadataResult GetObject(List listObject) + internal static PNSetUuidMetadataResult GetObject(IJsonPluggableLibrary jsonPlug, List listObject) { - Dictionary setUuidDicObj = (listObject != null && listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; + Dictionary setUuidDicObj = (listObject != null && listObject.Count >= 2) ? jsonPlug.ConvertToDictionaryObject(listObject[1]) : null; PNSetUuidMetadataResult result = null; if (setUuidDicObj != null && setUuidDicObj.ContainsKey("data")) { result = new PNSetUuidMetadataResult(); - Dictionary setUuidDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(setUuidDicObj["data"]); + Dictionary setUuidDataDic = jsonPlug.ConvertToDictionaryObject(setUuidDicObj["data"]); if (setUuidDataDic != null && setUuidDataDic.Count > 0) { result.Uuid = setUuidDataDic.ContainsKey("id") && setUuidDataDic["id"] != null ? setUuidDataDic["id"].ToString() : null; @@ -26,7 +23,7 @@ internal static PNSetUuidMetadataResult GetObject(List listObject) result.Updated = setUuidDataDic.ContainsKey("updated") && setUuidDataDic["updated"] != null ? setUuidDataDic["updated"].ToString() : ""; if (setUuidDataDic.ContainsKey("custom")) { - result.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(setUuidDataDic["custom"]); + result.Custom = jsonPlug.ConvertToDictionaryObject(setUuidDataDic["custom"]); } } } diff --git a/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs b/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs index e87a9e667..51d5492ab 100644 --- a/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs +++ b/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs @@ -14,7 +14,9 @@ public class NewtonsoftJsonDotNet : IJsonPluggableLibrary private readonly PNConfiguration config; private readonly IPubnubLog pubnubLog; private readonly JsonSerializerSettings defaultJsonSerializerSettings; + #region "IL2CPP workarounds" + //Got an exception when using JSON serialisation for [], //IL2CPP needs to know about the array type at compile time. //So please define private static filed like this: @@ -49,13 +51,14 @@ public NewtonsoftJsonDotNet(PNConfiguration pubnubConfig, IPubnubLog log) } #region IJsonPlugableLibrary methods implementation + private static bool IsValidJson(string jsonString, PNOperationType operationType) { bool ret = false; try { - if (operationType == PNOperationType.PNPublishOperation - || operationType == PNOperationType.PNHistoryOperation + if (operationType == PNOperationType.PNPublishOperation + || operationType == PNOperationType.PNHistoryOperation || operationType == PNOperationType.PNTimeOperation || operationType == PNOperationType.PNPublishFileMessageOperation) { @@ -65,6 +68,7 @@ private static bool IsValidJson(string jsonString, PNOperationType operationType { JObject.Parse(jsonString); } + ret = true; } catch @@ -80,8 +84,12 @@ private static bool IsValidJson(string jsonString, PNOperationType operationType ret = true; } } - catch { /* igonore */ } + catch + { + /* igonore */ + } } + return ret; } @@ -94,7 +102,10 @@ public object BuildJsonObject(string jsonString) var token = JToken.Parse(jsonString); ret = token; } - catch { /* ignore */ } + catch + { + /* ignore */ + } return ret; } @@ -112,7 +123,8 @@ public bool IsDictionaryCompatible(string jsonString, PNOperationType operationT { while (jsonTxtreader.Read()) { - if (jsonTxtreader.LineNumber == 1 && jsonTxtreader.LinePosition == 1 && jsonTxtreader.TokenType == JsonToken.StartObject) + if (jsonTxtreader.LineNumber == 1 && jsonTxtreader.LinePosition == 1 && + jsonTxtreader.TokenType == JsonToken.StartObject) { ret = true; break; @@ -122,6 +134,7 @@ public bool IsDictionaryCompatible(string jsonString, PNOperationType operationT break; } } + jsonTxtreader.Close(); } #if (NET35 || NET40 || NET45 || NET461 || NET48) @@ -129,8 +142,12 @@ public bool IsDictionaryCompatible(string jsonString, PNOperationType operationT #endif } } - catch { /* ignore */ } + catch + { + /* ignore */ + } } + return ret; } @@ -141,14 +158,36 @@ public string SerializeToJsonString(object objectToSerialize) public List DeserializeToListOfObject(string jsonString) { - List result = JsonConvert.DeserializeObject>(jsonString, defaultJsonSerializerSettings); + List result = + JsonConvert.DeserializeObject>(jsonString, defaultJsonSerializerSettings); return result; } + public object DeserializeToObject(object rawObject, Type type) + { + try + { + if (rawObject is JObject jObject) + { + return jObject.ToObject(type); + } + else + { + return rawObject; + } + } + catch (Exception e) + { + LoggingMethod.WriteToLog(pubnubLog, e.ToString(), config.LogVerbosity); + return rawObject; + } + } + public object DeserializeToObject(string jsonString) { - object result = JsonConvert.DeserializeObject(jsonString, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None, MaxDepth = 64 }); + object result = JsonConvert.DeserializeObject(jsonString, + new JsonSerializerSettings { DateParseHandling = DateParseHandling.None, MaxDepth = 64 }); if (result.GetType().ToString() == "Newtonsoft.Json.Linq.JArray") { JArray jarrayResult = result as JArray; @@ -163,9 +202,11 @@ public object DeserializeToObject(string jsonString) objectContainer[index] = internalItem.Select(item => (object)item).ToArray(); } } + result = objectContainer; } } + return result; } @@ -180,9 +221,13 @@ public virtual T DeserializeToObject(string jsonString) try { - ret = JsonConvert.DeserializeObject(jsonString, new JsonSerializerSettings { DateParseHandling = DateParseHandling.None, MaxDepth = 64 }); + ret = JsonConvert.DeserializeObject(jsonString, + new JsonSerializerSettings { DateParseHandling = DateParseHandling.None, MaxDepth = 64 }); + } + catch + { + /* ignore */ } - catch { /* ignore */ } return ret; } @@ -199,18 +244,33 @@ private bool IsGenericTypeForMessage() } LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, NET35/40 IsGenericTypeForMessage = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), ret.ToString()), config.LogVerbosity); #elif (NETSTANDARD10 || NETSTANDARD11 || NETSTANDARD12 || NETSTANDARD13 || NETSTANDARD14 || NETSTANDARD20 || NET60 || UAP || NETFX_CORE || WINDOWS_UWP) - if (typeof(T).GetTypeInfo().IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(PNMessageResult<>)) + if (typeof(T).GetTypeInfo().IsGenericType && + typeof(T).GetGenericTypeDefinition() == typeof(PNMessageResult<>)) { ret = true; } - LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, typeof(T).GetTypeInfo().IsGenericType = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), typeof(T).GetTypeInfo().IsGenericType.ToString()), config.LogVerbosity); + + LoggingMethod.WriteToLog(pubnubLog, + string.Format(CultureInfo.InvariantCulture, + "DateTime: {0}, typeof(T).GetTypeInfo().IsGenericType = {1}", + DateTime.Now.ToString(CultureInfo.InvariantCulture), + typeof(T).GetTypeInfo().IsGenericType.ToString()), config.LogVerbosity); if (typeof(T).GetTypeInfo().IsGenericType) { - LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, typeof(T).GetGenericTypeDefinition() = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), typeof(T).GetGenericTypeDefinition().ToString()), config.LogVerbosity); + LoggingMethod.WriteToLog(pubnubLog, + string.Format(CultureInfo.InvariantCulture, + "DateTime: {0}, typeof(T).GetGenericTypeDefinition() = {1}", + DateTime.Now.ToString(CultureInfo.InvariantCulture), + typeof(T).GetGenericTypeDefinition().ToString()), config.LogVerbosity); } - LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, PCL/CORE IsGenericTypeForMessage = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), ret.ToString()), config.LogVerbosity); + + LoggingMethod.WriteToLog(pubnubLog, + string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, PCL/CORE IsGenericTypeForMessage = {1}", + DateTime.Now.ToString(CultureInfo.InvariantCulture), ret.ToString()), config.LogVerbosity); #endif - LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, IsGenericTypeForMessage = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), ret.ToString()), config.LogVerbosity); + LoggingMethod.WriteToLog(pubnubLog, + string.Format(CultureInfo.InvariantCulture, "DateTime: {0}, IsGenericTypeForMessage = {1}", + DateTime.Now.ToString(CultureInfo.InvariantCulture), ret.ToString()), config.LogVerbosity); return ret; } @@ -313,7 +373,8 @@ private T DeserializeMessageToObjectBasedOnPlatform(List listObject) dataProp.SetValue(message, userMessage, null); } - else if (listObject[0].GetType() == typeof(Newtonsoft.Json.Linq.JObject) || listObject[0].GetType() == typeof(Newtonsoft.Json.Linq.JArray)) + else if (listObject[0].GetType() == typeof(Newtonsoft.Json.Linq.JObject) || + listObject[0].GetType() == typeof(Newtonsoft.Json.Linq.JArray)) { JToken token = listObject[0] as JToken; if (dataProp.PropertyType == typeof(string)) @@ -346,7 +407,8 @@ private T DeserializeMessageToObjectBasedOnPlatform(List listObject) // Set ChannelName PropertyInfo channelNameProp = specific.GetRuntimeProperty("Channel"); - channelNameProp.SetValue(message, (listObject.Count == 6) ? listObject[5].ToString() : listObject[4].ToString(), null); + channelNameProp.SetValue(message, + (listObject.Count == 6) ? listObject[5].ToString() : listObject[4].ToString(), null); // Set ChannelGroup if (listObject.Count == 6) @@ -380,858 +442,16 @@ public virtual T DeserializeToObject(List listObject) if (IsGenericTypeForMessage()) { -#region "Subscribe Message<>" - return DeserializeMessageToObjectBasedOnPlatform(listObject); -#endregion - } - else if (typeof(T) == typeof(PNAccessManagerGrantResult)) - { -#region "PNAccessManagerGrantResult" - PNAccessManagerGrantResult result = PNAccessManagerGrantJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerGrantResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNAccessManagerTokenResult)) - { - #region "PNAccessManagerTokenResult" - PNAccessManagerTokenResult result = PNGrantTokenJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerTokenResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNAccessManagerRevokeTokenResult)) - { - #region "PNAccessManagerRevokeTokenResult" - PNAccessManagerRevokeTokenResult result = PNRevokeTokenJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNAccessManagerRevokeTokenResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNAccessManagerAuditResult)) - { -#region "PNAccessManagerAuditResult" - Dictionary auditDicObj = ConvertToDictionaryObject(listObject[0]); - - PNAccessManagerAuditResult ack = null; - - if (auditDicObj != null) - { - ack = new PNAccessManagerAuditResult(); - - if (auditDicObj.ContainsKey("payload")) - { - Dictionary auditAckPayloadDic = ConvertToDictionaryObject(auditDicObj["payload"]); - if (auditAckPayloadDic != null && auditAckPayloadDic.Count > 0) - { - if (auditAckPayloadDic.ContainsKey("level")) - { - ack.Level = auditAckPayloadDic["level"].ToString(); - } - - if (auditAckPayloadDic.ContainsKey("subscribe_key")) - { - ack.SubscribeKey = auditAckPayloadDic["subscribe_key"].ToString(); - } - - if (auditAckPayloadDic.ContainsKey("channel")) - { - ack.Channel = auditAckPayloadDic["channel"].ToString(); - } - - if (auditAckPayloadDic.ContainsKey("channel-group")) - { - ack.ChannelGroup = auditAckPayloadDic["channel-group"].ToString(); - } - - if (auditAckPayloadDic.ContainsKey("auths")) - { - Dictionary auditAckAuthListDic = ConvertToDictionaryObject(auditAckPayloadDic["auths"]); - if (auditAckAuthListDic != null && auditAckAuthListDic.Count > 0) - { - ack.AuthKeys = new Dictionary(); - - foreach (string authKey in auditAckAuthListDic.Keys) - { - Dictionary authDataDic = ConvertToDictionaryObject(auditAckAuthListDic[authKey]); - if (authDataDic != null && authDataDic.Count > 0) - { - PNAccessManagerKeyData authData = new PNAccessManagerKeyData(); - authData.ReadEnabled = authDataDic["r"].ToString() == "1"; - authData.WriteEnabled = authDataDic["w"].ToString() == "1"; - authData.ManageEnabled = authDataDic.ContainsKey("m") ? authDataDic["m"].ToString() == "1" : false; - authData.DeleteEnabled = authDataDic.ContainsKey("d") ? authDataDic["d"].ToString() == "1" : false; - - ack.AuthKeys.Add(authKey, authData); - } - } - } - } - - } - } - } - - ret = (T)Convert.ChangeType(ack, typeof(PNAccessManagerAuditResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPublishResult)) - { -#region "PNPublishResult" - PNPublishResult result = null; - if (listObject.Count >= 2) - { - long publishTimetoken; - var _ = Int64.TryParse(listObject[2].ToString(), out publishTimetoken); - result = new PNPublishResult - { - Timetoken = publishTimetoken - }; - } - - ret = (T)Convert.ChangeType(result, typeof(PNPublishResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPresenceEventResult)) - { -#region "PNPresenceEventResult" - Dictionary presenceDicObj = ConvertToDictionaryObject(listObject[0]); - - PNPresenceEventResult ack = null; - - if (presenceDicObj != null) - { - ack = new PNPresenceEventResult(); - ack.Event = presenceDicObj["action"].ToString(); - long presenceTimeStamp; - if (Int64.TryParse(presenceDicObj["timestamp"].ToString(), out presenceTimeStamp)){ - ack.Timestamp = presenceTimeStamp; - } - if (presenceDicObj.ContainsKey("uuid")) - { - ack.Uuid = presenceDicObj["uuid"].ToString(); - } - int presenceOccupany; - if (Int32.TryParse(presenceDicObj["occupancy"].ToString(), out presenceOccupany)) - { - ack.Occupancy = presenceOccupany; - } - - if (presenceDicObj.ContainsKey("data")) - { - Dictionary stateDic = presenceDicObj["data"] as Dictionary; - if (stateDic != null) - { - ack.State = stateDic; - } - } - - long presenceTimetoken; - if (Int64.TryParse(listObject[2].ToString(), out presenceTimetoken)) - { - ack.Timetoken = presenceTimetoken; - } - ack.Channel = (listObject.Count == 6) ? listObject[5].ToString() : listObject[4].ToString(); - ack.Channel = ack.Channel.Replace("-pnpres", ""); - - if (listObject.Count == 6) - { - ack.Subscription = listObject[4].ToString(); - ack.Subscription = ack.Subscription.Replace("-pnpres", ""); - } - - if (listObject[1] != null) - { - ack.UserMetadata = listObject[1]; - } - - if (ack.Event != null && ack.Event.ToLowerInvariant() == "interval") - { - if (presenceDicObj.ContainsKey("join")) - { - List joinDeltaList = presenceDicObj["join"] as List; - if (joinDeltaList != null && joinDeltaList.Count > 0) - { - ack.Join = joinDeltaList.Select(x => x.ToString()).ToArray(); - } - } - if (presenceDicObj.ContainsKey("timeout")) - { - List timeoutDeltaList = presenceDicObj["timeout"] as List; - if (timeoutDeltaList != null && timeoutDeltaList.Count > 0) - { - ack.Timeout = timeoutDeltaList.Select(x => x.ToString()).ToArray(); - } - } - if (presenceDicObj.ContainsKey("leave")) - { - List leaveDeltaList = presenceDicObj["leave"] as List; - if (leaveDeltaList != null && leaveDeltaList.Count > 0) - { - ack.Leave = leaveDeltaList.Select(x => x.ToString()).ToArray(); - } - } - if (presenceDicObj.ContainsKey("here_now_refresh")) - { - string hereNowRefreshStr = presenceDicObj["here_now_refresh"].ToString(); - if (!string.IsNullOrEmpty(hereNowRefreshStr)) - { - bool boolHereNowRefresh = false; - if (Boolean.TryParse(hereNowRefreshStr, out boolHereNowRefresh)) - { - ack.HereNowRefresh = boolHereNowRefresh; - } - } - } - - } - - } - - ret = (T)Convert.ChangeType(ack, typeof(PNPresenceEventResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNHistoryResult)) - { -#region "PNHistoryResult" - PNHistoryResult result = PNHistoryJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNHistoryResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNFetchHistoryResult)) - { -#region "PNFetchHistoryResult" - PNFetchHistoryResult result = PNFetchHistoryJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNFetchHistoryResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNDeleteMessageResult)) - { -#region "PNDeleteMessageResult" - PNDeleteMessageResult ack = new PNDeleteMessageResult(); - ret = (T)Convert.ChangeType(ack, typeof(PNDeleteMessageResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNMessageCountResult)) - { - #region "PNMessageCountResult" - PNMessageCountResult ack = null; - Dictionary messageCouuntContainerDicObj = ConvertToDictionaryObject(listObject[0]); - if (messageCouuntContainerDicObj != null && messageCouuntContainerDicObj.ContainsKey("channels")) - { - ack = new PNMessageCountResult(); - Dictionary messageCountDic = ConvertToDictionaryObject(messageCouuntContainerDicObj["channels"]); - if (messageCountDic != null) - { - ack.Channels = new Dictionary(); - foreach (string channel in messageCountDic.Keys) - { - long msgCount=0; - if (Int64.TryParse(messageCountDic[channel].ToString(), out msgCount)) - { - ack.Channels.Add(channel, msgCount); - } - } - } - } - ret = (T)Convert.ChangeType(ack, typeof(PNMessageCountResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNHereNowResult)) - { -#region "PNHereNowResult" - Dictionary herenowDicObj = ConvertToDictionaryObject(listObject[0]); - - PNHereNowResult hereNowResult = null; - - if (herenowDicObj != null) - { - hereNowResult = new PNHereNowResult(); - - string hereNowChannelName = listObject[1].ToString(); - - if (herenowDicObj.ContainsKey("payload")) - { - Dictionary hereNowPayloadDic = ConvertToDictionaryObject(herenowDicObj["payload"]); - if (hereNowPayloadDic != null && hereNowPayloadDic.Count > 0) - { - int hereNowTotalOccupancy; - int hereNowTotalChannel; - if (Int32.TryParse(hereNowPayloadDic["total_occupancy"].ToString(), out hereNowTotalOccupancy)) - { - hereNowResult.TotalOccupancy = hereNowTotalOccupancy; - } - if (Int32.TryParse(hereNowPayloadDic["total_channels"].ToString(), out hereNowTotalChannel)) - { - hereNowResult.TotalChannels = hereNowTotalChannel; - } - if (hereNowPayloadDic.ContainsKey("channels")) - { - Dictionary hereNowChannelListDic = ConvertToDictionaryObject(hereNowPayloadDic["channels"]); - if (hereNowChannelListDic != null && hereNowChannelListDic.Count > 0) - { - foreach (string channel in hereNowChannelListDic.Keys) - { - Dictionary hereNowChannelItemDic = ConvertToDictionaryObject(hereNowChannelListDic[channel]); - if (hereNowChannelItemDic != null && hereNowChannelItemDic.Count > 0) - { - PNHereNowChannelData channelData = new PNHereNowChannelData(); - channelData.ChannelName = channel; - int hereNowOccupancy; - if (Int32.TryParse(hereNowChannelItemDic["occupancy"].ToString(), out hereNowOccupancy)) - { - channelData.Occupancy = hereNowOccupancy; - } - if (hereNowChannelItemDic.ContainsKey("uuids")) - { - object[] hereNowChannelUuidList = ConvertToObjectArray(hereNowChannelItemDic["uuids"]); - if (hereNowChannelUuidList != null && hereNowChannelUuidList.Length > 0) - { - List uuidDataList = new List(); - - for (int index = 0; index < hereNowChannelUuidList.Length; index++) - { - if (hereNowChannelUuidList[index].GetType() == typeof(string)) - { - PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); - uuidData.Uuid = hereNowChannelUuidList[index].ToString(); - uuidDataList.Add(uuidData); - } - else - { - Dictionary hereNowChannelItemUuidsDic = ConvertToDictionaryObject(hereNowChannelUuidList[index]); - if (hereNowChannelItemUuidsDic != null && hereNowChannelItemUuidsDic.Count > 0) - { - PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); - uuidData.Uuid = hereNowChannelItemUuidsDic["uuid"].ToString(); - if (hereNowChannelItemUuidsDic.ContainsKey("state")) - { - uuidData.State = ConvertToDictionaryObject(hereNowChannelItemUuidsDic["state"]); - } - uuidDataList.Add(uuidData); - } - } - } - channelData.Occupants = uuidDataList; - } - } - hereNowResult.Channels.Add(channel, channelData); - } - } - } - } - } - } - else if (herenowDicObj.ContainsKey("occupancy")) - { - int hereNowTotalOccupancy; - if (Int32.TryParse(herenowDicObj["occupancy"].ToString(), out hereNowTotalOccupancy)) - { - hereNowResult.TotalOccupancy = hereNowTotalOccupancy; - } - hereNowResult.Channels = new Dictionary(); - if (herenowDicObj.ContainsKey("uuids")) - { - object[] uuidArray = ConvertToObjectArray(herenowDicObj["uuids"]); - if (uuidArray != null && uuidArray.Length > 0) - { - List uuidDataList = new List(); - for (int index = 0; index < uuidArray.Length; index++) - { - Dictionary hereNowChannelItemUuidsDic = ConvertToDictionaryObject(uuidArray[index]); - if (hereNowChannelItemUuidsDic != null && hereNowChannelItemUuidsDic.Count > 0) - { - PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); - uuidData.Uuid = hereNowChannelItemUuidsDic["uuid"].ToString(); - if (hereNowChannelItemUuidsDic.ContainsKey("state")) - { - uuidData.State = ConvertToDictionaryObject(hereNowChannelItemUuidsDic["state"]); - } - uuidDataList.Add(uuidData); - } - else - { - PNHereNowOccupantData uuidData = new PNHereNowOccupantData(); - uuidData.Uuid = uuidArray[index].ToString(); - uuidDataList.Add(uuidData); - } - } - - PNHereNowChannelData channelData = new PNHereNowChannelData(); - channelData.ChannelName = hereNowChannelName; - channelData.Occupants = uuidDataList; - channelData.Occupancy = hereNowResult.TotalOccupancy; - - hereNowResult.Channels.Add(hereNowChannelName, channelData); - hereNowResult.TotalChannels = hereNowResult.Channels.Count; - } - } - else - { - string channels = listObject[1].ToString(); - string[] arrChannel = channels.Split(','); - int totalChannels = 0; - foreach (string channel in arrChannel) - { - PNHereNowChannelData channelData = new PNHereNowChannelData(); - channelData.Occupancy = 1; - hereNowResult.Channels.Add(channel, channelData); - totalChannels++; - } - hereNowResult.TotalChannels = totalChannels; - - - } - } - - } - - ret = (T)Convert.ChangeType(hereNowResult, typeof(PNHereNowResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNWhereNowResult)) - { -#region "WhereNowAck" - Dictionary wherenowDicObj = ConvertToDictionaryObject(listObject[0]); - - PNWhereNowResult ack = null; - - if (wherenowDicObj != null) - { - ack = new PNWhereNowResult(); - - if (wherenowDicObj.ContainsKey("payload")) - { - Dictionary whereNowPayloadDic = ConvertToDictionaryObject(wherenowDicObj["payload"]); - if (whereNowPayloadDic != null && whereNowPayloadDic.Count > 0) - { - if (whereNowPayloadDic.ContainsKey("channels")) - { - object[] whereNowChannelList = ConvertToObjectArray(whereNowPayloadDic["channels"]); - if (whereNowChannelList != null && whereNowChannelList.Length >= 0) - { - List channelList = new List(); - foreach (string channel in whereNowChannelList) - { - channelList.Add(channel); - } - ack.Channels = channelList; - } - - } - } - } - } - - ret = (T)Convert.ChangeType(ack, typeof(PNWhereNowResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNSetStateResult)) - { -#region "SetUserStateAck" - Dictionary setUserStatewDicObj = ConvertToDictionaryObject(listObject[0]); - - PNSetStateResult ack = null; - - if (setUserStatewDicObj != null) - { - ack = new PNSetStateResult(); - - ack.State = new Dictionary(); - - if (setUserStatewDicObj.ContainsKey("payload")) - { - Dictionary setStateDic = ConvertToDictionaryObject(setUserStatewDicObj["payload"]); - if (setStateDic != null) - { - ack.State = setStateDic; - } - } - - } - - ret = (T)Convert.ChangeType(ack, typeof(PNSetStateResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNGetStateResult)) - { -#region "PNGetStateResult" - Dictionary getUserStatewDicObj = ConvertToDictionaryObject(listObject[0]); - - PNGetStateResult ack = null; - - if (getUserStatewDicObj != null) - { - ack = new PNGetStateResult(); - - ack.StateByUUID = new Dictionary(); - - if (getUserStatewDicObj.ContainsKey("payload")) - { - Dictionary getStateDic = ConvertToDictionaryObject(getUserStatewDicObj["payload"]); - if (getStateDic != null) - { - ack.StateByUUID = getStateDic; - } - } - } - - ret = (T)Convert.ChangeType(ack, typeof(PNGetStateResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNChannelGroupsAllChannelsResult)) - { -#region "PNChannelGroupsAllChannelsResult" - Dictionary getCgChannelsDicObj = ConvertToDictionaryObject(listObject[0]); - - PNChannelGroupsAllChannelsResult ack = null; - - if (getCgChannelsDicObj != null) - { - ack = new PNChannelGroupsAllChannelsResult(); - Dictionary getCgChannelPayloadDic = ConvertToDictionaryObject(getCgChannelsDicObj["payload"]); - if (getCgChannelPayloadDic != null && getCgChannelPayloadDic.Count > 0) - { - ack.ChannelGroup = getCgChannelPayloadDic["group"].ToString(); - object[] channelGroupChPayloadChannels = ConvertToObjectArray(getCgChannelPayloadDic["channels"]); - if (channelGroupChPayloadChannels != null && channelGroupChPayloadChannels.Length > 0) - { - List channelList = new List(); - for (int index = 0; index < channelGroupChPayloadChannels.Length; index++) - { - channelList.Add(channelGroupChPayloadChannels[index].ToString()); - } - ack.Channels = channelList; - } - } - } - - ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsAllChannelsResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNChannelGroupsListAllResult)) - { -#region "PNChannelGroupsListAllResult" - Dictionary getAllCgDicObj = ConvertToDictionaryObject(listObject[0]); - - PNChannelGroupsListAllResult ack = null; - - if (getAllCgDicObj != null) - { - ack = new PNChannelGroupsListAllResult(); - - Dictionary getAllCgPayloadDic = ConvertToDictionaryObject(getAllCgDicObj["payload"]); - if (getAllCgPayloadDic != null && getAllCgPayloadDic.Count > 0) - { - object[] channelGroupAllCgPayloadChannels = ConvertToObjectArray(getAllCgPayloadDic["groups"]); - if (channelGroupAllCgPayloadChannels != null && channelGroupAllCgPayloadChannels.Length > 0) - { - List allCgList = new List(); - for (int index = 0; index < channelGroupAllCgPayloadChannels.Length; index++) - { - allCgList.Add(channelGroupAllCgPayloadChannels[index].ToString()); - } - ack.Groups = allCgList; - } - } - } - - ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsListAllResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNChannelGroupsAddChannelResult)) - { -#region "AddChannelToChannelGroupAck" - Dictionary addChToCgDicObj = ConvertToDictionaryObject(listObject[0]); - - PNChannelGroupsAddChannelResult ack = null; - - if (addChToCgDicObj != null) - { - ack = new PNChannelGroupsAddChannelResult(); - } - - ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsAddChannelResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNChannelGroupsRemoveChannelResult)) - { -#region "PNChannelGroupsRemoveChannelResult" - Dictionary removeChFromCgDicObj = ConvertToDictionaryObject(listObject[0]); - - PNChannelGroupsRemoveChannelResult ack = null; - - int statusCode = 0; - - if (removeChFromCgDicObj != null) - { - ack = new PNChannelGroupsRemoveChannelResult(); - - if (int.TryParse(removeChFromCgDicObj["status"].ToString(), out statusCode)) - { - ack.Status = statusCode; - } - - ack.Message = removeChFromCgDicObj["message"].ToString(); - ack.Service = removeChFromCgDicObj["service"].ToString(); - - ack.Error = Convert.ToBoolean(removeChFromCgDicObj["error"].ToString(), CultureInfo.InvariantCulture); - - ack.ChannelGroup = listObject[1].ToString(); - } - - ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsRemoveChannelResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNChannelGroupsDeleteGroupResult)) - { -#region "PNChannelGroupsDeleteGroupResult" - Dictionary removeCgDicObj = ConvertToDictionaryObject(listObject[0]); - - PNChannelGroupsDeleteGroupResult ack = null; - - int statusCode = 0; - - if (removeCgDicObj != null) - { - ack = new PNChannelGroupsDeleteGroupResult(); - - if (int.TryParse(removeCgDicObj["status"].ToString(), out statusCode)) - { - ack.Status = statusCode; - } - - ack.Service = removeCgDicObj["service"].ToString(); - ack.Message = removeCgDicObj["message"].ToString(); - - ack.Error = Convert.ToBoolean(removeCgDicObj["error"].ToString(), CultureInfo.InvariantCulture); - } - - ret = (T)Convert.ChangeType(ack, typeof(PNChannelGroupsDeleteGroupResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNTimeResult)) - { -#region "PNTimeResult" - - Int64 timetoken = 0; - - var _ = Int64.TryParse(listObject[0].ToString(), out timetoken); - - PNTimeResult result = new PNTimeResult - { - Timetoken = timetoken - }; - - ret = (T)Convert.ChangeType(result, typeof(PNTimeResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPushAddChannelResult)) - { -#region "PNPushAddChannelResult" + #region "Subscribe Message<>" - PNPushAddChannelResult result = new PNPushAddChannelResult(); - - ret = (T)Convert.ChangeType(result, typeof(PNPushAddChannelResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPushListProvisionsResult)) - { -#region "PNPushListProvisionsResult" - - PNPushListProvisionsResult result = new PNPushListProvisionsResult(); - result.Channels = listObject.OfType().Where(s => s.Trim() != "").ToList(); - - ret = (T)Convert.ChangeType(result, typeof(PNPushListProvisionsResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPushRemoveChannelResult)) - { -#region "PNPushRemoveChannelResult" - - PNPushRemoveChannelResult result = new PNPushRemoveChannelResult(); - - ret = (T)Convert.ChangeType(result, typeof(PNPushRemoveChannelResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNPushRemoveAllChannelsResult)) - { -#region "PNPushRemoveAllChannelsResult" - - PNPushRemoveAllChannelsResult result = new PNPushRemoveAllChannelsResult(); - - ret = (T)Convert.ChangeType(result, typeof(PNPushRemoveAllChannelsResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNHeartbeatResult)) - { -#region "PNHeartbeatResult" - Dictionary heartbeatDicObj = ConvertToDictionaryObject(listObject[0]); - PNHeartbeatResult result = null; - - if (heartbeatDicObj != null && heartbeatDicObj.ContainsKey("status")) - { - result = new PNHeartbeatResult(); - - int statusCode; - if (int.TryParse(heartbeatDicObj["status"].ToString(), out statusCode)) - { - result.Status = statusCode; - } - - if (heartbeatDicObj.ContainsKey("message")) - { - result.Message = heartbeatDicObj["message"].ToString(); - } - } - - ret = (T)Convert.ChangeType(result, typeof(PNHeartbeatResult), CultureInfo.InvariantCulture); -#endregion - } - else if (typeof(T) == typeof(PNSetUuidMetadataResult)) - { - #region "PNSetUuidMetadataResult" - PNSetUuidMetadataResult result = PNSetUuidMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNSetUuidMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNRemoveUuidMetadataResult)) - { - #region "PNDeleteUuidMetadataResult" - PNRemoveUuidMetadataResult ack = new PNRemoveUuidMetadataResult(); - ret = (T)Convert.ChangeType(ack, typeof(PNRemoveUuidMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGetAllUuidMetadataResult)) - { - #region "PNGetAllUuidMetadataResult" - PNGetAllUuidMetadataResult result = PNGetAllUuidMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGetAllUuidMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGetUuidMetadataResult)) - { - #region "PNGetUuidMetadataResult" - PNGetUuidMetadataResult result = PNGetUuidMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGetUuidMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNSetChannelMetadataResult)) - { - #region "PNSetChannelMetadataResult" - PNSetChannelMetadataResult result = PNSetChannelMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNSetChannelMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNRemoveChannelMetadataResult)) - { - #region "PNDeleteUserResult" - PNRemoveChannelMetadataResult ack = new PNRemoveChannelMetadataResult(); - ret = (T)Convert.ChangeType(ack, typeof(PNRemoveChannelMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGetAllChannelMetadataResult)) - { - #region "PNGetSpacesResult" - PNGetAllChannelMetadataResult result = PNGetAllChannelMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGetAllChannelMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGetChannelMetadataResult)) - { - #region "PNGetSpaceResult" - PNGetChannelMetadataResult result = PNGetChannelMetadataJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGetChannelMetadataResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNMembershipsResult)) - { - #region "PNMembershipsResult" - PNMembershipsResult result = PNMembershipsJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNMembershipsResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNChannelMembersResult)) - { - #region "PNChannelMembersResult" - PNChannelMembersResult result = PNChannelMembersJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNChannelMembersResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNObjectEventResult)) - { - #region "PNObjectEventResult" - PNObjectEventResult result = PNObjectEventJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNObjectEventResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNMessageActionEventResult)) - { - #region "PNMessageActionEventResult" - PNMessageActionEventResult result = PNMessageActionEventJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNMessageActionEventResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNAddMessageActionResult)) - { - #region "PNAddMessageActionResult" - PNAddMessageActionResult result = PNAddMessageActionJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNAddMessageActionResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNRemoveMessageActionResult)) - { - #region "PNRemoveMessageActionResult" - PNRemoveMessageActionResult result = PNRemoveMessageActionJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNRemoveMessageActionResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGetMessageActionsResult)) - { - #region "PNGetMessageActionsResult" - PNGetMessageActionsResult result = PNGetMessageActionsJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGetMessageActionsResult), CultureInfo.InvariantCulture); - #endregion - } - else if (typeof(T) == typeof(PNGenerateFileUploadUrlResult)) - { - #region "PNGenerateFileUploadUrlResult" - PNGenerateFileUploadUrlResult result = PNGenerateFileUploadUrlDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNGenerateFileUploadUrlResult), CultureInfo.InvariantCulture); - #endregion - - } - else if (typeof(T) == typeof(PNPublishFileMessageResult)) - { - #region "PNPublishFileMessageResult" - PNPublishFileMessageResult result = PNPublishFileMessageJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNPublishFileMessageResult), CultureInfo.InvariantCulture); - #endregion + return DeserializeMessageToObjectBasedOnPlatform(listObject); - } - else if (typeof(T) == typeof(PNListFilesResult)) - { - #region "PNListFilesResult" - PNListFilesResult result = PNListFilesJsonDataParse.GetObject(listObject); - ret = (T)Convert.ChangeType(result, typeof(PNListFilesResult), CultureInfo.InvariantCulture); #endregion } - else if (typeof(T) == typeof(PNDeleteFileResult)) - { - #region "PNDeleteFileResult" - PNDeleteFileResult ack = new PNDeleteFileResult(); - ret = (T)Convert.ChangeType(ack, typeof(PNDeleteFileResult), CultureInfo.InvariantCulture); - #endregion - - } else { - System.Diagnostics.Debug.WriteLine("DeserializeToObject(list) => NO MATCH"); - try - { - ret = (T)(object)listObject; - } - catch { /* ignore */ } + return DeserializeToInternalObjectUtility.DeserializeToInternalObject(this, listObject); } - - return ret; } public Dictionary DeserializeToDictionaryOfObject(string jsonString) @@ -1241,13 +461,15 @@ public Dictionary DeserializeToDictionaryOfObject(string jsonStr { if (JsonFastCheck(jsonString)) { - result = JsonConvert.DeserializeObject>(jsonString, defaultJsonSerializerSettings); + result = JsonConvert.DeserializeObject>(jsonString, + defaultJsonSerializerSettings); } } catch { //ignore } + return result; } @@ -1273,7 +495,8 @@ public Dictionary ConvertToDictionaryObject(object localContaine } } } - else if (localContainer.GetType().ToString() == "System.Collections.Generic.Dictionary`2[System.String,System.Object]") + else if (localContainer.GetType().ToString() == + "System.Collections.Generic.Dictionary`2[System.String,System.Object]") { ret = new Dictionary(); Dictionary dictionary = localContainer as Dictionary; @@ -1296,9 +519,9 @@ public Dictionary ConvertToDictionaryObject(object localContaine else if (localContainer.GetType().ToString() == "System.Collections.Generic.List`1[System.Object]") { List localList = localContainer as List; - if (localList != null) + if (localList != null && localList.Count > 0) { - if (localList.Count > 0 && localList[0].GetType() == typeof(KeyValuePair)) + if (localList[0].GetType() == typeof(KeyValuePair)) { ret = new Dictionary(); foreach (object item in localList) @@ -1314,16 +537,18 @@ public Dictionary ConvertToDictionaryObject(object localContaine } } } - else if (localList.Count == 1 && localList[0].GetType() == typeof(Dictionary)) + else if (localList[0].GetType() == typeof(Dictionary)) { ret = new Dictionary(); - - Dictionary localDic = localList[0] as Dictionary; - foreach (object item in localDic) + foreach (object item in localList) { - if (item is KeyValuePair kvpItem) + if (item is Dictionary dicItem) { - ret.Add(kvpItem.Key, kvpItem.Value); + if (dicItem.Count > 0 && dicItem.ContainsKey("key") && + dicItem.ContainsKey("value")) + { + ret.Add(dicItem["key"].ToString(), dicItem["value"]); + } } else { @@ -1336,10 +561,12 @@ public Dictionary ConvertToDictionaryObject(object localContaine } } } - catch { /* ignore */ } + catch + { + /* ignore */ + } return ret; - } public object[] ConvertToObjectArray(object localContainer) @@ -1376,10 +603,12 @@ public object[] ConvertToObjectArray(object localContainer) return ret; } - public static bool JsonFastCheck(string rawJson) { - var c = rawJson.TrimStart()[0]; - return c == '[' || c == '{'; + public static bool JsonFastCheck(string rawJson) + { + var c = rawJson.TrimStart()[0]; + return c == '[' || c == '{'; } + private static object ConvertJTokenToObject(JToken token) { if (token == null) @@ -1409,8 +638,8 @@ private static object ConvertJTokenToObject(JToken token) { var jsonDict = new Dictionary(); List propertyList = (from childToken in token - where childToken is JProperty - select childToken as JProperty).ToList(); + where childToken is JProperty + select childToken as JProperty).ToList(); foreach (JProperty property in propertyList) { jsonDict.Add(property.Name, ConvertJTokenToObject(property.Value)); @@ -1478,8 +707,6 @@ private static object ConvertToDataType(Type dataType, object inputValue) return userMessage; } -#endregion - + #endregion } - -} +} \ No newline at end of file diff --git a/src/Api/PubnubApi/Properties/AssemblyInfo.cs b/src/Api/PubnubApi/Properties/AssemblyInfo.cs index 4c0bdfdce..554715fa1 100644 --- a/src/Api/PubnubApi/Properties/AssemblyInfo.cs +++ b/src/Api/PubnubApi/Properties/AssemblyInfo.cs @@ -11,8 +11,8 @@ [assembly: AssemblyProduct("Pubnub C# SDK")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("6.20.0.0")] -[assembly: AssemblyFileVersion("6.20.0.0")] +[assembly: AssemblyVersion("6.20.1.0")] +[assembly: AssemblyFileVersion("6.20.1.0")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 602b8f48a..30299f97c 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -14,7 +14,7 @@ Pubnub - 6.20.0.0 + 6.20.1.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -22,8 +22,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added event engine implementation for subscribe and presence operation. -Added support for `RetryConfiguration` to configure subscribe request retry. + Fixes issue of Unity SDK not being able to have a fully independent IJsonPluggableLibrary implementation because of direct nu-get Newtonsoft usage in C# SDK (Unity has it's own version that works with IL2CPP builds). Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously diff --git a/src/Api/PubnubApi/PubnubCoreBase.cs b/src/Api/PubnubApi/PubnubCoreBase.cs index 621e19359..625cc4369 100644 --- a/src/Api/PubnubApi/PubnubCoreBase.cs +++ b/src/Api/PubnubApi/PubnubCoreBase.cs @@ -823,7 +823,7 @@ private void ResponseToUserCallback(List result, PNOperationType type Timetoken = pnFileResult.Timetoken, Publisher = pnFileResult.Publisher, }; - Dictionary pnMsgObjDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(pnFileResult.Message); + Dictionary pnMsgObjDic = jsonLib.ConvertToDictionaryObject(pnFileResult.Message); if (pnMsgObjDic != null && pnMsgObjDic.Count > 0) { if (pnMsgObjDic.ContainsKey("message") && pnMsgObjDic["message"]!= null) @@ -832,7 +832,7 @@ private void ResponseToUserCallback(List result, PNOperationType type } if (pnMsgObjDic.ContainsKey("file")) { - Dictionary fileObjDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(pnMsgObjDic["file"]); + Dictionary fileObjDic = jsonLib.ConvertToDictionaryObject(pnMsgObjDic["file"]); if (fileObjDic != null && fileObjDic.ContainsKey("id") && fileObjDic.ContainsKey("name")) { fileMessage.File = new PNFile { Id = fileObjDic["id"].ToString(), Name = fileObjDic["name"].ToString() }; diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 31f60f28c..1cd552360 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -15,7 +15,7 @@ PubnubPCL - 6.20.0.0 + 6.20.1.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -23,8 +23,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added event engine implementation for subscribe and presence operation. -Added support for `RetryConfiguration` to configure subscribe request retry. + Fixes issue of Unity SDK not being able to have a fully independent IJsonPluggableLibrary implementation because of direct nu-get Newtonsoft usage in C# SDK (Unity has it's own version that works with IL2CPP builds). Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously @@ -300,7 +299,9 @@ Added support for `RetryConfiguration` to configure subscribe request retry. Interface\IUrlRequestBuilder.cs - + + JsonDataParse\DeserializeToInternalObjectUtility.cs + @@ -985,7 +986,6 @@ Added support for `RetryConfiguration` to configure subscribe request retry. - diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 9c616f6ae..04da2ab34 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -16,7 +16,7 @@ PubnubUWP - 6.20.0.0 + 6.20.1.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -24,8 +24,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added event engine implementation for subscribe and presence operation. -Added support for `RetryConfiguration` to configure subscribe request retry. + Fixes issue of Unity SDK not being able to have a fully independent IJsonPluggableLibrary implementation because of direct nu-get Newtonsoft usage in C# SDK (Unity has it's own version that works with IL2CPP builds). Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously @@ -418,7 +417,9 @@ Added support for `RetryConfiguration` to configure subscribe request retry. Interface\IUrlRequestBuilder.cs - + + JsonDataParse\DeserializeToInternalObjectUtility.cs + @@ -799,7 +800,6 @@ Added support for `RetryConfiguration` to configure subscribe request retry. - diff --git a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj index ec2355320..350460416 100644 --- a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj +++ b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj @@ -15,7 +15,7 @@ PubnubApiUnity - 6.20.0.0 + 6.20.1.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -218,6 +218,9 @@ + + JsonDataParse\DeserializeToInternalObjectUtility.cs + RetryConfiguration.cs @@ -302,7 +305,6 @@ Interface\IUrlRequestBuilder.cs - @@ -980,7 +982,6 @@ -