コード例 #1
0
ファイル: SyncService.cs プロジェクト: yuva2achieve/dot42
        /// <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 > 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>
        /// <exception cref="SyncException"> </exception>
        /// <exception cref="IOException"> </exception>
        /// <exception cref="TimeoutException">
        /// </exception>
        /// <seealso cref= FileListingService.FileEntry </seealso>
        /// <seealso cref= #getNullProgressMonitor() </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void pull(com.android.ddmlib.FileListingService.FileEntry[] entries, String localPath, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        public void pull(FileListingService.FileEntry[] entries, string localPath, ISyncProgressMonitor monitor)
        {
            // first we check the destination is a directory and exists
            if (!Directory.Exists(localPath))
            {
                throw new SyncException(SyncException.SyncError.NO_DIR_TARGET);
            }
            if (File.Exists(localPath))
            {
                throw new SyncException(SyncException.SyncError.TARGET_IS_FILE);
            }

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

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

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

            doPull(entries, localPath, fls, monitor);

            monitor.stop();
        }
コード例 #2
0
ファイル: SyncService.cs プロジェクト: yuva2achieve/dot42
        /// <summary>
        /// compute the recursive file size of all the files in the list. Folder
        /// have a weight of 1. </summary>
        /// <param name="entries"> </param>
        /// <param name="fls">
        /// @return </param>
        private int getTotalRemoteFileSize(FileListingService.FileEntry[] entries, FileListingService fls)
        {
            int count = 0;

            foreach (FileListingService.FileEntry e in entries)
            {
                int type = e.type;
                if (type == FileListingService.TYPE_DIRECTORY)
                {
                    // get the children
                    FileListingService.FileEntry[] children = fls.getChildren(e, false, null);
                    count += getTotalRemoteFileSize(children, fls) + 1;
                }
                else if (type == FileListingService.TYPE_FILE)
                {
                    count += e.sizeValue;
                }
            }

            return(count);
        }
コード例 #3
0
ファイル: SyncService.cs プロジェクト: yuva2achieve/dot42
        /// <summary>
        /// Pulls multiple files/folders recursively. </summary>
        /// <param name="entries"> The list of entry to pull </param>
        /// <param name="localPath"> the localpath to a directory </param>
        /// <param name="fileListingService"> a FileListingService object to browse through remote directories. </param>
        /// <param name="monitor"> the progress monitor. Must be started already.
        /// </param>
        /// <exception cref="SyncException"> if file could not be pushed </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
        /// <exception cref="TimeoutException"> in case of a timeout reading responses from the device. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void doPull(com.android.ddmlib.FileListingService.FileEntry[] entries, String localPath, FileListingService fileListingService, ISyncProgressMonitor monitor) throws SyncException, java.io.IOException, TimeoutException
        private void doPull(FileListingService.FileEntry[] entries, string localPath, FileListingService fileListingService, ISyncProgressMonitor monitor)
        {
            foreach (FileListingService.FileEntry e in entries)
            {
                // check if we're cancelled
                if (monitor.canceled == true)
                {
                    throw new SyncException(SyncException.SyncError.CANCELED);
                }

                // get type (we only pull directory and files for now)
                int type = e.type;
                if (type == FileListingService.TYPE_DIRECTORY)
                {
                    monitor.startSubTask(e.fullPath);
                    var dest = Path.Combine(localPath, e.name);

                    // make the directory
                    Directory.CreateDirectory(dest);

                    // then recursively call the content. Since we did a ls command
                    // to get the number of files, we can use the cache
                    FileListingService.FileEntry[] children = fileListingService.getChildren(e, true, null);
                    doPull(children, dest, fileListingService, monitor);
                    monitor.advance(1);
                }
                else if (type == FileListingService.TYPE_FILE)
                {
                    monitor.startSubTask(e.fullPath);
                    string dest = Path.Combine(localPath, e.name);
                    doPullFile(e.fullPath, dest, monitor);
                }
            }
        }