Delint() static private method

1. Remove objects (zombies) that: A. claim to have owners, but the owners do not exist, or B. owners don't know they own it, or C. objects with no owners that are not supported as allowing no owners. 2. Remove 'dangling' references to objects that no longer exist. 3. Remove properties that have no attributes or content.
static private Delint ( IDomainObjectDTORepository dtoRepos ) : void
dtoRepos IDomainObjectDTORepository
return void
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// 1) Remove orphaned CmBaseAnnotations, as per FWR-98:
        /// "Since we won't try to reuse wfic or segment annotations that no longer have
        /// BeginObject point to a paragraph, we should remove (ignore) these annotations
        /// when migrating an old database (FW 6.0 or older) into the new architecture"
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000007);

/* Expected data (relevant data, that is) format.
 *                      <rt guid="22a8431f-f974-412f-a261-8bd1a4e1be1b" class="CmBaseAnnotation">
 *                              <CmObject />
 *                              <CmAnnotation>
 *                                      <AnnotationType> <!-- Entire element will be missing if prop is null. -->
 *                                              <objsur guid="eb92e50f-ba96-4d1d-b632-057b5c274132" t="r" />
 *                                      </AnnotationType>
 *                              </CmAnnotation>
 *                              <CmBaseAnnotation>
 *                                      <BeginObject> <!-- Entire element will be missing if prop is null. -->
 *                                              <objsur guid="93dcb15d-f622-4329-b1b5-e5cc832daf01" t="r" />
 *                                      </BeginObject>
 *                              </CmBaseAnnotation>
 *                      </rt>
 */
            var interestingAnnDefIds = new List <string>
            {
                DataMigrationServices.kSegmentAnnDefnGuid.ToLower(),
                DataMigrationServices.kTwficAnnDefnGuid.ToLower(),
                DataMigrationServices.kPficAnnDefnGuid.ToLower(),
                DataMigrationServices.kConstituentChartAnnotationAnnDefnGuid.ToLower()
            };

            //Collect up the ones to be removed.
            var goners = new List <DomainObjectDTO>();

            foreach (var annDTO in domainObjectDtoRepository.AllInstancesSansSubclasses("CmBaseAnnotation"))
            {
                var annElement  = XElement.Parse(annDTO.Xml);
                var typeElement = annElement.Element("CmAnnotation").Element("AnnotationType");
                if (typeElement == null ||
                    !interestingAnnDefIds.Contains(typeElement.Element("objsur").Attribute("guid").Value.ToLower()))
                {
                    continue;                     // uninteresing annotation type, so skip it.
                }
                // annDTO is a segment, wordform, punctform, or constituent chart annotation.
                if (annElement.Element("CmBaseAnnotation").Element("BeginObject") != null)
                {
                    continue;                     // Has data in BeginObject property, so skip it.
                }
                goners.Add(annDTO);
            }

            // Remove them.
            foreach (var goner in goners)
            {
                DataMigrationServices.RemoveIncludingOwnedObjects(domainObjectDtoRepository, goner, true);
            }

            // Some stuff may reference the defective Discourse Cahrt Annotation, so clear out the refs to them.
            DataMigrationServices.Delint(domainObjectDtoRepository);

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <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, 7000061);

            // Step 1.
            foreach (var resourceDto in domainObjectDtoRepository.AllInstancesSansSubclasses("CmResource"))
            {
                var resourceElement     = XElement.Parse(resourceDto.Xml);
                var resourceNameElement = resourceElement.Element("Name");
                if (resourceNameElement == null)
                {
                    continue;
                }
                var uniElement = resourceNameElement.Element("Uni");
                if (uniElement == null)
                {
                    continue;
                }
                string oldVersion;
                switch (uniElement.Value)
                {
                case "TeStyles":
                    oldVersion = "700176e1-4f42-4abd-8fb5-3c586670085d";
                    break;

                case "FlexStyles":
                    oldVersion = "13c213b9-e409-41fc-8782-7ca0ee983b2c";
                    break;

                default:
                    continue;
                }
                var versionElement = resourceElement.Element("Version");
                if (versionElement == null)
                {
                    resourceElement.Add(new XElement("Version", new XAttribute("val", oldVersion)));
                }
                else
                {
                    versionElement.Attribute("val").Value = oldVersion;
                }
                resourceDto.Xml = resourceElement.ToString();
                domainObjectDtoRepository.Update(resourceDto);
            }

            // Step 2.
            DataMigrationServices.Delint(domainObjectDtoRepository);

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
        public void PerformMigration(IDomainObjectDTORepository repoDto)
        {
            DataMigrationServices.CheckVersionNumber(repoDto, 7000060);

            // Step 1.A. & 3.
            //var unownedGonerCandidates = new List<DomainObjectDTO>();
            //unownedGonerCandidates.AddRange(repoDto.AllInstancesSansSubclasses("CmBaseAnnotation"));
            //unownedGonerCandidates.AddRange(repoDto.AllInstancesSansSubclasses("CmIndirectAnnotation"));
            //unownedGonerCandidates.AddRange(repoDto.AllInstancesSansSubclasses("StStyle"));
            //unownedGonerCandidates.AddRange(repoDto.AllInstancesSansSubclasses("StText"));
            //var unownedGoners = new List<DomainObjectDTO>();
            //foreach (var domainObjectDto in unownedGonerCandidates)
            //{
            //    DomainObjectDTO ownerDto;
            //    repoDto.TryGetOwner(domainObjectDto.Guid, out ownerDto);
            //    if (ownerDto != null)
            //        continue;
            //    unownedGoners.Add(domainObjectDto);
            //}
            //foreach (var unownedGoner in unownedGoners)
            //{
            //    DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, unownedGoner, false);
            //}

            // Step 1.B.
            foreach (var resourceDto in repoDto.AllInstancesSansSubclasses("CmResource"))
            {
                var resourceElement     = XElement.Parse(resourceDto.Xml);
                var resourceNameElement = resourceElement.Element("Name");
                if (resourceNameElement == null)
                {
                    continue;
                }
                var uniElement = resourceNameElement.Element("Uni");
                if (uniElement == null)
                {
                    continue;
                }
                string oldVersion;
                switch (uniElement.Value)
                {
                case "TeStyles":
                    oldVersion = "700176e1-4f42-4abd-8fb5-3c586670085d";
                    break;

                case "FlexStyles":
                    oldVersion = "13c213b9-e409-41fc-8782-7ca0ee983b2c";
                    break;

                default:
                    continue;
                }
                var versionElement = resourceElement.Element("Version");
                if (versionElement == null)
                {
                    resourceElement.Add(new XElement("Version", new XAttribute("val", oldVersion)));
                }
                else
                {
                    versionElement.Attribute("val").Value = oldVersion;
                }
                resourceDto.Xml = resourceElement.ToString();
                repoDto.Update(resourceDto);
            }

            // Step 2.
            var mdc = repoDto.MDC;

            foreach (var clid in mdc.GetClassIds())
            {
                if (mdc.GetAbstract(clid))
                {
                    continue;
                }

                var className = mdc.GetClassName(clid);
                foreach (var atomicPropId in mdc.GetFields(clid, true, (int)CellarPropertyTypeFilter.AllAtomic))
                {
                    var propName         = mdc.GetFieldName(atomicPropId);
                    var isCustomProperty = mdc.IsCustom(atomicPropId);
                    foreach (var dto in repoDto.AllInstancesSansSubclasses(className))
                    {
                        var element     = XElement.Parse(dto.Xml);
                        var propElement = isCustomProperty
                                                                                          ? (element.Elements("Custom").Where(customPropElement => customPropElement.Attribute("name").Value == propName)).FirstOrDefault()
                                                                                          : element.Element(propName);
                        if (propElement == null || !propElement.HasElements)
                        {
                            continue;
                        }

                        var objsurElements = propElement.Elements("objsur").ToList();
                        if (objsurElements.Count <= 1)
                        {
                            continue;
                        }

                        // Remove all but first one of them.
                        propElement.RemoveNodes();
                        propElement.Add(objsurElements[0]);
                        dto.Xml = element.ToString();
                        repoDto.Update(dto);
                    }
                }
            }

            // Step 4.
            DataMigrationServices.Delint(repoDto);

            DataMigrationServices.IncrementVersionNumber(repoDto);
        }