Example #1
0
        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 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();
        }
Example #3
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();
            }
        }
Example #4
0
        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();
            }
        }
        public static T TraceProgressOn <T>(ProgressFunc <T> func, ProgressProxy proxy)
        {
            var previousContext = SynchronizationContext.Current;

            try {
                var syncContext = new CurrentThreadSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(syncContext);

                proxy.progress = new Progress <ProgressValue>(v => proxy.Report(v));

                var task = Task.Run(() => func(proxy.progress));
                task.ContinueWith(delegate { syncContext.Complete(); }, TaskScheduler.Default);

                syncContext.RunOnCurrentThread();

                return(task.GetAwaiter().GetResult());
            } finally {
                SynchronizationContext.SetSynchronizationContext(previousContext);
            }
        }
        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);
        }
        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));
        }