/// <summary> /// Creates a tray application instance. /// </summary> /// <param name="title">Tray application title.</param> /// <param name="syncService"> /// Synchronization service instance. The tray application will enable/disable this application and show its status. /// </param> public WindowsTrayInterface(string title, FullSyncService syncService) { Title = title; notifyIcon = new NotifyIcon(); notifyIcon.Visible = true; notifyIcon.Icon = new System.Drawing.Icon("Images\\Drive.ico"); notifyIcon.Text = title; ContextMenuStrip contextMenu = new ContextMenuStrip(); contextMenu.Items.Add(Localization.Resources.StopSync, null, (s, e) => { StartStopSync(syncService); }); #if !DEBUG // Hide console on app start. Visible = false; SetConsoleWindowVisibility(false); contextMenu.Items.Add(Localization.Resources.ShowLog, null, (s, e) => { #else contextMenu.Items.Add(Localization.Resources.HideLog, null, (s, e) => { #endif Visible = !Visible; ConsoleManager.SetConsoleWindowVisibility(Visible); contextMenu.Items[1].Text = (Visible)? Localization.Resources.HideLog : Localization.Resources.ShowLog; }); contextMenu.Items.Add($"{Localization.Resources.Exit} {title}", null, (s, e) => { Application.Exit(); }); notifyIcon.ContextMenuStrip = contextMenu; notifyIcon.MouseClick += (object sender, MouseEventArgs e) => { //MessageBox.Show("Clicked"); }; }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="license">A license string.</param> /// <param name="userFileSystemRootPath"> /// A root folder of your user file system. Your file system tree will be located under this folder. /// </param> /// <param name="log">Log4net logger.</param> /// <param name="settings">Virtual drive settings.</param> public VirtualDriveBase(string license, string userFileSystemRootPath, Settings settings, ILog log) { this.Settings = settings; this.log = log; Engine = new VfsEngine(license, userFileSystemRootPath, this, log); SyncService = new FullSyncService(settings.SyncIntervalMs, userFileSystemRootPath, this, log); SyncService.SyncEvent += SyncService_SyncEvent; userFileSystemMonitor = new UserFileSystemMonitor(userFileSystemRootPath, this, log); }
/// <summary> /// Create new tray icon. /// </summary> /// <param name="productName">Product name.</param> /// <param name="syncService">Sync service</param> /// <param name="exitEvent">ManualResetEvent, used to stop application</param> /// <returns></returns> public static Thread CreateTrayInterface(string productName, FullSyncService syncService, ManualResetEvent exitEvent) { // Start tray application. Thread thread = new Thread(() => { WindowsTrayInterface windowsTrayInterface = new WindowsTrayInterface($"{productName}", syncService); syncService.syncEvent += windowsTrayInterface.HandleStatusChange; Application.Run(); exitEvent.Set(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.IsBackground = true; return(thread); }
/// <summary> /// This method handles StartStop Sycn button in tray menu. /// </summary> private async void StartStopSync(FullSyncService syncService) { if (!sycnStopped) { await syncService.StopAsync(); sycnStopped = true; StatusToSyncStopped(); } else { await syncService.StartAsync(); sycnStopped = false; StatusToIdle(); } }
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 any other key to exit without unregistering (simulate reboot)."); log.Info("\nPress 'q' to unregister file system and exit (simulate uninstall)."); log.Info("\nPress 'Q' to unregister file system, delete all files/folders and exit (simulate uninstall with full cleanup)."); 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."); } // Log indexed state. StorageFolder userFileSystemRootFolder = await StorageFolder.GetFolderFromPathAsync(Settings.UserFileSystemRootPath); log.Info($"\nIndexed state: {(await userFileSystemRootFolder.GetIndexedStateAsync())}\n"); ConsoleKeyInfo exitKey; try { engine = new VfsEngine(Settings.License, Settings.UserFileSystemRootPath, log); RemoteStorageMonitorInstance = new RemoteStorageMonitor(Settings.RemoteStorageRootPath, log); syncService = new FullSyncService(Settings.SyncIntervalMs, Settings.UserFileSystemRootPath, log); userFileSystemMonitor = new UserFileSystemMonitor(Settings.UserFileSystemRootPath, log); // Start processing OS file system calls. //engine.ChangesProcessingEnabled = false; 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(); #endif // Keep this application running until 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 if (exitKey.KeyChar == 'Q') { log.Info($"\n\nUnregistering {Settings.UserFileSystemRootPath} sync root."); log.Info("\nAll files and folders placeholders are deleted.\n"); // Unregister during programm uninstall and delete all files/folder. await Registrar.UnregisterAsync(SyncRootId); try { Directory.Delete(Settings.UserFileSystemRootPath, true); } catch (Exception ex) { log.Error($"\n{ex}"); } } else { log.Info("\n\nAll downloaded file / folder placeholders remain in file system. Restart the application to continue managing files.\n"); } return(1); }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="license">A license string.</param> /// <param name="userFileSystemRootPath"> /// A root folder of your user file system. Your file system tree will be located under this folder. /// </param> /// <param name="log">Log4net logger.</param> /// <param name="syncIntervalMs">Full synchronization interval in milliseconds.</param> public VirtualDriveBase(string license, string userFileSystemRootPath, ILog log, double syncIntervalMs) { engine = new VfsEngine(license, userFileSystemRootPath, this, log); SyncService = new FullSyncService(syncIntervalMs, userFileSystemRootPath, this, log); userFileSystemMonitor = new UserFileSystemMonitor(userFileSystemRootPath, this, log); }