static void Main(string[] args) { ConfigureSpeech(); Console.BufferWidth = 150; Console.WindowWidth = 150; _sourceFolder = new DirectoryInfo(args[0]); _initialDrives = DriveInfo.GetDrives(); Console.WriteLine($"Initial Drives: {_initialDrives.Select(d => d.Name).ToDelimitedString(", ")}"); Task.Run(() => MonitorDrives()); Console.WriteLine($"Started Monitorind Drives..."); Task.Run(() => MonitorReadyToCopyQueue()); Console.WriteLine($"Ready to copy data from {_sourceFolder} to your USB sticks, put them in these thiny wholes :P"); while (true) { if (_askForPositionQueue.TryDequeue(out var driveToProcess)) { Console.Write($"New USB Stick detected (Label: '{driveToProcess.VolumeLabel}', Name: '{driveToProcess.Name}') please enter location: "); var location = Console.ReadLine(); Console.WriteLine($"Start copy from '{_sourceFolder.FullName}' to '{driveToProcess.Name}', location: {location}"); _readyToCopyQueue.Enqueue(Tuple.Create(driveToProcess, location)); } if (_finishedQueue.TryDequeue(out var info)) { var x = info ?? null; Console.WriteLine($"Copy finished on '{ x.Item1.VolumeLabel}', Name: '{x.Item1.Name}') at location: '{x.Item2}'"); Console.Write("Please remove Drive and press any key to confirm."); _synth.Speak("Please confirm you fagot."); Console.ReadKey(intercept: true); _drivesInProgress.RemoveAll(d => string.Equals(d.Name, x.Item1.Name, StringComparison.CurrentCultureIgnoreCase)); Console.WriteLine("Tanks for your confirmation and see you soon :D"); } if (_errorQueue.TryDequeue(out var error)) { var x = error ?? null; Console.WriteLine($"Something happened to '{x.Item1.VolumeLabel}', Name: '{x.Item1.Name}' at location '{x.Item2}'"); Console.WriteLine(x.Item3); Console.Write("Please remove Drive and press any key to confirm."); _synth.Speak("Error! Error! Please confirm you fagot."); Console.Beep(); Console.ReadKey(intercept: true); _drivesInProgress.RemoveAll(d => string.Equals(d.Name, x.Item1.Name, StringComparison.CurrentCultureIgnoreCase)); Console.WriteLine("Tanks for your confirmation please fix drive on another PC and then try again."); } if (_progressQueue.TryDequeue(out var progress)) { var x = progress ?? null; Console.WriteLine($"Progress update: {progress.Item3}% '{x.Item1.VolumeLabel}', Name: '{x.Item1.Name}', Location '{x.Item2} "); } Thread.Sleep(100); } }
private static void MonitorDrives() { while (true) { foreach (var driveInfo in DriveInfo.GetDrives() .ExceptBy(_initialDrives, d => d.Name) .ExceptBy(_drivesInProgress, d => d.Name) .Where(d => d.IsReady && d.VolumeLabel == "USB DISK" && d.DriveType == DriveType.Removable)) { _drivesInProgress.Add(driveInfo); _askForPositionQueue.Enqueue(driveInfo); } Thread.Sleep(500); } }