Example #1
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));
        }
Example #2
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));
        }
Example #3
0
        private 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 = 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 = DoPushFile ( f.FullName, dest, monitor );
                        if ( result.Code != ErrorCodeHelper.RESULT_OK ) {
                            return result;
                        }
                    }
                }
            }

            return new SyncResult ( ErrorCodeHelper.RESULT_OK );
        }
Example #4
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 );
        }