Exemple #1
0
        private void TestRequestUploadFile(RequestUploadFileMessage obj)
        {
            var progressObserver = new Subject <ProgressState>();
            var disposable       = _bus.RegisterMessageSource(
                progressObserver.Select(ps => new FileUploadProgressChangedMessage(obj.CorrelationId, ps)));
            var requestStream = new NullStream();

            var  buf         = new byte[4096];
            var  inputStream = File.OpenRead(obj.Path);
            long total       = 0;
            long current     = 0;

            if (inputStream.CanSeek)
            {
                total = inputStream.Length;
            }

            progressObserver.OnNext(new ProgressState(total, current));

            int read;

            while ((read = inputStream.Read(buf, 0, buf.Length)) > 0)
            {
                requestStream.Write(buf, 0, read);
                current += read;
                progressObserver.OnNext(new ProgressState(total, current));
            }
            Thread.Sleep(1000);
            _bus.SendMessage(new FileUploadedMessage(obj.CorrelationId, obj.Path, new Upload()));
            disposable.Dispose();
        }
Exemple #2
0
        private void RequestUploadFile(RequestUploadFileMessage obj)
        {
            var subject = new Subject <ProgressState>();

            using (_bus.RegisterMessageSource(
                       subject.Select(ps => new FileUploadProgressChangedMessage(obj.CorrelationId, ps))))
            {
                CallApi(() => _api.UploadFile(obj.RoomId,
                                              new UploadFileParams(File.OpenRead(obj.Path), Path.GetFileName(obj.Path), obj.ContentType),
                                              subject),
                        upload => _bus.SendMessage(new FileUploadedMessage(obj.CorrelationId, obj.Path, upload)),
                        retry: false,
                        correlationId: obj.CorrelationId);
            }
        }