UpdateDTO() static private method

Rest the xml in the DTO and register the DTO as udated with the repository. Use this overload only if the class name is NOT changing.
There is no validation of the xml, other than making sure it is not null, or an emty string.
static private UpdateDTO ( IDomainObjectDTORepository dtoRepos, DomainObjectDTO dirtball, byte newXmlBytes ) : void
dtoRepos IDomainObjectDTORepository
dirtball DomainObjectDTO
newXmlBytes byte
return void
        private static void ChangeMultiUnicodeElementToMultiString(IDomainObjectDTORepository repoDto, DomainObjectDTO dto,
                                                                   string xpathToMultiUnicodeElement)
        {
            const string auniXpath = "/AUni";
            var          changed   = false;
            var          dataElt   = XElement.Parse(dto.Xml);

            foreach (var elt in dataElt.XPathSelectElements(xpathToMultiUnicodeElement + auniXpath))
            {
                elt.Name = "AStr";
                var unicodeData = elt.Value;
                elt.Value = string.Empty;
                var wsAttr = elt.Attribute("ws");
                var runElt = new XElement("Run")
                {
                    Value = unicodeData
                };
                runElt.SetAttributeValue("ws", wsAttr.Value);
                elt.Add(runElt);
                changed = true;
            }
            if (changed)
            {
                DataMigrationServices.UpdateDTO(repoDto, dto, dataElt.ToString());
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes LexEntries be unowned.
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000027);

            var lexDbDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LexDb").First();
            var lexDb    = XElement.Parse(lexDbDto.Xml);
            var entries  = lexDb.Element("Entries");

            if (entries != null)
            {
                entries.Remove();
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, lexDbDto, lexDb.ToString());
            }

            foreach (var entryDto in domainObjectDtoRepository.AllInstancesSansSubclasses("LexEntry"))
            {
                XElement entry     = XElement.Parse(entryDto.Xml);
                var      ownerAttr = entry.Attribute("ownerguid");
                if (ownerAttr != null)
                {
                    ownerAttr.Remove();
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, entryDto, entry.ToString());
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000062);

            var wmbLangProjList = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject");
            var wmbLangProj     = wmbLangProjList.First();
            var wmbLangProjElt  = XElement.Parse(wmbLangProj.Xml);
            // get the default vernacular ws - it's the 1st in the list of current ones.
            var vernWss = wmbLangProjElt.Element("CurVernWss");             // has to be only one

            // a new project migrates before adding writing systems to the cache, so if there are no CurVernWss, bail out
            if (vernWss != null)
            {
                var vernWssUni  = vernWss.Element("Uni");        // only one
                var vernWsList  = vernWssUni.Value.Split(' ');   // at least one
                var vernDefault = vernWsList[0];                 // the default

                // Create the new property
                var sb = new StringBuilder();
                sb.Append("<HomographWs>");
                sb.AppendFormat("<Uni>{0}</Uni>", vernDefault);
                sb.Append("</HomographWs>");
                var hgWsElt = XElement.Parse(sb.ToString());
                wmbLangProjElt.Add(hgWsElt);
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, wmbLangProj, wmbLangProjElt.ToString());
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        private void CleanOutBadRefTypes(IDomainObjectDTORepository repoDto)
        {
            const string unspecComplexEntryTypeGuid = "fec038ed-6a8c-4fa5-bc96-a4f515a98c50";
            const string unspecVariantEntryTypeGuid = "3942addb-99fd-43e9-ab7d-99025ceb0d4e";

            foreach (var dto in repoDto.AllInstancesWithSubclasses("LexEntryRef"))
            {
                var data                = XElement.Parse(dto.Xml);
                var refTypeElt          = data.Element("RefType");
                var varientEntryTypeElt = data.Element("VariantEntryTypes");
                var complexEntryTypeElt = data.Element("ComplexEntryTypes");
                if (refTypeElt.FirstAttribute.Value == LexEntryRefTags.krtComplexForm.ToString() && varientEntryTypeElt != null)
                {
                    varientEntryTypeElt.Remove();
                    DataMigrationServices.UpdateDTO(repoDto, dto, data.ToString());
                }
                else if (refTypeElt.FirstAttribute.Value == LexEntryRefTags.krtVariant.ToString() && complexEntryTypeElt != null)
                {
                    complexEntryTypeElt.Remove();
                    DataMigrationServices.UpdateDTO(repoDto, dto, data.ToString());
                }
                // Re-do the DM69 bit correctly if necessary
                if (refTypeElt.FirstAttribute.Value == LexEntryRefTags.krtComplexForm.ToString() && complexEntryTypeElt == null)
                {
                    DataMigration7000069.AddRefType(data, repoDto, dto, "ComplexEntryTypes", unspecComplexEntryTypeGuid, false);
                }
                else if (refTypeElt.FirstAttribute.Value == LexEntryRefTags.krtVariant.ToString() && varientEntryTypeElt == null)
                {
                    DataMigration7000069.AddRefType(data, repoDto, dto, "VariantEntryTypes", unspecVariantEntryTypeGuid, false);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Remove the owningFlid attribute from every "rt" element.
        /// </summary>
        /// <param name="domainObjectDtoRepository"></param>
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000008);

            foreach (var dto in domainObjectDtoRepository.AllInstancesWithValidClasses())
            {
                byte[] contents = dto.XmlBytes;
                int    index    = contents.IndexOfSubArray(owningFlidTag);
                if (index >= 0)
                {
                    contents = contents.ReplaceSubArray(index,
                                                        Array.IndexOf(contents, closeQuote, index + owningFlidTag.Length) - index + 1,
                                                        new byte[0]);
                }
                int index2 = contents.IndexOfSubArray(owningOrdTag);
                if (index2 >= 0)
                {
                    contents = contents.ReplaceSubArray(index2,
                                                        Array.IndexOf(contents, closeQuote, index2 + owningOrdTag.Length) - index2 + 1,
                                                        new byte[0]);
                }
                if (index >= 0 || index2 >= 0)
                {
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, dto, contents);
                }
            }
            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change any bogus non-owning footnote links in the vernacular (but NOT in the BT)
        /// to be owning links
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000034);

            foreach (var scrTxtPara in domainObjectDtoRepository.AllInstancesSansSubclasses("ScrTxtPara"))
            {
                XElement para     = XElement.Parse(scrTxtPara.Xml);
                XElement contents = para.Element("Contents");
                if (contents == null)
                {
                    continue;
                }
                XElement str = contents.Element("Str");
                if (str == null)
                {
                    continue;
                }

                foreach (XElement run in str.Elements("Run"))
                {
                    XAttribute linkAttr = run.Attribute("link");
                    if (linkAttr == null)
                    {
                        continue;                         // Run doesn't contain an unowned hot-link
                    }
                    XAttribute ownedLinkAttr = new XAttribute("ownlink", linkAttr.Value);
                    run.Add(ownedLinkAttr);
                    linkAttr.Remove();
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, scrTxtPara, para.ToString());
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the Name property for several CmPossibilityLists to match what is displayed
        /// in the Lists area. Sets Name for en, es, fa, fr, id, pt, ru and zh_CN wss.
        /// </summary>
        /// <param name="dtoRepos">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository dtoRepos)
        {
            DataMigrationServices.CheckVersionNumber(dtoRepos, 7000021);

            // We need 'LangProject' and its DsDiscourseData, LexDb and RnResearchNbk objects.
            var lpDto     = dtoRepos.AllInstancesSansSubclasses("LangProject").FirstOrDefault();
            var lpElement = lpDto == null ? null : XElement.Parse(lpDto.Xml);

            var discourseDataDto = dtoRepos.AllInstancesSansSubclasses("DsDiscourseData").FirstOrDefault();
            var dsDataElement    = discourseDataDto == null ? null : XElement.Parse(discourseDataDto.Xml);

            var lexDbDto     = dtoRepos.AllInstancesSansSubclasses("LexDb").FirstOrDefault();
            var lexDbElement = lexDbDto == null ? null : XElement.Parse(lexDbDto.Xml);

            var nbkDto     = dtoRepos.AllInstancesSansSubclasses("RnResearchNbk").FirstOrDefault();
            var nbkElement = nbkDto == null ? null : XElement.Parse(nbkDto.Xml);

            for (var i = 0; i < m_listNames.GetLength(0); i++)
            {
                var      owner = (ListOwner)Int32.Parse(m_listNames[i, 0]);
                XElement owningElem;
                switch (owner)
                {
                case ListOwner.Discourse:
                    owningElem = dsDataElement;
                    break;

                case ListOwner.LexDb:
                    owningElem = lexDbElement;
                    break;

                case ListOwner.RNbk:
                    owningElem = nbkElement;
                    break;

                default:
                    owningElem = lpElement;
                    break;
                }
                if (owningElem == null)
                {
                    continue;
                }
                var listDto = GetListDto(dtoRepos, owningElem, m_listNames[i, 1]);
                if (listDto == null || listDto.Xml == null)
                {
                    continue;
                }
                var listElement = XElement.Parse(listDto.Xml);
                var nameElem    = GetListNameElement(listElement) ?? MakeEmptyNameElementInList(listElement);
                for (var j = 2; j < m_listNames.GetLength(1); j++)
                {
                    AddReplaceLocalizedListName(nameElem, GetWsStrForColumn(j), i, j);
                }

                DataMigrationServices.UpdateDTO(dtoRepos, listDto, listElement.ToString());
            }

            DataMigrationServices.IncrementVersionNumber(dtoRepos);
        }
        internal static void AddRefType(XElement data, IDomainObjectDTORepository repoDto, DomainObjectDTO dto, string tagName, string guid, bool owned)
        {
            var varElementTag = data.Element(tagName);

            if (varElementTag == null)
            {
                var varTypeReference = new XElement(tagName);
                var typeReference    = new XElement("objsur");
                typeReference.SetAttributeValue("guid", guid);
                typeReference.SetAttributeValue("t", owned ? "o" : "r");
                varTypeReference.Add(typeReference);
                data.Add(varTypeReference);
                DataMigrationServices.UpdateDTO(repoDto, dto, data.ToString());
            }
            else
            {
                varElementTag = data.Element(tagName);
                var typeObject = new XElement("objsur");
                typeObject.SetAttributeValue("guid", guid);
                typeObject.SetAttributeValue("t", owned ? "o" : "r");
                if (varElementTag != null)
                {
                    varElementTag.Add(typeObject);
                }
                DataMigrationServices.UpdateDTO(repoDto, dto, data.ToString());
            }
        }
Example #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change model for Data Notebook to combine the RnEvent and RnAnalysis classes
        /// into RnGenericRec
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of its work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000004);

            // 1. Change EventTypes field to RecTypes
            var nbkDto            = domainObjectDtoRepository.AllInstancesSansSubclasses("RnResearchNbk").First();
            var nbkElement        = XElement.Parse(nbkDto.Xml);
            var nbkClsElement     = nbkElement.Element("RnResearchNbk");
            var typesFieldElement = nbkClsElement.Element("EventTypes");
            var typesSurElement   = typesFieldElement.Element("objsur");

            nbkClsElement.Add(new XElement("RecTypes", typesSurElement));
            typesFieldElement.Remove();
            DataMigrationServices.UpdateDTO(domainObjectDtoRepository, nbkDto, nbkElement.ToString());

            // 2. Add Analysis possibility to Record Types list
            var typesGuid    = typesSurElement.Attribute("guid").Value;
            var typesDto     = domainObjectDtoRepository.GetDTO(typesGuid);
            var typesElement = XElement.Parse(typesDto.Xml);

            typesElement.XPathSelectElement("CmMajorObject/Name/AUni[@ws='en']").SetValue("Entry Types");
            var posElement = typesElement.XPathSelectElement("CmPossibilityList/Possibilities");

            posElement.Add(
                DataMigrationServices.CreateOwningObjSurElement("82290763-1633-4998-8317-0EC3F5027FBD"));
            DataMigrationServices.UpdateDTO(domainObjectDtoRepository, typesDto,
                                            typesElement.ToString());
            var ord = posElement.Elements().Count();

            var nowStr      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var typeElement = new XElement("rt", new XAttribute("class", "CmPossibility"),
                                           new XAttribute("guid", "82290763-1633-4998-8317-0EC3F5027FBD"),
                                           new XAttribute("ownerguid", typesGuid),
                                           new XAttribute("owningflid", "8008"), new XAttribute("owningord", ord.ToString()),
                                           new XElement("CmObject"),
                                           new XElement("CmPossibility",
                                                        new XElement("Abbreviation",
                                                                     new XElement("AUni", new XAttribute("ws", "en"), "Ana")),
                                                        new XElement("BackColor", new XAttribute("val", "16711680")),
                                                        new XElement("DateCreated", new XAttribute("val", nowStr)),
                                                        new XElement("DateModified", new XAttribute("val", nowStr)),
                                                        new XElement("Description",
                                                                     new XElement("AStr", new XAttribute("ws", "en"),
                                                                                  new XElement("Run", new XAttribute("ws", "en"), "Reflection on events and other types of data, such as literature summaries or interviews. An analysis does not add data; it interprets and organizes data. An analysis entry may synthesize emerging themes. It may draw connections between observations. It is a place to speculate and hypothesize, or document moments of discovery and awareness. Analytic notes can be turned into articles. Or, they may just be steps on the stairway toward greater understanding."))),
                                                        new XElement("ForeColor", new XAttribute("val", "16777215")),
                                                        new XElement("Name",
                                                                     new XElement("AUni", new XAttribute("ws", "en"), "Analysis")),
                                                        new XElement("UnderColor", new XAttribute("val", "255")),
                                                        new XElement("UnderStyle", new XAttribute("val", "1"))));

            domainObjectDtoRepository.Add(new DomainObjectDTO("82290763-1633-4998-8317-0EC3F5027FBD",
                                                              "CmPossibility", typeElement.ToString()));

            // 3. Move the attributes that are in RnEvent and RnAnalysis into RnGenericRec.
            MigrateSubclassOfGenRec(domainObjectDtoRepository, "RnEvent");
            MigrateSubclassOfGenRec(domainObjectDtoRepository, "RnAnalysis");

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        private void AppendCustomToNamesAndUpdate(IDomainObjectDTORepository repoDto, DomainObjectDTO dto, XElement dtoXml)
        {
            var names = dtoXml.Elements("Name");

            foreach (var titleElement in names.Select(name => name.Element("AUni")).Where(titleElement => titleElement != null))
            {
                titleElement.Value = titleElement.Value + "-Custom";
            }
            DataMigrationServices.UpdateDTO(repoDto, dto, dtoXml.ToString());
        }
        /// <summary>
        /// If user created a Custom "Exemplar" or "UsageNote" of type MultiString or MultiUnicode,
        /// copy that data into the new built-in MultiString element and, if MultiString, remove the Custom Field.
        /// If a conflicting Custom Field cannot be migrated and removed, rename it to avoid conflict.
        /// </summary>
        internal static void MigrateIntoNewMultistringField(IDomainObjectDTORepository repoDto, string fieldName)
        {
            // This is the same algorithm used by FDOBackendProvider.PreLoadCustomFields to prevent naming conflicts with existing Custom Fields
            var nameSuffix   = 0;
            var lexSenseClid = repoDto.MDC.GetClassId("LexSense");

            while (repoDto.MDC.FieldExists(lexSenseClid, fieldName + nameSuffix, false))
            {
                ++nameSuffix;
            }
            var newFieldName = fieldName + nameSuffix;

            foreach (var dto in repoDto.AllInstancesSansSubclasses("LexSense"))
            {
                var data = XElement.Parse(dto.Xml);

                var customElt = data.Elements("Custom").FirstOrDefault(elt => elt.Attribute("name").Value == fieldName);
                if (customElt == null)
                {
                    continue;
                }
                customElt.SetAttributeValue("name", newFieldName);                 // rename to the new custom Exemplar name

                var builtInElt     = new XElement(fieldName);
                var isFieldBuiltIn = false;
                foreach (var multiStrElt in customElt.Elements("AStr"))
                {
                    builtInElt.Add(multiStrElt);
                    isFieldBuiltIn = true;
                }
                foreach (var multiStrElt in customElt.Elements("AUni"))
                {
                    multiStrElt.Name = "AStr";
                    var mutiStrData = multiStrElt.Value;
                    multiStrElt.Value = string.Empty;
                    var wsAttr = multiStrElt.Attribute("ws");
                    var runElt = new XElement("Run")
                    {
                        Value = mutiStrData
                    };
                    runElt.SetAttributeValue("ws", wsAttr.Value);
                    multiStrElt.Add(runElt);
                    builtInElt.Add(multiStrElt);
                    isFieldBuiltIn = true;
                }
                if (isFieldBuiltIn)
                {
                    customElt.Remove();
                    data.Add(builtInElt);
                }
                DataMigrationServices.UpdateDTO(repoDto, dto, data.ToString());
            }
        }
        /// <summary>
        /// Change LexEntry.Etymology to Owned Sequence, add several fields to LexEtymology
        /// Change some existing field signatures. Remove Source and put its data in LanguageNotes
        /// in a slightly different format (Unicode -> MultiString). Also add a new list Languages
        /// owned by LexDb. Languages list will be initially empty.
        /// </summary>
        /// <remarks>internal for testing</remarks>
        internal static void AugmentEtymologyCluster(IDomainObjectDTORepository repoDto)
        {
            const string languagesListGuid = "487c15b0-2ced-4417-8b77-9075f4a21e5f";
            var          lexDbDTO          = repoDto.AllInstancesSansSubclasses("LexDb").FirstOrDefault();

            if (lexDbDTO == null)
            {
                return;                 // This must be a test that doesn't care about LexDb.
            }
            var lexDbElt = XElement.Parse(lexDbDTO.Xml);

            CreateNewLexDbProperty(lexDbElt, "Languages", languagesListGuid);
            var lexDbGuid = lexDbElt.Attribute("guid").Value;

            // create Languages' possibility list
            DataMigrationServices.CreatePossibilityList(repoDto, languagesListGuid, lexDbGuid,
                                                        new[]
            {
                new Tuple <string, string, string>("en", "Lgs", "Languages"),
                new Tuple <string, string, string>("fr", "Lgs", "Langues"),
                new Tuple <string, string, string>("es", "Ids", "Idiomas")
            },
                                                        new DateTime(2016, 7, 25, 18, 48, 18), WritingSystemServices.kwsAnals);
            DataMigrationServices.UpdateDTO(repoDto, lexDbDTO, lexDbElt.ToString());             // update LexDb object

            // Augment existing Etymologies
            var etymologyDtos = repoDto.AllInstancesSansSubclasses("LexEtymology");

            if (!etymologyDtos.Any())
            {
                return;
            }
            var primaryAnalysisWs = ExtractPrimaryWsFromLangProj(repoDto, true);

            foreach (var etymologyDto in etymologyDtos)
            {
                ChangeMultiUnicodeElementToMultiString(repoDto, etymologyDto, "//Form");
                ChangeMultiUnicodeElementToMultiString(repoDto, etymologyDto, "//Gloss");
                var dataElt   = XElement.Parse(etymologyDto.Xml);
                var sourceElt = dataElt.Element("Source");
                if (sourceElt == null)
                {
                    continue;
                }
                sourceElt.Name = "LanguageNotes";                 // sourceElt is now the languageNotesElt!
                var oldSourceData = sourceElt.Element("Uni").Value;
                var multiStrElt   = BuildMultiStringElement(primaryAnalysisWs, oldSourceData);
                sourceElt.RemoveAll();
                sourceElt.Add(multiStrElt);
                DataMigrationServices.UpdateDTO(repoDto, etymologyDto, dataElt.ToString());
            }
        }
