Exemplo n.º 1
0
        /// <summary>
        /// Given that the element has been changed to represent the desired new state of some DTO,
        /// save the change. This overload finds the DTO from the guid attribute on the element.
        /// </summary>
        private void UpdateDto(IDomainObjectDTORepository domainObjectDtoRepository, XElement element)
        {
            DomainObjectDTO dto = domainObjectDtoRepository.GetDTO(element.Attribute("guid").Value);

            dto.Xml = element.ToString();
            domainObjectDtoRepository.Update(dto);
        }
Exemplo n.º 2
0
        private void AddToClassList(DomainObjectDTO dto)
        {
            var    className = dto.Classname;
            string superclassName;

            if (!m_classAndSuperClass.TryGetValue(className, out superclassName))
            {
                // Can't determine old superclass, without going through the DTO's xml.
                m_classAndSuperClass.Add(className, null);
                // Discovering old direct subclasses may not be possible.
                m_classesAndTheirDirectSubclasses.Add(className, new HashSet <string>());
            }
            if (superclassName == null)
            {
                // Unknown class, so must be obsolete.
                m_oldTimers.Add(dto);
            }
            HashSet <DomainObjectDTO> instances;

            if (!m_dtosByClass.TryGetValue(className, out instances))
            {
                instances = new HashSet <DomainObjectDTO>();
                m_dtosByClass.Add(className, instances);
            }
            instances.Add(dto);
        }
Exemplo n.º 3
0
        private void CheckEventSubTypes(IDomainObjectDTORepository repoDTO)
        {
            DomainObjectDTO dtoObs = GetDTOIfItExists(repoDTO, ksguidObservation);

            if (dtoObs != null)
            {
                VerifyOwner(repoDTO, dtoObs, ksguidEvent);
            }
            DomainObjectDTO dtoCon = GetDTOIfItExists(repoDTO, ksguidConversation);

            if (dtoCon != null)
            {
                VerifyOwner(repoDTO, dtoCon, ksguidEvent);
            }
            DomainObjectDTO dtoInt = GetDTOIfItExists(repoDTO, ksguidInterview);

            if (dtoInt != null)
            {
                VerifyOwner(repoDTO, dtoInt, ksguidEvent);
            }
            DomainObjectDTO dtoPer = GetDTOIfItExists(repoDTO, ksguidPerformance);

            if (dtoPer != null)
            {
                VerifyOwner(repoDTO, dtoPer, ksguidEvent);
            }
        }
