Beispiel #1
0
        public FileStream Pull(string remotePath)
        {
            File.Delete("./pull.log");
            remotePath = $"/sdcard/Android/data/{GlobalData.Instance.AndroidPackageName}/files/{remotePath}";
            var service = new SyncService(m_client, m_deviceData);
            var stream  = new FileStream("./pull.log", FileMode.Create);

            service.Pull(remotePath, stream, null, CancellationToken.None);
            service.Dispose();
            stream.Seek(0, SeekOrigin.Begin);
            service.Dispose();
            return(stream);
        }
Beispiel #2
0
        public void Push(string localSourceFile, string remotePath)
        {
            remotePath       = $"/sdcard/Android/data/{GlobalData.Instance.AndroidPackageName}/files/{remotePath}";
            using var stream = new FileStream(localSourceFile, FileMode.Open);
            var m_syncService = new SyncService(m_client, m_deviceData);

            m_syncService.Push(stream, remotePath, 666, DateTime.Now, null, CancellationToken.None);
            m_syncService.Dispose();
        }
        static async Task <int> Main(string[] args)
        {
            // Load Settings.
            IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build();

            Settings = configuration.ReadSettings();

            // Load Log4Net for net configuration.
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            log.Info($"\n{System.Diagnostics.Process.GetCurrentProcess().ProcessName}");
            log.Info("\nPress 'q' to unregister file system and exit (simulate uninstall).");
            log.Info("\nPress any other key to exit without unregistering (simulate reboot).");
            log.Info("\n----------------------\n");

            // Typically you will register sync root during your application installation.
            // Here we register it during first program start for the sake of the development convenience.
            if (!await Registrar.IsRegisteredAsync(Settings.UserFileSystemRootPath))
            {
                Directory.CreateDirectory(Settings.UserFileSystemRootPath);
                log.Info($"\nRegistering {Settings.UserFileSystemRootPath} sync root.");
                await Registrar.RegisterAsync(SyncRootId, Settings.UserFileSystemRootPath, "My Virtual File System");
            }
            else
            {
                log.Info($"\n{Settings.UserFileSystemRootPath} sync root already registered.");
            }

            ConsoleKeyInfo exitKey;

            try
            {
                engine = new VfsEngine(Settings.License, Settings.UserFileSystemRootPath, log);
                RemoteStorageMonitorInstance = new RemoteStorageMonitor(Settings.RemoteStorageRootPath, log);
                syncService           = new SyncService(Settings.SyncIntervalMs, Settings.UserFileSystemRootPath, log);
                userFileSystemMonitor = new UserFileSystemMonitor(Settings.UserFileSystemRootPath, log);

                // Start processing OS file system calls.
                await engine.StartAsync();

                // Start monitoring changes in remote file system.
                await RemoteStorageMonitorInstance.StartAsync();

                // Start periodical synchronyzation between client and server,
                // in case any changes are lost because the client or the server were unavailable.
                //await syncService.StartAsync();

                // Start monitoring pinned/unpinned attributes and files/folders creation in user file system.
                await userFileSystemMonitor.StartAsync();

#if DEBUG
                // Opens Windows File Manager with user file system folder and remote storage folder.
                ShowTestEnvironment(Settings.UserFileSystemRootPath, Settings.RemoteStorageRootPath);
#endif
                // Keep this application running untill user input.
                exitKey = Console.ReadKey();
            }
            finally
            {
                engine.Dispose();
                RemoteStorageMonitorInstance.Dispose();
                syncService.Dispose();
                userFileSystemMonitor.Dispose();
            }

            if (exitKey.KeyChar == 'q')
            {
                // Unregister during programm uninstall.
                await Registrar.UnregisterAsync(SyncRootId);

                log.Info($"\n\nUnregistering {Settings.UserFileSystemRootPath} sync root.");
                log.Info("\nAll empty file and folder placeholders are deleted. Hydrated placeholders are converted to regular files / folders.\n");
            }
            else
            {
                log.Info("\n\nAll downloaded file / folder placeholders remain in file system. Restart the application to continue managing files.\n");
            }

            return(1);
        }