예제 #1
0
 protected abstract void CreatePubNubResponse(object deSerializedResult, RequestState pnRequestState);
예제 #2
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);
            }
        }
예제 #3
0
 internal void RaiseCreateResponse(object createResponse, RequestState pnRequestState)
 {
     this.CreateResponse(createResponse, pnRequestState);
 }
예제 #4
0
 internal void RaiseError(PNStatusCategory pnStatusCategory, Exception exception, bool showInCallback, RequestState pnRequestState)
 {
     this.CreateErrorResponse(pnStatusCategory, exception, showInCallback, pnRequestState);
 }
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNGetMessageActionsResult pnGetMessageActionsResult = new PNGetMessageActionsResult();

            pnGetMessageActionsResult.Data = new List <PNMessageActionsResult>();
            pnGetMessageActionsResult.More = new PNGetMessageActionsMore();
            PNStatus pnStatus = new PNStatus();

            try{
                Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>;

                if (dictionary != null)
                {
                    object objData;
                    dictionary.TryGetValue("data", out objData);
                    if (objData != null)
                    {
                        object[] objArr = objData as object[];
                        foreach (object data in objArr)
                        {
                            Dictionary <string, object> objDataDict = data as Dictionary <string, object>;
                            if (objDataDict != null)
                            {
                                PNMessageActionsResult pnMessageActionsResult = MessageActionsHelpers.ExtractMessageAction(objDataDict);
                                pnGetMessageActionsResult.Data.Add(pnMessageActionsResult);
                            }
                            else
                            {
                                pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                            }
                        }
                    }
                    else
                    {
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                    object objMore;
                    dictionary.TryGetValue("more", out objMore);
                    if (objMore != null)
                    {
                        Dictionary <string, object> objMoreDict = objMore as Dictionary <string, object>;
                        string log;
                        long   start;
                        Utility.TryCheckKeyAndParseLong(objMoreDict, "start", "start", out log, out start);
                        pnGetMessageActionsResult.More.Start = start;

                        int limit;
                        Utility.TryCheckKeyAndParseInt(objMoreDict, "limit", "limit", out log, out limit);
                        pnGetMessageActionsResult.More.Limit = limit;

                        long end;
                        Utility.TryCheckKeyAndParseLong(objMoreDict, "end", "end", out log, out end);
                        pnGetMessageActionsResult.More.End = start;

                        pnGetMessageActionsResult.More.URL = Utility.ReadMessageFromResponseDictionary(objMoreDict, "url");
                    }
                }
            } catch (Exception ex) {
                pnGetMessageActionsResult = null;
                pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnGetMessageActionsResult, pnStatus);
        }
 public void PublishFileMessage(PNSendFileResult pnSendFileResult, PNStatus pnStatus, RequestState requestState, int tryCount)
 {
     base.PubNubInstance.PublishFileMessage().Channel(SendFileChannel).FileID(pnSendFileResult.Data.ID).FileName(SendFileName).MessageText(SendFileMessage).TTL(PublishTTL).ShouldStore(ShouldStoreInHistory).Meta(Metadata).Async((presult, pstatus) => {
         if (pstatus.Error)
         {
             if (tryCount >= base.PubNubInstance.PNConfig.FileMessagePublishRetryLimit)
             {
                 pnStatus = base.CreateErrorResponseFromException(new PubNubException("Unable to send Publish File Message"), requestState, PNStatusCategory.PNUnknownCategory);
                 PNFileInfoForPublish pnFileInfoForPublish = new PNFileInfoForPublish();
                 pnFileInfoForPublish.ID   = pnSendFileResult.Data.ID;
                 pnFileInfoForPublish.Name = SendFileName;
                 pnStatus.AdditionalData   = pnFileInfoForPublish;
                 pnSendFileResult          = new PNSendFileResult();
                 Callback(pnSendFileResult, pnStatus);
             }
             else
             {
                 tryCount++;
                 PublishFileMessage(pnSendFileResult, pnStatus, requestState, tryCount);
             }
         }
         else
         {
             pnSendFileResult.Timetoken = presult.Timetoken;
             Callback(pnSendFileResult, pnStatus);
         }
     });
 }
