コード例 #1
0
        public IEnumerator Start()
        {
            CommonIntergrationTests common = new CommonIntergrationTests();

            string[] multiChannel = { "testChannel" };
            //
            CurrentRequestType crt              = CurrentRequestType.NonSubscribe;
            string             expectedMessage  = "[[]";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.Time;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            long nanoSecondTime = 0;//Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds (DateTime.UtcNow);

            string url = string.Format("http://pubsub.pubnub.com/subscribe/{0}/{1}/0/{2}?uuid={3}&pnsdk={4}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, nanoSecondTime, pubnub.SessionUUID, pubnub.Version
                                       );

            IEnumerator ienum = common.TestCoroutineRunProcessResponse(url, 20, -1, multiChannel, false,
                                                                       false, this.name, expectedMessage, expectedChannels, false, false, false, 0, crt, respType);

            yield return(StartCoroutine(ienum));

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
        }
コード例 #2
0
        public IEnumerator Start()
        {
            CommonIntergrationTests common = new CommonIntergrationTests();

            System.Random r       = new System.Random();
            string        channel = "UnityIntegrationTestsTimeout_" + r.Next(100);

            string[] multiChannel = new string[1];
            multiChannel [0] = channel;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            CurrentRequestType crt              = CurrentRequestType.NonSubscribe;
            string             expectedMessage  = "Aborted";
            string             expectedChannels = string.Join(",", multiChannel);
            long nanoSecondTime = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);

            //Send a sub request (intentional) that waits for response
            string url = string.Format("http://ps.pndsn.com/subscribe/{0}/{1}/0/{2}?uuid={3}&pnsdk={4}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, nanoSecondTime, pubnub.SessionUUID, pubnub.Version
                                       );
            ResponseType respType = ResponseType.HereNow;

            common.TestCoroutineBounce(url, 5, 0, multiChannel, false,
                                       false, this.name, expectedMessage, expectedChannels, true, false, false, 0, crt, respType);

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
        }
コード例 #3
0
        public IEnumerator Start()
        {
            CommonIntergrationTests common = new CommonIntergrationTests();

            string[] multiChannel = { "testChannel" };

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            CurrentRequestType crt              = CurrentRequestType.PresenceHeartbeat;
            string             expectedMessage  = "{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}";
            string             expectedChannels = string.Join(",", multiChannel);
            string             url              = string.Format("http://ps.pndsn.com/v2/presence/sub_key/{0}/channel/{1}/heartbeat?uuid={2}&heartbeat=62&pnsdk={3}", CommonIntergrationTests.SubscribeKey,
                                                                expectedChannels, pubnub.SessionUUID, pubnub.Version
                                                                );
            ResponseType respType = ResponseType.PresenceHeartbeat;

            IEnumerator ienum = common.TestCoroutineRunProcessResponse(url, 20, -1, multiChannel, false,
                                                                       false, this.name, expectedMessage, expectedChannels, false, false, false, 0, crt, respType);

            yield return(StartCoroutine(ienum));

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
        }
コード例 #4
0
        void CheckElapsedTime <T>(CurrentRequestType crt, float timer, WWW www, bool completeFlag)
        {
            GameObject     go = new GameObject("PubnubUnitTestCoroutine");
            CoroutineClass cc = go.AddComponent <CoroutineClass> ();

            if (crt.Equals(CurrentRequestType.Subscribe))
            {
                cc.isSubscribeComplete        = completeFlag;
                cc.SubCompleteOrTimeoutEvent += CcCoroutineComplete <T>;
            }
            else if (crt.Equals(CurrentRequestType.NonSubscribe))
            {
                cc.isNonSubscribeComplete        = completeFlag;
                cc.NonsubCompleteOrTimeoutEvent += CcCoroutineComplete <T>;
            }
            else if (crt.Equals(CurrentRequestType.PresenceHeartbeat))
            {
                cc.isPresenceHeartbeatComplete              = completeFlag;
                cc.PresenceHeartbeatCompleteOrTimeoutEvent += CcCoroutineComplete <T>;
            }
            else if (crt.Equals(CurrentRequestType.Heartbeat))
            {
                cc.isHearbeatComplete = completeFlag;
                cc.HeartbeatCompleteOrTimeoutEvent += CcCoroutineComplete <T>;
            }
            sCrt            = crt;
            responseHandled = false;

            cc.CheckElapsedTime(crt, timer, www);
            UnityEngine.Debug.Log("waiting");
            //Wait ();
            //Assert.True (responseHandled);
        }
