Exemplo n.º 1
0
        public static ChannelEntity CreateChannelEntity(string channelOrChannelGroupName2, bool isAwaitingConnectCallback, bool isChannelGroup, Dictionary <string, object> userState, PNLoggingMethod pnLog)
        {
            string channelOrChannelGroupName = channelOrChannelGroupName2.Trim();

            #if (ENABLE_PUBNUB_LOGGING)
            pnLog.WriteToLog(string.Format("CreateChannelEntity: channelOrChannelGroupName {0}, {1}", channelOrChannelGroupName.ToString(), channelOrChannelGroupName2.ToString()), PNLoggingMethod.LevelInfo);
            #endif

            if (!string.IsNullOrEmpty(channelOrChannelGroupName))
            {
                ChannelIdentity ci = new ChannelIdentity();
                ci.ChannelOrChannelGroupName = channelOrChannelGroupName;
                ci.IsPresenceChannel         = Utility.IsPresenceChannel(channelOrChannelGroupName);
                ci.IsChannelGroup            = isChannelGroup;

                ChannelParameters cp = new ChannelParameters();
                cp.IsAwaitingConnectCallback = isAwaitingConnectCallback;
                cp.UserState = userState;
                ChannelEntity ce = new ChannelEntity(ci, cp);

                return(ce);
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity: channelOrChannelGroupName empty, is channel group {0}", isChannelGroup.ToString()), PNLoggingMethod.LevelInfo);
                #endif

                return(null);
            }
        }
Exemplo n.º 2
0
        public static List <ChannelEntity> CreateChannelEntity(string[] channelOrChannelGroupNames, bool isAwaitingConnectCallback, bool isChannelGroup, Dictionary <string, object> userState, PNLoggingMethod pnLog)
        {
            List <ChannelEntity> channelEntities = null;

            if (channelOrChannelGroupNames != null)
            {
                channelEntities = new List <ChannelEntity> ();
                foreach (string ch in channelOrChannelGroupNames)
                {
                    ChannelEntity chEntity = CreateChannelEntity(ch, isAwaitingConnectCallback, isChannelGroup, userState, pnLog);
                    if (chEntity != null)
                    {
                        channelEntities.Add(chEntity);
                    }
                }
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity 2: channelEntities={0}", channelEntities.Count), PNLoggingMethod.LevelInfo);
                #endif
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                pnLog.WriteToLog(string.Format("CreateChannelEntity 2: channelOrChannelGroupNames null, is channel group {0}", isChannelGroup.ToString()), PNLoggingMethod.LevelInfo);
                #endif
            }

            return(channelEntities);
        }
Exemplo n.º 3
0
        public static TimetokenMetadata CreateTimetokenMetadata(object timeTokenDataObject, string whichTT, PNLoggingMethod pnLog)
        {
            Dictionary <string, object> timeTokenData = (Dictionary <string, object>)timeTokenDataObject;
            string log;
            long   timetoken;

            Utility.TryCheckKeyAndParseLong(timeTokenData, whichTT, "t", out log, out timetoken);
            TimetokenMetadata timetokenMetadata = new TimetokenMetadata(timetoken, (timeTokenData.ContainsKey("r")) ? timeTokenData["r"].ToString(): "");

            #if (ENABLE_PUBNUB_LOGGING)
            pnLog.WriteToLog(string.Format("TimetokenMetadata: {0} \nTimetoken: {1} \nRegion: {2}\nlog : {3}", whichTT, timetokenMetadata.Timetoken, timetokenMetadata.Region, log), PNLoggingMethod.LevelInfo);
            #endif

            return(timetokenMetadata);
        }
Exemplo n.º 4
0
        public static List <SubscribeMessage> CreateListOfSubscribeMessage(object message, PNLoggingMethod pnLog)
        {
            List <SubscribeMessage> subscribeMessages = new List <SubscribeMessage> ();

            if (message != null)
            {
                //JSONFx
                object[] messages = message as object[];

                if (messages != null)
                {
                    var myObjectArray = (from item in messages
                                         select item as object).ToArray();
                    if ((myObjectArray != null) && (myObjectArray.Length > 0))
                    {
                        foreach (object dictObject in myObjectArray)
                        {
                            TryAddToSubscribeMessageList(dictObject, ref subscribeMessages, pnLog);
                        }
                    }
                }
                else
                {
                    //MiniJSON
                    List <object> messageList = message as List <object>;
                    if ((messageList != null) && messageList.Count > 0)
                    {
                        foreach (object dictObject in messageList)
                        {
                            TryAddToSubscribeMessageList(dictObject, ref subscribeMessages, pnLog);
                        }
                    }
                }
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                pnLog.WriteToLog(string.Format("CreateListOfSubscribeMessage: no messages "), PNLoggingMethod.LevelInfo);
            }
            #endif

            return(subscribeMessages);
        }
Exemplo n.º 5
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);
        }