Example #13
0
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000051);

            var          newGuidValue = Guid.NewGuid().ToString().ToLowerInvariant();
            const string className    = "WfiMorphBundle";
            var          wmbList      = domainObjectDtoRepository.AllInstancesSansSubclasses(className);

            foreach (var wmb in wmbList)
            {
                XElement wmbElt   = XElement.Parse(wmb.Xml);
                var      morphElt = wmbElt.Element("Morph");
                // if we don't have a morph reference,
                // then there's nothing to copy into the form field.
                if (morphElt == null)
                {
                    continue;
                }
                var objsurElt      = morphElt.Element("objsur");
                var dtoMorphTarget = domainObjectDtoRepository.GetDTO(objsurElt.Attribute("guid").Value);
                // for each form alternative, copy the writing system

                // if for some reason there is a morphbundle form that already exists, delete it before inserting another.
                var formElt = wmbElt.Element("Form");
                if (formElt != null)
                {
                    formElt.Remove();
                }

                var morphTargetElt     = XElement.Parse(dtoMorphTarget.Xml);
                var morphTargetFormElt = morphTargetElt.Element("Form");
                if (morphTargetFormElt == null)
                {
                    continue;
                }
                formElt = XElement.Parse("<Form/>");
                wmbElt.AddFirst(formElt);
                foreach (var aUniElt in morphTargetFormElt.Elements("AUni"))
                {
                    string ws            = aUniElt.Attribute("ws").Value;
                    string form          = aUniElt.Value;
                    var    newFormAltElt = XElement.Parse(String.Format("<AStr ws=\"{0}\"/>", ws));
                    formElt.Add(newFormAltElt);
                    var newRunElt = XElement.Parse(String.Format("<Run ws=\"{0}\">{1}</Run>", ws, XmlUtils.MakeSafeXml(form)));
                    newFormAltElt.Add(newRunElt);
                }
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, wmb, wmbElt.ToString());
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the ParaContainingOrc property for all ScrFootnotes
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000026);

            foreach (var scrTxtPara in domainObjectDtoRepository.AllInstancesSansSubclasses("ScrTxtPara"))
            {
                XElement para     = XElement.Parse(scrTxtPara.Xml);
                XElement contents = para.Element("Contents");
                if (contents == null)
                {
                    continue;
                }
                XElement str = contents.Element("Str");
                if (str == null)
                {
                    continue;
                }

                foreach (XElement run in str.Elements("Run"))
                {
                    XAttribute linkAttr = run.Attribute("ownlink");
                    if (linkAttr == null)
                    {
                        continue;                         // Run doesn't contain a link
                    }
                    DomainObjectDTO linkObj;
                    // skip links to missing footnotes - user will have to clean these up later.
                    if (!domainObjectDtoRepository.TryGetValue(linkAttr.Value, out linkObj))
                    {
                        continue;
                    }
                    XElement footnote = XElement.Parse(linkObj.Xml);
                    if (footnote.Attribute("class").Value != "ScrFootnote")
                    {
                        continue;                         // Link is not for a footnote
                    }
                    if (footnote.Element("ParaContainingOrc") == null)
                    {
                        // ParaContainingOrc property is not present in the footnote, so it needs
                        // to be added.
                        XElement paraContainingOrcElm = XElement.Parse("<ParaContainingOrc><objsur guid=\"" +
                                                                       scrTxtPara.Guid + "\" t=\"r\" /></ParaContainingOrc>");
                        footnote.Add(paraContainingOrcElm);

                        DataMigrationServices.UpdateDTO(domainObjectDtoRepository, linkObj, footnote.ToString());
                    }
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change all guids to lowercase to help the Chorus diff/merge code.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000022);

            foreach (var dto in domainObjectDtoRepository.AllInstancesWithValidClasses())
            {
                var rtElement = XElement.Parse(dto.Xml);
                if (ShiftCase(rtElement))
                {
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, dto, rtElement.ToString());
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #16
0
        private void RemoveReferenceFromPictures(IDomainObjectDTORepository repoDto, DomainObjectDTO langProj,
                                                 string guid)
        {
            var langProjElement = XElement.Parse(langProj.Xml);

            foreach (var x in langProjElement.Element("Pictures").Elements())
            {
                if (x.Attribute("guid").Value == guid)
                {
                    x.Remove();
                    break;
                }
            }
            DataMigrationServices.UpdateDTO(repoDto, langProj, langProjElement.ToString());
        }
Example #17
0
        bool TryChangeOwnerClass(IDomainObjectDTORepository dtoRepo, DomainObjectDTO dtoToChange, string oldClassname, string newClassname)
        {
            XElement dtoToChangeElt = XElement.Parse(dtoToChange.Xml);

            if (dtoToChangeElt.Attribute("class").Value != oldClassname)
            {
                return(false);
            }
            dtoToChangeElt.Attribute("class").Value = newClassname;
            dtoToChange.Classname = newClassname;
            // next go through all the children of these known system variant types and change all of their children's classes.

            DataMigrationServices.UpdateDTO(dtoRepo, dtoToChange, dtoToChangeElt.ToString(), oldClassname);
            return(true);
        }
Example #18
0
        private void MoveFileToFolder(IDomainObjectDTORepository repoDto, DomainObjectDTO folder, DomainObjectDTO fileToMove)
        {
            // Create surogate for file and add it to the folder
            var surrogate     = DataMigrationServices.CreateOwningObjSurElement(fileToMove.Guid);
            var folderElement = XElement.Parse(folder.Xml);
            var filesElement  = folderElement.Element("Files");

            filesElement.Add(surrogate);
            DataMigrationServices.UpdateDTO(repoDto, folder, folderElement.ToString());

            // Change owner of file
            var fileElement = XElement.Parse(fileToMove.Xml);

            fileElement.Attribute("ownerguid").SetValue(folder.Guid);
            DataMigrationServices.UpdateDTO(repoDto, fileToMove, fileElement.ToString());
        }
Example #19
0
        private void UpdatePictureReferences(IDomainObjectDTORepository repoDto, DomainObjectDTO file,
                                             string replacementFileGuid,
                                             Dictionary <string, List <DomainObjectDTO> > pictureMap)
        {
            List <DomainObjectDTO> pictures;

            if (pictureMap.TryGetValue(file.Guid, out pictures))
            {
                foreach (var picture in pictures)
                {
                    var pictureElement      = XElement.Parse(picture.Xml);
                    var objSurrogateElement = pictureElement.Element("PictureFile").Element("objsur");
                    objSurrogateElement.Attribute("guid").Value = replacementFileGuid;
                    DataMigrationServices.UpdateDTO(repoDto, picture, pictureElement.ToString());
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes Texts (IText) be unowned.
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000058);

            // Remove LangProject Texts property
            var lpDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            var lp    = XElement.Parse(lpDto.Xml);
            var texts = lp.Element("Texts");

            if (texts != null)
            {
                texts.Remove();
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, lpDto, lp.ToString());
            }

            // Change RnGenericRec Text property from owned to reference
            foreach (var rnRecDto in domainObjectDtoRepository.AllInstancesSansSubclasses("RnGenericRec"))
            {
                var rec     = XElement.Parse(rnRecDto.Xml);
                var textElt = rec.Element("Text");
                if (textElt != null)
                {
                    var objsurElt = textElt.Element("objsur");
                    if (objsurElt != null && objsurElt.Attribute("t") != null)
                    {
                        objsurElt.Attribute("t").SetValue("r");
                        DataMigrationServices.UpdateDTO(domainObjectDtoRepository, rnRecDto, rec.ToString());
                    }
                }
            }

            // Remove owner from all Texts
            foreach (var textDto in domainObjectDtoRepository.AllInstancesSansSubclasses("Text"))
            {
                XElement text      = XElement.Parse(textDto.Xml);
                var      ownerAttr = text.Attribute("ownerguid");
                if (ownerAttr != null)
                {
                    ownerAttr.Remove();
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, textDto, text.ToString());
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #21
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Cleans up legacy ChkRendering objects with null SurfaceForms.
        /// </summary>
        /// <param name="repoDto">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository repoDto)
        {
            DataMigrationServices.CheckVersionNumber(repoDto, 7000046);

            Dictionary <Guid, DomainObjectDTO> mapOfRenderingsToChk = new Dictionary <Guid, DomainObjectDTO>();
            HashSet <DomainObjectDTO>          renderingsToDelete   = new HashSet <DomainObjectDTO>();

            foreach (DomainObjectDTO dto in repoDto.AllInstances())
            {
                XElement   data      = XElement.Parse(dto.Xml);
                XAttribute classAttr = data.Attribute("class");
                if (classAttr.Value == "ChkTerm")
                {
                    XElement renderings = data.Element("Renderings");
                    if (renderings != null)
                    {
                        foreach (XElement r in renderings.Elements())
                        {
                            mapOfRenderingsToChk[new Guid(r.Attribute("guid").Value)] = dto;
                        }
                    }
                }
                else if (classAttr.Value == "ChkRendering")
                {
                    XElement surfaceForm = data.Element("SurfaceForm");
                    if (surfaceForm == null || !surfaceForm.HasElements)
                    {
                        renderingsToDelete.Add(dto);
                    }
                }
            }

            foreach (DomainObjectDTO rendering in renderingsToDelete)
            {
                DomainObjectDTO chkTerm        = mapOfRenderingsToChk[new Guid(rendering.Guid)];
                XElement        termData       = XElement.Parse(chkTerm.Xml);
                XElement        renderings     = termData.Element("Renderings");
                XElement        bogusRendering = renderings.Elements().First(e => e.Attribute("guid").Value.Equals(rendering.Guid, StringComparison.OrdinalIgnoreCase));
                bogusRendering.Remove();
                DataMigrationServices.UpdateDTO(repoDto, chkTerm, termData.ToString());
                repoDto.Remove(rendering);
            }

            DataMigrationServices.IncrementVersionNumber(repoDto);
        }
 private static void ConvertClassAndSubclasses(IDomainObjectDTORepository domainObjectDtoRepository,
                                               IEnumerable <DomainObjectDTO> allInstancesWithSubclasses, IEnumerable <string> dateTimeProperties)
 {
     foreach (var dto in allInstancesWithSubclasses)
     {
         var rtElement  = XElement.Parse(dto.Xml);
         var wasChanged = false;
         foreach (var propElement in dateTimeProperties
                  .Select(propName => rtElement.Element(propName)).Where(propElement => propElement != null))
         {
             ConvertLocalToUtc(propElement.Attribute("val"));
             wasChanged = true;
         }
         if (wasChanged)
         {
             DataMigrationServices.UpdateDTO(domainObjectDtoRepository, dto, rtElement.ToString());
         }
     }
 }
        /// <summary>
        /// Add a new list DialectLabels owned by LexDb. The list will be initially empty.
        /// The migration will also add a reference sequence property to LexEntry and
        /// LexSense, but since they will be empty too, there's no migration to happen here.
        /// </summary>
        /// <remarks>internal for testing</remarks>
        internal static void AddDialectLabelsList(IDomainObjectDTORepository repoDto)
        {
            const string dialectListGuid = "a3a8188b-ab00-4a43-b925-a1eed62287ba";
            var          lexDbDTO        = repoDto.AllInstancesSansSubclasses("LexDb").FirstOrDefault();

            if (lexDbDTO == null)
            {
                return;                 // This must be a test that doesn't care about LexDb.
            }
            var lexDbElt = XElement.Parse(lexDbDTO.Xml);

            CreateNewLexDbProperty(lexDbElt, "DialectLabels", dialectListGuid);
            var lexDbGuid = lexDbElt.Attribute("guid").Value;

            // create Languages' possibility list with no Possibilities
            DataMigrationServices.CreatePossibilityList(repoDto, dialectListGuid, lexDbGuid,
                                                        new[] { new Tuple <string, string, string>("en", "Dials", "Dialect Labels") }, new DateTime(2016, 8, 9, 18, 48, 18), WritingSystemServices.kwsVernAnals);
            DataMigrationServices.UpdateDTO(repoDto, lexDbDTO, lexDbElt.ToString());             // update LexDb object
        }
Example #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes unused fields in UserViewField.
        /// </summary>
        /// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for
        /// one migration step.</param>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000011);

            // 1) Select the UserViewField classes.
            // 2) Delete the following attributes: Details, Visibility, IsCustomField, SubfieldOf, PossList
            foreach (var uvfDto in domainObjectDtoRepository.AllInstancesSansSubclasses("UserViewField"))
            {
                XElement rtElement  = XElement.Parse(uvfDto.Xml);
                XElement uvfElement = rtElement.Element("UserViewField");
                RemoveField(uvfDto, uvfElement, "Details");
                RemoveField(uvfDto, uvfElement, "Visibility");
                RemoveField(uvfDto, uvfElement, "SubfieldOf");
                RemoveField(uvfDto, uvfElement, "IsCustomField");
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, uvfDto, rtElement.ToString());
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add DateModified to StText
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000035);

            foreach (var stTextDTO in domainObjectDtoRepository.AllInstancesWithSubclasses("StText"))
            {
                XElement stText = XElement.Parse(stTextDTO.Xml);
                if (stText.Element("DateModified") != null)
                {
                    continue;                     // Already has a DateModified property (probably an StJounalText
                }
                XElement   dateModified = new XElement("DateModified", null);
                XAttribute value        = new XAttribute("val", ReadWriteServices.FormatDateTime(DateTime.Now));
                dateModified.Add(value);
                stText.Add(dateModified);
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, stTextDTO, stText.ToString());
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #26
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change model to remove the Name field from CmProject
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of its work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000005);

            // 1. Select the CmProject classes.
            // 2. Delete the 'Name' attribute.
            foreach (var cmProjDto in domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject"))
            {
                var rtElement   = XElement.Parse(cmProjDto.Xml);
                var ProjElement = rtElement.Element("CmProject");
                var nmElement   = ProjElement.Element("Name");
                if (nmElement != null)
                {
                    nmElement.Remove();
                }

                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, cmProjDto, rtElement.ToString());
            }
            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #27
0
        private void MoveFileReferences(IDomainObjectDTORepository repoDto, DomainObjectDTO langProj,
                                        DomainObjectDTO srcFolder, DomainObjectDTO destFolder)
        {
            var srcFolderElement  = XElement.Parse(srcFolder.Xml);
            var destFolderElement = XElement.Parse(destFolder.Xml);
            var destFileRefs      = destFolderElement.Element("Files");

            foreach (var fileRef in srcFolderElement.Element("Files").Elements())
            {
                destFileRefs.Add(fileRef);
                var guid        = fileRef.Attribute("guid").Value;
                var file        = repoDto.GetDTO(guid);
                var fileElement = XElement.Parse(file.Xml);
                fileElement.Attribute("ownerguid").SetValue(destFolder.Guid);
                DataMigrationServices.UpdateDTO(repoDto, file, fileElement.ToString());
            }

            RemoveReferenceFromPictures(repoDto, langProj, srcFolder.Guid);
            repoDto.Remove(srcFolder);
            DataMigrationServices.UpdateDTO(repoDto, destFolder, destFolderElement.ToString());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Perform one increment migration step.
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of it work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000000);

            DataMigrationServices.Delint(domainObjectDtoRepository);

            var lpDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            // 1. Remove property from LangProg.
            var lpElement = XElement.Parse(lpDto.Xml);

            lpElement.Descendants("WordformInventory").Remove();
            DataMigrationServices.UpdateDTO(domainObjectDtoRepository, lpDto, lpElement.ToString());

            // 2. Remove three owner-related attributes from each WfiWordform.
            // (There may be zero, or more, instances to upgrade.)
            foreach (var wordformDto in domainObjectDtoRepository.AllInstancesSansSubclasses("WfiWordform"))
            {
                var wfElement = XElement.Parse(wordformDto.Xml);
                wfElement.Attribute("ownerguid").Remove();
                var flidAttr = wfElement.Attribute("owningflid");
                if (flidAttr != null)
                {
                    flidAttr.Remove();
                }
                var ordAttr = wfElement.Attribute("owningord");
                if (ordAttr != null)
                {
                    ordAttr.Remove();
                }
                DataMigrationServices.UpdateDTO(domainObjectDtoRepository, wordformDto, wfElement.ToString());
            }

            // 3. Remove WordformInventory instance.
            domainObjectDtoRepository.Remove(
                domainObjectDtoRepository.AllInstancesSansSubclasses("WordformInventory").First());

            // There are no references to the WFI, so don't fret about leaving dangling refs to it.

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #29
0
 private static void MigrateSubclassOfGenRec(IDomainObjectDTORepository domainObjectDtoRepository,
                                             string subclassName)
 {
     // We need a copy of the collection because we will remove items from it during the loop.
     foreach (var GenRecDto in domainObjectDtoRepository.AllInstancesSansSubclasses(subclassName).ToArray())
     {
         var rtElement  = XElement.Parse(GenRecDto.Xml);
         var clsElement = rtElement.Element(GenRecDto.Classname);
         var recElement = rtElement.Element("RnGenericRec");
         recElement.Add(clsElement.Elements());
         clsElement.Remove();
         rtElement.Attribute("class").Value = "RnGenericRec";
         if (GenRecDto.Classname == "RnAnalysis")
         {
             recElement.Add(new XElement("Type",
                                         DataMigrationServices.CreateReferenceObjSurElement("82290763-1633-4998-8317-0EC3F5027FBD")));
         }
         String oldClassName = GenRecDto.Classname;
         GenRecDto.Classname = "RnGenericRec";
         DataMigrationServices.UpdateDTO(domainObjectDtoRepository, GenRecDto, rtElement.ToString(), oldClassName);
     }
 }
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000036);

            string path    = domainObjectDtoRepository.ProjectFolder;
            string project = Path.GetFileName(path);

            foreach (var dto in domainObjectDtoRepository.AllInstancesWithValidClasses())
            {
                if (dto.XmlBytes.IndexOfSubArray(s_externalLinkTag) < 0)
                {
                    continue;
                }
                XElement xel = XElement.Parse(dto.Xml);
                if (FixExternalLinks(xel, project))
                {
                    DataMigrationServices.UpdateDTO(domainObjectDtoRepository, dto, xel.ToString());
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }