Exemplo n.º 1
0
        internal void CreatePNMessageResult(SubscribeMessage subscribeMessage, out PNMessageResult messageResult)
        {
            long timetoken            = (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken : 0;
            long originatingTimetoken = (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Timetoken : 0;

            messageResult = new PNMessageResult(
                subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""),
                subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""),
                subscribeMessage.Payload,
                timetoken,
                originatingTimetoken,
                subscribeMessage.UserMetadata,
                subscribeMessage.IssuingClientId
                );
        }
Exemplo n.º 2
0
        internal void CreatePNPresenceEventResult(SubscribeMessage subscribeMessage, out PNPresenceEventResult messageResult)
        {
            long            timetoken       = (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken : 0;
            PNPresenceEvent pnPresenceEvent = CreatePNPresenceEvent(subscribeMessage.Payload);

            messageResult = new PNPresenceEventResult(
                subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""),
                subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""),
                pnPresenceEvent.Action,
                timetoken,
                pnPresenceEvent.Timestamp,
                subscribeMessage.UserMetadata,
                pnPresenceEvent.State,
                pnPresenceEvent.UUID,
                pnPresenceEvent.Occupancy,
                subscribeMessage.IssuingClientId,
                pnPresenceEvent.Join,
                pnPresenceEvent.Leave,
                pnPresenceEvent.Timeout
                );
        }
Exemplo n.º 3
0
        internal void FindChannelEntityAndCallback(SubscribeMessage subscribeMessage, ChannelIdentity ci)
        {
            bool isPresenceChannel = Utility.IsPresenceChannel(subscribeMessage.Channel);

            PNStatus pns = new PNStatus();

            pns.Error = false;
            SubscribeEventEventArgs mea = new SubscribeEventEventArgs();

            mea.Status = pns;

            if (((subscribeMessage.SubscriptionMatch.Contains(".*")) && isPresenceChannel) || (isPresenceChannel))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("Raising presence message event ", PNLoggingMethod.LevelInfo);
                #endif

                PNPresenceEventResult subMessageResult;
                CreatePNPresenceEventResult(subscribeMessage, out subMessageResult);
                mea.PresenceEventResult = subMessageResult;
                PubNubInstance.RaiseEvent(mea);
            }
            else
            {
                PNMessageResult subMessageResult;
                CreatePNMessageResult(subscribeMessage, out subMessageResult);
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("Raising message event ", PNLoggingMethod.LevelInfo);
                #endif

                if (!string.IsNullOrEmpty(this.PubNubInstance.PNConfig.CipherKey) && (this.PubNubInstance.PNConfig.CipherKey.Length > 0))
                {
                    subMessageResult.Payload = Helpers.DecodeMessage(PubNubInstance.PNConfig.CipherKey, subMessageResult.Payload, PNOperationType.PNSubscribeOperation, this.PubNubInstance);
                }
                mea.MessageResult = subMessageResult;
                PubNubInstance.RaiseEvent(mea);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        internal void CreateObjectsEventResult(SubscribeMessage subscribeMessage, out PNUserEventResult pnUserEventResult, out PNSpaceEventResult pnSpaceEventResult, out PNMembershipEventResult pnMembershipEventResult)
        {
            pnUserEventResult       = null;
            pnSpaceEventResult      = null;
            pnMembershipEventResult = null;

            object payload = subscribeMessage.Payload;
            Dictionary <string, object> pnObjectEventDict = payload as Dictionary <string, object>;
            string objectsEventType          = Utility.ReadMessageFromResponseDictionary(pnObjectEventDict, "type");
            string objectsEvent              = Utility.ReadMessageFromResponseDictionary(pnObjectEventDict, "event");
            Dictionary <string, object> data = Utility.ReadDictionaryFromResponseDictionary(pnObjectEventDict, "data");

            if (data != null)
            {
                string userID      = Utility.ReadMessageFromResponseDictionary(data, "userId");
                string ID          = Utility.ReadMessageFromResponseDictionary(data, "id");
                string spaceID     = Utility.ReadMessageFromResponseDictionary(data, "spaceId");
                string name        = Utility.ReadMessageFromResponseDictionary(data, "name");
                string externalID  = Utility.ReadMessageFromResponseDictionary(data, "externalId");
                string profileURL  = Utility.ReadMessageFromResponseDictionary(data, "profileUrl");
                string email       = Utility.ReadMessageFromResponseDictionary(data, "email");
                string description = Utility.ReadMessageFromResponseDictionary(data, "description");
                string timestamp   = Utility.ReadMessageFromResponseDictionary(data, "timestamp");
                string created     = Utility.ReadMessageFromResponseDictionary(data, "created");
                string updated     = Utility.ReadMessageFromResponseDictionary(data, "updated");
                string eTag        = Utility.ReadMessageFromResponseDictionary(data, "eTag");
                Dictionary <string, object> custom = Utility.ReadDictionaryFromResponseDictionary(pnObjectEventDict, "custom");

                if (objectsEventType.Equals(PNObjectsEventType.PNObjectsUserEvent.GetDescription().ToString()))
                {
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsUserEvent"), PNLoggingMethod.LevelInfo);
                    #endif

                    pnUserEventResult = new PNUserEventResult();
                    pnUserEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent);
                    pnUserEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, "");
                    pnUserEventResult.Channel      = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, "");
                    pnUserEventResult.Email        = email;
                    pnUserEventResult.UserID       = ID;
                    pnUserEventResult.Timestamp    = timestamp;
                    pnUserEventResult.Created      = created;
                    pnUserEventResult.Updated      = updated;
                    pnUserEventResult.ETag         = eTag;
                    pnUserEventResult.Custom       = custom;
                    pnUserEventResult.Name         = name;
                    pnUserEventResult.ExternalID   = externalID;
                    pnUserEventResult.ProfileURL   = profileURL;

                    this.PubNubInstance.PNLog.WriteToLog("pnUserEventResult.UserID" + pnUserEventResult.UserID, PNLoggingMethod.LevelInfo);
                }
                else if (objectsEventType.Equals(PNObjectsEventType.PNObjectsSpaceEvent.GetDescription().ToString()))
                {
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsSpaceEvent"), PNLoggingMethod.LevelInfo);
                    #endif

                    pnSpaceEventResult = new PNSpaceEventResult();
                    pnSpaceEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent);
                    pnSpaceEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, "");
                    pnSpaceEventResult.Channel      = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, "");
                    pnSpaceEventResult.Description  = description;
                    pnSpaceEventResult.SpaceID      = ID;
                    pnSpaceEventResult.Timestamp    = timestamp;
                    pnSpaceEventResult.Created      = created;
                    pnSpaceEventResult.Updated      = updated;
                    pnSpaceEventResult.ETag         = eTag;
                    pnSpaceEventResult.Custom       = custom;
                    pnSpaceEventResult.Name         = name;
                }
                else if (objectsEventType.Equals(PNObjectsEventType.PNObjectsMembershipEvent.GetDescription().ToString()))
                {
                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsMembershipEvent"), PNLoggingMethod.LevelInfo);
                    #endif

                    pnMembershipEventResult = new PNMembershipEventResult();
                    pnMembershipEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent);
                    pnMembershipEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, "");
                    pnMembershipEventResult.Channel      = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, "");
                    pnMembershipEventResult.Description  = description;
                    pnMembershipEventResult.SpaceID      = spaceID;
                    pnMembershipEventResult.UserID       = userID;
                    pnMembershipEventResult.Timestamp    = timestamp;
                    pnMembershipEventResult.Custom       = custom;
                }
            }
        }