public HiDriveSyncService(FolderConfigurationService folderConfigurationService, IHiDriveClient hiDriveClient, AccountService accountService)
        {
            var allConfigs = folderConfigurationService.GetAllConfigs();

            foreach (var folderConfiguration in allConfigs.Where(configuration => !string.IsNullOrEmpty(configuration.Schedule)))
            {
                _hiDriveSyncTasks.TryAdd(folderConfiguration.Id, new HiDriveSyncTask(folderConfiguration, hiDriveClient, accountService));
            }

            folderConfigurationService.ConfigurationUpdated.Subscribe(configuration =>
            {
                if (_hiDriveSyncTasks.TryGetValue(configuration.Id, out var hiDriveSyncTask))
                {
                    Log.Information("Folder {folder} updated!", configuration);
                    hiDriveSyncTask.Update(configuration);
                }
                else
                {
                    Log.Information("Folder {folder} added!", configuration);
                    hiDriveSyncTask = new HiDriveSyncTask(configuration, hiDriveClient,
                                                          accountService);
                    if (_hiDriveSyncTasks.TryAdd(configuration.Id, hiDriveSyncTask))
                    {
                        hiDriveSyncTask.Activate(_cts.Token);
                        //_tasks.TryAdd(configuration.Id, Task.Factory.StartNew(() => hiDriveSyncTask.Start(_cts.Token), TaskCreationOptions.LongRunning));
                    }
                }
            });
            folderConfigurationService.ConfigurationDeleted.Subscribe(configuration =>
            {
                if (_hiDriveSyncTasks.TryRemove(configuration.Id, out var hiDriveSyncTask))
                {
                    Log.Information("Folder {folder} removed!", configuration);
                    hiDriveSyncTask.Stop();
                }
            });
        }
Exemplo n.º 2
0
 public IndexModel(AccountService accountService, FolderConfigurationService folderConfigurationService, HiDriveSyncService hiDriveSyncService)
 {
     _accountService             = accountService;
     _folderConfigurationService = folderConfigurationService;
     _hiDriveSyncService         = hiDriveSyncService;
 }
Exemplo n.º 3
0
 public DeleteModel(FolderConfigurationService folderConfigurationService)
 {
     _folderConfigurationService = folderConfigurationService;
 }
Exemplo n.º 4
0
 public CreateEditModel(FolderConfigurationService folderConfigService, AccountService accountService, HiDriveSyncService hiDriveSyncService)
 {
     _folderConfigService = folderConfigService;
     _accountService      = accountService;
     _hiDriveSyncService  = hiDriveSyncService;
 }