Exemplo n.º 4
0
        private void RemoveInvalidFiles(IDomainObjectDTORepository repoDto,
                                        DomainObjectDTO langProj, DomainObjectDTO folder)
        {
            var langProjElement = XElement.Parse(langProj.Xml);
            var pictures        = langProjElement.Element("Pictures");
            var fileMap         = CreateFilePathToGuidMap(repoDto, folder);
            var pictureMap      = CreateFileGuidToPictureMap(repoDto);

            foreach (var x in pictures.Elements())
            {
                var xObj = repoDto.GetDTO(x.Attribute("guid").Value);
                if (xObj.Classname == "CmFile")
                {
                    string replacementFileGuid;
                    string filePath = GetFilePath(xObj);
                    if (filePath != null &&
                        fileMap.TryGetValue(filePath.ToLowerInvariant(), out replacementFileGuid))
                    {
                        UpdatePictureReferences(repoDto, xObj, replacementFileGuid, pictureMap);
                        DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, xObj, true);
                    }
                    else if (!pictureMap.ContainsKey(xObj.Guid))
                    {
                        DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, xObj, true);
                    }
                    else
                    {
                        MoveFileToFolder(repoDto, folder, xObj);
                        RemoveReferenceFromPictures(repoDto, langProj, xObj.Guid);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a CmPossibility with all the basic properties filled in for the xml (necessary for S/R) and adds it to the dto
        /// </summary>
        public static DomainObjectDTO CreatePossibility(IDomainObjectDTORepository repoDto, string listGuid, string possibilityGuid, string name,
                                                        string abbr, DateTime createTime, string className = "CmPossibility")
        {
            var sb = new StringBuilder();

            sb.AppendFormat("<rt class=\"{0}\" guid=\"{1}\" ownerguid=\"{2}\">", className, possibilityGuid, listGuid);
            sb.Append("<Abbreviation>");
            sb.AppendFormat("<AUni ws=\"en\">{0}</AUni>", abbr);
            sb.Append("</Abbreviation>");
            sb.Append(string.Format("<DateCreated val=\"{0:yyyy-MM-dd HH:mm:ss.fff}\" />", createTime));
            sb.Append(string.Format("<DateModified val=\"{0:yyyy-MM-dd HH:mm:ss.fff}\" />", createTime));
            sb.Append("<BackColor val=\"-1073741824\" />");
            sb.Append("<ForeColor val=\"-1073741824\" />");
            sb.Append("<IsProtected val=\"True\" />");
            sb.Append("<Hidden val=\"False\" />");
            sb.Append("<Name>");
            sb.AppendFormat("<AUni ws=\"en\">{0}</AUni>", name);
            sb.Append("</Name>");
            sb.Append("<SortSpec val=\"-1073741824\" />");
            sb.Append("<UnderColor val=\"-1073741824\" />");
            sb.Append("<UnderStyle val=\"-1073741824\" />");
            sb.Append("</rt>");
            var dtoCmPossibility = new DomainObjectDTO(possibilityGuid, className, sb.ToString());

            repoDto.Add(dtoCmPossibility);
            return(dtoCmPossibility);
        }
Exemplo n.º 6
0
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000050);

            var          newGuidValue = Guid.NewGuid().ToString().ToLowerInvariant();
            const string className    = "LangProject";
            var          lpDto        = domainObjectDtoRepository.AllInstancesSansSubclasses(className).First();
            var          ownedDtos    = domainObjectDtoRepository.GetDirectlyOwnedDTOs(lpDto.Guid).ToList();
            var          data         = lpDto.Xml;

            domainObjectDtoRepository.Remove(lpDto);             // It is pretty hard to change an immutable Guid identifier in BEP-land, so nuke it, and make a new one.

            var lpElement = XElement.Parse(data);

            lpElement.Attribute("guid").Value = newGuidValue;
            var newLpDto = new DomainObjectDTO(newGuidValue, className, lpElement.ToString());

            domainObjectDtoRepository.Add(newLpDto);

            // Change ownerguid attr for each owned item to new guid.
            foreach (var ownedDto in ownedDtos)
            {
                var ownedElement = XElement.Parse(ownedDto.Xml);
                ownedElement.Attribute("ownerguid").Value = newGuidValue;
                ownedDto.Xml = ownedElement.ToString();
                domainObjectDtoRepository.Update(ownedDto);
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Exemplo n.º 7
0
        private string GetCmFilePath(DomainObjectDTO fileDto)
        {
            XElement cmFileXML          = XElement.Parse(fileDto.Xml);
            var      filePathMoreDirect = cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value;

            return(filePathMoreDirect);
        }
Exemplo n.º 8
0
        private static void CheckPhPhonData(DomainObjectDTO dtoPhPhonDataTest, IDomainObjectDTORepository dtoRepos)
        {
            var eltWmbPhPhonDataTest = XElement.Parse(dtoPhPhonDataTest.Xml);
            // get phon rule feats
            var eltPhonRuleFeatsTest = eltWmbPhPhonDataTest.Element("PhonRuleFeats");

            Assert.IsNotNull(eltPhonRuleFeatsTest);
            var eltObjsurTest = eltPhonRuleFeatsTest.Element("objsur");

            Assert.IsNotNull(eltObjsurTest);
            // get possibility list itself
            var guidPossibilityListTest = eltObjsurTest.Attribute("guid").Value;

            Assert.IsNotNull(guidPossibilityListTest);
            DomainObjectDTO dtoCmPossiblityTest;

            dtoRepos.TryGetValue(guidPossibilityListTest, out dtoCmPossiblityTest);
            Assert.IsNotNull(dtoCmPossiblityTest);
            var eltWmbCmPossibilityListTest = XElement.Parse(dtoCmPossiblityTest.Xml);

            Assert.IsNotNull(eltWmbCmPossibilityListTest);
            var attrCmPossiblityListClassTest = eltWmbCmPossibilityListTest.Attribute("class").Value;

            Assert.AreEqual("CmPossibilityList", attrCmPossiblityListClassTest);
            var attrCmPossiblityListOwnerGuidTest = eltWmbCmPossibilityListTest.Attribute("ownerguid").Value;

            Assert.AreEqual(dtoPhPhonDataTest.Guid, attrCmPossiblityListOwnerGuidTest);
        }
Exemplo n.º 9
0
        private string GetCmFileGuid(DomainObjectDTO fileDto)
        {
            XElement cmFileXML  = XElement.Parse(fileDto.Xml);
            var      cmFileGuid = cmFileXML.Attribute("guid").Value;

            return(cmFileGuid);
        }
Exemplo n.º 10
0
        public void DeleteWeatherListAndField()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000017.xml");

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository repoDTO = new DomainObjectDtoRepository(7000016, dtos, mockMdc, null,
                                                                               TestDirectoryFinder.LcmDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(repoDTO, 7000017, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000017, repoDTO.CurrentModelVersion, "Wrong updated version.");

            DomainObjectDTO dtoLP = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("LangProject"))
            {
                Assert.IsNull(dtoLP, "Only one LangProject object should exist");
                dtoLP = dto;
            }
            Assert.NotNull(dtoLP, "The LangProject object should exist");
            string sXml = dtoLP.Xml;

            Assert.IsFalse(sXml.Contains("<WeatherConditions>"), "The <WeatherConditions> element should have disappeared");
            string sLpOwnerGuid = GetGuidAsOwnerGuid(sXml);

            DomainObjectDTO dtoNbk = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("RnResearchNbk"))
            {
                Assert.IsNull(dtoNbk, "Only one RnResearchNbk should exist");
                Assert.IsTrue(dto.Xml.Contains(sLpOwnerGuid), "The RnResearchNbk should be owned by the LangProject");
                dtoNbk = dto;
            }
            Assert.NotNull(dtoNbk, "The RnResearchNbk should exist");
            string sNbkOwnerGuid = GetGuidAsOwnerGuid(dtoNbk.Xml);
            int    cList         = 0;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("CmPossibilityList"))
            {
                sXml = dto.Xml;
                Assert.IsTrue(sXml.Contains(sNbkOwnerGuid), "Possibility List must be owned by Data Notebook");
                ++cList;
            }
            Assert.AreEqual(1, cList, "Only one CmPossibilityList should exist");

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesWithSubclasses("RnGenericRec"))
            {
                Assert.IsFalse(dto.Xml.Contains("<Weather"), "Any <Weather> element should have disappeared");
                Assert.IsFalse(dto.Xml.Contains("<Custom name="), "No <Custom> element should have been created");
            }

            // This test file has three overlays; the first refers to a weather item and the weather possibility list,
            // and should be delted. The second refers to a non-weather possibility, and the third to a non-weather
            // possibility list; they should survive.
            Assert.That(repoDTO.AllInstancesSansSubclasses("CmOverlay"), Has.Count.EqualTo(2));
        }