예제 #7
0
        public string Run(RequestState pubnubRequestState)
        {
            if (!string.IsNullOrEmpty(pubnubRequestState.WebRequestId))
            {
                AbortRequest(pubnubRequestState.WebRequestId, false);
            }

            bool delayStart = false;
            //for heartbeat and presence heartbeat treat reconnect as pause
            PNCurrentRequestType crt;

            switch (pubnubRequestState.OperationType)
            {
            case PNOperationType.PNHeartbeatOperation:
                crt        = PNCurrentRequestType.Heartbeat;
                delayStart = pubnubRequestState.Reconnect;
                break;

            case PNOperationType.PNPresenceHeartbeatOperation:
                crt        = PNCurrentRequestType.PresenceHeartbeat;
                delayStart = pubnubRequestState.Reconnect;
                break;

            case PNOperationType.PNSubscribeOperation:
                crt = PNCurrentRequestType.Subscribe;
                if (pubnubRequestState.Pause > 0)
                {
                    delayStart = true;
                }
                break;

            default:
                crt = PNCurrentRequestType.NonSubscribe;
                break;
            }

            #if (ENABLE_PUBNUB_LOGGING)
            this.PNLog.WriteToLog(string.Format("pubnubRequestState: {0}", pubnubRequestState.OperationType), PNLoggingMethod.LevelInfo);
            #endif

            string webRequestId = "";
            UnityWebRequestWrapper webRequestWrapper = new UnityWebRequestWrapper(crt, pubnubRequestState);

            lock (syncRoot){
                webRequestId = GenerateAndValidateWebRequestId();
                currentWebRequests.Add(webRequestId, webRequestWrapper);
            }

            #if (ENABLE_PUBNUB_LOGGING)
            this.PNLog.WriteToLog(string.Format("Run crt: {0}", crt), PNLoggingMethod.LevelInfo);
            #endif

            if (delayStart)
            {
                webRequestWrapper.PauseTimer    = pubnubRequestState.Pause;
                webRequestWrapper.RunPauseTimer = true;
            }
            else
            {
                StartWebRequests(webRequestWrapper, webRequestId);
            }
            return(webRequestId);
        }
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            //Returned JSON: `{"status": 200, "message": "OK", "payload": {"channels": {"channel1": {"k": "v"}, "channel2": {}}}, "uuid": "pn-c5a12d424054a3688066572fb955b7a0", "service": "Presence"}`

            //TODO read all values.

            PNSetStateResult pnSetStateResult = new PNSetStateResult();

            Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>;
            PNStatus pnStatus = new PNStatus();

            if (dictionary != null)
            {
                string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message");
                if (Utility.CheckDictionaryForError(dictionary, "error"))
                {
                    pnSetStateResult = null;
                    pnStatus         = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory);
                }
                else
                {
                    object objPayload;
                    dictionary.TryGetValue("payload", out objPayload);

                    if (objPayload != null)
                    {
                        Dictionary <string, object> payload = objPayload as Dictionary <string, object>;
                        object objChannelsDict;
                        payload.TryGetValue("channels", out objChannelsDict);

                        if (objChannelsDict != null)
                        {
                            Dictionary <string, object> channelsDict = objPayload as Dictionary <string, object>;
                            #if (ENABLE_PUBNUB_LOGGING)
                            foreach (KeyValuePair <string, object> kvp in channelsDict)
                            {
                                this.PubNubInstance.PNLog.WriteToLog(string.Format("KVP: {0} -- {1}", kvp.Key, kvp.Value), PNLoggingMethod.LevelInfo);
                            }
                            #endif

                            pnSetStateResult.StateByChannels = channelsDict;
                        }
                        else
                        {
                            pnSetStateResult.StateByChannels = payload;
                        }
                    }
                    else
                    {
                        pnSetStateResult = null;
                        pnStatus         = base.CreateErrorResponseFromMessage("Payload dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory);
                    }
                }
            }
            else
            {
                pnSetStateResult = null;
                pnStatus         = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory);
            }
            Callback(pnSetStateResult, pnStatus);
        }
예제 #9
0
        public static PNStatus CreatePNStatus(PNStatusCategory category, string errorString, Exception errorException, bool error, PNOperationType operation, List <string> channels, List <string> channelGroups, RequestState pnRequestState, PubNubUnity pnUnity)
        {
            PNErrorData errorData = CreateErrorData(errorString, errorException);

            return(CreatePNStatus(category, errorData, error, operation, channels, channelGroups, pnRequestState, pnUnity));
        }
