CSHARP HELP
I have these block of codes and what does is if some file is in input directory moves them to an output file and also verify if the file is duplicated with the hash.
Lets say we made the validation in memory, i think?
Now the task 1 is what i want is to make it persistent with a file so that if the program is restarted it does not duplicate i dont know much about databases but if you help me in this one i will apreciate it
The task 2
I need to apply a delegate to the program (which already has hashes and validates duplicates) apart from validating with the file we need to put a delegate so that when line 40-41 of the MoveFile.cs program is reached, it does something when the files are duplicated and pass it as a method to delete the file when it is duplicated.
This is the block of code. (Sorry to post it here i know there exists stackoverflow but i need i fast answer with the solution not that answers with im not going to do your homework but i dont have too much time) BIG THANKS IN ADVANCE!
Edit # I dont know how to make it persistent but i think the easist way is to connect to a database the oroblem is thag i dont know how (if there is another method i would be apreciate it) but if you can help me with the database like mysql i will apreciate it too! thanks!
EDIT 2#
This is the source code in raw
MoveFile.cs : pastebin.com/raw/A70A0nNe
First.cs : pastebin.com/rawYgv2GHQ
Watcher.cs : pastebin.com/raw/sP2GnPap
Folder.ca : pstebin.com/raw/g59YUiY1
PLEASE THE CODE IS IN THE PASTEBIN URL
I Cant edit with all the code in here
MoveFile.csx First.cs Watcher.cs Folder.cs HMK2. MoveFile Cu Tarea2 2 3 4 5 & 7 8 Fusing System; using System.Collections.Generic; using System.Text; using System.IO; using System.Security.Cryptography, Einamespace HMK2 1erence class MoveFile { private static Dictionary
validator = new Dictionary(); public static void move() reference 21 string origfiles = @"c:\File\Input"; string detFiles = @"c:\file\Output\"; string[] files = Directory.GetFiles(origFiles); foreach (var iten in files) { string strhash = null; using (SHA1Managed sha1 = new SHAIManaged()) { var hash - Shai.computeHash(File.ReadAllBytes(item)); var sb = new StringBuilder (hash.Length - 2); foreach (byte b in hash) // can be "x2" if you want lowercase sb.Append(b.tostring("x2")); 25 26 27 28 38 31 32 33 34 35 36 37 38 strhash - sb.ToString(); if(validator.containskey(strhash)) { Console.WriteLine("The file {0} is duplicated.",item); continue; else { validator.Add(strhash, item); File.Copy(item, detFiles + Path.GetFileName(item)); File.Delete(iten); Folder.cs HMK2.First Maino MoveFile.cs First.cs X Watcher.cs Ce Tarea2 Fusing System; 2 using System.Collections.Generic; 3 using System.Text; using System. Tiners; 5 Enamespace HK2 { Orences class First Oreferences static void Main() { gumengw var timer = new Timer (Timespan.FronSeconds(1e). TotalMilliseconds); // This will execute every 10 seconds timer.Elapsed - async (sender, e) -> { MoveFile.move(); }; Folder.createFolder(); timer.start(); watcher. Watcherstart(); console.ReadKey(); MoveFile.cs Tarea2 Watcherstart() First.cs Watcher.cs x Folder.cs HMK2.Watcher 1 reference class Watcher { I reference public static void watcherstart(). Filesystematcher watcher = new Filesystematcher(ec: Archivo\Input"); watcher.EnableRaisingEvents = true; watcher. IncludeSubdirectories = true; watcher. Changed - watcher_Changed; watcher.created tw watcher Created; watcher.Deleted += watcher_Deleted; watcher. Renamed watcher_Renamed; Console.Read(); AREAS ARSHANAM IE static void watcher_Renamed(object sender, RenamedeventArgs e) { Console.WriteLine("file: (} renaned to (1} at time: {2}", e.Oldmane, e.Nane, DateTime.Now. ToLocal Time()); > static void watcher_Deleted(object sender, FilesystemEventArgs e) Console.WriteLine("File: {@} deleted at time: (1), e. Name, DateTime.Now. TolocalTime()); } luce static void watcher_Created(object sender, FilesystemEventArgs e) { Console.WriteLine("File: {@} created at time: (1) ", e. Name, DateTime.Now. ToLocalTime()); } une do CELU Watcher.cs MoveFile.cs First.cs Tarea2 using System; 2 using System.IO; Folder.cs X HMK2 Folder CreateFolder Enamespace HMK2 1 class Folder SHARE ANNARRAR public static void createroider() DirectoryInfo nedir = new DirectoryInfo("C:\File"); DirectoryInfo subiri = new DirectoryInfocenc: File Input"); DirectoryInfo suboir2 = new DirectoryInfo(@mc:\File\output); if (n.Dir.Exists) { Console.WriteLine("The folder already exists"); if(suboiri.Exists ww false) C subiri.create(); } if (subdir2. Exists - false) C subDir2.create(); } } else newbir.Create(); nedir.createsubdirectory("Input"); nobir.createsubdirectory("output"); MoveFile.csx First.cs Watcher.cs Folder.cs HMK2. MoveFile Cu Tarea2 2 3 4 5 & 7 8 Fusing System; using System.Collections.Generic; using System.Text; using System.IO; using System.Security.Cryptography, Einamespace HMK2 1erence class MoveFile { private static Dictionary validator = new Dictionary(); public static void move() reference 21 string origfiles = @"c:\File\Input"; string detFiles = @"c:\file\Output\"; string[] files = Directory.GetFiles(origFiles); foreach (var iten in files) { string strhash = null; using (SHA1Managed sha1 = new SHAIManaged()) { var hash - Shai.computeHash(File.ReadAllBytes(item)); var sb = new StringBuilder (hash.Length - 2); foreach (byte b in hash) // can be "x2" if you want lowercase sb.Append(b.tostring("x2")); 25 26 27 28 38 31 32 33 34 35 36 37 38 strhash - sb.ToString(); if(validator.containskey(strhash)) { Console.WriteLine("The file {0} is duplicated.",item); continue; else { validator.Add(strhash, item); File.Copy(item, detFiles + Path.GetFileName(item)); File.Delete(iten); Folder.cs HMK2.First Maino MoveFile.cs First.cs X Watcher.cs Ce Tarea2 Fusing System; 2 using System.Collections.Generic; 3 using System.Text; using System. Tiners; 5 Enamespace HK2 { Orences class First Oreferences static void Main() { gumengw var timer = new Timer (Timespan.FronSeconds(1e). TotalMilliseconds); // This will execute every 10 seconds timer.Elapsed - async (sender, e) -> { MoveFile.move(); }; Folder.createFolder(); timer.start(); watcher. Watcherstart(); console.ReadKey(); MoveFile.cs Tarea2 Watcherstart() First.cs Watcher.cs x Folder.cs HMK2.Watcher 1 reference class Watcher { I reference public static void watcherstart(). Filesystematcher watcher = new Filesystematcher(ec: Archivo\Input"); watcher.EnableRaisingEvents = true; watcher. IncludeSubdirectories = true; watcher. Changed - watcher_Changed; watcher.created tw watcher Created; watcher.Deleted += watcher_Deleted; watcher. Renamed watcher_Renamed; Console.Read(); AREAS ARSHANAM IE static void watcher_Renamed(object sender, RenamedeventArgs e) { Console.WriteLine("file: (} renaned to (1} at time: {2}", e.Oldmane, e.Nane, DateTime.Now. ToLocal Time()); > static void watcher_Deleted(object sender, FilesystemEventArgs e) Console.WriteLine("File: {@} deleted at time: (1), e. Name, DateTime.Now. TolocalTime()); } luce static void watcher_Created(object sender, FilesystemEventArgs e) { Console.WriteLine("File: {@} created at time: (1) ", e. Name, DateTime.Now. ToLocalTime()); } une do CELU Watcher.cs MoveFile.cs First.cs Tarea2 using System; 2 using System.IO; Folder.cs X HMK2 Folder CreateFolder Enamespace HMK2 1 class Folder SHARE ANNARRAR public static void createroider() DirectoryInfo nedir = new DirectoryInfo("C:\File"); DirectoryInfo subiri = new DirectoryInfocenc: File Input"); DirectoryInfo suboir2 = new DirectoryInfo(@mc:\File\output); if (n.Dir.Exists) { Console.WriteLine("The folder already exists"); if(suboiri.Exists ww false) C subiri.create(); } if (subdir2. Exists - false) C subDir2.create(); } } else newbir.Create(); nedir.createsubdirectory("Input"); nobir.createsubdirectory("output")