Example #1
0
        /// <summary>
        /// This parses the MOI files and populates ParsedMOIFiles and ParseExceptions.
        /// </summary>
        /// <returns>If there were no parsing errors</returns>
        public bool Parse()
        {
            parsedMoiFiles = new List<MOIFile>();
            parseErrors = new List<MOIParserError>();

            //Parse each path to create an MOIFile or ParserError
            foreach (string moiFilePath in moiFilePaths)
            {
                try
                {
                    byte[] moiFileData = File.ReadAllBytes(moiFilePath);
                    MOIFileParser fileParser = new MOIFileParser(moiFileData);

                    if (fileParser.Parse())
                    {
                        fileParser.MOIFile.FileName = Path.GetFileName(moiFilePath);
                        parsedMoiFiles.Add(fileParser.MOIFile);
                    }
                    else
                    {
                        fileParser.ParseError.FilePath = moiFilePath;
                        parseErrors.Add(fileParser.ParseError);
                    }
                }
                catch (Exception e) //if an unexpected error occured, create a ParserError for it.
                {
                    MOIParserError parseError = new MOIParserError(e);
                    parseError.FilePath = moiFilePath;
                    parseErrors.Add(parseError);
                }
            }

            return parseErrors.Count == 0;
        }
Example #2
0
        /// <summary>
        /// Sets the CreationDate field on the moiFile.
        /// </summary>
        /// <returns>If setting the video length was successful.</returns>
        /// <remarks>This handles the possible errors resulting from the instantiation of a DateTime.</remarks>
        private bool SetCreationDate(ushort year, byte month, byte day, byte hour, byte minute)
        {
            try
            {
                moiFile.CreationDate = new DateTime(year, month, day, hour, minute, 0);
            }
            catch (ArgumentException)
            {
                string errorMessage = String.Format("Could not parse the creation date. {2}\\{1}\\{0} {3}:{4} is not a valid date and time.",
                    year, month, day, hour, minute);
                ParseError = new MOIParserError("CreationDate", errorMessage);
                return false;
            }

            return true;
        }
Example #3
0
        /// <summary>
        /// Sets the VideoLength field on the moiFile.
        /// </summary>
        /// <param name="videoLengthMs">video length in milliseconds.</param>
        /// <returns>If setting the video length was successful.</returns>
        /// <remarks>This handles the possible errors resulting from the instantiation of a TimeSpan.</remarks>
        private bool SetVideoLength(uint videoLengthMs)
        {
            try
            {
                moiFile.VideoLength = TimeSpan.FromMilliseconds(videoLengthMs);
            }
            catch (SystemException e)
            {
                //Handle the docuemented possible exceptions.
                if (e is ArgumentException || e is OverflowException)
                {
                    string errorMessage = String.Format("Could not parse the video length. {0} could not be converted to a length of time.",
                        videoLengthMs);
                    ParseError = new MOIParserError("VideoLength", errorMessage);
                    return false;
                }
                else //Unexpected exception
                {
                    throw;
                }
            }

            return true;
        }
Example #4
0
        /// <summary>
        /// Parses the file data into an MOIFile object which is stored in the MOIFile property.
        /// </summary>
        /// <returns>If parsing passed</returns>
        public bool Parse()
        {
            try
            {
                //Pull data out from the byte array into variables
                string version = GetString(VERSION_POS, 2);
                uint moiFileSize = GetUInt32(FILE_SIZE_POS);
                ushort year = GetUInt16(YEAR_POS);
                byte month = GetByte(MONTH_POS);
                byte day = GetByte(DAY_POS);
                byte hour = GetByte(HOUR_POS);
                byte minute = GetByte(MIN_POS);
                uint videoLengthMs = GetUInt32(VIDEO_LENGTH_POS);
                byte videoFmt = GetByte(VIDEO_FMT_POS);

                //Create a MOI file object to store the parsed values.
                moiFile = new MOIFile { Version = version, FileSize = moiFileSize };

                if (!SetCreationDate(year, month, day, hour, minute))
                    return false;

                if (!SetVideoLength(videoLengthMs))
                    return false;

                moiFile.AspectRatio = ParseAspectRatio(videoFmt);
                moiFile.TVSystem = ParseTVSystem(videoFmt);

                return true;
            }
            catch (Exception e)
            {
                ParseError = new MOIParserError(e);
            }

            return false;
        }