예제 #10
0
        public static PNStatus CreatePNStatus(PNStatusCategory category, string errorString, Exception errorException, bool error, PNOperationType operation, ChannelEntity channelEntity, RequestState pnRequestState, PubNubUnity pnUnity)
        {
            PNErrorData errorData = null;

            if ((!string.IsNullOrEmpty(errorString)) || (errorException != null))
            {
                errorData      = new PNErrorData();
                errorData.Info = errorString;
                errorData.Ex   = errorException;
            }
            List <string> affectedChannels      = null;
            List <string> affectedChannelGroups = null;

            if (channelEntity.ChannelID.IsChannelGroup)
            {
                affectedChannelGroups = new List <string>();
                affectedChannelGroups.Add(channelEntity.ChannelID.ChannelOrChannelGroupName);
            }
            else
            {
                affectedChannels = new List <string>();
                affectedChannels.Add(channelEntity.ChannelID.ChannelOrChannelGroupName);
            }

            return(CreatePNStatus(category, errorData, error, operation, affectedChannels, affectedChannelGroups, pnRequestState, pnUnity));
        }
예제 #11
0
        internal static PNStatus CreatePNStatus(PNStatusCategory category, PNErrorData errorData, bool error, PNOperationType operation, List <string> channels, List <string> channelGroups, RequestState pnRequestState, PubNubUnity pnUnity)
        {
            long   statusCode = 0;
            string url        = "";

            if (pnRequestState != null)
            {
                statusCode = pnRequestState.ResponseCode;
                url        = pnRequestState.URL;
            }

            PNStatus pnStatus = new PNStatus(
                category,
                errorData,
                error,
                statusCode,
                operation,
                pnUnity.PNConfig.Secure,
                pnUnity.PNConfig.UUID,
                pnUnity.PNConfig.AuthKey,
                pnUnity.PNConfig.Origin,
                channels,
                channelGroups,
                url
                );

            #if (ENABLE_PUBNUB_LOGGING)
            pnUnity.PNLog.WriteToLog(string.Format("CreatePNStatus: \n" +
                                                   "category={0} \n" +
                                                   "errorData={1} \n" +
                                                   "error={2} \n" +
                                                   "statusCode={3} \n" +
                                                   "operation={4} \n" +
                                                   "tlsEnabled={5} \n" +
                                                   "uuid={6} \n" +
                                                   "authKey={7} \n" +
                                                   "origin={8} \n" +
                                                   "channels={9} \n" +
                                                   "channelGroups={10} \n" +
                                                   "clientRequest={11} \n",
                                                   category.ToString(),
                                                   ((errorData != null) && (errorData.Ex != null)) ? errorData.Ex.ToString() : "null",
                                                   error.ToString(),
                                                   statusCode.ToString(),
                                                   operation.ToString(),
                                                   pnUnity.PNConfig.Secure,
                                                   pnUnity.PNConfig.UUID,
                                                   pnUnity.PNConfig.AuthKey,
                                                   pnUnity.PNConfig.Origin,
                                                   (channels != null) ? string.Join(",", channels.ToArray()) : "null",
                                                   (channelGroups != null) ? string.Join(",", channelGroups.ToArray()) : "null",
                                                   url
                                                   ), PNLoggingMethod.LevelInfo);
            #endif

            return(pnStatus);
        }
예제 #12
0
 //Removed
 protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
 {
     throw new NotImplementedException();
 }
예제 #13
0
        protected override void RunWebRequest(QueueManager qm)
        {
            RequestState requestState = new RequestState();

            requestState.OperationType = OperationType;
        }
예제 #14
0
 protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
 {
     //No processing here
 }
