diff --git a/Program.cs b/Program.cs index 9b5625d..c2f1693 100644 --- a/Program.cs +++ b/Program.cs @@ -24,6 +24,7 @@ namespace placeholdervo private static ConcurrentQueue scriptFragmentFiles = new ConcurrentQueue(); private static ConcurrentQueue titleCardLines = new ConcurrentQueue(); + private static ConcurrentDictionary filePickups = new ConcurrentDictionary(); private static CancellationToken scriptFileCancellationToken; //from when I cut it up into separate files @@ -71,50 +72,48 @@ namespace placeholdervo // } // } - // private static async void filePickup() - // { - // while(true) - // { - // while(!scriptFragmentVoiceFiles.IsEmpty) - // { - // var files = Directory.GetFiles(conf.sync_dropoff); - // Console.WriteLine($"files listed: {string.Join(", ", files)}"); - // Console.WriteLine($"hoping for: {string.Join(", ", scriptFragmentVoiceFiles.Keys)}"); - // // Console.WriteLine($"sanity check: first listed file: {Path.GetFileName(files.FirstOrDefault())}"); - // // Console.WriteLine($"sanity check: first key: {scriptFragmentVoiceFiles.Keys.FirstOrDefault()}"); - // // Console.WriteLine($"sanity check: first value: {scriptFragmentVoiceFiles[scriptFragmentVoiceFiles.Keys.FirstOrDefault()]}"); - // var audioFile = files.FirstOrDefault(f => scriptFragmentVoiceFiles.ContainsKey(Path.GetFileName(f))); - // if(!string.IsNullOrWhiteSpace(audioFile)) - // { - // Console.WriteLine($"found {audioFile}"); - // try - // { - // var bareAudioFile = Path.GetFileName(audioFile); - // var destFile = scriptFragmentVoiceFiles[bareAudioFile]; - // destFile = Path.GetFileNameWithoutExtension(destFile) + ".wav"; - // destFile = Path.Combine(workingDir, destFile); - // File.Move(audioFile, destFile); - - // if(!scriptFragmentVoiceFiles.Remove(bareAudioFile, out string throwaway)) - // { - // Console.WriteLine($"failed to remove {bareAudioFile}"); - // } - // } - // catch(Exception e) - // { - // Console.Error.WriteLine(e.Message); - // } - // } - // System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); - // } - // if(scriptFileCancellationToken.IsCancellationRequested) - // { - // return; - // } + ///mostly just to give myself the reminder about paths + ///the *complete path* of the awaited file. you might want conf.sync_dropoff + ///the *complete path* to move the file to. + private static async void awaitFile(string src, string dest) + { + filePickups[src] = dest; + } + private static async void filePickup() + { + while(true) + { + foreach(var srcKey in filePickups.Keys) + { + // var files = Directory.GetFiles(conf.sync_dropoff); + // Console.WriteLine($"files listed: {string.Join(", ", files)}"); + // Console.WriteLine($"hoping for: {string.Join(", ", filePickups.Keys)}"); + // Console.WriteLine($"sanity check: first listed file: {Path.GetFileName(files.FirstOrDefault())}"); + // Console.WriteLine($"sanity check: first key: {scriptFragmentVoiceFiles.Keys.FirstOrDefault()}"); + // Console.WriteLine($"sanity check: first value: {scriptFragmentVoiceFiles[scriptFragmentVoiceFiles.Keys.FirstOrDefault()]}"); + if(File.Exists(srcKey)) + { + Console.WriteLine($"found {srcKey}"); + string dest; + if (filePickups.TryRemove(srcKey, out dest)) + { + File.Move(srcKey, dest); + } + else + { + Console.Error.WriteLine($"Failed to remove {srcKey} from filepickups. Unrecoverable, I think."); + Environment.Exit(-1); + } + } + } + if(scriptFileCancellationToken.IsCancellationRequested) + { + return; + } - // System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); - // } - // } + System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); + } + } public static async Task Main(string[] args) { @@ -264,9 +263,9 @@ namespace placeholdervo } // execute them all - // Task.Run(OfflineStuff); //e.g., generate title cards and credits - // Task.Run(ApiCalls); //e.g. generate voice - // await Task.Run(FilePickups); + //Task.Run(OfflineStuff); + //Task.Run(ApiCalls); + var fpTask = Task.Run(filePickup); // cancelSource.Cancel(); // Console.WriteLine("http client \"cancelled\".");