コード例 #5
0
        public void SetGetCoroutineParams <T>(string[] multiChannel, string url, CurrentRequestType crt, ResponseType respType,
                                              int timeout, bool resumeOnReconnect, bool isTimeout
                                              )
        {
            List <ChannelEntity> channelEntities = Helpers.CreateChannelEntity <T>(multiChannel,
                                                                                   true, false, null, null,
                                                                                   null, null, null, null);

            RequestState <T> pubnubRequestState = BuildRequests.BuildRequestState <T> (channelEntities, respType,
                                                                                       resumeOnReconnect, 0, isTimeout, 0, typeof(T));

            CoroutineParams <T> cp = new CoroutineParams <T> (url, timeout, 0, crt, typeof(T), pubnubRequestState);

            GameObject     go = new GameObject("PubnubUnitTestCoroutine");
            CoroutineClass cc = go.AddComponent <CoroutineClass> ();

            cc.SetCoroutineParams <T>(crt, cp);

            CoroutineParams <T> cp2 = cc.GetCoroutineParams <T>(crt) as CoroutineParams <T>;

            Assert.True(cp.crt.Equals(cp2.crt));
            Assert.True(cp.pause.Equals(cp2.pause));
            Assert.True(cp.timeout.Equals(cp2.timeout));
            Assert.True(cp.url.Equals(cp2.url));
        }
コード例 #6
0
        void CheckIfRequestIsRunning <T>(CurrentRequestType crt, bool completeFlag)
        {
            GameObject     go = new GameObject("PubnubUnitTestCoroutine");
            CoroutineClass cc = go.AddComponent <CoroutineClass> ();

            if (crt.Equals(CurrentRequestType.Subscribe))
            {
                cc.isSubscribeComplete = completeFlag;
            }
            else if (crt.Equals(CurrentRequestType.NonSubscribe))
            {
                cc.isNonSubscribeComplete = completeFlag;
            }
            else if (crt.Equals(CurrentRequestType.PresenceHeartbeat))
            {
                cc.isPresenceHeartbeatComplete = completeFlag;
            }
            else if (crt.Equals(CurrentRequestType.Heartbeat))
            {
                cc.isHearbeatComplete = completeFlag;
            }
            if (completeFlag)
            {
                Assert.False(cc.CheckIfRequestIsRunning(crt));
            }
            else
            {
                Assert.True(cc.CheckIfRequestIsRunning(crt));
            }
        }
コード例 #7
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
 void SetComplete(CurrentRequestType crt)
 {
     try {
         if (crt == CurrentRequestType.Heartbeat)
         {
             StopCoroutine(HeartbeatTimeoutCoroutine);
             isHearbeatComplete = true;
         }
         else if (crt == CurrentRequestType.PresenceHeartbeat)
         {
             StopCoroutine(PresenceHeartbeatTimeoutCoroutine);
             isPresenceHeartbeatComplete = true;
         }
         else if (crt == CurrentRequestType.Subscribe)
         {
             StopCoroutine(SubTimeoutCoroutine);
             isSubscribeComplete = true;
         }
         else
         {
             StopCoroutine(NonSubTimeoutCoroutine);
             isNonSubscribeComplete = true;
         }
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, SetComplete Complete {1}", DateTime.Now.ToString(), crt.ToString()), LoggingMethod.LevelInfo);
         #endif
     } catch (Exception ex) {
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, SetComplete Exception: ", DateTime.Now.ToString(), ex.ToString()), LoggingMethod.LevelError);
     }
 }
コード例 #8
0
 public object GetStoredRequestState(CurrentRequestType aKey)
 {
     if (requestStates.ContainsKey(aKey))
     {
         if (requestStates.ContainsKey(aKey))
         {
             #if (ENABLE_PUBNUB_LOGGING)
             LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState {1}",
                                                    DateTime.Now.ToString(), aKey.ToString()), LoggingMethod.LevelInfo);
             #endif
             return(requestStates [aKey]);
         }
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState returning false", DateTime.Now.ToString()), LoggingMethod.LevelInfo);
         #endif
     }
     #if (ENABLE_PUBNUB_LOGGING)
     else
     {
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState doesnt contain key {1}",
                                                DateTime.Now.ToString(), aKey.ToString()), LoggingMethod.LevelInfo);
     }
     #endif
     return(null);
 }