예제 #15
0
        //TODO refactor
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            //Retruned JSON: `{"status": 200, "message": "OK", "payload": {"channels": {"channel1": {"occupancy": 1, "uuids": ["a"]}, "channel2": {"occupancy": 1, "uuids": ["a"]}}, "total_channels": 2, "total_occupancy": 2}, "service": "Presence"}`
            //Retruned JSON: `{"status": 200, "message": "OK", "occupancy": 1, "uuids": [{"uuid": "UnityTestHereNowUUID"}], "service": "Presence"}`
            PNHereNowResult pnHereNowResult = new PNHereNowResult();

            Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>;
            PNStatus pnStatus = new PNStatus();

            if (dictionary != null)
            {
                string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message");
                if (Utility.CheckDictionaryForError(dictionary, "error"))
                {
                    pnHereNowResult = null;
                    pnStatus        = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory);
                }
                else
                {
                    int    totalChannels, total_occupancy;
                    string log = "";
                    object objPayload;

                    dictionary.TryGetValue("payload", out objPayload);

                    if (objPayload != null)
                    {
                        Dictionary <string, object> payload = objPayload as Dictionary <string, object>;
                        object objChannelsDict;
                        payload.TryGetValue("channels", out objChannelsDict);

                        if (objChannelsDict != null)
                        {
                            Dictionary <string, PNHereNowChannelData> channelsResult;
                            pnStatus.Error = CreateHereNowResult(objChannelsDict, out channelsResult);

                            pnHereNowResult.Channels = channelsResult;
                        }
                    }
                    else if (Utility.TryCheckKeyAndParseInt(dictionary, "total_channels", "total_channels", out log, out totalChannels))
                    {
                        pnHereNowResult.TotalChannels = totalChannels;
                            #if (ENABLE_PUBNUB_LOGGING)
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("log: {0}", log), PNLoggingMethod.LevelInfo);
                            #endif
                    }
                    else if (Utility.TryCheckKeyAndParseInt(dictionary, "total_occupancy", "total_occupancy", out log, out total_occupancy))
                    {
                        pnHereNowResult.TotalOccupancy = total_occupancy;
                            #if (ENABLE_PUBNUB_LOGGING)
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("log2: {0}", log), PNLoggingMethod.LevelInfo);
                            #endif
                    }
                    else if ((ChannelsToUse.Count.Equals(1) && (ChannelGroupsToUse == null)) && dictionary.TryGetValue("uuids", out objPayload))
                    {
                        Dictionary <string, object> objChannelsDict = new Dictionary <string, object>();
                        Dictionary <string, PNHereNowChannelData> channelsResult;
                        object[] uuidsArray = objPayload as object[];
                        Dictionary <string, object> channelsResultDict = new Dictionary <string, object>();
                        channelsResultDict.Add("uuids", uuidsArray);
                        objChannelsDict.Add(ChannelsToUse[0], channelsResultDict);
                        pnStatus.Error = CreateHereNowResult(objChannelsDict, out channelsResult);

                        pnHereNowResult.Channels = channelsResult;
                        #if (ENABLE_PUBNUB_LOGGING)
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("pnStatus.Error: {0} channelsResult.Count().ToString(): {1} ChannelsToUse[0]: {2}", pnStatus.Error, channelsResult.Count().ToString(), ChannelsToUse[0]), PNLoggingMethod.LevelInfo);

                        foreach (KeyValuePair <string, PNHereNowChannelData> kvp in channelsResult)
                        {
                            this.PubNubInstance.PNLog.WriteToLog(string.Format("kvp.Key: {0} ", kvp.Key), PNLoggingMethod.LevelInfo);

                            PNHereNowChannelData         pnHereNowChannelData      = kvp.Value;
                            List <PNHereNowOccupantData> pnHereNowOccupantDataList = pnHereNowChannelData.Occupants;
                            foreach (PNHereNowOccupantData pnHereNowOccupantData in pnHereNowOccupantDataList)
                            {
                                this.PubNubInstance.PNLog.WriteToLog(string.Format("pnHereNowOccupantData.UUID: {0} ", pnHereNowOccupantData.UUID), PNLoggingMethod.LevelInfo);
                            }
                        }
                        #endif
                    }
                    else
                    {
                        if (objPayload != null)
                        {
                            pnHereNowResult = null;
                            string msg = string.Format("Payload dictionary is not null of type: {0}", objPayload.GetType());
                            pnStatus = base.CreateErrorResponseFromMessage(msg, requestState, PNStatusCategory.PNMalformedResponseCategory);
                        }
                        else
                        {
                            pnHereNowResult = null;
                            pnStatus        = base.CreateErrorResponseFromMessage("Payload dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory);
                        }
                    }
                }
            }
            else
            {
                pnHereNowResult = null;
                pnStatus        = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory);
            }

            Callback(pnHereNowResult, pnStatus);
        }
