Exemplo n.º 1
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="ArgumentNullException">Throws if monitor is null</exception>
        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)
            {
                Log.W(TAG, ffe);
            }
            monitor.Start(totalWork);

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

            monitor.Stop();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Installs the application package that was pushed to a temporary location on the device.
        /// </summary>
        /// <param name="remoteFilePath">absolute file path to package file on device</param>
        /// <param name="reinstall">set to <code>true</code> if re-install of app should be performed</param>
        public void InstallRemotePackage(String remoteFilePath, bool reinstall)
        {
            InstallReceiver receiver = new InstallReceiver( );
            FileEntry       entry    = FileListingService.FindFileEntry(remoteFilePath);
            String          cmd      = String.Format("pm install {1}{0}", entry.FullEscapedPath, reinstall ? "-r " : String.Empty);

            ExecuteShellCommand(cmd, receiver);

            if (!String.IsNullOrEmpty(receiver.ErrorMessage))
            {
                throw new PackageInstallationException(receiver.ErrorMessage);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a file entry from the specified path on the device.
        /// </summary>
        /// <param name="device">The device to check</param>
        /// <param name="path">the path to check</param>
        /// <exception cref="IOException">If the device is not connected.</exception>
        /// <exception cref="ArgumentNullException">If the device or path is null.</exception>
        /// <exception cref="FileNotFoundException">If the entrty is not found.</exception>
        /// <returns></returns>
        public static FileEntry Find(IDevice device, FileListingService fileListingService, String path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                return(fileListingService.FindFileEntry(path));
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Finds the file entry, or creates an empty FileEntry if it does not exist.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="path">The path.</param>
        /// <remarks>This does not create the FileEntry on disk. It only creates the FileEntry object.</remarks>
        /// <returns></returns>
        public static FileEntry FindOrCreate(IDevice device, FileListingService fileListingService, String path)
        {
            device.ThrowIfNull("device");
            path.ThrowIfNullOrEmpty("path");

            if (!device.IsOffline)
            {
                try
                {
                    return(fileListingService.FindFileEntry(path));
                }
                catch (FileNotFoundException)
                {
                    var fe = new FileEntry(device, path);
                    fe.Create();
                    return(fe);
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Exemplo n.º 5
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 ) {
                Console.WriteLine ( ffe.ToString ( ) );
                Log.w ( "ddms", ffe );
            }
            monitor.Start ( totalWork );

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

            monitor.Stop ( );
            return result;
        }