Exemplo n.º 1
0
        /// <summary>
        /// Fully Parse an MXF file
        /// </summary>
        protected void ParseFull(BackgroundWorker worker)
        {
            Stopwatch sw = Stopwatch.StartNew();

            MXFKLVFactory klvFactory = new MXFKLVFactory();

            MXFPartition currentPartition   = null;
            int          previousPercentage = 0;
            Dictionary <UInt16, MXFEntryPrimer> allPrimerKeys = null;

            //int[] counters = new int[Enum.GetNames(typeof(KeyType)).Length];
            using (m_reader = new MXFReader(this.Filename))
            {
                this.Filesize = m_reader.Size;
                MXFObject partitions = new MXFNamedObject("Partitions", 0);
                this.AddChild(partitions);

                int partitionNumber = 0; // For easy partition identification
                while (!m_reader.EOF)
                {
                    try
                    {
                        MXFKLV klv = klvFactory.CreateObject(m_reader, currentPartition);

                        //// Update overall counters
                        //if (klv.Key.Type == KeyType.None)
                        //    counters[(int)klv.Key.Type]++;

                        // Process the new KLV
                        ProcessKLVObject(klv, partitions, ref currentPartition, ref partitionNumber, ref allPrimerKeys);

                        // Next KLV please
                        m_reader.Seek(klv.DataOffset + klv.Length);
                    }
                    catch (Exception e)
                    {
                        m_reader.SeekForNextPotentialKey();
                    }



                    // Only report progress when the percentage has changed
                    int currentPercentage = (int)((m_reader.Position * 90) / m_reader.Size);
                    if (currentPercentage != previousPercentage)
                    {
                        worker.ReportProgress(currentPercentage, "Parsing MXF file");
                        previousPercentage = currentPercentage;
                    }
                }
            }

            Debug.WriteLine("Finished parsing file '{0}' in {1} ms", this.Filename, sw.ElapsedMilliseconds);

            // Progress should now be 90%

            DoPostWork(worker, sw, allPrimerKeys);

            // And Execute ALL test
            sw.Restart();
            this.ExecuteValidationTest(worker, true);
            Debug.WriteLine("Tests executed in {0} ms", sw.ElapsedMilliseconds);

            // Finished
            worker.ReportProgress(100, "Finished");
        }