Example #1
0
        /// <summary>
        /// Deserialization ctor
        /// </summary>
        public WindowsFile(SerializationInfo info, StreamingContext context)
        {
            isDir = info.GetBoolean("IsDir");
            string path = (string)info.GetValue("FullName", typeof(string));

            if (isDir)
            {
                adapted = new DirectoryInfo(path);
            }
            else
            {
                adapted = new FileInfo(path);
            }

            if (isDir)
            {
                //TODO: Improve it
                //Size = FileSize.CreateForDirectory(FullName);
                Size = FileSize.Empty;
            }
            else if (adapted.Exists)
            {
                Size = FileSize.CreateFromBytes(((FileInfo)adapted).Length);
            }
            else
            {
                Size = FileSize.CreateFromBytes(0);
            }
        }
Example #2
0
        public static FTPFile CreateFromServerCall(edtFTPFile fileInfo, string baseDir, int accountId)
        {
            var file = new FTPFile(accountId);

            file.LastModifiedTime = fileInfo.LastModified;
            file.IsDirectory      = fileInfo.Dir;
            file.Size             = FileSize.CreateFromBytes(fileInfo.Size);
            file.name             = fileInfo.Name;
            file.fullName         = PathExt.Combine(baseDir, fileInfo.Name, false);

            return(file);
        }
Example #3
0
        public WindowsFile(FileSystemInfo toAdapt)
        {
            adapted = toAdapt;
            isDir   = toAdapt is DirectoryInfo;

            if (toAdapt == null)
            {
                Size = FileSize.Empty;
            }
            else if (isDir)
            {
                //TODO: Make computing directory size
                //Size = FileSize.CreateForDirectory(FullName);
                Size = FileSize.Empty;
            }
            else
            {
                Size = FileSize.CreateFromBytes(((FileInfo)toAdapt).Length);
            }
        }
Example #4
0
        public CopyFileCallbackAction MovedPieceOfFile(FileInfo source, FileInfo destination, object state,
                                                       long totalFileSize, long totalBytesTransferred)
        {
            if (totalBytesTransferred > 0)
            {
                long totalOperationBytesForNow = movedBytes + totalBytesTransferred;
                Progress = (totalOperationBytesForNow / (double)SizeInBytes);
                Duration = DateTime.Now - Started;
                Speed    = FileSize.CreateFromBytes((long)(totalOperationBytesForNow / Duration.TotalSeconds));
                if (Speed.ToBytes() > 0)
                {
                    EstimatedEnd = TimeSpan.FromSeconds(SizeInBytes / Speed.ToBytes()) - Duration;
                }
                if (totalFileSize == totalBytesTransferred)
                {
                    movedBytes += totalBytesTransferred;
                }
            }

            return(IsCanceled ? CopyFileCallbackAction.Cancel : CopyFileCallbackAction.Continue);
        }