Exemplo n.º 1
0
        public override TypedData Process(TypedData data, IMutableProgressTracker progress, CancellationToken cancelToken)
        {
            switch (data.DataType) {
                case TypedDataType.Image:
                    var rawImageProgress = new MutableProgressTracker();
                    var uploadProgress = new MutableProgressTracker();

                    var aggregateProgress = new AggregateProgressTracker(new ProgressTrackerCollection {
                        { rawImageProgress, ImageWriter.ProcessTimeEstimate.ProgressWeight },
                        { uploadProgress, ProcessTimeEstimate.ProgressWeight },
                    });

                    aggregateProgress.BindTo(progress);

                    progress.Status = "Converting image";

                    using (var rawImageData = ImageWriter.Process(data, rawImageProgress, cancelToken)) {
                        progress.Status = "Uploading image";

                        return Upload(rawImageData, uploadProgress, cancelToken);
                    }

                default:
                    return null;
            }
        }
Exemplo n.º 2
0
        public void UpdateRaised()
        {
            var mpt = new MutableProgressTracker();
            int progressChangedCallCount = 0;

            mpt.ProgressUpdated += (sender, e) => {
                progressChangedCallCount += 1;
            };

            mpt.Progress = 1;
            Assert.AreEqual(1, progressChangedCallCount);

            mpt.Progress = 1;
            Assert.AreEqual(2, progressChangedCallCount);
        }
Exemplo n.º 3
0
        public static HttpWebResponse Execute(Uri uri, Stream requestData, IMutableProgressTracker progress, CancellationToken cancelToken)
        {
            // QUICK HACK

            var requestProgress = new MutableProgressTracker();
            var responseProgress = new MutableProgressTracker();

            var aggregateProgress = new AggregateProgressTracker(new ProgressTrackerCollection {
                { requestProgress,  TimeEstimates.LongOperation.ProgressWeight },
                { responseProgress, TimeEstimates.ShortOperation.ProgressWeight },
            });

            aggregateProgress.BindTo(progress);

            try {
                var request = CreateRequest(uri, @"POST");
                request.ContentLength = requestData.Length;

                using (var requestStream = request.GetRequestStream())
                using (var progressStream = new ProgressTrackingStreamWrapper(requestStream, request.ContentLength)) {
                    progressStream.BindTo(requestProgress);

                    requestData.CopyTo(progressStream, cancelToken);
                }

                bool canCancel = true;

                cancelToken.Register(() => {
                    if (canCancel) {
                        request.Abort();
                    }
                });

                var response = (HttpWebResponse) request.GetResponse();

                responseProgress.Progress = 1; // TODO HTTP download Progress

                canCancel = false;

                return response;
            } catch (WebException e) {
                if (e.Status == WebExceptionStatus.RequestCanceled) {
                    throw new OperationCanceledException(e.Message, e, cancelToken);
                }

                throw new OperationCanceledException(e.Message, e, cancelToken);
            }
        }
Exemplo n.º 4
0
        public TypedData Process(TypedData data, IMutableProgressTracker progress, CancellationToken cancelToken)
        {
            progress.Status = "Uploading data";

            var galleryProgress = new MutableProgressTracker();
            var uploadProgress = new MutableProgressTracker();

            var aggregateProgress = new AggregateProgressTracker(new ProgressTrackerCollection {
                { galleryProgress, TimeEstimates.ShortOperation.ProgressWeight },
                { uploadProgress,  TimeEstimates.LongOperation.ProgressWeight },
            });

            aggregateProgress.BindTo(progress);

            var galleryAccessData = CreateGallery(galleryProgress, cancelToken);

            return UploadData(galleryAccessData, data, uploadProgress, cancelToken);
        }
Exemplo n.º 5
0
        public void ZeroProgressOnNew()
        {
            var mpt = new MutableProgressTracker();

            Assert.AreEqual(0, mpt.Progress);
        }
Exemplo n.º 6
0
        public static HttpWebResponse Execute(Uri uri, MultipartData requestData, HttpRequestMethod requestMethod, IMutableProgressTracker progress, CancellationToken cancelToken)
        {
            var requestProgress = new MutableProgressTracker();
            var responseProgress = new MutableProgressTracker();

            var aggregateProgress = new AggregateProgressTracker(new ProgressTrackerCollection {
                { requestProgress,  TimeEstimates.LongOperation.ProgressWeight },
                { responseProgress, TimeEstimates.ShortOperation.ProgressWeight },
            });

            aggregateProgress.BindTo(progress);

            try {
                var request = BuildRequest(uri, requestMethod, requestData, requestProgress, cancelToken);

                bool canCancel = true;

                cancelToken.Register(() => {
                    if (canCancel) {
                        request.Abort();
                    }
                });

                var response = (HttpWebResponse) request.GetResponse();

                responseProgress.Progress = 1; // TODO HTTP download Progress

                canCancel = false;

                return response;
            } catch (WebException e) {
                if (e.Status == WebExceptionStatus.RequestCanceled) {
                    throw new OperationCanceledException(e.Message, e, cancelToken);
                }

                throw new OperationCanceledException(e.Message, e, cancelToken);
            }
        }