Beispiel #1
0
        public void ProgressProxy_WhereFuncReturnsResult_ReportsProgressOnCurrentThread()
        {
            const string activity         = "ACTIVITY";
            const string target           = "TARGET";
            const int    percentComplete  = 50;
            const int    bytesTransferred = 512;
            const int    bytesTotal       = 1024;
            const int    result           = 42;

            var currentThreadId = Thread.CurrentThread.ManagedThreadId;

            var providerContextMock = new Mock <IProviderContext>(MockBehavior.Strict);

            providerContextMock.Setup(p => p.WriteProgress(It.Is <ProgressRecord>(r => r.Activity == activity && r.StatusDescription == target && r.PercentComplete == percentComplete &&
                                                                                  r.CurrentOperation == "Transferring 512b/1Kb" && r.RecordType == ProgressRecordType.Processing &&
                                                                                  Thread.CurrentThread.ManagedThreadId == currentThreadId)
                                                           ));

            var sut = new ProgressProxy(providerContextMock.Object, activity, target);

            ProgressProxy.ProgressFunc <int> func = async p => {
                return(await Task.Run(() => {
                    Assert.AreNotEqual(currentThreadId, Thread.CurrentThread.ManagedThreadId, "Current Thread not expected for func evaluation");
                    p.Report(new ProgressValue(percentComplete, bytesTransferred, bytesTotal));
                    return result;
                }));
            };
            Assert.AreEqual(result, ProgressProxy.TraceProgressOn(func, sut), "Unexpected result");

            providerContextMock.VerifyAll();
        }
        public void ProgressProxy_WhereFuncReturnsResult_ReportsProgressOnCurrentThread()
        {
            const string activity = "ACTIVITY";
            const string target = "TARGET";
            const int percentComplete = 50;
            const int bytesTransferred = 512;
            const int bytesTotal = 1024;
            const int result = 42;

            var currentThreadId = Thread.CurrentThread.ManagedThreadId;

            var providerContextMock = new Mock<IProviderContext>(MockBehavior.Strict);
            providerContextMock.Setup(p => p.WriteProgress(It.Is<ProgressRecord>(r => r.Activity == activity && r.StatusDescription == target && r.PercentComplete == percentComplete
                            && r.CurrentOperation == "Transferring 512b/1Kb" && r.RecordType == ProgressRecordType.Processing
                            && Thread.CurrentThread.ManagedThreadId == currentThreadId)
            ));

            var sut = new ProgressProxy(providerContextMock.Object, activity, target);

            ProgressProxy.ProgressFunc<int> func = async p => {
                return await Task.Run(() => {
                    Assert.AreNotEqual(currentThreadId, Thread.CurrentThread.ManagedThreadId, "Current Thread not expected for func evaluation");
                    p.Report(new ProgressValue(percentComplete, bytesTransferred, bytesTotal));
                    return result;
                });
            };
            Assert.AreEqual(result, ProgressProxy.TraceProgressOn(func, sut), "Unexpected result");

            providerContextMock.VerifyAll();
        }
        public Stream GetContent(FileInfoContract source, ProgressProxy progress)
        {
            var result = gateway.GetContent(rootName, source.Id);

            if (!result.CanSeek) {
                var bufferStream = new MemoryStream();
                result.CopyTo(bufferStream, MAX_BULKDOWNLOAD_SIZE);
                bufferStream.Seek(0, SeekOrigin.Begin);
                result.Dispose();
                result = bufferStream;
            }

            result = new ProgressStream(result, progress);

            if (!string.IsNullOrEmpty(encryptionKey))
                result = result.Decrypt(encryptionKey);

            return result;
        }
Beispiel #4
0
        public ProgressField()
        {
            InitializeComponent();

            proxy = new ProgressProxy(this, null, null, lblProgress1, progressBar);
        }
        public void SetContent(FileInfoContract target, Stream content, ProgressProxy progress)
        {
            if (!string.IsNullOrEmpty(encryptionKey))
                content = content.Encrypt(encryptionKey);

            gateway.SetContent(rootName, target.Id, content, progress);
            target.Size = content.Length;

            InvalidateDrive();
        }
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content, ProgressProxy progress)
        {
            if (!string.IsNullOrEmpty(encryptionKey))
                content = content.Encrypt(encryptionKey);

            InvalidateDrive();

            return gateway.NewFileItem(rootName, parent.Id, name, content, progress);
        }
 public BurningAsyncOperationToken(ProgressProxy ProgressProxy)
     : base(ProgressProxy, true)
 {
     ProgressToken = ProgressProxy;
     _id = Interlocked.Increment(ref _nextBurningOperationId);
 }
Beispiel #8
0
        public void OnProgessMessage(object sender, PublishEventArgs e)
        {
            if (_progress == null)
            {
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(() => OnProgessMessage(sender, e)));
                    return;
                }
                _progress = new ProgressProxy(this.Handle);
                _progress.SetRange(e.ProgressSteps);
            }

            if (e.Message != "Hide") //Todo: Small hack
            {
                _progress.SetProgressTitle(e.Message);
                _progress.Step();
            }
            else
            {
                HideProgress();
            }
        }
Beispiel #9
0
 private void HideProgress()
 {
     if (_progress != null)
     {
         _progress.ShowWindow(false);
         _progress = null;
     }
 }
        public Stream GetContent(FileInfoContract source, ProgressProxy progress)
        {
            try {
                var result = gateway.GetContentAsync(rootName, source.Id).Result;

                if (!result.CanSeek) {
                    var bufferStream = new MemoryStream();
                    result.CopyTo(bufferStream, MAX_BULKDOWNLOAD_SIZE);
                    bufferStream.Seek(0, SeekOrigin.Begin);
                    result.Dispose();
                    result = bufferStream;
                }

                result = new ProgressStream(result, progress);

                if (!string.IsNullOrEmpty(encryptionKey))
                    result = result.Decrypt(encryptionKey);

                return result;
            } catch (AggregateException ex) when (ex.InnerExceptions.Count == 1) {
                throw ex.InnerExceptions[0];
            }
        }
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content, ProgressProxy progress)
        {
            try {
                if (content != null && !string.IsNullOrEmpty(encryptionKey))
                    content = content.Encrypt(encryptionKey);

                ProgressProxy.ProgressFunc<FileInfoContract> func = p => gateway.NewFileItemAsync(rootName, parent.Id, name, content, p);
                return ProgressProxy.TraceProgressOn(func, progress);
            } catch (AggregateException ex) when (ex.InnerExceptions.Count == 1) {
                throw ex.InnerExceptions[0];
            } finally {
                InvalidateDrive();
            }
        }
        public void SetContent(FileInfoContract target, Stream content, ProgressProxy progress)
        {
            try {
                if (!string.IsNullOrEmpty(encryptionKey))
                    content = content.Encrypt(encryptionKey);

                Func<FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(target);
                ProgressProxy.ProgressFunc<bool> func = p => gateway.SetContentAsync(rootName, target.Id, content, p, locator);
                ProgressProxy.TraceProgressOn(func, progress);
                target.Size = content.Length;
            } catch (AggregateException ex) when (ex.InnerExceptions.Count == 1) {
                throw ex.InnerExceptions[0];
            } finally {
                InvalidateDrive();
            }
        }