Example #1
0
 /// <summary>
 /// Retry failed HTTP requests once.
 /// </summary>
 /// <param name="httpRequestFailedEventArgs">The exception event details.</param>
 private static void RetryFailedRequestOnce(HttpRequestFailedEventArgs httpRequestFailedEventArgs)
 {
     if (httpRequestFailedEventArgs.UserData == null)
     {
         DebugLogs.LogWarning(string.Format("[CotcSdkTemplate:CloudFeatures] HTTP request failed ›› Retry in {0}ms ({1})", httpRequestRetryDelay, httpRequestFailedEventArgs.Url));
         httpRequestFailedEventArgs.UserData = new object();
         httpRequestFailedEventArgs.RetryIn(httpRequestRetryDelay);
     }
     else
     {
         DebugLogs.LogError(string.Format("[CotcSdkTemplate:CloudFeatures] HTTP request failed ›› Abort ({0})", httpRequestFailedEventArgs.Url));
         httpRequestFailedEventArgs.Abort();
     }
 }
Example #2
0
        /// <summary>
        /// Once an event is retrieved from the server, check its type and call the corresponding callback.
        /// </summary>
        /// <param name="sender">The event loop instance which raised the event.</param>
        /// <param name="eventData">Received event's data.</param>
        private static void OnEventReceived(DomainEventLoop sender, EventLoopArgs eventData)
        {
            // Get the Bundle data from the raised event
            Bundle eventBundle = eventData.Message;

            if (verboseEventLoop)
            {
                DebugLogs.LogVerbose(string.Format("[CotcSdkTemplate:EventFeatures] Received event ›› {0}", eventBundle.ToString()));
            }

            switch (eventBundle["type"].AsString())
            {
            // Event type: message sent from the BackOffice
            case "backoffice":
                if (Event_BackOfficeMessage == null)
                {
                    DebugLogs.LogError(string.Format(noEventCallbackFormat, "Event_BackOfficeMessage"));
                }
                else
                {
                    Event_BackOfficeMessage(eventBundle);
                }
                break;

            // Event type: another gamer added the currently logged in one as friend (automatic)
            case "friend.add":
                DebugLogs.LogWarning(string.Format(soonDeprecatedEvent, "friend.add"));
                break;

            // Event type: another gamer added the currently logged in one as blacklisted (automatic)
            case "friend.blacklist":
                DebugLogs.LogWarning(string.Format(soonDeprecatedEvent, "friend.blacklist"));
                break;

            // Event type: another gamer removed the currently logged in one from friend/blacklisted (automatic)
            case "friend.forget":
                DebugLogs.LogWarning(string.Format(soonDeprecatedEvent, "friend.forget"));
                break;

            // Event type: another gamer used the currently logged in one's referral code (automatic)
            case "godchildren":
                if (Event_NewGodchild == null)
                {
                    DebugLogs.LogError(string.Format(noEventCallbackFormat, "Event_NewGodchild"));
                }
                else
                {
                    Event_NewGodchild(eventBundle);
                }
                break;

            // Event type: message sent from another gamer (our "custom" events sent by gamer.Community.SendEvent() are of this type)
            case "user":
                OnCustomEventReceived(eventBundle);
                break;

            // Unhandled event types
            default:
                DebugLogs.LogError(string.Format("[CotcSdkTemplate:EventFeatures] An unhandled event has been received ›› {0}", eventBundle.ToString()));
                break;
            }
        }