Example #1
0
        internal void SendResponseToConnectCallback(RequestState pnRequestState)
        {
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("SendResponseToConnectCallback", PNLoggingMethod.LevelInfo);
            #endif

            int count = PubNubInstance.SubscriptionInstance.ChannelsAndChannelGroupsAwaitingConnectCallback.Count;
            if (count > 0)
            {
                bool updateIsAwaitingConnectCallback = false;
                for (int i = 0; i < count; i++)
                {
                    ChannelEntity ce = PubNubInstance.SubscriptionInstance.ChannelsAndChannelGroupsAwaitingConnectCallback[i];
                    updateIsAwaitingConnectCallback = true;
                    PNStatus pnStatus = Helpers.CreatePNStatus(
                        PNStatusCategory.PNConnectedCategory,
                        "",
                        null,
                        false,
                        PNOperationType.PNSubscribeOperation,
                        ce,
                        pnRequestState,
                        PubNubInstance
                        );

                    CreateEventArgsAndRaiseEvent(pnStatus);
                }
                if (updateIsAwaitingConnectCallback)
                {
                    PubNubInstance.SubscriptionInstance.UpdateIsAwaitingConnectCallbacksOfEntity(PubNubInstance.SubscriptionInstance.ChannelsAndChannelGroupsAwaitingConnectCallback, false);
                }
            }
        }
Example #2
0
        void InternetDisconnectedHandler(object sender, EventArgs ea)
        {
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("Internet disconnected", PNLoggingMethod.LevelInfo);
            #endif

            AbortPreviousRequest(null);
            internetStatus = false;
            if (
                PubNubInstance.PNConfig.HeartbeatNotificationOption.Equals(PNHeartbeatNotificationOption.All) ||
                PubNubInstance.PNConfig.HeartbeatNotificationOption.Equals(PNHeartbeatNotificationOption.Failures)
                )
            {
                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNDisconnectedCategory,
                    "",
                    null,
                    true,
                    PNOperationType.PNSubscribeOperation,
                    PubNubInstance.SubscriptionInstance.AllChannels,
                    PubNubInstance.SubscriptionInstance.AllChannelGroups,
                    null,
                    this.PubNubInstance
                    );

                CreateEventArgsAndRaiseEvent(pnStatus);
            }
        }
Example #3
0
        void InternetAvailableHandler(object sender, EventArgs ea)
        {
            reconnect      = true;
            internetStatus = true;
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("Internet available", PNLoggingMethod.LevelInfo);
            #endif

            if (
                PubNubInstance.PNConfig.HeartbeatNotificationOption.Equals(PNHeartbeatNotificationOption.All)
                )
            {
                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNReconnectedCategory,
                    "",
                    null,
                    true,
                    PNOperationType.PNSubscribeOperation,
                    PubNubInstance.SubscriptionInstance.AllChannels,
                    PubNubInstance.SubscriptionInstance.AllChannelGroups,
                    null,
                    this.PubNubInstance
                    );

                CreateEventArgsAndRaiseEvent(pnStatus);
            }

            ExceptionHandler(null);
        }
Example #4
0
        protected void ExceptionHandler(RequestState pnRequestState)
        {
            #if (ENABLE_PUBNUB_LOGGING)
            List <ChannelEntity> channelEntities = PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;

            this.PubNubInstance.PNLog.WriteToLog(string.Format("InExceptionHandler: responsetype"), PNLoggingMethod.LevelInfo);
            string channelGroups = Helpers.GetNamesFromChannelEntities(channelEntities, true);
            string channels      = Helpers.GetNamesFromChannelEntities(channelEntities, false);
            #endif


            if (!internetStatus)
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ExceptionHandler: Subscribe channels = {0} and channelgroups = {1} - No internet connection. ", channels, channelGroups), PNLoggingMethod.LevelInfo);
                #endif
                if (this.PubNubInstance.PNConfig.ReconnectionPolicy.Equals(PNReconnectionPolicy.NONE))
                {
                    PNStatus pnStatus = Helpers.CreatePNStatus(
                        PNStatusCategory.PNDisconnectedCategory,
                        "",
                        null,
                        true,
                        PNOperationType.PNSubscribeOperation,
                        PubNubInstance.SubscriptionInstance.AllChannels,
                        PubNubInstance.SubscriptionInstance.AllChannelGroups,
                        null,
                        this.PubNubInstance
                        );

                    CreateEventArgsAndRaiseEvent(pnStatus);
                }
                return;
            }

            long tt = lastSubscribeTimetoken;
            if (!enableResumeOnReconnect && reconnect)
            {
                tt = 0; //send 0 time token to enable presence event
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ExceptionHandler: Reconnect true and EnableResumeOnReconnect false sending tt = 0. "), PNLoggingMethod.LevelInfo);
                #endif
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ExceptionHandler: sending tt = {0}. ", tt.ToString()), PNLoggingMethod.LevelInfo);
            }
            #endif


            RunSubscribeRequest(tt, reconnect);
        }
