public ZipRepositoryWatcher(Configuration.PalaceServerSettings settings, MicroServiceCollectorManager microServiceCollectorManager, ILogger <ZipRepositoryWatcher> logger) { this.Settings = settings; this.MicroServiceCollectorManager = microServiceCollectorManager; this.Logger = logger; }
private async void OnChanged(object sender, FileSystemEventArgs args) { Logger.LogDebug("Detect file {ChangeType} {FullPath}", args.FullPath, args.ChangeType); if (args.Name.EndsWith(".tmp", StringComparison.InvariantCultureIgnoreCase)) { Logger.LogTrace("detect temp file {0} {1}", args.Name, args.ChangeType); return; } // Filtrer sur les zip uniquement if (args.Name.IndexOf(".zip", StringComparison.InvariantCultureIgnoreCase) == -1) { Logger.LogTrace("detect {0} {1} not zip file", args.Name, args.ChangeType); return; } var unlock = await WaitForUnlock(args.FullPath); if (!unlock) { Logger.LogWarning("detect {0} file {1} not closed", args.Name, args.ChangeType); return; } Logger.LogInformation("File unlocked detected {ChangeType} {FullPath}", args.FullPath, args.ChangeType); try { MicroServiceCollectorManager.BackupAndUpdateRepositoryFile(args.FullPath); } catch (Exception ex) { ex.Data.Add("FullPath", args.FullPath); Logger.LogError(ex, ex.ToString()); } }