コード例 #9
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
 public CoroutineParams(string url, int timeout, int pause, CurrentRequestType crt, Type typeParameterType, RequestState <T> requestState)
 {
     this.url               = url;
     this.timeout           = timeout;
     this.pause             = pause;
     this.crt               = crt;
     this.typeParameterType = typeParameterType;
     this.requestState      = requestState;
 }
コード例 #10
0
        public void SetRequestState(CurrentRequestType key, object requestState)
        {
            object reqState = requestState as object;

            requestStates.AddOrUpdate(key, reqState, (oldData, newData) => reqState);
            #if (ENABLE_PUBNUB_LOGGING)
            LoggingMethod.WriteToLog(string.Format("DateTime {0}, SetStoredRequestState {1}",
                                                   DateTime.Now.ToString(), key.ToString()), LoggingMethod.LevelInfo);
            #endif
        }
コード例 #11
0
 public override bool IsValidate()
 {
     if (base.IsValidate())
     {
         var currentType = CurrentRequestType.ToString().ToUpper();
         if (CurrentRequestType == RequestType.All ||
             CurrentHttpRequest.Context.Request.RequestType == currentType)
         {
             return(true);
         }
     }
     throw new AjaxException("此方法无法用{0}方式进行访问".FormatWith(CurrentHttpRequest.Context.Request.RequestType));
 }
コード例 #12
0
        public IEnumerator Start()
        {
            #if (REDUCE_PUBNUB_COROUTINES)
            CommonIntergrationTests common = new CommonIntergrationTests();
            System.Random           r      = new System.Random();
            string channel  = "UnityIntegrationTestsTimeout_" + r.Next(100);
            string channel2 = "UnityIntegrationTestsTimeout_" + r.Next(100);

            string[] multiChannel = new string[2];
            multiChannel [0] = channel;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            CurrentRequestType crt              = CurrentRequestType.Subscribe;
            string             expectedMessage  = "Aborted";
            string             expectedChannels = string.Join(",", multiChannel);
            long nanoSecondTime = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);

            string url = string.Format("http://pubsub.pubnub.com/v2/subscribe/{0}/{1}/0/{2}?uuid={3}&tt={2}&pnsdk={4}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, nanoSecondTime, pubnub.SessionUUID, pubnub.Version
                                       );
            multiChannel [1] = channel2;
            expectedChannels = string.Join(",", multiChannel);
            string url2 = string.Format("http://pubsub.pubnub.com/v2/subscribe/{0}/{1}/0?uuid={3}&tt={2}&pnsdk={4}", CommonIntergrationTests.SubscribeKey,
                                        expectedChannels, nanoSecondTime, pubnub.SessionUUID, pubnub.Version
                                        );
            ResponseType respType = ResponseType.SubscribeV2;

            IEnumerator ienum = common.TestCoroutineRunSubscribeMultiple(url, url2, 20, -1, multiChannel, false,
                                                                         false, this.name, expectedMessage, expectedChannels, false, false, false, 0, crt, respType);
            yield return(StartCoroutine(ienum));

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
            #else
            yield return(null);

            UnityEngine.Debug.Log(string.Format("{0}: Ignoring test", this.name));
            IntegrationTest.Pass();
            #endif
        }
コード例 #13
0
        void StopTimeouts(CurrentRequestType crt)
        {
            GameObject     go = new GameObject("PubnubUnitTestCoroutine");
            CoroutineClass cc = go.AddComponent <CoroutineClass> ();

            if (crt.Equals(CurrentRequestType.Subscribe))
            {
                cc.runSubscribeTimer = true;
            }
            else if (crt.Equals(CurrentRequestType.NonSubscribe))
            {
                cc.runNonSubscribeTimer = true;
            }
            else if (crt.Equals(CurrentRequestType.PresenceHeartbeat))
            {
                cc.runPresenceHeartbeatTimer = true;
            }
            else if (crt.Equals(CurrentRequestType.Heartbeat))
            {
                cc.runHeartbeatTimer = true;
            }
            cc.StopTimeouts(crt);
            if (crt.Equals(CurrentRequestType.Subscribe))
            {
                Assert.True(!cc.runSubscribeTimer);
                Assert.True(cc.subscribeTimer.Equals(0));
            }
            else if (crt.Equals(CurrentRequestType.NonSubscribe))
            {
                Assert.True(!cc.runNonSubscribeTimer);
                Assert.True(cc.nonSubscribeTimer.Equals(0));
            }
            else if (crt.Equals(CurrentRequestType.PresenceHeartbeat))
            {
                Assert.True(!cc.runPresenceHeartbeatTimer);
                Assert.True(cc.presenceHeartbeatTimer.Equals(0));
                Assert.True(!cc.runPresenceHeartbeatPauseTimer);
                Assert.True(cc.presenceHeartbeatPauseTimer.Equals(0));
            }
            else if (crt.Equals(CurrentRequestType.Heartbeat))
            {
                Assert.True(!cc.runHeartbeatTimer);
                Assert.True(cc.heartbeatTimer.Equals(0));
                Assert.True(!cc.runPresenceHeartbeatPauseTimer);
                Assert.True(cc.heartbeatPauseTimer.Equals(0));
            }
        }
コード例 #14
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
 void StopRunningCoroutines(CurrentRequestType crt)
 {
     if (crt == CurrentRequestType.Heartbeat)
     {
         if ((heartbeatWww != null) && (!heartbeatWww.isDone))
         {
             heartbeatWww.Dispose();
             heartbeatWww = null;
             StopCoroutine(HeartbeatCoroutine);
         }
         if (DelayRequestCoroutineHB != null)
         {
             StopCoroutine(DelayRequestCoroutineHB);
         }
     }
     else if (crt == CurrentRequestType.PresenceHeartbeat)
     {
         if ((presenceHeartbeatWww != null) && (!presenceHeartbeatWww.isDone))
         {
             presenceHeartbeatWww.Dispose();
             presenceHeartbeatWww = null;
             StopCoroutine(PresenceHeartbeatCoroutine);
         }
         if (DelayRequestCoroutinePHB != null)
         {
             StopCoroutine(DelayRequestCoroutinePHB);
         }
     }
     else if ((crt == CurrentRequestType.Subscribe) && (subscribeWww != null) && (!subscribeWww.isDone))
     {
         subscribeWww = null;
         StopCoroutine(SubCoroutine);
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, Coroutine stopped Subscribe: ", DateTime.Now.ToString()), LoggingMethod.LevelInfo);
         #endif
     }
     else if ((crt == CurrentRequestType.NonSubscribe) && (nonSubscribeWww != null) && (!nonSubscribeWww.isDone))
     {
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, Dispose nonSubscribeWww: ", DateTime.Now.ToString()), LoggingMethod.LevelInfo);
         #endif
         nonSubscribeWww.Dispose();
         nonSubscribeWww = null;
         StopCoroutine(NonSubCoroutine);
     }
 }
コード例 #15
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
        public bool CheckComplete(CurrentRequestType crt)
        {
            try {
                if (crt == CurrentRequestType.Heartbeat)
                {
                    if ((!isHearbeatComplete) && (heartbeatWww != null) && (!heartbeatWww.isDone))
                    {
                        StopCoroutine(HeartbeatCoroutine);
                        return(false);
                    }
                }
                else if (crt == CurrentRequestType.PresenceHeartbeat)
                {
                    if ((!isPresenceHeartbeatComplete) && (presenceHeartbeatWww != null) && (!presenceHeartbeatWww.isDone))
                    {
                        StopCoroutine(PresenceHeartbeatCoroutine);
                        return(false);
                    }
                }
                else if (crt == CurrentRequestType.Subscribe)
                {
                    if ((!isSubscribeComplete) && (subscribeWww != null) && (!subscribeWww.isDone))
                    {
                        StopCoroutine(SubCoroutine);
                        return(false);
                    }
                }
                else
                {
                    if ((!isNonSubscribeComplete) && (nonSubscribeWww != null) && (!nonSubscribeWww.isDone))
                    {
                        StopCoroutine(NonSubCoroutine);
                        return(false);
                    }
                }
            } catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetCompleteAndDispose Exception: ", DateTime.Now.ToString(), ex.ToString()), LoggingMethod.LevelError);
                #endif
            }

            return(true);
        }
        public IEnumerator Start()
        {
            CommonIntergrationTests common = new CommonIntergrationTests();
            string url = "https://pubsub.pubnub.com/time/0";

            string[] multiChannel = { "testChannel" };
            //
            CurrentRequestType crt              = CurrentRequestType.NonSubscribe;
            string             expectedMessage  = "[14";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.Time;

            IEnumerator ienum = common.TestCoroutineRunProcessResponse(url, 20, -1, multiChannel, false,
                                                                       false, this.name, expectedMessage, expectedChannels, false, false, false, 0, crt, respType);

            yield return(StartCoroutine(ienum));

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
        }