Example #5
0
        void RetriesExceededHandler(object sender, EventArgs ea)
        {
            BounceRequest();

            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("Retries exceeded", PNLoggingMethod.LevelInfo);
            #endif

            hbWorker.ResetInternetCheckSettings();

            #if (ENABLE_PUBNUB_LOGGING)
            List <ChannelEntity> channelEntities = PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;
            string channelGroups = Helpers.GetNamesFromChannelEntities(channelEntities, true);
            string channels      = Helpers.GetNamesFromChannelEntities(channelEntities, false);
            this.PubNubInstance.PNLog.WriteToLog(string.Format("ExceptionHandler: MAX retries reached. Exiting the subscribe for channels = {0} and channelgroups = {1}", channels, channelGroups), PNLoggingMethod.LevelInfo);
            #endif

            UnsubscribeAllBuilder unsubBuilder = new UnsubscribeAllBuilder(this.PubNubInstance);
            unsubBuilder.Async((result, status) => {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("in UnsubscribeAll", PNLoggingMethod.LevelInfo);
                if (status.Error)
                {
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("In Example, UnsubscribeAll Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category), PNLoggingMethod.LevelInfo);
                }
                else
                {
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("In UnsubscribeAll, result: {0}", result.Message), PNLoggingMethod.LevelInfo);
                }
                #endif
            });

            if (
                PubNubInstance.PNConfig.HeartbeatNotificationOption.Equals(PNHeartbeatNotificationOption.All) ||
                PubNubInstance.PNConfig.HeartbeatNotificationOption.Equals(PNHeartbeatNotificationOption.Failures)
                )
            {
                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNReconnectionAttemptsExhausted,
                    "",
                    null,
                    true,
                    PNOperationType.PNSubscribeOperation,
                    PubNubInstance.SubscriptionInstance.AllChannels,
                    PubNubInstance.SubscriptionInstance.AllChannelGroups,
                    null,
                    this.PubNubInstance
                    );

                CreateEventArgsAndRaiseEvent(pnStatus);
            }
        }
Example #6
0
 protected PNStatus CreateErrorResponseFromMessage(string message, RequestState pnRequestState, PNStatusCategory pnStatusCategory)
 {
     return(Helpers.CreatePNStatus(
                pnStatusCategory,
                message,
                new PubNubException(message),
                true,
                OperationType,
                ChannelsToUse,
                ChannelGroupsToUse,
                pnRequestState,
                PubNubInstance
                ));
 }
Example #7
0
 protected PNStatus CreateErrorResponseFromException(Exception ex, RequestState pnRequestState, PNStatusCategory pnStatusCategory)
 {
     return(Helpers.CreatePNStatus(
                pnStatusCategory,
                ex.Message,
                ex,
                true,
                OperationType,
                ChannelsToUse,
                ChannelGroupsToUse,
                pnRequestState,
                PubNubInstance
                ));
 }
Example #8
0
 protected PNStatus CreateStatusResponseFromMessage(bool isError, string message, RequestState pnRequestState, PNStatusCategory pnStatusCategory)
 {
     return(Helpers.CreatePNStatus(
                pnStatusCategory,
                message,
                (isError)?new PubNubException(message):null,
                isError,
                OperationType,
                ChannelsToUse,
                ChannelGroupsToUse,
                pnRequestState,
                PubNubInstance
                ));
 }
Example #9
0
        protected void CreateErrorResponse(PNStatusCategory pnStatusCategory, Exception exception, bool showInCallback, RequestState pnRequestState)
        {
            PNStatus pnStatus = Helpers.CreatePNStatus(
                pnStatusCategory,
                exception.Message,
                exception,
                true,
                OperationType,
                ChannelsToUse,
                ChannelGroupsToUse,
                pnRequestState,
                PubNubInstance
                );

            if (showInCallback)
            {
                Callback(null, pnStatus);
            }
        }
Example #10
0
        internal void ResponseToUserCallbackForSubscribe(List <SubscribeMessage> subscribeMessages)
        {
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog(string.Format("In ResponseToUserCallbackForSubscribeV2"), PNLoggingMethod.LevelInfo);
            #endif
            if (subscribeMessages.Count >= this.PubNubInstance.PNConfig.MessageQueueOverflowCount)
            {
                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNRequestMessageCountExceededCategory,
                    "",
                    null,
                    true,
                    PNOperationType.PNSubscribeOperation,
                    PubNubInstance.SubscriptionInstance.AllChannels,
                    PubNubInstance.SubscriptionInstance.AllChannelGroups,
                    null,
                    this.PubNubInstance
                    );

                CreateEventArgsAndRaiseEvent(pnStatus);
            }

            foreach (SubscribeMessage subscribeMessage in subscribeMessages)
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ResponseToUserCallbackForSubscribeV2:\n SubscribeMessage:\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",
                                                                   subscribeMessage.Shard,
                                                                   subscribeMessage.SubscriptionMatch,
                                                                   subscribeMessage.Channel,
                                                                   subscribeMessage.Payload.ToString(),
                                                                   subscribeMessage.Flags,
                                                                   subscribeMessage.IssuingClientId,
                                                                   subscribeMessage.SubscribeKey,
                                                                   subscribeMessage.SequenceNumber,
                                                                   (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Timetoken.ToString() : "",
                                                                   (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Region : "",
                                                                   (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken.ToString() : "",
                                                                   (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Region : "",
                                                                   (subscribeMessage.UserMetadata != null) ? subscribeMessage.UserMetadata.ToString() : "null"),
                                                     PNLoggingMethod.LevelInfo);
                #endif

                bool isPresenceChannel = Utility.IsPresenceChannel(subscribeMessage.Channel);
                if (string.IsNullOrEmpty(subscribeMessage.SubscriptionMatch) || subscribeMessage.Channel.Equals(subscribeMessage.SubscriptionMatch))
                {
                    //channel

                    ChannelIdentity ci = new ChannelIdentity(subscribeMessage.Channel, false, isPresenceChannel);
                    FindChannelEntityAndCallback(subscribeMessage, ci);
                }
                else if (subscribeMessage.SubscriptionMatch.Contains(".*") && isPresenceChannel)
                {
                    //wildcard presence channel

                    ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, false, false);
                    FindChannelEntityAndCallback(subscribeMessage, ci);
                }
                else if (subscribeMessage.SubscriptionMatch.Contains(".*"))
                {
                    //wildcard channel
                    ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, false, isPresenceChannel);
                    FindChannelEntityAndCallback(subscribeMessage, ci);
                }
                else
                {
                    ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, true, isPresenceChannel);
                    FindChannelEntityAndCallback(subscribeMessage, ci);

                    //ce will be the cg and subscriptionMatch will have the cg name
                }
            }
        }
        public void Execute()
        {
            if (((this.ChannelsToUse == null) || (this.ChannelsToUse.Count <= 0)) && ((this.ChannelGroupsToUse == null) || (this.ChannelGroupsToUse.Count <= 0)))
            {
                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNUnknownCategory,
                    "Both Channels and ChannelGroups cannot be empty",
                    null,
                    true,
                    PNOperationType.PNSubscribeOperation,
                    this.ChannelsToUse,
                    this.ChannelGroupsToUse,
                    null,
                    PubNubInstance
                    );

                PubNubInstance.SubWorker.CreateEventArgsAndRaiseEvent(pnStatus);
            }

            List <ChannelEntity> subscribedChannels = this.PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;
            List <ChannelEntity> newChannelEntities;
            List <string>        rawChannels      = this.ChannelsToUse;
            List <string>        rawChannelGroups = this.ChannelGroupsToUse;

            CheckPresenceAndAddSuffix(ref rawChannels, IncludePresenceChannel, SubscribeToPresenceChannelOnly);
            CheckPresenceAndAddSuffix(ref rawChannelGroups, IncludePresenceChannel, SubscribeToPresenceChannelOnly);
            PNOperationType pnOpType       = PNOperationType.PNSubscribeOperation;
            long            timetokenToUse = this.Timetoken;

            bool channelsOrChannelGroupsAdded = this.PubNubInstance.SubscriptionInstance.TryRemoveDuplicatesCheckAlreadySubscribedAndGetChannels(pnOpType, rawChannels, rawChannelGroups, false, out newChannelEntities);

            if (channelsOrChannelGroupsAdded)
            {
                this.PubNubInstance.SubscriptionInstance.Add(newChannelEntities);
                this.PubNubInstance.SubWorker.Add(timetokenToUse, subscribedChannels);
                this.PubNubInstance.SubWorker.QueryParams = QueryParams;
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("MultiChannelSubscribeInit: channelsOrChannelGroupsAdded {0}", channelsOrChannelGroupsAdded.ToString()), PNLoggingMethod.LevelInfo);
                #endif

                PNStatus pnStatus = Helpers.CreatePNStatus(
                    PNStatusCategory.PNUnknownCategory,
                    CommonText.DuplicateChannelsOrChannelGroups,
                    new PubNubException(CommonText.DuplicateChannelsOrChannelGroups),
                    true,
                    PNOperationType.PNSubscribeOperation,
                    rawChannels,
                    rawChannelGroups,
                    null,
                    PubNubInstance
                    );

                PubNubInstance.SubWorker.CreateEventArgsAndRaiseEvent(pnStatus);
            }

            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog(string.Format("channelsOrChannelGroupsAdded: {0}\nnewChannelEntities:{1}", channelsOrChannelGroupsAdded, newChannelEntities.Count), PNLoggingMethod.LevelInfo);
            #endif
        }