コード例 #1
0
        private bool ReCheckSourceFileIsValid()
        {
            if (!LongPath.CheckIfFileExists(_SourceFilePath))  //OK to be >= Globals.MaxPathLength (Robocopy moves them to transcode temp directory and makes them < Globals.MaxPathLength)
            {
                return(false);
            }

            if (_SourceFilePath.Length < Globals.MaxPathLenth)
            {
                try
                {
                    FileInfo sourceFileInfo = new FileInfo(_SourceFilePath);

                    if (!sourceFileInfo.Exists)
                    {
                        return(false);
                    }

                    if (_SourceFileModifiedDate != sourceFileInfo.LastWriteTime.ToString())
                    {
                        return(false);
                    }

                    if (_SourceFileSize != sourceFileInfo.Length)
                    {
                        return(false);
                    }

                    if (_SourceFileSize == 0)
                    {
                        return(false);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        private void EncodeAudioFile()
        {
            if (Globals.IsDevelopmentEnvironment)
            {
                Thread.Sleep(Globals.SimulatedEncodingTimeMilliseconds);
                FinishCopyOrEncoding(Globals.Encoded);   //Skip actual encoding if in development environment
                return;
            }

            DeleteTranscodeTempDirectoryThisEncoding();           //If already exists, delete the transcode temp directory for this encoding

            if (LongPath.CheckIfFileExists(_LSR.DestinationPath)) //Encoded File already exists at our DestinationPath
            {
                FinishCopyOrEncoding("Failed:  File Already Exists At The Encoded File Path");
                return;
            }

            string tempSourceFilePath = _TranscodeTempDirectoryThisEncoding + "\\" + Guid.NewGuid().ToString() + Path.GetExtension(_LSR.SuggestedAudioFile.FullPath);

            if (tempSourceFilePath.Length >= Globals.MaxPathLenth)
            {
                FinishCopyOrEncoding("Failed:  Transcode Temp Source Path Too Long (" + tempSourceFilePath.Length + " chars)");
                return;
            }

            Directory.CreateDirectory(_TranscodeTempDirectoryThisEncoding);  //Create transcode temp directory for this encoding

            if (!Directory.Exists(_TranscodeTempDirectoryThisEncoding))
            {
                FinishCopyOrEncoding("Failed:  Unable To Create Transcode Temp Directory");
                return;
            }

            if (_LSR.DestinationPath.Length >= Globals.MaxPathLenth)
            {
                FinishCopyOrEncoding("Failed:  Destination File Path Too Long (" + _LSR.DestinationPath.Length + " chars)");
                return;
            }

            Directory.CreateDirectory(Path.GetDirectoryName(_LSR.DestinationPath));  //If Destination directory path does not exist, create it

            if (!Directory.Exists(Path.GetDirectoryName(_LSR.DestinationPath)))
            {
                FinishCopyOrEncoding("Failed:  Unable To Create Destination Directory");
                return;
            }

            if (!LongPath.CheckIfFileExists(_LSR.SuggestedAudioFile.FullPath))  //Could be >= Globals.MaxPathLength
            {
                FinishCopyOrEncoding("Failed:  Missing Source File In Audio Library");
                return;
            }

            RobocopySourceFileToTranscodeTempDirectory(tempSourceFilePath); //Copy source file to transcode temp directory for this encoding

            if (!File.Exists(tempSourceFilePath))                           //should not be >= Globals.MaxPathLength
            {
                FinishCopyOrEncoding("Failed:  Unable To Copy/Rename Source File To Transcode Temp Directory");
                return;
            }

            int psExitCode = RunPowerShellScript(tempSourceFilePath);    //Run Andy's PowerShell Script to encode audio file

            if (psExitCode != 0)
            {
                FinishCopyOrEncoding("Failed:  PowerShell Script Returned Exit Code != 0");
                return;
            }

            string psOutputFilePath = _TranscodeTempDirectoryThisEncoding + "\\" + "outputfile" + _LSR.OutputFilenameExtension;

            if (psOutputFilePath.Length >= Globals.MaxPathLenth)
            {
                FinishCopyOrEncoding("Failed:  Transcode Temp PS Output File Path Too Long (" + psOutputFilePath.Length + " chars)");
                return;
            }

            if (!File.Exists(psOutputFilePath))  //should not be >= Globals.MaxPathLength
            {
                FinishCopyOrEncoding("Failed:  PowerShell Script Did Not Leave Output File In Transcode Temp Directory (Source File Might Be Corrupt)");
                return;
            }

            long psOutputFileSize = new FileInfo(psOutputFilePath).Length;

            if (psOutputFileSize <= 0)
            {
                FinishCopyOrEncoding("Failed:  PowerShell Script Output File Is 0 Bytes");
                return;
            }

            if (LongPath.CheckIfFileExists(_LSR.DestinationPath))  //Encoded File already exists at our DestinationPath (Check one last time before we start a copy in case another encode/copy began creating a file here)
            {
                FinishCopyOrEncoding("Failed:  File Already Exists At The Encoded File Path");
                return;
            }

            bool isSuccessful = MovePSOutputFileToDestinationPath(psOutputFilePath); //Copy PS Output File to Destination Path

            if (!File.Exists(_LSR.DestinationPath))                                  //should not be >= Globals.MaxPathLength
            {
                FinishCopyOrEncoding("Failed:  Missing Destination File");
                return;
            }

            if (!isSuccessful)
            {
                FinishCopyOrEncoding("Failed:  File Already Exists At The Encoded File Path");
                return;
            }

            FinishCopyOrEncoding(Globals.Encoded);   //All tests passed, file should be encoded correctly
            return;
        }
コード例 #3
0
        private bool CopyAudioFile()
        {
            if (Globals.IsDevelopmentEnvironment)
            {
                Thread.Sleep(Globals.SimulatedEncodingTimeMilliseconds);
                return(true);  //Skip actual copying if in development environment
            }

            DeleteTranscodeTempDirectoryThisEncoding();           //If already exists, delete the transcode temp directory for this encoding

            if (LongPath.CheckIfFileExists(_LSR.DestinationPath)) //Encoded File already exists at our DestinationPath
            {
                return(false);
            }

            if (_FileToCopy == null)  //Was not able to find a suitable already encoded file to copy?
            {
                return(false);
            }

            if (!_FileToCopy.ReCheckIfValid())  //Verify one last time that it is valid (and hasn't been overwritten by another encode?)
            {
                return(false);
            }

            if (_FileToCopy.EncodedFilePath.Length >= Globals.MaxPathLenth)  //EncodedFilePath is too long
            {
                return(false);
            }

            string tempSourceFilePath = _TranscodeTempDirectoryThisEncoding + "\\" + Path.GetFileName(_FileToCopy.EncodedFilePath);

            if (tempSourceFilePath.Length >= Globals.MaxPathLenth)
            {
                return(false);
            }

            Directory.CreateDirectory(_TranscodeTempDirectoryThisEncoding);  //Create transcode temp directory for this encoding

            if (!Directory.Exists(_TranscodeTempDirectoryThisEncoding))
            {
                return(false);
            }

            if (_LSR.DestinationPath.Length >= Globals.MaxPathLenth)  //Destination Path too long
            {
                return(false);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(_LSR.DestinationPath));  //If Destination directory path does not exist, create it

            if (!Directory.Exists(Path.GetDirectoryName(_LSR.DestinationPath)))
            {
                return(false);
            }

            if (LongPath.CheckIfFileExists(_LSR.DestinationPath))  //Encoded File already exists at our DestinationPath (Check one last time before we start a copy in case another encode/copy began creating a file here)
            {
                return(false);
            }

            bool isSuccessful = RobocopyAlreadyEncodedFile();        //Copy already encoded file and rename to our DestinationPath for this loadsheet row

            if (!File.Exists(_LSR.DestinationPath) || !isSuccessful) //should not be >= Globals.MaxPathLength
            {
                return(false);
            }

            FileInfo copiedFileInfo = new FileInfo(_LSR.DestinationPath);

            string copiedFileModifiedDate = copiedFileInfo.LastWriteTime.ToString();

            if (copiedFileModifiedDate != _FileToCopy.EncodedFileModifiedDate)
            {
                return(false);
            }

            long copiedFileSize = copiedFileInfo.Length;

            if (copiedFileSize != _FileToCopy.EncodedFileSize)
            {
                return(false);
            }

            return(true);
        }