コード例 #17
0
        public void TestSetGetCoroutineParamsHB()
        {
            string[] multiChannel = { "testChannel" };

            CurrentRequestType crt              = CurrentRequestType.Heartbeat;
            string             expectedMessage  = "[[]";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.Heartbeat;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            string url = "https://ps.pndsn.com/time/0";

            SetGetCoroutineParams <string> (multiChannel, url, crt, respType, pubnub.NonSubscribeTimeout, false, false);
        }
コード例 #18
0
        public IEnumerator Start()
        {
            CommonIntergrationTests common = new CommonIntergrationTests();
            string url = "http://pubsub.pubnub.com";

            string[] multiChannel = { "testChannel" };

            //Inducing Error by setting wrong request type
            CurrentRequestType crt              = CurrentRequestType.Heartbeat;
            string             expectedMessage  = "404 Nothing";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.Heartbeat;

            IEnumerator ienum = common.TestCoroutineRunError(url, 20, -1, multiChannel, false,
                                                             false, this.name, expectedMessage, expectedChannels, true, false, false, 0, crt, respType);

            yield return(StartCoroutine(ienum));

            UnityEngine.Debug.Log(string.Format("{0}: After StartCoroutine", this.name));
            yield return(new WaitForSeconds(CommonIntergrationTests.WaitTimeBetweenCalls));
        }
コード例 #19
0
        public void TestSetGetCoroutineParamsPHB()
        {
            string[] multiChannel = { "testChannel" };

            CurrentRequestType crt              = CurrentRequestType.PresenceHeartbeat;
            string             expectedMessage  = "[[]";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.PresenceHeartbeat;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            string url = string.Format("http://ps.pndsn.com/v2/presence/sub_key/{0}/channel/{1}/heartbeat?uuid={2}&heartbeat=62&pnsdk={3}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, pubnub.SessionUUID, pubnub.Version
                                       );

            SetGetCoroutineParams <string> (multiChannel, url, crt, respType, pubnub.NonSubscribeTimeout, false, false);
        }
コード例 #20
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
        public void BounceRequest <T> (CurrentRequestType crt, RequestState <T> pubnubRequestState, bool fireEvent)
        {
            try {
                StopRunningCoroutines(crt);

                SetComplete(crt);

                if ((pubnubRequestState != null) && (fireEvent))
                {
                    FireEvent("Aborted", true, false, pubnubRequestState, crt);
                    #if (ENABLE_PUBNUB_LOGGING)
                    LoggingMethod.WriteToLog(string.Format("DateTime {0}, event fired {1}", DateTime.Now.ToString(), crt.ToString()), LoggingMethod.LevelInfo);
                    #endif
                }
            } catch (Exception ex) {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, BounceRequest Exception: {1}", DateTime.Now.ToString(), ex.ToString()), LoggingMethod.LevelError);
                #endif
            }
            #if (ENABLE_PUBNUB_LOGGING)
            LoggingMethod.WriteToLog(string.Format("DateTime {0}, BounceRequest {1}", DateTime.Now.ToString(), crt.ToString()), LoggingMethod.LevelInfo);
            #endif
        }
コード例 #21
0
        public void TestCheckElapsedTimePHBTimeElapsed()
        {
            string[] multiChannel = { "testChannel" };

            CurrentRequestType crt              = CurrentRequestType.PresenceHeartbeat;
            string             expectedMessage  = "[[]";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.PresenceHeartbeat;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            string url = string.Format("http://ps.pndsn.com/v2/presence/sub_key/{0}/channel/{1}/heartbeat?uuid={2}&heartbeat=62&pnsdk={3}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, pubnub.SessionUUID, pubnub.Version
                                       );
            WWW www = new WWW(url);

            CheckElapsedTime <string> (CurrentRequestType.PresenceHeartbeat, 0, www, false);
        }
