Esempio n. 1
0
        private void EvalFileAndSend(Session session, FileEvalRequest request)
        {
            var evalFileEventArgs = new EvalFileEventArgs(request.Key);
            var response          = new FileEvalResponse()
            {
                MessageId    = request.MessageId,
                ResponseType = ResponseType.OK
            };

            try
            {
                EvalFile?.Invoke(this, evalFileEventArgs);
                response.Data = evalFileEventArgs.Data;
            }
            catch (Exception ex)
            {
                OnException(session, ex, disconnect: false);
                response.ResponseType = ResponseType.Exception;
                response.Exception    = ex.Message;
            }

            SendData(
                session,
                SerializeManager.Current.Serialize(response));
        }
Esempio n. 2
0
        public Task <byte[]> GetFileAsync(string key, TimeSpan?timeout = null)
        {
            if (timeout == null)
            {
                timeout = TimeSpan.FromSeconds(30);
            }

            var request = new FileEvalRequest()
            {
                MessageId = Guid.NewGuid(),
                Key       = key
            };

            var bytes = SerializeManager.Current.Serialize(request);

            var waitItem = new FileWaitItem(request.MessageId);

            lock (_Sync)
            {
                _WaitDic.Add(waitItem.MessageId, waitItem);
            }

            AttachCompletionToWaitItem(waitItem, timeout.Value);
            SendData(bytes);

            return(waitItem.CompletionSource.Task);
        }