Beispiel #1
0
        SubscribeEnvelope ParseReceiedJSONV2(string jsonString)
        {
            if (!string.IsNullOrEmpty(jsonString))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ParseReceiedJSONV2: jsonString = {0}", jsonString), PNLoggingMethod.LevelInfo);
                #endif

                //this doesnt work on JSONFx for Unity in case a string is passed in an variable of type object
                //SubscribeEnvelope resultSubscribeEnvelope = jsonPluggableLibrary.Deserialize<SubscribeEnvelope>(jsonString);
                object            resultSubscribeEnvelope = PubNubInstance.JsonLibrary.DeserializeToObject(jsonString);
                SubscribeEnvelope subscribeEnvelope       = new SubscribeEnvelope();

                if (resultSubscribeEnvelope is Dictionary <string, object> )
                {
                    Dictionary <string, object> message = (Dictionary <string, object>)resultSubscribeEnvelope;
                    subscribeEnvelope.TimetokenMeta = Helpers.CreateTimetokenMetadata(message ["t"], "Subscribe TT: ", this.PubNubInstance.PNLog);
                    subscribeEnvelope.Messages      = Helpers.CreateListOfSubscribeMessage(message ["m"], this.PubNubInstance.PNLog);

                    return(subscribeEnvelope);
                }
                else
                {
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("ParseReceiedJSONV2: resultSubscribeEnvelope is not dict"), PNLoggingMethod.LevelError);
                    #endif

                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public static bool TryAddToSubscribeMessageList(object dictObject, ref List <SubscribeMessage> subscribeMessages, PNLoggingMethod pnLog)
        {
            var dict = dictObject as IDictionary;

            if ((dict != null) && (dict.Count > 1))
            {
                string shard             = (dict.Contains("a")) ? dict ["a"].ToString() : "";
                string subscriptionMatch = (dict.Contains("b")) ? dict ["b"].ToString() : "";
                string channel           = (dict.Contains("c")) ? dict ["c"].ToString() : "";
                object payload           = (dict.Contains("d")) ? (object)dict ["d"] : null;
                string flags             = (dict.Contains("f")) ? dict ["f"].ToString() : "";
                string issuingClientId   = (dict.Contains("i")) ? dict ["i"].ToString() : "";
                string subscribeKey      = (dict.Contains("k")) ? dict ["k"].ToString() : "";
                string log;
                long   sequenceNumber;
                Utility.TryCheckKeyAndParseLong(dict, "sequenceNumber", "s", out log, out sequenceNumber);

                TimetokenMetadata originatingTimetoken = (dict.Contains("o")) ? Helpers.CreateTimetokenMetadata(dict ["o"], "Originating TT: ", pnLog) : null;
                TimetokenMetadata publishMetadata      = (dict.Contains("p")) ? Helpers.CreateTimetokenMetadata(dict ["p"], "Publish TT: ", pnLog) : null;
                object            userMetadata         = (dict.Contains("u")) ? (object)dict ["u"] : null;

                int messageType;
                Utility.TryCheckKeyAndParseInt(dict, "messageType", "e", out log, out messageType);

                SubscribeMessage subscribeMessage = new SubscribeMessage(
                    shard,
                    subscriptionMatch,
                    channel,
                    payload,
                    flags,
                    issuingClientId,
                    subscribeKey,
                    sequenceNumber,
                    originatingTimetoken,
                    publishMetadata,
                    userMetadata,
                    messageType
                    );
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("AddToSubscribeMessageList: \n" +
                                               "shard : {0},\n" +
                                               "subscriptionMatch: {1},\n" +
                                               "channel: {2},\n" +
                                               "payload: {3},\n" +
                                               "flags: {4},\n" +
                                               "issuingClientId: {5},\n" +
                                               "subscribeKey: {6},\n" +
                                               "sequenceNumber: {7},\n" +
                                               "originatingTimetoken tt: {8},\n" +
                                               "originatingTimetoken region: {9},\n" +
                                               "publishMetadata tt: {10},\n" +
                                               "publishMetadata region: {11},\n" +
                                               "userMetadata {12} \n" +
                                               "log {13} \n",
                                               "messageType {14}\n",

                                               shard,
                                               subscriptionMatch,
                                               channel,
                                               payload.ToString(),
                                               flags,
                                               issuingClientId,
                                               subscribeKey,
                                               sequenceNumber,
                                               (originatingTimetoken != null) ? originatingTimetoken.Timetoken.ToString() : "",
                                               (originatingTimetoken != null) ? originatingTimetoken.Region : "",
                                               (publishMetadata != null) ? publishMetadata.Timetoken.ToString() : "",
                                               (publishMetadata != null) ? publishMetadata.Region : "",
                                               (userMetadata != null) ? userMetadata.ToString() : "null",
                                               log,
                                               messageType),
                                 PNLoggingMethod.LevelInfo);
                #endif

                subscribeMessages.Add(subscribeMessage);
                return(true);
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                pnLog.WriteToLog(string.Format("AddToSubscribeMessageList: CreateListOfSubscribeMessage create SubscribeMessage failed. dictObject type: {0}, dict type : {1}", dictObject.ToString(), dict.ToString()), PNLoggingMethod.LevelInfo);
            }
            #endif
            return(false);
        }