예제 #16
0
        protected override void RunWebRequest(QueueManager qm)
        {
            RequestState requestState = new RequestState();

            requestState.OperationType = OperationType;

            string channels = "";

            if (ChannelsToUse != null)
            {
                channels = string.Join(",", ChannelsToUse.ToArray());
            }
            string channelGroups = "";

            if (ChannelGroupsToUse != null)
            {
                channelGroups = string.Join(",", ChannelGroupsToUse.ToArray());
            }

            if (string.IsNullOrEmpty(channels) && (string.IsNullOrEmpty(channelGroups)))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("Both ChannelGroupsToLeave and ChannelsToLeave are empty, running unsubscribe all"), PNLoggingMethod.LevelInfo);
                #endif

                channelGroups      = Helpers.GetNamesFromChannelEntities(this.PubNubInstance.SubscriptionInstance.AllChannelGroups, true);
                channels           = Helpers.GetNamesFromChannelEntities(this.PubNubInstance.SubscriptionInstance.AllChannels, false);
                ChannelsToUse      = Helpers.CreateListOfStringFromListOfChannelEntity(this.PubNubInstance.SubscriptionInstance.AllChannels);
                ChannelGroupsToUse = Helpers.CreateListOfStringFromListOfChannelEntity(this.PubNubInstance.SubscriptionInstance.AllChannelGroups);
            }

            List <ChannelEntity> subscribedChannels = this.PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;

            List <ChannelEntity> newChannelEntities;
            this.PubNubInstance.SubscriptionInstance.TryRemoveDuplicatesCheckAlreadySubscribedAndGetChannels(
                OperationType,
                ChannelsToUse,
                ChannelGroupsToUse,
                true,
                out
                newChannelEntities
                );

            //Retrieve the current channels already subscribed previously and terminate them
            this.PubNubInstance.SubWorker.AbortPreviousRequest(subscribedChannels);

            if (!this.PubNubInstance.PNConfig.SuppressLeaveEvents)
            {
                Uri request = BuildRequests.BuildLeaveRequest(
                    channels,
                    channelGroups,
                    this.PubNubInstance,
                    this.QueryParams
                    );
                base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
            }

            RemoveUnsubscribedChannelsAndDeleteUserState(newChannelEntities);


            //Get all the channels
            this.PubNubInstance.SubWorker.ContinueToSubscribeRestOfChannels();
        }
 protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
 {
     //Intentionally not implemented.
 }
