コード例 #1
0
        public static T Create(string serverUrl, RequestDataBase requestData = null)
        {
            var request = new T();

            request.FullUrl = serverUrl + request.RequestUrl;
            request.SetRequestData(requestData);
            return(request);
        }
コード例 #2
0
        public void Send <TRequest, TResponse>(RequestDataBase data, Action <TResponse> callback) where TRequest : RequestBase <TRequest>, new() where TResponse : SimpleResponse, new()
        {
            Debug.Log("Send - " + typeof(TRequest));
            Debug.Log(data);
            var request = RequestBase <TRequest> .Create(_serverUrl, data);

            StartCoroutine(SendRequestWithTimer(request, () =>
            {
                request.OnSendCompleted();
                callback.Invoke(ParseResponse <TResponse, TRequest>(request));
            }, () =>
            {
                callback.Invoke(new TResponse {
                    error = "Timeout", errorCode = 408
                });
            }));
        }
コード例 #3
0
        /// <summary>
        /// Send a request to a server that has been extended from the RequestBase class
        /// </summary>
        /// <typeparam name="TRequest">Your request type that has been extended from the RequestBase class</typeparam>
        /// <typeparam name="TResponse">SimpleResponse type or RequestResponse type that has been extended from the SimpleResponse class</typeparam>
        /// <param name="requestData">Data container type that has been extended from the RequestDataBase class</param>
        /// <param name="resultCallback">Callback which signals the completion of communication with the server</param>
        public void Send <TRequest, TResponse>(RequestDataBase requestData, Action <TResponse> resultCallback) where TRequest : RequestBase <TRequest>, new() where TResponse : SimpleResponse, new()
        {
            Debug.Log("Send - " + typeof(TRequest));
            Debug.Log(requestData);
            var request = RequestBase <TRequest> .Create(_serverUrl, requestData);

            StartCoroutine(SendRequestWithTimer(request, compliteCallback: () =>
            {
                request.OnSendCompleted();
                if (resultCallback != null)
                {
                    resultCallback.Invoke(ParseResponse <TResponse, TRequest>(request));
                }
            }, timeoutCallback: () =>
            {
                if (resultCallback != null)
                {
                    resultCallback.Invoke(new TResponse {
                        error = "Timeout", errorCode = 408
                    });
                }
            }));
        }
コード例 #4
0
 protected abstract void SetRequestData(RequestDataBase requestData);
コード例 #5
0
 public RequestService()
 {
     dataBase = new RequestDataBase();
 }