Exemplo n.º 11
0
        public void DataMigration7000016Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000016.xml");

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository repoDTO = new DomainObjectDtoRepository(7000015, dtos, mockMdc, null,
                                                                               TestDirectoryFinder.LcmDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(repoDTO, 7000016, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000016, repoDTO.CurrentModelVersion, "Wrong updated version.");

            DomainObjectDTO nbkDto = null;

            foreach (DomainObjectDTO dot in repoDTO.AllInstancesSansSubclasses("RnResearchNbk"))
            {
                nbkDto = dot;
                break;
            }
            Assert.NotNull(nbkDto);
            XElement nbkElem      = XElement.Parse(nbkDto.Xml);
            var      recTypesGuid = (string)nbkElem.XPathSelectElement("RecTypes/objsur").Attribute("guid");

            Assert.AreEqual(recTypesGuid.ToLowerInvariant(), ksguidRecTypesList);

            // All we can guarantee being able to check are those items that we create, and to a
            // limited degree, those items that are moved to belong to a created item.
            bool fFoundEvent   = false;
            bool fFoundMethod  = false;
            bool fFoundWeather = false;

            foreach (DomainObjectDTO dto in repoDTO.GetDirectlyOwnedDTOs(ksguidRecTypesList))
            {
                string sguid = dto.Guid.ToLowerInvariant();
                Assert.AreNotEqual(sguid, ksguidObservation);
                Assert.AreNotEqual(sguid, ksguidConversation);
                Assert.AreNotEqual(sguid, ksguidInterview);
                Assert.AreNotEqual(sguid, ksguidPerformance);
                if (sguid == ksguidEvent)
                {
                    fFoundEvent = true;
                    CheckEventSubTypes(repoDTO);
                }
                else if (sguid == ksguidMethodology)
                {
                    fFoundMethod = true;
                }
                else if (sguid == ksguidWeather)
                {
                    fFoundWeather = true;
                }
            }
            Assert.IsTrue(fFoundEvent);
            Assert.IsTrue(fFoundMethod);
            Assert.IsTrue(fFoundWeather);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Add to weatherItems the guids of all the things owned directly or indirectly by dtoRoot.
 /// Does not include the root itself.
 /// </summary>
 private void CollectItems(IDomainObjectDTORepository repoDTO, DomainObjectDTO dtoRoot, HashSet <string> guidCollector)
 {
     foreach (var dto in repoDTO.GetDirectlyOwnedDTOs(dtoRoot.Guid))
     {
         guidCollector.Add(dto.Guid);
         CollectItems(repoDTO, dto, guidCollector);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// The weather list is used, so convert it to a custom (unowned) list, create a new
        /// custom field for RnGenericRec elements, and convert any Weather elements to that
        /// new custom field.
        /// </summary>
        private void ConvertWeatherToCustomListAndField(IDomainObjectDTORepository repoDTO)
        {
            // Change the Weather list to being unowned.
            DomainObjectDTO dtoLP = null;

            foreach (var dto in repoDTO.AllInstancesWithSubclasses("LangProject"))
            {
                dtoLP = dto;
                break;
            }
            string sWeatherListGuid = RemoveWeatherConditionsElement(dtoLP).ToLowerInvariant();

            repoDTO.Update(dtoLP);
            DomainObjectDTO dtoWeatherList = null;

            foreach (var dto in repoDTO.AllInstancesWithSubclasses("CmPossibilityList"))
            {
                if (dto.Guid.ToLowerInvariant() == sWeatherListGuid)
                {
                    dtoWeatherList = dto;
                    break;
                }
            }
            dtoWeatherList.Xml = RemoveOwnerGuid(dtoWeatherList.Xml);
            repoDTO.Update(dtoWeatherList);

            // Create the custom field.
            string fieldName = "Weather";

            while (repoDTO.IsFieldNameUsed("RnGenericRec", fieldName))
            {
                fieldName = fieldName + "A";
            }
            repoDTO.CreateCustomField("RnGenericRec", fieldName, CellarPropertyType.ReferenceCollection,
                                      CmPossibilityTags.kClassId, "originally a standard part of Data Notebook records",
                                      WritingSystemServices.kwsAnals, new Guid(sWeatherListGuid));

            string customStart = String.Format("<Custom name=\"{0}\">", fieldName);

            // Remove any empty Weather elements in the RnGenericRec objects, and convert
            // nonempty ones to custom elements.
            foreach (var dto in repoDTO.AllInstancesWithSubclasses("RnGenericRec"))
            {
                string sXml = dto.Xml;
                int    idx  = sXml.IndexOf("<Weather");
                if (idx > 0)
                {
                    string sXmlT = RemoveEmptyWeather(sXml, idx);
                    if (sXmlT == sXml)
                    {
                        sXmlT = sXml.Replace("<Weather>", customStart);
                        sXmlT = sXmlT.Replace("</Weather>", "</Custom>");
                    }
                    dto.Xml = sXmlT;
                    repoDTO.Update(dto);
                }
            }
        }
Exemplo n.º 14
0
        private void RemoveFromClassList(DomainObjectDTO obj, string oldClassName)
        {
            HashSet <DomainObjectDTO> instances;

            if (m_dtosByClass.TryGetValue(oldClassName, out instances))
            {
                instances.Remove(obj);
            }
        }
Exemplo n.º 15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Removes the specified field.
        /// </summary>
        /// <param name="dto">The domain transfer object that has a field that may need to be deleted.</param>
        /// <param name="objElement">Name of the object containing fieldToDelete.</param>
        /// <param name="fieldToDelete">The name of the field to delete.</param>
        /// ------------------------------------------------------------------------------------
        private void RemoveField(DomainObjectDTO dto, XElement objElement, string fieldToDelete)
        {
            XElement rmElement = objElement.Element(fieldToDelete);

            if (rmElement != null)
            {
                rmElement.Remove();
            }
        }
Exemplo n.º 16
0
 private void GatherDeadObjects(IDomainObjectDTORepository repoDTO, DomainObjectDTO dtoDead,
                                List <DomainObjectDTO> rgdtoDead)
 {
     rgdtoDead.Add(dtoDead);
     foreach (var dto in repoDTO.GetDirectlyOwnedDTOs(dtoDead.Guid))
     {
         GatherDeadObjects(repoDTO, dto, rgdtoDead);
     }
 }
Exemplo n.º 17
0
        internal static void CheckDtoRemoved(IDomainObjectDTORepository dtoRepos, DomainObjectDTO goner)
        {
            DomainObjectDTO dto;

            if (dtoRepos.TryGetValue(goner.Guid, out dto))
            {
                Assert.Fail("Still has deleted (or zombie) DTO.");
            }
            Assert.IsTrue(((DomainObjectDtoRepository)dtoRepos).Goners.Contains(goner));
        }
Exemplo n.º 18
0
        private void RemoveUnwantedOverlays(IDomainObjectDTORepository repoDTO, List <DomainObjectDTO> collectOverlaysToRemove)
        {
            DomainObjectDTO dtoLP = GetDtoLangProj(repoDTO);

            foreach (var dto in collectOverlaysToRemove)
            {
                RemoveOverlayElement(dtoLP, dto.Guid);
                repoDTO.Remove(dto);
            }
        }
Exemplo n.º 19
0
        public void DataMigration7000051Test()
        {
            var dtos = new HashSet <DomainObjectDTO>();
            var sb   = new StringBuilder();
            // Add Lang Project dto.
            const string sLpGuid    = "9719A466-2240-4DEA-9722-9FE0746A30A6";
            const string afxCatGuid = "60ab6c6c-43f3-4a7f-af61-96b4b77648a5";

            sb.AppendFormat("<rt class=\"LangProject\" guid=\"{0}\">", sLpGuid);
            sb.Append("<AffixCategories>");
            sb.AppendFormat("<objsur guid=\"{0}\" t=\"o\" />", afxCatGuid);
            sb.Append("</AffixCategories>");
            sb.Append("</rt>");
            var oldDto = new DomainObjectDTO(sLpGuid, "LangProject", sb.ToString());

            dtos.Add(oldDto);
            sb.Length = 0;

            sb.AppendFormat("<rt class=\"CmPossibilityList\" guid=\"{0}\"  ownerguid=\"{1}\" />", afxCatGuid, sLpGuid);
            var afxCatDto = new DomainObjectDTO(afxCatGuid, "CmPossibilityList", sb.ToString());

            dtos.Add(afxCatDto);

            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();

            mockMDC.AddClass(1, "CmObject", null, new List <string> {
                "LangProject", "CmPossibilityList"
            });                                                                                                         // Not true, but no matter.
            mockMDC.AddClass(2, "LangProject", "CmObject", new List <string>());
            mockMDC.AddClass(3, "CmPossibilityList", "CmObject", new List <string>());
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000050, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000051, new DummyProgressDlg());
            Assert.AreEqual(7000051, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // Check that the old LP is not present.
            DomainObjectDTO gonerDto;

            Assert.IsFalse(dtoRepos.TryGetValue(sLpGuid, out gonerDto));
            Assert.IsTrue(((DomainObjectDtoRepository)dtoRepos).Goners.Contains(oldDto));
            var newDto = dtoRepos.AllInstancesSansSubclasses("LangProject").FirstOrDefault();

            Assert.IsNotNull(newDto);
            Assert.AreNotSame(oldDto, newDto);
            var newDtoGuid = newDto.Guid.ToLowerInvariant();

            Assert.AreNotEqual(sLpGuid.ToLowerInvariant(), newDtoGuid);

            // Check that ownerguid was changed on afxCatDto.
            var afxCatElm = XElement.Parse(afxCatDto.Xml);

            Assert.AreEqual(newDtoGuid, afxCatElm.Attribute("ownerguid").Value.ToLowerInvariant());
        }
Exemplo n.º 20
0
        public void PerformMigration7000018()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000018.xml");

            var mockMdc = SetupMdc();

            IDomainObjectDTORepository repoDTO = new DomainObjectDtoRepository(7000017, dtos, mockMdc, null,
                                                                               TestDirectoryFinder.LcmDirectories);

            // SUT: Do the migration.
            m_dataMigrationManager.PerformMigration(repoDTO, 7000018, new DummyProgressDlg());

            // Verification Phase
            Assert.AreEqual(7000018, repoDTO.CurrentModelVersion, "Wrong updated version.");

            DomainObjectDTO dtoLP = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("LangProject"))
            {
                Assert.IsNull(dtoLP, "Only one Language Project object should exist");
                dtoLP = dto;
            }
            Assert.NotNull(dtoLP, "The Language Project object should exist");

            DomainObjectDTO dtoNtbk = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("RnResearchNbk"))
            {
                Assert.IsNull(dtoNtbk, "Only one Data Notebook object should exist");
                dtoNtbk = dto;
            }
            Assert.NotNull(dtoNtbk, "The Data Notebook object should exist");

            DomainObjectDTO dtoLexDb = null;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("LexDb"))
            {
                Assert.IsNull(dtoLexDb, "Only one Lexical Database object should exist");
                dtoLexDb = dto;
            }
            Assert.NotNull(dtoLexDb, "The Lexical Database object should exist");

            string sLexDbXml = dtoLexDb.Xml;

            Assert.False(sLexDbXml.Contains("<Styles>"), "The Styles field should be gone from the Lexical Database object");

            string sLpXml = dtoLP.Xml;

            Assert.True(sLpXml.Contains("<Styles>"), "The Styles field should still exist in the Language Project object");

            VerifyStylesRenamedOrDeleted(repoDTO);
            VerifyStyleReferencesUpdated(repoDTO);
            VerifyScriptureStylesUnchanged(repoDTO);
            VerifyNoDirectFormatting(repoDTO);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Does two components of changing the class of a DTO representation of the object:
        /// Fixes the class attribute, and fixes the Classname of the DTO.
        /// Caller should arrange to move it from one list to another, and fix the
        /// embedded elements (see e.g. ChangeToSubClass).
        /// </summary>
        /// <param name="target"></param>
        /// <param name="oldClass"></param>
        /// <param name="newClass"></param>
        private static void ChangeClass(DomainObjectDTO target, string oldClass, string newClass)
        {
            // If there's no unexpected white space we can do this efficiently.
            // This depends (like various other code) on NOT having unexpected white space around the '='.
            byte[] classBytes = Encoding.UTF8.GetBytes("class=\"" + oldClass + "\"");
            int    index      = target.XmlBytes.IndexOfSubArray(classBytes);

            byte[] newClassBytes = Encoding.UTF8.GetBytes("class=\"" + newClass + "\"");
            target.XmlBytes  = target.XmlBytes.ReplaceSubArray(index, classBytes.Length, newClassBytes);
            target.Classname = newClass;
        }
