/// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="gameToken">The GameToken.</param>
        public StartSessionRequest(StartSessionRequestDesc desc, string gameToken)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.UserId, "UserId cannot be null.");

            ReleaseAssert.IsNotNull(gameToken, "Game Token cannot be null.");

            UserId     = desc.UserId;
            AppVersion = desc.AppVersion;
            Country    = desc.Country;
            if (desc.DeviceType == null)
            {
                DeviceType = DeviceTypeDefaultProvider.GetDefault();
            }
            else
            {
                DeviceType = desc.DeviceType;
            }
            if (desc.Platform == null)
            {
                Platform = PlatformDefaultProvider.GetDefault();
            }
            else
            {
                Platform = desc.Platform;
            }
            TestKey      = desc.TestKey;
            TestGroupKey = desc.TestGroupKey;
            GameToken    = gameToken;
            Date         = DateTime.Now;

            Url = "https://metrics.chilliconnect.com/1.0/session/start";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the start of a new session with the metrics platforms. Sessions are
        /// used when calculating DAU, WAU, MAU and Retention Metrics. On successfully
        /// starting a session, a Metrics-Access-Token value will be returned. This should
        /// then be used on subsequent calls to register custom events within the session, as
        /// well as closing the session.
        /// </summary>
        ///
        /// <param name="desc">The request description.</param>
        /// <param name="successCallback">The delegate which is called if the request was successful.</param>
        /// <param name="errorCallback">The delegate which is called if the request was unsuccessful. Provides
        /// a container with information on what went wrong.</param>
        public void StartSession(StartSessionRequestDesc desc, Action <StartSessionRequest> successCallback, Action <StartSessionRequest, StartSessionError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Start Session request.");

            var gameToken = m_dataStore.GetString("AppToken");
            var request   = new StartSessionRequest(desc, gameToken);

            m_serverRequestSystem.SendImmediateRequest(request, (IImmediateServerRequest sentRequest, ServerResponse serverResponse) =>
            {
                ReleaseAssert.IsTrue(request == sentRequest, "Received request is not the same as the one sent!");

                if (serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode)
                {
                    NotifyStartSessionSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyStartSessionError(serverResponse, request, errorCallback);
                }
            });
        }