예제 #1
0
        /// <summary>
        /// Push a single file.
        /// </summary>
        /// <param name="local">the local filepath.</param>
        /// <param name="remote">The remote filepath.</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>
        public SyncResult PushFile(String local, String remote, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            FileInfo f = new FileInfo(local);

            if (!f.Exists)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_NO_LOCAL_FILE));
            }

            if (f.IsDirectory( ))
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_LOCAL_IS_DIRECTORY));
            }

            monitor.Start(f.Length);
            SyncResult result = DoPushFile(local, remote, monitor);

            monitor.Stop( );

            return(result);
        }
예제 #2
0
파일: Device.cs 프로젝트: NasC0/Side_Stuff
        /// <summary>
        /// Pushes a file to device
        /// </summary>
        /// <param name="localFilePath">the absolute path to file on local host</param>
        /// <returns>destination path on device for file</returns>
        /// <exception cref="IOException">if fatal error occurred when pushing file</exception>
        public String SyncPackageToDevice(String localFilePath)
        {
            try {
                String packageFileName = Path.GetFileName(localFilePath);
                // only root has access to /data/local/tmp/... not sure how adb does it then...
                // workitem: 16823
                // workitem: 19711
                String remoteFilePath = LinuxPath.Combine(TEMP_DIRECTORY_FOR_INSTALL, packageFileName);

                Console.WriteLine(String.Format("Uploading {0} onto device '{1}'", packageFileName, SerialNumber));
                Log.d(packageFileName, String.Format("Uploading {0} onto device '{1}'", packageFileName, SerialNumber));

                SyncService sync = SyncService;
                if (sync != null)
                {
                    String message = String.Format("Uploading file onto device '{0}'", SerialNumber);
                    Log.d(LOG_TAG, message);
                    SyncResult result = sync.PushFile(localFilePath, remoteFilePath, SyncService.NullProgressMonitor);

                    if (result.Code != ErrorCodeHelper.RESULT_OK)
                    {
                        throw new IOException(String.Format("Unable to upload file: {0}", result.Message));
                    }
                }
                else
                {
                    throw new IOException("Unable to open sync connection!");
                }
                return(remoteFilePath);
            } catch (IOException e) {
                Log.e(LOG_TAG, String.Format("Unable to open sync connection! reason: {0}", e.Message));
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Push several files.
        /// </summary>
        /// <param name="local">An array of local files to push</param>
        /// <param name="remote">the remote FileEntry representing a directory.</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 cannot be null</exception>
        /// <gist id="380b3c149499bf31e49d" />
        public SyncResult Push(IEnumerable <String> local, FileEntry remote, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            if (!remote.IsDirectory)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_REMOTE_IS_FILE));
            }

            // make a list of File from the list of String
            List <FileSystemInfo> files = new List <FileSystemInfo> ( );

            foreach (String path in local)
            {
                files.Add(path.GetFileSystemInfo( ));
            }

            // get the total count of the bytes to transfer
            long total = GetTotalLocalFileSize(files);

            monitor.Start(total);
            SyncResult result = DoPush(files, remote.FullPath, monitor);

            monitor.Stop( );

            return(result);
        }
예제 #4
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);
        }
예제 #5
0
        public SyncResult DoPush(IEnumerable <FileSystemInfo> files, string remotePath, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            // check if we're canceled
            if (monitor.IsCanceled)
            {
                return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
            }

            foreach (FileSystemInfo f in files)
            {
                // check if we're canceled
                if (monitor.IsCanceled)
                {
                    return(new SyncResult(ErrorCodeHelper.RESULT_CANCELED));
                }

                // append the name of the directory/file to the remote path
                string dest = LinuxPath.Combine(remotePath, f.Name);
                if (f.Exists)
                {
                    if (f.IsDirectory())
                    {
                        DirectoryInfo fsiDir = f as DirectoryInfo;
                        monitor.StartSubTask(f.FullName, dest);
                        SyncResult result = this.DoPush(fsiDir.GetFileSystemInfos(), dest, monitor);

                        if (result.Code != ErrorCodeHelper.RESULT_OK)
                        {
                            return(result);
                        }

                        monitor.Advance(1);
                    }
                    else if (f.IsFile())
                    {
                        monitor.StartSubTask(f.FullName, dest);
                        SyncResult result = this.DoPushFile(f.FullName, dest, monitor);
                        if (result.Code != ErrorCodeHelper.RESULT_OK)
                        {
                            return(result);
                        }
                    }
                }
            }

            return(new SyncResult(ErrorCodeHelper.RESULT_OK));
        }
예제 #6
0
        /// <summary>
        /// Pulls a single file.
        /// </summary>
        /// <param name="remote">remote 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="39fdc76b6f394b9bdf88" />
        public SyncResult PullFile(FileEntry remote, String localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long total = remote.Size;

            monitor.Start(total);

            SyncResult result = DoPullFile(remote.FullPath, localFilename, monitor);

            monitor.Stop( );
            return(result);
        }
예제 #7
0
        /// <include file='.\ISyncService.xml' path='/SyncService/PullFile2/*'/>
        public SyncResult PullFile(string remoteFilepath, string localFilename, ISyncProgressMonitor monitor)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor", "Monitor cannot be null");
            }

            long totalWork = 0;

            monitor.Start(totalWork);

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

            monitor.Stop();
            return(result);
        }
예제 #8
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);

            Log.d(TAG, "total transfer: {0}", total);

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

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

            monitor.Stop( );

            return(result);
        }
예제 #9
0
        /// <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));
        }