Beispiel #1
0
        public override async Task <FileSystemResult> CopyAsync(IDirectory destination)
        {
            try
            {
                DirectoryImplementation to = destination as DirectoryImplementation;
                if (to == null)
                {
                    return(new FileSystemResult("Destination should be a Local Directory"));
                }
                if (to is LocalRoot)
                {
                    return(new FileSystemResult("Root cannot be destination"));
                }
                string destname = Path.Combine(to.FullName, Name);

                File.Copy(FullName, destname);
                FileInfo  finfo = new FileInfo(destname);
                LocalFile local = new LocalFile(finfo, FS);
                local.Parent = destination;
                to.IntFiles.Add(local);
                return(await Task.FromResult(new FileSystemResult()));
            }
            catch (Exception e)
            {
                return(new FileSystemResult(e.Message));
            }
        }
Beispiel #2
0
 public override async Task <FileSystemResult> MoveAsync(IDirectory destination)
 {
     try
     {
         DirectoryImplementation to = destination as DirectoryImplementation;
         if (to == null)
         {
             return(new FileSystemResult("Destination should be a Local Directory"));
         }
         if (to is LocalRoot)
         {
             return(new FileSystemResult("Root cannot be destination"));
         }
         string destname = Path.Combine(to.FullName, Name);
         File.Move(FullName, destname);
         ((DirectoryImplementation)Parent).IntFiles.Remove(this);
         to.IntFiles.Add(this);
         this.Parent = to;
         file        = new FileInfo(destname);
         return(await Task.FromResult(new FileSystemResult()));
     }
     catch (Exception e)
     {
         return(new FileSystemResult(e.Message));
     }
 }
Beispiel #3
0
        internal async Task <FileSystemResult <IFile> > InternalCreateFile(DirectoryImplementation dir, string name, Stream readstream, CancellationToken token, IProgress <FileProgress> progress, Dictionary <string, object> properties)
        {
            if (properties == null)
            {
                properties = new Dictionary <string, object>();
            }
            string path = name;

            if (dir.Parent != null)
            {
                path = Path.Combine(dir.FullName, path);
            }
            Stream s = File.Open(path, FileMode.Create, FileAccess.Write);

            byte[] block = new byte[1024 * 128];
            long   left  = readstream.Length;

            do
            {
                int size  = (int)Math.Min(left, block.Length);
                int rsize = await readstream.ReadAsync(block, 0, size, token);

                await s.WriteAsync(block, 0, rsize, token);

                left -= rsize;
                FileProgress p = new FileProgress
                {
                    Percentage   = ((float)(readstream.Length - left) * 100) / readstream.Length,
                    TotalSize    = readstream.Length,
                    TransferSize = readstream.Length - left
                };
                progress.Report(p);
            } while (left > 0 && !token.IsCancellationRequested);
            s.Close();
            if (token.IsCancellationRequested)
            {
                try
                {
                    File.Delete(path);
                }
                catch
                {
                    // ignored
                }
                return(new FileSystemResult <IFile>("Transfer canceled"));
            }
            FileInfo finfo = new FileInfo(path);

            if (properties.Any(a => a.Key.Equals("ModifiedDate", StringComparison.InvariantCultureIgnoreCase)))
            {
                finfo.LastWriteTime = (DateTime)properties.First(a => a.Key.Equals("ModifiedDate", StringComparison.InvariantCultureIgnoreCase)).Value;
            }
            if (properties.Any(a => a.Key.Equals("CreatedDate", StringComparison.InvariantCultureIgnoreCase)))
            {
                finfo.CreationTime = (DateTime)properties.First(a => a.Key.Equals("CreatedDate", StringComparison.InvariantCultureIgnoreCase)).Value;
            }
            LocalFile f = new LocalFile(finfo, FS);

            return(new FileSystemResult <IFile>(f));
        }
Beispiel #4
0
        public override async Task <FileSystemResult> MoveAsync(IDirectory destination)
        {
            DirectoryImplementation to = destination as DirectoryImplementation;

            if (to == null)
            {
                return(new FileSystemResult("Destination should be a Local Directory"));
            }
            if (to is LocalRoot)
            {
                return(new FileSystemResult("Root cannot be destination"));
            }
            string destname = Path.Combine(to.FullName, Name);

            Directory.Move(FullName, destname);
            Parent = destination;
            return(await Task.FromResult(new FileSystemResult()));
        }
        public override async Task <FileSystemResult> MoveAsync(IDirectory destination)
        {
            DirectoryImplementation to = destination as DirectoryImplementation;

            if (to == null)
            {
                return(new FileSystemResult("Destination should be a Local Directory"));
            }
            if (to is LocalRoot)
            {
                return(new FileSystemResult("Root cannot be destination"));
            }
            string destname    = Path.Combine(to.FullName, Name);
            string oldFullname = this.FullName;

            Directory.Move(FullName, destname);
            FS.Refs.Remove(oldFullname);
            ((DirectoryImplementation)Parent).IntDirectories.Remove(this);
            to.IntDirectories.Add(this);
            Parent            = destination;
            FS.Refs[FullName] = this;
            return(await Task.FromResult(new FileSystemResult()));
        }