コード例 #1
0
        /// <summary>
        /// Queues a wait for a get message.  Allows us to send only one request and notify
        /// multiple threads of a GET response
        /// </summary>
        /// <returns>True there was already a get request out and there is no need to send another, false if not</returns>
        private bool QueueGetWaiter(ClientRequestMsg request, ResponseWaiter waiter)
        {
            bool requestExisted = false;

            if (request.Type == ClientRequestMsg.RequestType.GET)
            {
                lock (_getResponseWaiters)
                {
                    string uuid = request.GetUuid();

                    //if someone is already waiting for a response,
                    //make a note, we dont have to send out a request
                    if (_getResponseWaiters.ContainsKey(uuid))
                    {
                        requestExisted = true;
                    }
                    else
                    {
                        _getResponseWaiters.Add(request.GetUuid(), new List <ResponseWaiter>());
                    }

                    //insert us as a waiter
                    _getResponseWaiters[uuid].Add(waiter);
                }
            }

            return(requestExisted);
        }
コード例 #2
0
        public string GetAssetIds(string prefix)
        {
            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.STORED_ASSET_IDS_GET, prefix);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);

                //ErrorMessage takes the status string out of the data field
                return(responseWaiter.response.ErrorMessage);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #3
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public Asset GetAsset(string uuid)
        {
            uuid = Util.FixUuid(uuid);

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, uuid);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);

                //no error, return the asset
                return(responseWaiter.asset);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #4
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void GetAssetAsync(string uuid, AsyncAssetCallback callBack)
        {
            uuid = Util.FixUuid(uuid);

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, uuid);

            //send request and wait for response
            try
            {
                this.SendRequest(request, callBack);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #5
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void PutAsset(Asset asset)
        {
            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, asset.Serialize().data);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #6
0
        /// <summary>
        /// Sends the given request to the server
        /// </summary>
        /// <param name="request">The request to send</param>
        private ResponseWaiter SendRequest(ClientRequestMsg request, AsyncAssetCallback callBack)
        {
            ResponseWaiter waiter = new ResponseWaiter();

            waiter.callBack = callBack;
            waiter.type     = request.Type;

            if (!this.QueueGetWaiter(request, waiter))
            {
                lock (_sendSync)
                {
                    //we need to enqueue the right waiter here in the right order
                    lock (_waitingRequests)
                    {
                        _waitingRequests.Enqueue(waiter);
                    }

                    request.Send(_conn);
                }
            }

            return(waiter);
        }
コード例 #7
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void MaintPurgeLocals()
        {
            string uuid = ZERO_UUID;

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.MAINT_PURGELOCALS, uuid);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #8
0
        /// <summary>
        /// Queues a wait for a get message.  Allows us to send only one request and notify
        /// multiple threads of a GET response
        /// </summary>
        /// <returns>True there was already a get request out and there is no need to send another, false if not</returns>
        private bool QueueGetWaiter(ClientRequestMsg request, ResponseWaiter waiter)
        {
            bool requestExisted = false;
            if (request.Type == ClientRequestMsg.RequestType.GET)
            {
                lock (_getResponseWaiters)
                {
                    string uuid = request.GetUuid();

                    //if someone is already waiting for a response,
                    //make a note, we dont have to send out a request
                    if (_getResponseWaiters.ContainsKey(uuid))
                    {
                        requestExisted = true;
                    }
                    else
                    {
                        _getResponseWaiters.Add(request.GetUuid(), new List<ResponseWaiter>());
                    }

                    //insert us as a waiter
                    _getResponseWaiters[uuid].Add(waiter);
                }
            }

            return requestExisted;
        }
コード例 #9
0
        /// <summary>
        /// Sends the given request to the server
        /// </summary>
        /// <param name="request">The request to send</param>
        private ResponseWaiter SendRequest(ClientRequestMsg request, AsyncAssetCallback callBack)
        {
            ResponseWaiter waiter = new ResponseWaiter();
            waiter.callBack = callBack;
            waiter.type = request.Type;

            if (!this.QueueGetWaiter(request, waiter))
            {
                lock (_sendSync)
                {
                    //we need to enqueue the right waiter here in the right order
                    lock (_waitingRequests)
                    {
                        _waitingRequests.Enqueue(waiter);
                    }

                    request.Send(_conn);
                }
            }

            return waiter;
        }
コード例 #10
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void PutAsset(Asset asset)
        {
            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, asset.Serialize().data);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #11
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void MaintPurgeLocals()
        {
            string uuid = ZERO_UUID;

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.MAINT_PURGELOCALS, uuid);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #12
0
        public string GetServerStatus()
        {
            string uuid = ZERO_UUID;

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.STATUS_GET, uuid);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);

                //ErrorMessage takes the status string out of the data field
                return responseWaiter.response.ErrorMessage;
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #13
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public void GetAssetAsync(string uuid, AsyncAssetCallback callBack)
        {
            uuid = Util.FixUuid(uuid);

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, uuid);

            //send request and wait for response
            try
            {
                this.SendRequest(request, callBack);
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }
コード例 #14
0
        /// <summary>
        /// Attempts to retrieve the given asset from the server synchronously
        /// </summary>
        /// <param name="uuid">The asset UUID as a string</param>
        /// <returns>Asset</returns>
        public Asset GetAsset(string uuid)
        {
            uuid = Util.FixUuid(uuid);

            //build the request
            ClientRequestMsg request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, uuid);

            //send request and wait for response
            try
            {
                ResponseWaiter responseWaiter = this.SendRequest(request, null);
                responseWaiter.waitEvent.WaitOne();

                //we got a response
                //is there an error?
                this.CheckThrowError(responseWaiter);

                //no error, return the asset
                return responseWaiter.asset;
            }
            catch (SocketException e)
            {
                //a socket exception means we need to signal all waiters
                this.HandleSendError(e);
                throw new AssetServerError(e.Message, e);
            }
        }