Пример #1
0
        /// <summary>
        /// Returns the appropriate authenticated provider based on the parameters
        /// </summary>
        /// <param name="providerType">Service provider</param>
        /// <param name="acc">User account</param>
        /// <returns></returns>
        private static async Task <IFileTransferProvider> getProvider(ServiceProviders providerType, Account acc)
        {
            IFileTransferProvider retval = null;

            switch (providerType)
            {
            case ServiceProviders.Local:
                retval = LocalStorageProvider.Instance();
                break;

            case ServiceProviders.Google:
                retval = await GoogleDriveProvider.Instance(acc as GoogleDriveAccount);

                break;

            case ServiceProviders.DropBox:
                retval = await DropBoxProvider.Instance(acc as DropBoxAccount);

                break;

            case ServiceProviders.OneDrive:
                retval = await OneDriveProvider.Instance(acc as OneDriveAccount);

                break;

            case ServiceProviders.SSH:
                retval = await SSHProvider.Instance(acc as SSHAccount);

                break;
            }
            return(retval);
        }
Пример #2
0
        /// <summary>
        /// Method which copies files and folders from the source path and sends them to the destination path
        /// </summary>
        /// <param name="source">Source path</param>
        /// <param name="destination">Destination path</param>
        /// <param name="copySubDirs">Whether or not to copy sub directories</param>
        /// <param name="isRoot">Whether or not the current copy is at the root level</param>
        public static async Task Copy(Path source, Path destination, bool copySubDirs, bool isRoot)
        {
            Dictionary <FileDescription, byte[]> fileDescToBytesMapping = new Dictionary <FileDescription, byte[]>();
            List <DirectoryDescription>          subDirectories         = copySubDirs ? new List <DirectoryDescription>() : null;

            try
            {
                IFileTransferProvider provider = null;

                // Fetching process
                provider = await getProvider(source.Provider, source.UserAccount);

                await provider.Fetch(source, copySubDirs, fileDescToBytesMapping, subDirectories);

                // Dispatching process
                provider = await getProvider(destination.Provider, destination.UserAccount);

                await provider.Dispatch(destination, copySubDirs, fileDescToBytesMapping, subDirectories);

                fileDescToBytesMapping = null; // Dispose of files and bytes that have been used

                if (copySubDirs)
                {
                    CopySubDirs(source, destination, subDirectories, copySubDirs);
                }

                if (isRoot) // Once all the copies have been completed report the success
                {
                    ReportIO.WriteStatement("Backup between " + source.AbsolutePath + " and " + destination.AbsolutePath + " completed successfully.");
                }
            }
            catch (Exception e)
            {
                if (isRoot) // Report the error only at the root level, otherwise throw so root can catch
                {
                    ReportIO.WriteStatement("Backup between " + source.AbsolutePath + " and " + destination.AbsolutePath + " failed. Reason: " + e.Message);
                }
                else
                {
                    throw e;
                }
            }
        }
Пример #3
0
 internal FileTransferManager()
 {
     // XXX: Hard-coded for now, may change later!
     provider = new FileFind.Meshwork.FileTransfer.BitTorrent.BitTorrentFileTransferProvider();
 }
Пример #4
0
 public FileTransferManager(IFileTransferProvider provider, ILoggingService loggingService)
 {
     //TODO: Support other providers?!
     Provider            = provider;
     this.loggingService = loggingService;
 }
Пример #5
0
 internal FileTransferManager(Core.Core core)
 {
     // XXX: Hard-coded for now, may change later!
     provider = new BitTorrentFileTransferProvider(core);
 }