Пример #1
0
        /// <summary>
        /// Compares the files provided in the data and add to an internal result.
        /// </summary>
        /// <param name="data">The data for this entry.</param>
        public void CompareAndAddToResult(CompareData data)
        {
            string onclick = "";
            string clss    = "green";
            int    changes = 0;

            if (data.ExitCode != 0)
            {
                changes = -1;
                clss    = "red";
                lock (this)
                {
                    BuilderDiff.WriteLine(String.Format(@"<div style=""display:none;"" id=""{0}"">CCExtractor quit with exit code {1}</div>", "entry_" + Count, data.ExitCode));
                    BuilderDiff.Flush();
                }
                onclick = String.Format(@"onclick=""toggle('{0}'); mark(this);""", "entry_" + Count);
            }
            else
            {
                SideBySideModel sbsm = null;
                if (!Hasher.filesAreEqual(data.CorrectFile, data.ProducedFile))
                {
                    string oldText = "ERROR - COULD NOT LOAD";
                    string newText = "ERROR - COULD NOT LOAD";
                    if (data.ProducedFile.EndsWith(".bin"))
                    {
                        if (File.Exists(data.CorrectFile))
                        {
                            using (FileStream fs = new FileStream(data.CorrectFile, FileMode.Open, FileAccess.Read))
                            {
                                StringBuilder sb = new StringBuilder();
                                int           hexIn, counter = 1;
                                while ((hexIn = fs.ReadByte()) != -1)
                                {
                                    sb.AppendFormat("{0:X2} ", hexIn);
                                    if (counter % 17 == 0)
                                    {
                                        sb.AppendLine();
                                        counter = 0;
                                    }
                                    counter++;
                                }
                                oldText = sb.ToString();
                            }
                        }
                        if (File.Exists(data.ProducedFile))
                        {
                            using (FileStream fs = new FileStream(data.ProducedFile, FileMode.Open, FileAccess.Read))
                            {
                                StringBuilder sb = new StringBuilder();
                                int           hexIn, counter = 1;
                                while ((hexIn = fs.ReadByte()) != -1)
                                {
                                    sb.AppendFormat("{0:X2} ", hexIn);
                                    if (counter % 17 == 0)
                                    {
                                        sb.AppendLine();
                                        counter = 0;
                                    }
                                    counter++;
                                }
                                newText = sb.ToString();
                            }
                        }
                    }
                    else
                    {
                        if (File.Exists(data.CorrectFile))
                        {
                            using (FileStream fs = new FileStream(data.CorrectFile, FileMode.Open, FileAccess.Read))
                            {
                                using (StreamReader streamReader = new StreamReader(fs, Encoding.UTF8))
                                {
                                    oldText = streamReader.ReadToEnd();
                                }
                            }
                        }
                        if (File.Exists(data.ProducedFile))
                        {
                            using (FileStream fs = new FileStream(data.ProducedFile, FileMode.Open, FileAccess.Read))
                            {
                                using (StreamReader streamReader = new StreamReader(fs, Encoding.UTF8))
                                {
                                    newText = streamReader.ReadToEnd();
                                }
                            }
                        }
                    }

                    sbsm    = Differ.BuildDiffModel(oldText, newText);
                    changes = sbsm.GetNumberOfChanges();
                    if ((oldText == "ERROR - COULD NOT LOAD" || newText == "ERROR - COULD NOT LOAD") && !data.Dummy)
                    {
                        changes = -1;
                    }
                }
                if (changes != 0)
                {
                    lock (this)
                    {
                        BuilderDiff.WriteLine(sbsm.GetDiffHTML(String.Format(@"style=""display:none;"" id=""{0}""", "entry_" + Count), Reduce));
                        BuilderDiff.Flush();
                    }
                    onclick = String.Format(@"onclick=""toggle('{0}'); mark(this);""", "entry_" + Count);
                    clss    = "red";
                }
                else
                {
                    Successes++;
                }
            }
            Builder.AppendFormat(
                @"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td class=""{4}"" {5}>{6}</td></tr>",
                data.SampleFile,
                data.Command,
                data.RunTime.ToString(),
                data.ProducedFile,
                clss,
                onclick,
                changes);
            Count++;
        }