private bool AreAlreadyEncodedFilesTheSame(AlreadyEncodedFile file, AlreadyEncodedFile uniqueFile)
        {
            if (file.SourceFilePath != uniqueFile.SourceFilePath)
            {
                return(false);
            }

            if (file.SourceFilePath.Length < Globals.MaxPathLenth)
            {
                if (file.SourceFileModifiedDate != uniqueFile.SourceFileModifiedDate)
                {
                    return(false);
                }

                if (file.SourceFileSize != uniqueFile.SourceFileSize)
                {
                    return(false);
                }
            }

            if (file.EncodedFileExtension != uniqueFile.EncodedFileExtension)
            {
                return(false);
            }

            return(true);
        }
        private void ReadAlreadyEncodedFilesFromFile()
        {
            _AlreadyEncodedFiles = new LinkedList <AlreadyEncodedFile>();

            if (File.Exists(_EncodingHistoryFilePath))
            {
                try
                {
                    string[] lines = File.ReadAllLines(_EncodingHistoryFilePath);

                    foreach (string line in lines)
                    {
                        List <string> valuesFromHistoryFile = line.Split('*').ToList();

                        if (valuesFromHistoryFile.Count == 7)
                        {
                            AlreadyEncodedFile file = new AlreadyEncodedFile(valuesFromHistoryFile);

                            if (file.IsValid)
                            {
                                _AlreadyEncodedFiles.AddLast(file);  //Add to END of list
                            }
                            else
                            {
                                DeleteAlreadyEncodedFile(file);
                            }
                        }
                    }
                }
                catch (Exception) { }
            }
        }
        public bool IsLSREncodingEligibleForCopying(AlreadyEncodedFile file)
        {
            if (_SuggestedAudioFile.FullPath != file.SourceFilePath)  //Must use same source file to copy
            {
                return(false);
            }

            if (_SuggestedAudioFile.FullPath.Length < Globals.MaxPathLenth)
            {
                if (_SuggestedAudioFile.ModifiedDate != file.SourceFileModifiedDate)
                {
                    return(false);
                }

                if (_SuggestedAudioFile.FileSize != file.SourceFileSize)
                {
                    return(false);
                }
            }

            if (_OutputFilenameExtension != file.EncodedFileExtension)  //Must use same encoding codec to copy
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private void CopyOrEncodeAudioFile(AudioFileEncoding encoding)
        {
            if (!encoding.TryToCopyAlreadyEncodedFile)
            {
                encoding.EncodeAudioFile_Async();  //We need to encode it

                return;
            }

            AlreadyEncodedFile file = _History.GetAlreadyEncodedFileAndReCheckValidation(encoding);

            if (file != null)  //Already Encoded File found (copy it)
            {
                encoding.CopyOrEncodeAudioFile_Async(file);

                return;
            }

            AudioFileEncoding activeEncoding = GetActiveEncodingForPendingCopy(encoding);

            if (activeEncoding != null)  //Pending active encoding should be creating the Already Encoded file we seek (copy it)
            {
                encoding.CopyOrEncodeAudioFile_Async(activeEncoding);

                return;
            }

            encoding.EncodeAudioFile_Async();  //If all else fails, just encode it
        }
Exemplo n.º 5
0
        public void CopyOrEncodeAudioFile_Async(AlreadyEncodedFile file)
        {
            _CopyOrEncodeActionTaken = "Copy Already Encoded File";

            _FileToCopy = file;

            Task.Run(() => CopyorEncodeAudioFile());
        }
        private string GetGUIDPath(AlreadyEncodedFile file)
        {
            while (true)
            {
                string GUIDPath = _Config.HistoryFilesArchiveDirectory + "\\" + Guid.NewGuid().ToString() + file.EncodedFileExtension;

                if (!_AlreadyEncodedFiles.Any(uniqueFile => uniqueFile.EncodedFilePath == GUIDPath) && !File.Exists(GUIDPath))    //verify unique (should be when using GUIDs!)
                {
                    return(GUIDPath);
                }
            }
        }
 private void DeleteAlreadyEncodedFile(AlreadyEncodedFile file)
 {
     if (File.Exists(file.EncodedFilePath))
     {
         if (file.EncodedFilePath.StartsWith(_Config.HistoryFilesArchiveDirectory))   //verify for safety that we are not deleting the deliverable file at DestinationPath
         {
             try
             {
                 File.Delete(file.EncodedFilePath);
             }
             catch (Exception) { }
         }
     }
 }
        private bool IsAlreadyEncodedFileUnique(AlreadyEncodedFile file)
        {
            foreach (AlreadyEncodedFile uniqueFile in _AlreadyEncodedFiles)
            {
                if (file != uniqueFile)  //Don't Check Itself
                {
                    if (AreAlreadyEncodedFilesTheSame(file, uniqueFile))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        private void CopyOrEncodeAudioFile(AudioFileEncoding activeEncoding)
        {
            while (activeEncoding.HasFinished == false)
            {
                Thread.Sleep(1000);
            }

            _IsWaiting = false;

            _FileToCopy = new AlreadyEncodedFile(activeEncoding);  //Now Finished (Need to get updated 'Encoding Result' to verify if valid)

            if (_FileToCopy.IsValid)
            {
                CopyorEncodeAudioFile();
            }
            else
            {
                EncodeAudioFile();
            }
        }
        public void AddNewAlreadyEncodedFiles(List <AudioFileEncoding> newFinishedEncodings)
        {
            foreach (AudioFileEncoding finishedEncoding in newFinishedEncodings)
            {
                AlreadyEncodedFile file = new AlreadyEncodedFile(finishedEncoding);

                if (file.EncodedStatus == Globals.Encoded && file.IsValid) //We only want to have encoded file history for the original encoded file (not endless copies as well)
                {
                    string oldFilePath = file.EncodedFilePath;             //Same as LSR DestinationPath

                    string newFilePath = GetGUIDPath(file);                //History already encoded file new path

                    file.SetEncodedFilePath(newFilePath);                  //Set already encoded file 'EncodedFilePath' to new archive history file path

                    if (IsAlreadyEncodedFileUnique(file))                  //verify unique (so we don't have duplicate files in our history)
                    {
                        try
                        {
                            File.Copy(oldFilePath, newFilePath);     //Copy file at LSR DestinationPath to new History Archive path
                        }
                        catch (Exception) {  }

                        file.ReCheckIfValid();                       //Verify if new archive path (EncodedFilePath) is valid

                        if (file.IsValid)
                        {
                            _AlreadyEncodedFiles.AddFirst(file);     //Add to BEGINNING of list (most recent NEW  AlreadyEncodedFiles first)
                        }
                        else
                        {
                            DeleteAlreadyEncodedFile(file);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void AssignSuggestedAudioFile()
        {
            if (_SearchCollection != null)
            {
                _SuggestedAudioFile = _SearchCollection.GetSuggestedAudioFile();

                if (_SuggestedAudioFile == null)  //should never be the case, and if so, something is wrong
                {
                    ConsolePrintHelpers.PrintRedText("\n\n  ERROR  Unassigned Suggested Audio File at LSR #:  ");
                    ConsolePrintHelpers.PrintWhiteText((_LoadSheetRowNumber + 1).ToString());
                    ConsolePrintHelpers.PressAnyKeyToExit();
                }

                _PotentialFile = new AlreadyEncodedFile(this, false);  //Non-validated AlreadyEncodedFile (Used For Faster Queue Building)

                _IsSuggestedAudioFileAssigned = true;
            }
            else
            {
                ConsolePrintHelpers.PrintRedText("\n\n  ERROR  Trying To Assign Suggested Audio File With Null Search Collection at LSR #:  ");
                ConsolePrintHelpers.PrintWhiteText((_LoadSheetRowNumber + 1).ToString());
                ConsolePrintHelpers.PressAnyKeyToExit();
            }
        }
Exemplo n.º 12
0
        public void PrintEncodingQueue_DEBUG(AudioEncoderController controller)
        {
            ConsolePrintHelpers.PrintHeader();

            ConsolePrintHelpers.PrintWhiteText("  Printing Encoding Queue...");

            PrintPendingCopyOrEncodeStats();

            ConsolePrintHelpers.Wait();

            Console.WriteLine("\n");

            foreach (AudioFileEncoding encoding in _EncodingQueue)
            {
                ConsolePrintHelpers.PrintFullWidthLine();

                ConsolePrintHelpers.PrintWhiteText("  Encoding ID           :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.EncodingID.ToString());
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Load Sheet Row #      :  ");
                ConsolePrintHelpers.PrintCyanText((encoding.LSR.LoadSheetRowNumber + 1).ToString());
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Source File Size      :  ");
                ConsolePrintHelpers.PrintCyanText((encoding.LSR.SuggestedAudioFile.FileSize / 1024 / 1024).ToString() + " MB");
                Console.WriteLine("\n");

                ConsolePrintHelpers.PrintWhiteText("  Source File           :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.SuggestedAudioFile.FullPath);
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Destination File      :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.DestinationPath);
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Destination File Ext  :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.OutputFilenameExtension);
                Console.WriteLine("\n");

                ConsolePrintHelpers.PrintWhiteText("  Copy Or Encode        :  ");

                if (encoding.TryToCopyAlreadyEncodedFile)
                {
                    AlreadyEncodedFile file = controller.History.GetAlreadyEncodedFileAndReCheckValidation(encoding);

                    if (file != null)  //Already Encoded File found
                    {
                        ConsolePrintHelpers.PrintYellowText("Copy Already Encoded File");
                    }
                    else
                    {
                        AudioFileEncoding activeEncoding = controller.GetActiveEncodingForPendingCopy(encoding);

                        if (activeEncoding != null)  //Pending active encoding should be creating the Already Encoded file we seek
                        {
                            file = activeEncoding.LSR.PotentialFile;

                            ConsolePrintHelpers.PrintYellowText("Copy from Active Encoding (ID: " + activeEncoding.EncodingID.ToString() + ")");
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText("Encode (No Eligible File To Copy Found)");
                        }
                    }

                    if (file != null)
                    {
                        Console.WriteLine("\n");
                        ConsolePrintHelpers.PrintWhiteText("  Load Sheet Row #      :  ");
                        ConsolePrintHelpers.PrintGreenText((file.LoadSheetRowNumber + 1).ToString());
                        Console.WriteLine();
                        ConsolePrintHelpers.PrintWhiteText("  Source File           :  ");

                        if (encoding.LSR.SuggestedAudioFile.FullPath == file.SourceFilePath)
                        {
                            ConsolePrintHelpers.PrintGreenText(file.SourceFilePath);
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText(file.SourceFilePath);
                        }

                        Console.WriteLine();
                        ConsolePrintHelpers.PrintWhiteText("  Encoded File          :  ");

                        if (encoding.LSR.OutputFilenameExtension == file.EncodedFileExtension)
                        {
                            ConsolePrintHelpers.PrintGreenText(file.EncodedFilePath);
                            Console.WriteLine();
                            ConsolePrintHelpers.PrintWhiteText("  Encoded File Ext      :  ");
                            ConsolePrintHelpers.PrintGreenText(file.EncodedFileExtension);
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText(file.EncodedFilePath);
                            Console.WriteLine();
                            ConsolePrintHelpers.PrintWhiteText("  Encoded File Ext      :  ");
                            ConsolePrintHelpers.PrintRedText(file.EncodedFileExtension);
                        }
                    }
                }
                else
                {
                    ConsolePrintHelpers.PrintCyanText("Encode");
                }

                Console.WriteLine("\n");
            }

            ConsolePrintHelpers.PressAnyKeyToContinue();
        }
Exemplo n.º 13
0
        private void FinishEncodingQueue()
        {
            ConsolePrintHelpers.PrintYellowText("\n\n\n  Optimizing Encoding Queue");
            ConsolePrintHelpers.PrintWhiteText(" ► ");

            bool cancelProgressTicker = false;

            Task ticker = Task.Run(() => ConsolePrintHelpers.PrintProgressTicker(ref cancelProgressTicker));

            _TempEncodingOrCopyList = _TempEncodingOrCopyList.OrderBy(lsr => lsr.LoadSheetRowNumber).ToList();  //Ordered by load sheet row number (1 -> n)

            _TempSkippedList = _TempSkippedList.OrderBy(lsr => lsr.LoadSheetRowNumber).ToList();                //Ordered by load sheet row number (1 -> n)

            if (!Globals.IsDevelopmentEnvironment)
            {
                List <AODLoadSheetRow> encodingList       = new List <AODLoadSheetRow>();
                List <AODLoadSheetRow> uniqueEncodingList = new List <AODLoadSheetRow>();
                List <AODLoadSheetRow> copyFromAlreadyEncodedFilesList = new List <AODLoadSheetRow>();
                List <AODLoadSheetRow> copyFromPendingEncodedFilesList = new List <AODLoadSheetRow>();

                _TempEncodingOrCopyList = _TempEncodingOrCopyList.OrderByDescending(lsr => lsr.SuggestedAudioFile.FileSize).ToList();  //Order by largest -> smallest source files (speeds up parallel encoding)

                foreach (AODLoadSheetRow lsr in _TempEncodingOrCopyList)
                {
                    AlreadyEncodedFile file = _Controller.History.GetAlreadyEncodedFile(lsr);

                    if (file == null)
                    {
                        encodingList.Add(lsr);  //Files that need to be encoded (and some that could be copied, we'll check in the next step)  (ordered by DESCENDING source file size)
                    }
                    else
                    {
                        copyFromAlreadyEncodedFilesList.Add(lsr);  //Files that are strictly able to be copied (not waiting on any encodes to finish)  (ordered by DESCENDING source file size)
                    }
                }

                foreach (AODLoadSheetRow lsr in encodingList)
                {
                    if (!uniqueEncodingList.Any(uniqueLSREncoding => lsr.IsLSREncodingEligibleForCopying(uniqueLSREncoding.PotentialFile)))
                    {
                        uniqueEncodingList.Add(lsr);  //Files that absolutely have to be encoded from scratch (ordered by DESCENDING source file size)
                    }
                    else
                    {
                        copyFromPendingEncodedFilesList.Add(lsr);  //Any additional files added here can be copied once the uniquely encoded list above creates those encoded files  (ordered by DESCENDING source file size)
                    }
                }

                int encodingID = 1;

                foreach (AODLoadSheetRow lsr in uniqueEncodingList)
                {
                    _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, false));  //Files that NEED to be encoded, added first (ordered by DESCENDING source file size)
                    encodingID++;
                }

                foreach (AODLoadSheetRow lsr in copyFromAlreadyEncodedFilesList)
                {
                    _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, true));  //Files that can be copied from already encoded files added next (The are not waiting on any prior encodes to finish) (ordered by DESCENDING source file size)
                    encodingID++;
                }

                foreach (AODLoadSheetRow lsr in copyFromPendingEncodedFilesList)
                {
                    _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, true));  //Files that can be copied from pending encodes once they complete  (ordered by DESCENDING source file size)
                    encodingID++;
                }
            }
            else  //Keep original load sheet row number ordering for better debugging in Development Environment
            {
                int encodingID = 1;

                foreach (AODLoadSheetRow lsr in _TempEncodingOrCopyList)
                {
                    _EncodingQueue.Enqueue(new AudioFileEncoding(lsr, encodingID, false));  //Ordered by load sheet row number (1 -> n)
                    encodingID++;
                }
            }

            foreach (AODLoadSheetRow skippedLSR in _TempSkippedList)
            {
                _SkippedQueue.Enqueue(skippedLSR);  //Ordered by load sheet row number (1 -> n)
            }

            //Temporary lists no longer needed
            _TempEncodingOrCopyList = null;
            _TempSkippedList        = null;
            GC.Collect();

            cancelProgressTicker = true;

            ticker.Wait();

            ConsolePrintHelpers.PrintYellowText("Done");

            ConsolePrintHelpers.Wait();
        }