Пример #1
0
        private void InitAndSend(Session session, FileInitRequest request)
        {
            var initEventArgs = new InitEventArgs(request.Data);
            var response      = new FileInitResponse()
            {
                MessageId    = request.MessageId,
                ResponseType = ResponseType.OK
            };

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

            SendData(
                session,
                SerializeManager.Current.Serialize(response));
        }
Пример #2
0
        public Task InitAsync(object data, TimeSpan?timeout = null)
        {
            if (timeout == null)
            {
                timeout = TimeSpan.FromSeconds(30);
            }

            var request = new FileInitRequest()
            {
                MessageId = Guid.NewGuid(),
                Data      = data
            };

            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);
        }