Esempio n. 1
0
        /// <summary>
        /// Notifies the user that a Query Collection request has failed.
        /// </summary>
        ///
        /// <param name="serverResponse">A container for information on the response from the server. Only
        /// failed responses can be passed into this method.</param>
        /// <param name="request"> The request that was sent to the server.</param>
        /// <param name="callback">The error callback.</param>
        private void NotifyQueryCollectionError(ServerResponse serverResponse, QueryCollectionRequest request, Action <QueryCollectionRequest, QueryCollectionError> errorCallback)
        {
            ReleaseAssert.IsTrue(serverResponse.Result != HttpResult.Success || serverResponse.HttpResponseCode != SuccessHttpResponseCode, "Input server request must describe an error.");

            switch (serverResponse.Result)
            {
            case HttpResult.Success:
                m_logging.LogVerboseMessage("Query Collection request failed with http response code: " + serverResponse.HttpResponseCode);
                break;

            case HttpResult.CouldNotConnect:
                m_logging.LogVerboseMessage("Query Collection request failed becuase a connection could be established.");
                break;

            default:
                m_logging.LogVerboseMessage("Query Collection request failed for an unknown reason.");
                throw new ArgumentException("Invalid value for server response result.");
            }

            QueryCollectionError error = new QueryCollectionError(serverResponse);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                errorCallback(request, error);
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Notifies the user that a Query Collection request was successful.
        /// </summary>
        ///
        /// <param name="serverResponse">A container for information on the response from the server. Only
        /// successful responses can be passed into this method.</param>
        /// <param name="request"> The request that was sent to the server.</param>
        /// <param name="callback">The success callback.</param>
        private void NotifyQueryCollectionSuccess(ServerResponse serverResponse, QueryCollectionRequest request, Action <QueryCollectionRequest, QueryCollectionResponse> successCallback)
        {
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode, "Input server request must describe a success.");

            m_logging.LogVerboseMessage("QueryCollection request succeeded.");

            QueryCollectionResponse outputResponse = new QueryCollectionResponse(serverResponse.Body);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                successCallback(request, outputResponse);
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Returns objects that satisfy the query for a specified collection.
        /// </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 QueryCollection(QueryCollectionRequestDesc desc, Action <QueryCollectionRequest, QueryCollectionResponse> successCallback, Action <QueryCollectionRequest, QueryCollectionError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Query Collection request.");

            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new QueryCollectionRequest(desc, connectAccessToken);

            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)
                {
                    NotifyQueryCollectionSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyQueryCollectionError(serverResponse, request, errorCallback);
                }
            });
        }