Exemplo n.º 22
0
        private string GetFilePath(DomainObjectDTO file)
        {
            var fileElement = XElement.Parse(file.Xml);
            var pathElement = fileElement.Element("InternalPath");

            if (pathElement != null)
            {
                pathElement = pathElement.Element("Uni");
            }
            return(pathElement != null ? pathElement.Value : null);
        }
Exemplo n.º 23
0
        public void DataMigration7000056Test()
        {
            var dtos = DataMigrationTestServices.ParseProjectFile("DataMigration7000056.xml");
            // Set up mock MDC.
            var mockMDC = new MockMDCForDataMigration();
            IDomainObjectDTORepository dtoRepos = new DomainObjectDtoRepository(7000055, dtos, mockMDC, null,
                                                                                TestDirectoryFinder.LcmDirectories);

            m_dataMigrationManager.PerformMigration(dtoRepos, 7000056, new DummyProgressDlg());
            Assert.AreEqual(7000056, dtoRepos.CurrentModelVersion, "Wrong updated version.");

            // check that PhPhonData has the PhonRuleFeats possibility list
            {
                var             dtosList          = dtoRepos.AllInstancesSansSubclasses("PhPhonData");
                DomainObjectDTO dtoPhPhonDataTest = dtosList.First();
                CheckPhPhonData(dtoPhPhonDataTest, dtoRepos);
            }

            // In the extremely unlikely event that there is no PhPhonData yet, check that we add it
            {
                dtos = new HashSet <DomainObjectDTO>();

                var sb = new StringBuilder();
                // Add WfiMorphBundle that already has a form.
                const string sGuid_wmbLangProj = "00b35f9f-86ce-4f07-bde7-b65c28503641";

                sb.AppendFormat("<rt class=\"LangProj\" guid=\"{0}\">", sGuid_wmbLangProj);
                sb.Append("</rt>");
                var dtoLangProj = new DomainObjectDTO(sGuid_wmbLangProj, "LangProj", sb.ToString());
                dtos.Add(dtoLangProj);
                sb.Length = 0;

                mockMDC  = new MockMDCForDataMigration();
                dtoRepos = new DomainObjectDtoRepository(7000055, dtos, mockMDC, null, TestDirectoryFinder.LcmDirectories);
                m_dataMigrationManager.PerformMigration(dtoRepos, 7000056, new DummyProgressDlg());
                Assert.AreEqual(7000056, dtoRepos.CurrentModelVersion, "Wrong updated version.");

                var             dtosList           = dtoRepos.AllInstancesSansSubclasses("LangProj");
                DomainObjectDTO dtoLangProjTest    = dtosList.First();
                var             eltWmbLangProjTest = XElement.Parse(dtoLangProjTest.Xml);
                // get phon rule feats
                var eltPhonologicalDataTest = eltWmbLangProjTest.Element("PhonologicalData");
                Assert.IsNotNull(eltPhonologicalDataTest);
                var eltObjsurTest = eltPhonologicalDataTest.Element("objsur");
                Assert.IsNotNull(eltObjsurTest);
                // get possibility list itself
                var guidPhPhonDataTest = eltObjsurTest.Attribute("guid").Value;
                Assert.IsNotNull(guidPhPhonDataTest);
                DomainObjectDTO dtoPhPhonDataTest;
                dtoRepos.TryGetValue(guidPhPhonDataTest, out dtoPhPhonDataTest);
                Assert.IsNotNull(dtoPhPhonDataTest);
                CheckPhPhonData(dtoPhPhonDataTest, dtoRepos);
            }
        }