コード例 #22
0
        public void TestSetGetCoroutineParamsSub()
        {
            string[] multiChannel = { "testChannel" };

            CurrentRequestType crt              = CurrentRequestType.Subscribe;
            string             expectedMessage  = "[[]";
            string             expectedChannels = string.Join(",", multiChannel);
            ResponseType       respType         = ResponseType.SubscribeV2;

            Pubnub pubnub = new Pubnub(
                CommonIntergrationTests.PublishKey,
                CommonIntergrationTests.SubscribeKey,
                "",
                "",
                true
                );

            //http://ps.pndsn.com/subscribe/{0}/{1}/0/{2}?uuid={3}&pnsdk={4}
            string url = string.Format("http://ps.pndsn.com/subscribe/{0}/{1}/0/{2}?uuid={3}&pnsdk={4}", CommonIntergrationTests.SubscribeKey,
                                       expectedChannels, 0, pubnub.SessionUUID, pubnub.Version
                                       );

            SetGetCoroutineParams <string> (multiChannel, url, crt, respType, pubnub.SubscribeTimeout, false, false);
        }
コード例 #23
0
        public NameValueCollection GetWebParameters(HttpContext context)
        {
            if (context == null)
            {
                throw new AjaxException("请求的上下文为空");
            }
            NameValueCollection webParameters;

            switch (CurrentRequestType.ToString().ToUpper())
            {
            case "POST":
                webParameters = context.Request.Form;
                break;

            case "GET":
                webParameters = context.Request.QueryString;
                break;

            default:
                webParameters = context.Request.Params;
                break;
            }
            return(webParameters);
        }
コード例 #24
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
 public void DelayStartCoroutine <T>(string url, RequestState <T> pubnubRequestState, int timeout, int pause, CurrentRequestType crt)
 {
     if (pubnubRequestState.RespType == ResponseType.Heartbeat)
     {
         DelayRequestCoroutineHB = DelayRequest <T>(url, pubnubRequestState, timeout, pause, crt);
         StartCoroutine(DelayRequestCoroutineHB);
     }
     else
     {
         DelayRequestCoroutinePHB = DelayRequest <T>(url, pubnubRequestState, timeout, pause, crt);
         StartCoroutine(DelayRequestCoroutinePHB);
     }
 }
コード例 #25
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
        public void FireEvent <T> (string message, bool isError, bool isTimeout, RequestState <T> pubnubRequestState, CurrentRequestType crt)
        {
            CustomEventArgs <T> cea = new CustomEventArgs <T> ();

            cea.PubnubRequestState = pubnubRequestState;
            cea.Message            = message;
            cea.IsError            = isError;
            cea.IsTimeout          = isTimeout;
            cea.CurrRequestType    = crt;
            #if (ENABLE_PUBNUB_LOGGING)
            LoggingMethod.WriteToLog(string.Format("DateTime {0}, Raising Event of type : {1}", DateTime.Now.ToString(), crt.ToString()), LoggingMethod.LevelInfo);
            #endif

            if ((crt == CurrentRequestType.Heartbeat) && (heartbeatCoroutineComplete != null))
            {
                heartbeatCoroutineComplete.Raise(this, cea);
            }
            else if ((crt == CurrentRequestType.PresenceHeartbeat) && (presenceHeartbeatCoroutineComplete != null))
            {
                presenceHeartbeatCoroutineComplete.Raise(this, cea);
            }
            else if ((crt == CurrentRequestType.Subscribe) && (subCoroutineComplete != null))
            {
                subCoroutineComplete.Raise(this, cea);
            }
            else if ((crt == CurrentRequestType.NonSubscribe) && (nonSubCoroutineComplete != null))
            {
                nonSubCoroutineComplete.Raise(this, cea);
            }
            #if (ENABLE_PUBNUB_LOGGING)
            else
            {
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, Request Type not matched {1}", DateTime.Now.ToString(), crt.ToString()), LoggingMethod.LevelInfo);
            }
            #endif
        }
コード例 #26
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
        public IEnumerator DelayRequest <T> (string url, RequestState <T> pubnubRequestState, int timeout, int pause, CurrentRequestType crt)
        {
            yield return(new WaitForSeconds(pause));

            StartCoroutinesByName <T> (url, pubnubRequestState, timeout, pause, crt);
        }
