コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Pulls file(s) or folder(s).
        /// </summary>
        /// <param name="entries">the remote item(s) to pull</param>
        /// <param name="localPath">The local destination. If the entries count is &gt; 1 or if the unique entry is a
        /// folder, this should be a folder.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <gist id="c9ca09c0c0779d0a5fb8" />
        public SyncResult Pull(IEnumerable <FileEntry> entries, string localPath, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            // first we check the destination is a directory and exists
            DirectoryInfo d = new DirectoryInfo(localPath);

            if (!d.Exists)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_NO_DIR_TARGET));
            }

            if (!d.IsDirectory())
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_TARGET_IS_FILE));
            }

            // get a FileListingService object
            FileListingService fls = new FileListingService(Device);

            // compute the number of file to move
            long total = GetTotalRemoteFileSize(entries, fls);

            Util.ConsoleTraceError("total transfer: {0}", total);

            // start the monitor
            monitor.Start(total);

            SyncResult result = DoPull(entries, localPath, fls, monitor);

            monitor.Stop( );

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Pulls a single file.
        /// <para>Because this method just deals with a String for the remote file instead of FileEntry,
        /// the size of the file being pulled is unknown and the ISyncProgressMonitor will not properly
        /// show the progress</para>
        /// </summary>
        /// <param name="remoteFilepath">the full path to the remote file</param>
        /// <param name="localFilename">The local destination.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        /// <gist id="9021e6c39ee20a6e122b" />
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long totalWork = 0;

            try {
                FileListingService fls             = new FileListingService(this.Device);
                FileEntry          remoteFileEntry = fls.FindFileEntry(remoteFilepath);
                totalWork = remoteFileEntry.Size;
            } catch (FileNotFoundException ffe) {
                Util.ConsoleTraceError(ffe.ToString( ));
                Log.w("ddms", ffe);
            }
            monitor.Start(totalWork);

            SyncResult result = DoPullFile(remoteFilepath, localFilename, monitor);

            monitor.Stop( );
            return(result);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entries"></param>
        /// <param name="localPath"></param>
        /// <param name="fileListingService"></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));
        }
コード例 #5
0
ファイル: SyncService.cs プロジェクト: SwerveRobotics/tools
        /// <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;
        }
コード例 #6
0
ファイル: SyncService.cs プロジェクト: SwerveRobotics/tools
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entries"></param>
        /// <param name="localPath"></param>
        /// <param name="fileListingService"></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 );
        }
コード例 #7
0
ファイル: SyncService.cs プロジェクト: SwerveRobotics/tools
        /// <summary>
        /// Pulls a single file.
        /// <para>Because this method just deals with a String for the remote file instead of FileEntry,
        /// the size of the file being pulled is unknown and the ISyncProgressMonitor will not properly
        /// show the progress</para>
        /// </summary>
        /// <param name="remoteFilepath">the full path to the remote file</param>
        /// <param name="localFilename">The local destination.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <exception cref="ArgumentNullException">Throws if monitor is null</exception>
        /// <gist id="9021e6c39ee20a6e122b" />
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            long totalWork = 0;
            try {
                FileListingService fls = new FileListingService ( this.Device );
                FileEntry remoteFileEntry = fls.FindFileEntry ( remoteFilepath );
                totalWork = remoteFileEntry.Size;
            } catch ( FileNotFoundException ffe ) {
                Util.ConsoleTraceError ( ffe.ToString ( ) );
                Log.w ( "ddms", ffe );
            }
            monitor.Start ( totalWork );

            SyncResult result = DoPullFile ( remoteFilepath, localFilename, monitor );

            monitor.Stop ( );
            return result;
        }
コード例 #8
0
ファイル: SyncService.cs プロジェクト: SwerveRobotics/tools
        /// <summary>
        /// Pulls file(s) or folder(s).
        /// </summary>
        /// <param name="entries">the remote item(s) to pull</param>
        /// <param name="localPath">The local destination. If the entries count is &gt; 1 or if the unique entry is a
        /// folder, this should be a folder.</param>
        /// <param name="monitor">The progress monitor. Cannot be null.</param>
        /// <returns>
        /// a SyncResult object with a code and an optional message.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">monitor;Monitor cannot be null</exception>
        /// <gist id="c9ca09c0c0779d0a5fb8" />
        public SyncResult Pull( IEnumerable<FileEntry> entries, string localPath, ISyncProgressMonitor monitor )
        {
            if ( monitor == null ) {
                throw new ArgumentNullException ( "monitor", "Monitor cannot be null" );
            }

            // first we check the destination is a directory and exists
            DirectoryInfo d = new DirectoryInfo ( localPath );
            if ( !d.Exists ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_NO_DIR_TARGET );
            }

            if ( !d.IsDirectory() ) {
                return new SyncResult ( ErrorCodeHelper.RESULT_TARGET_IS_FILE );
            }

            // get a FileListingService object
            FileListingService fls = new FileListingService ( Device );

            // compute the number of file to move
            long total = GetTotalRemoteFileSize ( entries, fls );
            Util.ConsoleTraceError ( "total transfer: {0}", total );

            // start the monitor
            monitor.Start ( total );

            SyncResult result = DoPull ( entries, localPath, fls, monitor );

            monitor.Stop ( );

            return result;
        }