Exemplo n.º 24
0
        private string RemoveWeatherConditionsElement(DomainObjectDTO dtoLP)
        {
            string sLpXml             = dtoLP.Xml;
            int    idx                = sLpXml.IndexOf("<WeatherConditions>");
            int    idxEnd             = sLpXml.IndexOf("</WeatherConditions>");
            int    cch                = (idxEnd + 20) - idx;
            string sWeatherConditions = sLpXml.Substring(idx, cch);

            dtoLP.Xml = sLpXml.Remove(idx, cch);
            return(ExtractFirstGuid(sWeatherConditions, 0, " guid=\""));
        }
Exemplo n.º 25
0
        private DomainObjectDTO GetDtoLangProj(IDomainObjectDTORepository repoDTO)
        {
            DomainObjectDTO dtoLP = null;

            foreach (var dto in repoDTO.AllInstancesWithSubclasses("LangProject"))
            {
                dtoLP = dto;
                break;
            }
            return(dtoLP);
        }
Exemplo n.º 26
0
 void ChangeClassOfOwnerAndChildren(IDomainObjectDTORepository dtoRepo, DomainObjectDTO dtoToChange, string oldClassname, string newClassname)
 {
     // bail out if we've already changed the class name (assume we've already changed its children too).
     if (!TryChangeOwnerClass(dtoRepo, dtoToChange, oldClassname, newClassname))
     {
         return;
     }
     foreach (var dtoChild in dtoRepo.GetDirectlyOwnedDTOs(dtoToChange.Guid))
     {
         ChangeClassOfOwnerAndChildren(dtoRepo, dtoChild, oldClassname, newClassname);
     }
 }
