/// <summary> /// compute the recursive file size of all the files in the list. Folder have a weight of 1. /// </summary> /// <param name="entries">The remote files</param> /// <param name="fls">The FileListingService</param> /// <returns>The total number of bytes of the specified remote files</returns> private long GetTotalRemoteFileSize(IEnumerable <FileEntry> entries, FileListingService fls) { long count = 0; foreach (FileEntry e in entries) { FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { // get the children IEnumerable <FileEntry> children = fls.GetChildren(e, false, null); count += GetTotalRemoteFileSize(children, fls) + 1; } else if (type == FileListingService.FileTypes.File) { count += e.Size; } } return(count); }
/// <summary> /// compute the recursive file size of all the files in the list. Folder have a weight of 1. /// </summary> /// <param name="entries">The remote files</param> /// <param name="fls">The FileListingService</param> /// <returns>The total number of bytes of the specified remote files</returns> private long GetTotalRemoteFileSize( IEnumerable<FileEntry> entries, FileListingService fls ) { long count = 0; foreach ( FileEntry e in entries ) { FileListingService.FileTypes type = e.Type; if ( type == FileListingService.FileTypes.Directory ) { // get the children IEnumerable<FileEntry> children = fls.GetChildren ( e, false, null ); count += GetTotalRemoteFileSize ( children, fls ) + 1; } else if ( type == FileListingService.FileTypes.File ) { count += e.Size; } } return count; }
/// <summary> /// /// </summary> /// <param name="entries"></param> /// <param name="localPath"></param> /// <param name="fls"></param> /// <param name="monitor"></param> /// <returns></returns> /// <exception cref="System.IO.IOException">Throws if unable to create a file or folder</exception> /// <exception cref="System.ArgumentNullException">Throws if the ISyncProgressMonitor is null</exception> private SyncResult DoPull(IEnumerable <FileEntry> entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor", "Monitor cannot be null"); } // check if we're cancelled if (monitor.IsCanceled) { return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED)); } // check if we need to create the local directory DirectoryInfo localDir = new DirectoryInfo(localPath); if (!localDir.Exists) { localDir.Create( ); } foreach (FileEntry e in entries) { // check if we're canceled if (monitor.IsCanceled) { return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED)); } // the destination item (folder or file) String dest = Path.Combine(localPath, e.Name); // get type (we only pull directory and files for now) FileListingService.FileTypes type = e.Type; if (type == FileListingService.FileTypes.Directory) { monitor.StartSubTask(e.FullPath, dest); // then recursively call the content. Since we did a ls command // to get the number of files, we can use the cache FileEntry[] children = fileListingService.GetChildren(e, true, null); SyncResult result = DoPull(children, dest, fileListingService, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } monitor.Advance(1); } else if (type == FileListingService.FileTypes.File) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = DoPullFile(e.FullPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } } else if (type == FileListingService.FileTypes.Link) { monitor.StartSubTask(e.FullPath, dest); SyncResult result = DoPullFile(e.FullResolvedPath, dest, monitor); if (result.Code != ErrorCodeHelper.RESULT_OK) { return(result); } } else { Log.d("ddms-sync", String.Format("unknown type to transfer: {0}", type)); } } return(new SyncResult(ErrorCodeHelper.RESULT_OK)); }
/// <summary> /// /// </summary> /// <param name="entries"></param> /// <param name="localPath"></param> /// <param name="fls"></param> /// <param name="monitor"></param> /// <returns></returns> /// <exception cref="System.IO.IOException">Throws if unable to create a file or folder</exception> /// <exception cref="System.ArgumentNullException">Throws if the ISyncProgressMonitor is null</exception> private SyncResult DoPull( IEnumerable<FileEntry> entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor ) { if ( monitor == null ) { throw new ArgumentNullException ( "monitor", "Monitor cannot be null" ); } // check if we're cancelled if ( monitor.IsCanceled ) { return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED ); } // check if we need to create the local directory DirectoryInfo localDir = new DirectoryInfo ( localPath ); if ( !localDir.Exists ) { localDir.Create ( ); } foreach ( FileEntry e in entries ) { // check if we're canceled if ( monitor.IsCanceled ) { return new SyncResult ( ErrorCodeHelper.RESULT_CANCELED ); } // the destination item (folder or file) String dest = Path.Combine ( localPath, e.Name ); // get type (we only pull directory and files for now) FileListingService.FileTypes type = e.Type; if ( type == FileListingService.FileTypes.Directory ) { monitor.StartSubTask ( e.FullPath, dest ); // then recursively call the content. Since we did a ls command // to get the number of files, we can use the cache FileEntry[] children = fileListingService.GetChildren ( e, true, null ); SyncResult result = DoPull ( children, dest, fileListingService, monitor ); if ( result.Code != ErrorCodeHelper.RESULT_OK ) { return result; } monitor.Advance ( 1 ); } else if ( type == FileListingService.FileTypes.File ) { monitor.StartSubTask ( e.FullPath, dest ); SyncResult result = DoPullFile ( e.FullPath, dest, monitor ); if ( result.Code != ErrorCodeHelper.RESULT_OK ) { return result; } } else if ( type == FileListingService.FileTypes.Link ) { monitor.StartSubTask ( e.FullPath, dest ); SyncResult result = DoPullFile ( e.FullResolvedPath, dest, monitor ); if ( result.Code != ErrorCodeHelper.RESULT_OK ) { return result; } } else { Log.d ( "ddms-sync", String.Format ( "unknown type to transfer: {0}", type ) ); } } return new SyncResult ( ErrorCodeHelper.RESULT_OK ); }