public void GetChangeReport_NoChanges_PerformanceTest()
        {
            using (TempFile working = new TempFile(_originalLift))
            {
                int howManyEntries = 10000;
                Debug.WriteLine("running test using " + howManyEntries.ToString() + " entries");
                using (XmlWriter w = XmlWriter.Create(working.Path))
                {
                    w.WriteStartElement("lift");
                    for (int i = 0; i < howManyEntries; i++)
                    {
                        w.WriteStartElement("entry");
                        w.WriteAttributeString("id", i.ToString());
                        w.WriteElementString("lexical-unit", "<form lang='x'><text>"
                                             + Path.GetRandomFileName()
                                             //just a way to get some random text
                                             + "</text></form>");
                        w.WriteElementString("gloss", "<form lang='y'><text>"
                                             + Path.GetRandomFileName()          //just a way to get some random text
                                             + "</text></form>");
                        w.WriteEndElement();
                    }
                    w.WriteEndElement();
                }
                using (TempFolder cache = new TempFolder("LiftChangeDetectorTestsCache"))
                {
                    LiftChangeDetector detector = new LiftChangeDetector(working.Path, cache.Path);

                    System.Diagnostics.Stopwatch timer = new Stopwatch();
                    timer.Start();
                    detector.Reset();
                    timer.Stop();
                    Debug.WriteLine("reset took " + timer.Elapsed.TotalSeconds + " seconds");

                    timer.Reset();
                    timer.Start();
                    ILiftChangeReport report = detector.GetChangeReport(null);
                    timer.Stop();
                    Debug.WriteLine("getting report took " + timer.Elapsed.TotalSeconds + " seconds");

                    timer.Reset();
                    timer.Start();
                    for (int i = 0; i < howManyEntries; i++)
                    {
                        report.GetChangeType(i.ToString());
                    }
                    timer.Stop();
                    Debug.WriteLine("Time to inquire about each entry " + timer.Elapsed.TotalSeconds + " seconds");
                }
            }
        }
 public void GetChangeReport_AfterChange_Reasonable()
 {
     using (TempFile working = new TempFile(_originalLift))
     {
         using (TempFolder cache = new TempFolder("LiftChangeDetectorTestsCache"))
         {
             LiftChangeDetector detector = new LiftChangeDetector(working.Path, cache.Path);
             detector.Reset();
             File.WriteAllText(working.Path, _modifiedLift);
             ILiftChangeReport report = detector.GetChangeReport(new NullProgress());
             Assert.AreEqual(LiftChangeReport.ChangeType.Editted, report.GetChangeType("one"));
             Assert.AreEqual(LiftChangeReport.ChangeType.Deleted, report.GetChangeType("two"));
             Assert.AreEqual(1, report.IdsOfDeletedEntries.Count);
         }
     }
 }
Example #3
0
        //private static bool NodeContentIsJustAString(XmlNode node)
        //{
        //    return node.InnerText != null
        //                        && (node.ChildNodes.Count == 1)
        //                        && (node.ChildNodes[0].NodeType == XmlNodeType.Text)
        //                        && node.InnerText.Trim() != string.Empty;
        //}

//        public LexExampleSentence ReadExample(XmlNode xmlNode)
//        {
//            LexExampleSentence example = new LexExampleSentence();
//            LocateAndReadMultiText(xmlNode, "source", example.Sentence);
//            //NB: will only read in one translation
//            LocateAndReadMultiText(xmlNode, "trans", example.Translation);
//            return example;
//        }
//

        /// <summary>
        /// Read a LIFT file. Must be the current lift version.
        /// </summary>
        public int ReadLiftFile(string pathToLift)
        {
            _pathToLift = pathToLift;                   // may need this to find its ranges file.
            if (_defaultCreationModificationUTC == default(DateTime))
            {
                _defaultCreationModificationUTC = File.GetLastWriteTimeUtc(pathToLift);
            }

            ProgressTotalSteps     = GetEstimatedNumberOfEntriesInFile(pathToLift);
            ProgressStepsCompleted = 0;

            if (Validator.GetLiftVersion(pathToLift) != Validator.LiftVersion)
            {
                throw new LiftFormatException("Programmer should migrate the lift file before calling this method.");
            }

            int numberOfEntriesRead = 0;

            if (_changeDetector != null && _changeDetector.CanProvideChangeRecord)
            {
                ProgressMessage = "Detecting Changes To Lift File...";
                _changeReport   = _changeDetector.GetChangeReport(new NullProgress());
            }

            using (XmlReader reader = XmlReader.Create(pathToLift, NormalReaderSettings))
            {
                reader.ReadStartElement("lift");
                ReadHeader(reader);
                numberOfEntriesRead = ReadEntries(reader);
            }
            if (_changeReport != null && _changeReport.IdsOfDeletedEntries.Count > 0)
            {
                ProgressMessage = "Removing entries that were removed from the Lift file...";
                foreach (string id in _changeReport.IdsOfDeletedEntries)
                {
                    Extensible eInfo = new Extensible();
                    eInfo.Id = id;
                    _merger.EntryWasDeleted(eInfo, default(DateTime) /* we don't know... why is this part of the interface, anyhow? */);
                }
            }
            return(numberOfEntriesRead);
        }