Exemplo n.º 27
0
        private static void GetWsNamesFromReversalIndex(DomainObjectDTO revIndexDto, Dictionary <string, string> wsCodeNameDict)
        {
            var wsElt = XElement.Parse(revIndexDto.Xml).Element(Name);
            var existingNameAUniElts = wsElt.Elements(Auni);

            foreach (var aUniElt in existingNameAUniElts)
            {
                var wsCode  = aUniElt.Attribute("ws").Value;
                var wsUiStr = aUniElt.Value;
                wsCodeNameDict.Add(wsCode, wsUiStr);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Remove a 'deleted' <see cref="DomainObjectDTO"/> from the repository.
        ///
        /// The deletion of the underlying CmObject object won't happen,
        /// until the entire current migration is finished.
        /// </summary>
        /// <param name="goner">The object being deleted.</param>
        void IDomainObjectDTORepository.Remove(DomainObjectDTO goner)
        {
            if (goner == null)
            {
                throw new ArgumentNullException("goner");
            }

            m_goners.Add(goner);
            m_dtoByGuid.Remove(goner.Guid.ToLower());
            m_dtos.Remove(goner);
            RemoveFromClassList(goner);
        }
Exemplo n.º 29
0
        private bool IsWeatherUsed(IDomainObjectDTORepository repoDTO, List <DomainObjectDTO> collectOverlaysToRemove)
        {
            DomainObjectDTO dtoLP        = GetDtoLangProj(repoDTO);
            string          sLpXml       = dtoLP.Xml;
            int             idxW         = sLpXml.IndexOf("<WeatherConditions>");
            var             sguidWeather = ExtractFirstGuid(sLpXml, idxW, " guid=\"");
            DomainObjectDTO dtoWeather   = repoDTO.GetDTO(sguidWeather);
            var             weatherItems = new HashSet <string>();

            CollectItems(repoDTO, dtoWeather, weatherItems);
            foreach (var dto in repoDTO.AllInstancesWithSubclasses("RnGenericRec"))
            {
                string sXml = dto.Xml;
                int    idx  = sXml.IndexOf("<Weather>");
                if (idx > 0)
                {
                    int idxEnd = sXml.IndexOf("</Weather>");
                    if (idxEnd > idx)
                    {
                        string s = sXml.Substring(idx, idxEnd - idx);
                        if (s.Contains("<objsur "))
                        {
                            return(true);
                        }
                    }
                }
                bool dummy = false;
                if (StringContainsRefToItemInList("PhraseTags", weatherItems, sXml, ref dummy))
                {
                    return(true);
                }
            }
            foreach (var dto in repoDTO.AllInstancesSansSubclasses("CmOverlay"))
            {
                string sXml           = dto.Xml;
                bool   hasOtherItems  = false;
                bool   hasWeatherRef  = StringContainsRefToItemInList("PossItems", weatherItems, sXml, ref hasOtherItems);
                var    weatherListSet = new HashSet <string>();
                weatherListSet.Add(sguidWeather.ToLowerInvariant());
                hasWeatherRef |= StringContainsRefToItemInList("PossList", weatherListSet, sXml, ref hasOtherItems);
                if (hasWeatherRef)
                {
                    if (hasOtherItems)
                    {
                        return(true);                        // an overlay with a mixture of weather and non-weather items is a problem
                    }
                    // One with only weather refs (and not used, since we know nothing is tagged to weather)
                    // will be deleted.
                    collectOverlaysToRemove.Add(dto);
                }
            }
            return(false);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Let the Repository know that <paramref name="dirtball"/> has been modified.
        /// </summary>
        /// <param name="dirtball">The object that was modified.</param>
        /// <remarks>
        /// The underlying CmObject won't be changed, until the end of the current
        /// migration is finished.
        /// </remarks>
        void IDomainObjectDTORepository.Update(DomainObjectDTO dirtball)
        {
            if (dirtball == null)
            {
                throw new ArgumentNullException("dirtball");
            }
            if (!m_dtoByGuid.ContainsKey(dirtball.Guid.ToLower()))
            {
                throw new InvalidOperationException("Can't update DTO that isn't in the system.");
            }

            m_dirtballs.Add(dirtball);
        }