public override void OnChanged(object sender, FileSystemEventArgs e) { try { Watcher.EnableRaisingEvents = false; Console.WriteLine("Файл изменен " + e.Name); using (Bitmap bmp = new Bitmap(e.FullPath)) { if (!File.Exists(RootFolder + "/" + e.Name + IndexFormat)) { File.Create(RootFolder + "/" + e.Name + IndexFormat).Close(); DataImg dataImg = new DataImg(bmp.Height, bmp.Width); File.WriteAllText(RootFolder + "/" + e.Name + IndexFormat, JsonConvert.SerializeObject(dataImg)); } else { DataImg dataImg = JsonConvert.DeserializeObject <DataImg>(File.ReadAllText(RootFolder + "/" + e.Name + IndexFormat)); dataImg.height = bmp.Height; dataImg.width = bmp.Width; File.WriteAllText(RootFolder + "/" + e.Name + IndexFormat, JsonConvert.SerializeObject(dataImg)); } } } finally { Watcher.EnableRaisingEvents = true; } }
public void RunIndexImg() { foreach (string file in Directory.EnumerateFiles(RootFolder, "*.png", SearchOption.AllDirectories)) { using (Bitmap bmp = new Bitmap(file)) { if (!File.Exists(file + IndexFormat)) { File.Create(file + IndexFormat).Close(); DataImg dataImg = new DataImg(bmp.Height, bmp.Width); File.WriteAllText(file + IndexFormat, JsonConvert.SerializeObject(dataImg)); } else { DataImg dataImg = JsonConvert.DeserializeObject <DataImg>(File.ReadAllText(file + IndexFormat)); dataImg.height = bmp.Height; dataImg.width = bmp.Width; File.WriteAllText(file + IndexFormat, JsonConvert.SerializeObject(dataImg)); } } } }