コード例 #27
0
        public void TestResponseCallbackWebExceptionHandlerCommon <T>(string message, string[] channels,
                                                                      bool resumeOnReconnect, ResponseType responseType, CurrentRequestType crt, Action <T> userCallback,
                                                                      Action <T> connectCallback, Action <PubnubClientError> errorCallback,
                                                                      bool isTimeout, bool isError, long timetoken, bool ssl, PubnubErrorFilter.Level errorLevel
                                                                      )
        {
            ExceptionMessage = message;
            ExceptionChannel = string.Join(",", channels);

            if (isTimeout)
            {
                ExceptionMessage = "Operation Timeout";
                IsTimeout        = true;
            }
            else
            {
                IsTimeout = false;
            }

            if (isError)
            {
                IsError = true;
            }
            else
            {
                IsError = false;
            }

            RequestState <T> requestState = BuildRequests.BuildRequestState <T> (channels, responseType,
                                                                                 resumeOnReconnect, userCallback, connectCallback, errorCallback, 0, isTimeout, timetoken, typeof(T));

            CustomEventArgs <T> cea = new CustomEventArgs <T> ();

            cea.PubnubRequestState = requestState;
            cea.Message            = message;
            cea.IsError            = isError;
            cea.IsTimeout          = isTimeout;
            cea.CurrRequestType    = crt;

            CRequestType = responseType;
            if (responseType == ResponseType.Presence || responseType == ResponseType.Subscribe)
            {
                ExceptionHandlers.MultiplexException += HandleMultiplexException <T>;
                resultPart1 = false;
            }

            WebException webEx = new WebException("Test web exception");

            SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks = new SafeDictionary <PubnubChannelCallbackKey, object> ();

            PubnubChannelCallbackKey callbackKey = new PubnubChannelCallbackKey();

            callbackKey.Channel = ExceptionChannel;
            callbackKey.Type    = responseType;
            PubnubChannelCallback <T> pubnubChannelCallbacks = new PubnubChannelCallback <T>();

            pubnubChannelCallbacks.Callback        = userCallback;
            pubnubChannelCallbacks.ConnectCallback = connectCallback;
            pubnubChannelCallbacks.ErrorCallback   = errorCallback;
            channelCallbacks.AddOrUpdate(callbackKey, pubnubChannelCallbacks, (key, oldValue) => pubnubChannelCallbacks);

            ExceptionHandlers.ResponseCallbackWebExceptionHandler <T> (cea, requestState, webEx, ExceptionChannel, channelCallbacks,
                                                                       errorLevel);

            /*if (responseType == ResponseType.Presence || responseType == ResponseType.Subscribe) {
             *  DateTime dt = DateTime.Now;
             *  while (dt.AddSeconds(2) > DateTime.Now) {
             *      UnityEngine.Debug.Log ("waiting");
             *  }
             * }*/
        }
コード例 #28
0
        public void SetRequestState(CurrentRequestType key, object requestState)
        {
            object reqState = requestState as object;

            requestStates.AddOrUpdate(key, reqState, (oldData, newData) => reqState);
        }
        public void TestResponseCallbackWebExceptionHandlerCommon <T>(string message, string[] channels,
                                                                      bool resumeOnReconnect, ResponseType responseType, CurrentRequestType crt, Action <T> userCallback,
                                                                      Action <T> connectCallback, Action <PubnubClientError> errorCallback,
                                                                      bool isTimeout, bool isError, long timetoken, bool ssl, PubnubErrorFilter.Level errorLevel
                                                                      )
        {
            ExceptionMessage = message;
            ExceptionChannel = string.Join(",", channels);

            if (isTimeout)
            {
                ExceptionMessage = "Operation Timeout";
                IsTimeout        = true;
            }
            else
            {
                IsTimeout = false;
            }

            if (isError)
            {
                IsError = true;
            }
            else
            {
                IsError = false;
            }

            List <ChannelEntity> channelEntities = Helpers.CreateChannelEntity <T>(channels,
                                                                                   true, false, null, userCallback, connectCallback, errorCallback, null, null);

            RequestState <T> requestState = BuildRequests.BuildRequestState <T> (channelEntities, responseType,
                                                                                 resumeOnReconnect, 0, isTimeout, timetoken, typeof(T), "", userCallback, errorCallback);

            CustomEventArgs <T> cea = new CustomEventArgs <T> ();

            cea.PubnubRequestState = requestState;
            cea.Message            = message;
            cea.IsError            = isError;
            cea.IsTimeout          = isTimeout;
            cea.CurrRequestType    = crt;

            CRequestType = responseType;
            if (responseType == ResponseType.PresenceV2 || responseType == ResponseType.SubscribeV2)
            {
                ExceptionHandlers.MultiplexException += HandleMultiplexException <T>;
                resultPart1 = false;
            }

            WebException webEx = new WebException("Test web exception");


            ExceptionHandlers.ResponseCallbackWebExceptionHandler <T> (cea, requestState, webEx,
                                                                       errorLevel);

            /*if (responseType == ResponseType.Presence || responseType == ResponseType.Subscribe) {
             *  DateTime dt = DateTime.Now;
             *  while (dt.AddSeconds(2) > DateTime.Now) {
             *      UnityEngine.Debug.Log ("waiting");
             *  }
             * }*/
        }
