Пример #1
0
        public async Task <SyncResult> Sync(HiDriveSyncExecutionInfo syncExecutionInfo, CancellationToken token)
        {
            var result = new SyncResult(syncExecutionInfo);

            Directory.CreateDirectory(syncExecutionInfo.LogPath);
            using (_logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.File(Path.Combine(syncExecutionInfo.LogPath, $"{syncExecutionInfo.Name}_Log_{DateTime.Now:yyyy_MM_dd_HH_mm_ss}.txt"), syncExecutionInfo.LogEventLevel).WriteTo.Debug().CreateLogger())
            {
                _logger.Information("Starting Sync of '{LocalDirectory}' to '{RemotePath}'", syncExecutionInfo.SourcePath, syncExecutionInfo.DestinationPath);
                result.Start = DateTime.Now;
                try
                {
                    var destination = await CreateDirectoryPath(syncExecutionInfo.DestinationPath, token);

                    var source = new DirectoryInfo(syncExecutionInfo.SourcePath);
                    result.Items = await SyncDirectory(destination, source, token);

                    result.State = SyncState.Successful;
                }
                catch (OperationCanceledException operationCanceledException)
                {
                    _logger.Warning(operationCanceledException, "Sync Process was cancelled!");
                    result.Items = new List <ItemSyncResult>();
                    result.State = SyncState.Cancelled;
                }
                catch (Exception exception)
                {
                    _logger.Fatal(exception, "");
                    result.Items     = new List <ItemSyncResult>();
                    result.State     = SyncState.Failed;
                    result.Exception = exception;
                }
                finally
                {
                    result.End = DateTime.Now;
                }
            }

            return(result);
        }
Пример #2
0
        private async Task Process(CancellationToken token)
        {
            try
            {
                Log.Verbose("Start HiDrive Sync run for {@folder}", _folderConfiguration);

                var hiDriveSyncExecutor = new HiDriveSyncExecutor(_hiDriveClient);
                await _hiDriveClient.Authenticator.AuthenticateByRefreshTokenAsync(_accountService.Accounts.HiDriveAccount.RefreshToken);

                var syncExecutionInfo = new HiDriveSyncExecutionInfo
                {
                    Name            = _folderConfiguration.Label,
                    SourcePath      = _folderConfiguration.SourcePath,
                    DestinationPath = _folderConfiguration.DestinationPath,
                    LogPath         = _folderConfiguration.LogPath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SyncService", "Log"),
                    SyncContentOnly = false
                };

                var syncResult = await hiDriveSyncExecutor.Sync(syncExecutionInfo, token);

                if (_folderConfiguration.NotificationConfiguration.SendEmail && !_folderConfiguration.NotificationConfiguration.SendEmailOnlyOnError)
                {
                    await SendEmail(syncResult);
                }
            }
            catch (AuthenticationException exception)
            {
                Log.Error(exception, "Authentication for account {@account} failed", _accountService.Accounts.HiDriveAccount);
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failure while executing sync!");
                if (_folderConfiguration.NotificationConfiguration.SendEmail)
                {
                    await SendFailureEmail(exception);
                }
            }
        }
Пример #3
0
 public SyncResult(HiDriveSyncExecutionInfo syncExecutionInfo)
 {
     TaskName = syncExecutionInfo.Name;
 }