Ejemplo n.º 1
0
        /// <summary>
        /// Notifies the user that a Get Collection Objects 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 NotifyGetCollectionObjectsError(ServerResponse serverResponse, GetCollectionObjectsRequest request, Action <GetCollectionObjectsRequest, GetCollectionObjectsError> 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("Get Collection Objects request failed with http response code: " + serverResponse.HttpResponseCode);
                break;

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

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

            GetCollectionObjectsError error = new GetCollectionObjectsError(serverResponse);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                errorCallback(request, error);
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of Collection Objects identified by their ObjectID.
        /// </summary>
        ///
        /// <param name="key">The Collection Key.</param>
        /// <param name="objectIds">The ObjectIDs for which to retrieve the objects of. Maximum 20.</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 GetCollectionObjects(string key, IList <string> objectIds, Action <GetCollectionObjectsRequest, GetCollectionObjectsResponse> successCallback, Action <GetCollectionObjectsRequest, GetCollectionObjectsError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Get Collection Objects request.");

            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new GetCollectionObjectsRequest(key, objectIds, 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)
                {
                    NotifyGetCollectionObjectsSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyGetCollectionObjectsError(serverResponse, request, errorCallback);
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Notifies the user that a Get Collection Objects 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 NotifyGetCollectionObjectsSuccess(ServerResponse serverResponse, GetCollectionObjectsRequest request, Action <GetCollectionObjectsRequest, GetCollectionObjectsResponse> successCallback)
        {
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode, "Input server request must describe a success.");

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

            GetCollectionObjectsResponse outputResponse = new GetCollectionObjectsResponse(serverResponse.Body);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                successCallback(request, outputResponse);
            });
        }