예제 #18
0
        private void RunSubscribeRequest(long timetoken, bool reconnect)
        {
            //Exit if the channel is unsubscribed
            #if (ENABLE_PUBNUB_LOGGING)
            this.PubNubInstance.PNLog.WriteToLog("in  RunSubscribeRequest", PNLoggingMethod.LevelInfo);
            #endif

            if (CheckAllChannelsAreUnsubscribed())
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("All channels unsubscribed", PNLoggingMethod.LevelInfo);
                #endif

                return;
            }
            List <ChannelEntity> channelEntities = PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;

            // Begin recursive subscribe
            try {
                long lastTimetoken = SaveLastTimetoken(timetoken);

                hbWorker.RunHeartbeat(false, hbWorker.HeartbeatInterval);
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("RunRequests: Heartbeat started"), PNLoggingMethod.LevelInfo);
                #endif
                RequestSentAt = DateTime.UtcNow.Second;
                if (PubNubInstance.PNConfig.PresenceInterval > 0)
                {
                    PHBWorker.RunPresenceHeartbeat(false, PubNubInstance.PNConfig.PresenceInterval);
                }

                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("MultiChannelSubscribeRequest: Building request for {0} with timetoken={1}", Helpers.GetAllNamesFromChannelEntities(channelEntities, true), lastTimetoken), PNLoggingMethod.LevelInfo);
                #endif
                // Build URL
                string channelsJsonState = PubNubInstance.SubscriptionInstance.CompiledUserState;

                string channels      = Helpers.GetNamesFromChannelEntities(channelEntities, false);
                string channelGroups = Helpers.GetNamesFromChannelEntities(channelEntities, true);

                //v2
                string filterExpr = (!string.IsNullOrEmpty(this.PubNubInstance.PNConfig.FilterExpression)) ? this.PubNubInstance.PNConfig.FilterExpression : string.Empty;
                Uri    requestUrl = BuildRequests.BuildSubscribeRequest(
                    channels,
                    channelGroups,
                    lastTimetoken.ToString(),
                    channelsJsonState,
                    region,
                    filterExpr,
                    this.PubNubInstance,
                    this.QueryParams
                    );

                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("RunSubscribeRequest: {0}", requestUrl.OriginalString), PNLoggingMethod.LevelError);
                #endif

                RequestState requestState = new RequestState();
                requestState.OperationType = PNOperationType.PNSubscribeOperation;
                requestState.URL           = requestUrl.OriginalString;
                requestState.Timeout       = PubNubInstance.PNConfig.SubscribeTimeout;
                requestState.Pause         = 0;
                requestState.Reconnect     = reconnect;
                //http://ps.pndsn.com/v2/presence/sub-key/sub-c-5c4fdcc6-c040-11e5-a316-0619f8945a4f/uuid/UUID_WhereNow?pnsdk=PubNub-Go%2F3.14.0&uuid=UUID_WhereNow
                webRequestId = webRequest.Run(requestState);
            } catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("MultiChannelSubscribeRequest: method:_subscribe \n channel={0} \n timetoken={1} \n Exception Details={2}", Helpers.GetAllNamesFromChannelEntities(channelEntities, true), timetoken.ToString(), ex.ToString()), PNLoggingMethod.LevelError);
                #endif
                this.RunSubscribeRequest(timetoken, false);
            }
        }
예제 #19
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
                ));
 }
예제 #20
0
        void StartPresenceHeartbeat(bool pause, int pauseTime)
        {
            try {
                string channelsJsonState;
                int    allNonPresenceChannelsOrChannelGroupsCount;
                string channels;
                string channelGroups;

                if (RunIndependentOfSubscribe)
                {
                    channelsJsonState = State;
                    allNonPresenceChannelsOrChannelGroupsCount = ((ChannelGroups.Length > 0)?ChannelGroups.Split(',').Count():0) + ((Channels.Length > 0)?Channels.Split(',').Count():0);
                    Debug.Log("allNonPresenceChannelsOrChannelGroupsCount:" + allNonPresenceChannelsOrChannelGroupsCount);
                    channels      = Channels;
                    channelGroups = ChannelGroups;
                }
                else
                {
                    channelsJsonState = PubNubInstance.SubscriptionInstance.CompiledUserState;
                    allNonPresenceChannelsOrChannelGroupsCount = PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups.Count;
                    channels      = Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, false);
                    channelGroups = Helpers.GetNamesFromChannelEntities(PubNubInstance.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups, true);
                }

                if (allNonPresenceChannelsOrChannelGroupsCount > 0)
                {
                    isPresenceHearbeatRunning = true;
                    Uri request = BuildRequests.BuildPresenceHeartbeatRequest(
                        channels,
                        channelGroups,
                        channelsJsonState,
                        this.PubNubInstance,
                        null
                        );

                    RequestState requestState = new RequestState();
                    requestState.OperationType = PNOperationType.PNPresenceHeartbeatOperation;
                    requestState.URL           = request.OriginalString;
                    requestState.Timeout       = PubNubInstance.PNConfig.NonSubscribeTimeout;
                    requestState.Pause         = pauseTime;
                    requestState.Reconnect     = pause;

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("presenceheartbeat: /presence/ request.OriginalString {0} ", request.OriginalString), PNLoggingMethod.LevelError);
                    #endif

                    webRequestId = webRequest.Run(requestState);

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat running, {0} ", pauseTime), PNLoggingMethod.LevelInfo);
                    #endif
                }
                #if (ENABLE_PUBNUB_LOGGING)
                else
                {
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: AllNonPresenceChannelsOrChannelGroups < 0 "), PNLoggingMethod.LevelInfo);
                }
                #endif
            }
            catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("StartPresenceHeartbeat: PresenceHeartbeat exception {0}", ex.ToString()), PNLoggingMethod.LevelError);
                #endif
            }
        }
예제 #21
0
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNSendFileResult pnSendFileResult = new PNSendFileResult();
            PNStatus         pnStatus         = new PNStatus();

            try{
                Dictionary <string, object> dictionary           = deSerializedResult as Dictionary <string, object>;
                PNSendFileInputsToS3        pnSendFileInputsToS3 = new PNSendFileInputsToS3();

                if (dictionary != null)
                {
                    pnSendFileInputsToS3.Data = ExtractPNFileData(dictionary);
                    pnSendFileInputsToS3.FileUploadRequest = ExtractFileUploadRequest(dictionary);

                    #if (ENABLE_PUBNUB_LOGGING)
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("pnSendFileToS3Result.Data: {0}", pnSendFileInputsToS3.Data.ID), PNLoggingMethod.LevelInfo);
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("pnSendFileToS3Result.FileUploadRequest.URL: {0}", pnSendFileInputsToS3.FileUploadRequest.URL), PNLoggingMethod.LevelInfo);
                    this.PubNubInstance.PNLog.WriteToLog(string.Format("pnSendFileToS3Result.FileUploadRequest.Method: {0}", pnSendFileInputsToS3.FileUploadRequest.Method), PNLoggingMethod.LevelInfo);
                    foreach (PNFormField f in pnSendFileInputsToS3.FileUploadRequest.FormFields)
                    {
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("pnSendFileToS3Result.FileUploadRequest.FormFields Key: {0}", f.Key), PNLoggingMethod.LevelInfo);
                        this.PubNubInstance.PNLog.WriteToLog(string.Format("pnSendFileToS3Result.FileUploadRequest.FormFields Value: {0}", f.Value), PNLoggingMethod.LevelInfo);
                    }
                    #endif

                    // read file, encrypt, save file to temp, send enc file path
                    string upFilePath   = SendFilePath;
                    string tempFilePath = string.Format("{0}/{1}.up.enc", Application.temporaryCachePath, SendFileName);
                    bool   delTempFile  = false;
                    if (!string.IsNullOrEmpty(SendFileCipherKey))
                    {
                        upFilePath = tempFilePath;
                        PubnubCrypto pubnubCrypto = new PubnubCrypto(SendFileCipherKey, this.PubNubInstance.PNLog);
                        pubnubCrypto.EncryptFile(null, SendFilePath, upFilePath);
                        delTempFile = true;
                    }
                    else if (!string.IsNullOrEmpty(PubNubInstance.PNConfig.CipherKey))
                    {
                        upFilePath = tempFilePath;
                        PubnubCrypto pubnubCrypto = new PubnubCrypto(PubNubInstance.PNConfig.CipherKey, this.PubNubInstance.PNLog);
                        pubnubCrypto.EncryptFile(null, SendFilePath, upFilePath);
                        delTempFile = true;
                    }

                    s3.FileName(SendFileName).File(upFilePath).FileUploadRequestData(pnSendFileInputsToS3.FileUploadRequest);
                    s3.Execute((pnSendFileToS3Result, status) => {
                        if (status.StatusCode != 204)
                        {
                            pnSendFileResult          = null;
                            requestState.ResponseCode = status.StatusCode;
                            pnStatus = base.CreateErrorResponseFromException(new PubNubException(string.Format("File Upload Failed {0}", pnSendFileToS3Result.Text)), requestState, PNStatusCategory.PNUnknownCategory);
                            Callback(pnSendFileResult, pnStatus);
                        }
                        else
                        {
                            pnSendFileResult.Data    = new PNFileData();
                            pnSendFileResult.Data.ID = pnSendFileInputsToS3.Data.ID;
                            PublishFileMessage(pnSendFileResult, pnStatus, requestState, 0);
                        }
                        if (delTempFile)
                        {
                            File.Delete(tempFilePath);
                        }
                    });
                }
                else
                {
                    pnSendFileResult = null;
                    pnStatus         = base.CreateErrorResponseFromException(new PubNubException("Data not present"), requestState, PNStatusCategory.PNUnknownCategory);
                    Callback(pnSendFileResult, pnStatus);
                }
            } catch (Exception ex) {
                pnSendFileResult = null;
                pnStatus         = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
                Callback(pnSendFileResult, pnStatus);
            }
        }