Example #1
0
        public void StoreLatency(long startTime, long endTime, PNOperationType operationType)
        {
            float latency = (endTime - startTime) / 10000000f; // seconds

            //TODO Add delete history
            switch (operationType)
            {
            case PNOperationType.PNTimeOperation:
                TimeLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNPublishOperation:
            case PNOperationType.PNPublishFileMessageOperation:
                PublishLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNSignalOperation:
                SignalLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNWhereNowOperation:
            case PNOperationType.PNHereNowOperation:
            case PNOperationType.PNLeaveOperation:
            case PNOperationType.PNSetStateOperation:
            case PNOperationType.PNGetStateOperation:
                PresenceLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNRemoveAllPushNotificationsOperation:
            case PNOperationType.PNAddPushNotificationsOnChannelsOperation:
            case PNOperationType.PNPushNotificationEnabledChannelsOperation:
            case PNOperationType.PNRemovePushNotificationsFromChannelsOperation:
                MobilePushLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNMessageCountsOperation:
                MessageCountsLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNFetchMessagesOperation:
            case PNOperationType.PNHistoryOperation:
            case PNOperationType.PNHistoryWithActionsOperation:
                HistoryLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNGetMessageActionsOperation:
            case PNOperationType.PNAddMessageActionsOperation:
            case PNOperationType.PNRemoveMessageActionsOperation:
                MessageActionsLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNSetUUIDMetadataOperation:
            case PNOperationType.PNGetAllUUIDMetadataOperation:
            case PNOperationType.PNGetUUIDMetadataOperation:
            case PNOperationType.PNRemoveUUIDMetadataOperation:
            case PNOperationType.PNGetAllChannelMetadataOperation:
            case PNOperationType.PNSetChannelMetadataOperation:
            case PNOperationType.PNRemoveChannelMetadataOperation:
            case PNOperationType.PNGetMembershipsOperation:
            case PNOperationType.PNGetChannelMembersOperation:
            case PNOperationType.PNManageMembershipsOperation:
            case PNOperationType.PNManageChannelMembersOperation:
                ObjectsLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNAddChannelsToGroupOperation:
            case PNOperationType.PNChannelGroupsOperation:
            case PNOperationType.PNChannelsForGroupOperation:
            case PNOperationType.PNRemoveChannelsFromGroupOperation:
            case PNOperationType.PNRemoveGroupOperation:
                ChannelGroupsLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            case PNOperationType.PNDeleteFileOperation:
            case PNOperationType.PNDownloadFileOperation:
            case PNOperationType.PNGetFileURLOperation:
            case PNOperationType.PNListFilesOperation:
            case PNOperationType.PNSendFileOperation:
                FileLatency.Add(DateTime.UtcNow.Ticks, latency);
                break;

            default:
                break;
            }
        }
Example #2
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);
        }