public void ProcessTimeout <T> (CoroutineParams <T> cp) { try { if (!CheckComplete(cp.crt)) { if (cp.typeParameterType == typeof(string)) { FireEvent("Timed out", true, true, cp.requestState, cp.crt); #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Error: {1} sec timeout", DateTime.Now.ToString(), cp.timeout.ToString()), LoggingMethod.LevelInfo); #endif } else if (cp.typeParameterType == typeof(object)) { FireEvent("Timed out", true, true, cp.requestState, cp.crt); #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Error: {1} sec timeout", DateTime.Now.ToString(), cp.timeout.ToString()), LoggingMethod.LevelInfo); #endif } else { throw new Exception("'string' and 'object' are the only types supported in generic method calls"); } } } catch (Exception ex) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, CheckTimeout: {1} {2}", DateTime.Now.ToString(), ex.ToString(), cp.crt.ToString()), LoggingMethod.LevelError); #endif } }
public IEnumerator SendRequestSub <T> (CoroutineParams <T> cp) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, URL Sub {1} ", DateTime.Now.ToString(), cp.url.ToString()), LoggingMethod.LevelInfo); #endif WWW www; isSubscribeComplete = false; subscribeWww = new WWW(cp.url); yield return(subscribeWww); if ((subscribeWww != null) && (subscribeWww.isDone)) { www = subscribeWww; } else { www = null; } #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0},After www type {1}", DateTime.Now.ToString(), typeof(T)), LoggingMethod.LevelError); #endif ProcessResponse <T> (www, cp); }
public IEnumerator CheckTimeoutHeartbeat <T> (CoroutineParams <T> cp) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, yielding: {1} sec timeout", DateTime.Now.ToString(), cp.timeout.ToString()), LoggingMethod.LevelInfo); #endif yield return(new WaitForSeconds(cp.timeout)); ProcessTimeout <T> (cp); }
public void ProcessResponse <T> (WWW www, CoroutineParams <T> cp) { try { if (www != null) { SetComplete(cp.crt); string message = ""; bool isError = false; if (string.IsNullOrEmpty(www.error)) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Sub {1} Message: {2}", DateTime.Now.ToString(), cp.crt.ToString(), www.text), LoggingMethod.LevelInfo); #endif message = www.text; isError = false; } else { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Sub {1} Error: {2}", DateTime.Now.ToString(), cp.crt.ToString(), www.error), LoggingMethod.LevelInfo); #endif message = www.error; isError = true; } #if (ENABLE_PUBNUB_LOGGING) if (cp.requestState == null) { LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Sub request null2", DateTime.Now.ToString()), LoggingMethod.LevelInfo); } else { LoggingMethod.WriteToLog(string.Format("DateTime {0}, WWW Sub request2 {1} {2}", DateTime.Now.ToString(), cp.requestState.RespType, cp.crt), LoggingMethod.LevelInfo); } #endif FireEvent(message, isError, false, cp.requestState, cp.crt); } } catch (Exception ex) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, RunCoroutineSub {1}, Exception: {2}", DateTime.Now.ToString(), cp.crt.ToString(), ex.ToString()), LoggingMethod.LevelError); #endif } }
public IEnumerator SendRequestHeartbeat <T> (CoroutineParams <T> cp) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, URL Heartbeat {1} ", DateTime.Now.ToString(), cp.url.ToString()), LoggingMethod.LevelInfo); #endif WWW www; isHearbeatComplete = false; heartbeatWww = new WWW(cp.url); yield return(heartbeatWww); if ((heartbeatWww != null) && (heartbeatWww.isDone)) { www = heartbeatWww; } else { www = null; } ProcessResponse(www, cp); }
public void CallFireEvent <T> (string message, bool isError, bool isTimeout, RequestState <T> pubnubRequestState, CoroutineParams <T> cp) { #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, CallFireEvent RequestType {1} {2} {3}", DateTime.Now.ToString(), typeof(T), pubnubRequestState.GetType(), pubnubRequestState.Channels), LoggingMethod.LevelInfo); #endif FireEvent(message, isError, false, pubnubRequestState, cp.crt); }
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); } }