コード例 #30
0
ファイル: CoroutineClass.cs プロジェクト: laiqiqi/unity
        private void StartCoroutinesByName <T> (string url, RequestState <T> pubnubRequestState, int timeout, int pause, CurrentRequestType crt)
        {
            CoroutineParams <T> cp = new CoroutineParams <T> (url, timeout, pause, crt, typeof(T), pubnubRequestState);

            if (crt == CurrentRequestType.Subscribe)
            {
                if ((SubTimeoutCoroutine != null) && (!isSubscribeComplete))
                {
                    StopCoroutine(SubTimeoutCoroutine);
                    #if (ENABLE_PUBNUB_LOGGING)
                    LoggingMethod.WriteToLog(string.Format("DateTime {0}, Stopped existing timeout coroutine {1}", DateTime.Now.ToString(), cp.crt.ToString()), LoggingMethod.LevelInfo);
                    #endif
                }

                SubTimeoutCoroutine = CheckTimeoutSub <T> (cp);
                SubCoroutine        = SendRequestSub <T> (cp);
                StartCoroutine(SubTimeoutCoroutine);
                StartCoroutine(SubCoroutine);
            }
            else if (crt == CurrentRequestType.NonSubscribe)
            {
                if ((NonSubTimeoutCoroutine != null) && (!isNonSubscribeComplete))
                {
                    StopCoroutine(NonSubTimeoutCoroutine);
                    #if (ENABLE_PUBNUB_LOGGING)
                    LoggingMethod.WriteToLog(string.Format("DateTime {0}, Stopped existing timeout coroutine {1}", DateTime.Now.ToString(), cp.crt.ToString()), LoggingMethod.LevelInfo);
                    #endif
                }

                NonSubTimeoutCoroutine = CheckTimeoutNonSub <T> (cp);
                NonSubCoroutine        = SendRequestNonSub <T> (cp);
                StartCoroutine(NonSubTimeoutCoroutine);
                StartCoroutine(NonSubCoroutine);
            }
            else if (crt == CurrentRequestType.PresenceHeartbeat)
            {
                if ((PresenceHeartbeatTimeoutCoroutine != null) && (!isPresenceHeartbeatComplete))
                {
                    StopCoroutine(PresenceHeartbeatTimeoutCoroutine);
                    #if (ENABLE_PUBNUB_LOGGING)
                    LoggingMethod.WriteToLog(string.Format("DateTime {0}, Stopped existing timeout coroutine {1}", DateTime.Now.ToString(), cp.crt.ToString()), LoggingMethod.LevelInfo);
                    #endif
                }

                PresenceHeartbeatTimeoutCoroutine = CheckTimeoutPresenceHeartbeat <T> (cp);
                PresenceHeartbeatCoroutine        = SendRequestPresenceHeartbeat <T> (cp);
                StartCoroutine(PresenceHeartbeatTimeoutCoroutine);
                StartCoroutine(PresenceHeartbeatCoroutine);
            }
            else if (crt == CurrentRequestType.Heartbeat)
            {
                if ((HeartbeatTimeoutCoroutine != null) && (!isHearbeatComplete))
                {
                    StopCoroutine(HeartbeatTimeoutCoroutine);
                    #if (ENABLE_PUBNUB_LOGGING)
                    LoggingMethod.WriteToLog(string.Format("DateTime {0}, Stopped existing timeout coroutine {1}", DateTime.Now.ToString(), cp.crt.ToString()), LoggingMethod.LevelInfo);
                    #endif
                }

                HeartbeatTimeoutCoroutine = CheckTimeoutHeartbeat <T> (cp);
                HeartbeatCoroutine        = SendRequestHeartbeat <T> (cp);
                StartCoroutine(HeartbeatTimeoutCoroutine);
                StartCoroutine(HeartbeatCoroutine);
            }
        }