Пример #1
0
		/// ------------------------------------------------------------------------------------
		/// <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);
		}
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Пример #3
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);
        }
Пример #4
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, 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);
		}
Пример #5
0
		/// <summary>
		/// Updates the Data Notebook RecordTypes possibilities to use specific GUIDs.
		/// </summary>
		/// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for one migration step.</param>
		public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
		{
			DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000010);

			DomainObjectDTO nbkDto = domainObjectDtoRepository.AllInstancesSansSubclasses("RnResearchNbk").First();
			XElement nbkElem = XElement.Parse(nbkDto.Xml);
			var recTypesGuid = (string) nbkElem.XPathSelectElement("RnResearchNbk/RecTypes/objsur").Attribute("guid");
			var stack = new Stack<DomainObjectDTO>(domainObjectDtoRepository.GetDirectlyOwnedDTOs(recTypesGuid));
			IEnumerable<DomainObjectDTO> recDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("RnGenericRec");
			IEnumerable<DomainObjectDTO> overlayDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("CmOverlay");
			while (stack.Count > 0)
			{
				DomainObjectDTO dto = stack.Pop();
				foreach (DomainObjectDTO childDto in domainObjectDtoRepository.GetDirectlyOwnedDTOs(dto.Guid))
					stack.Push(childDto);
				XElement posElem = XElement.Parse(dto.Xml);
				XElement uniElem = posElem.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']");
				if (uniElem != null)
				{
					string newGuid = null;
					switch (uniElem.Value)
					{
						case "Con":
							newGuid = "B7B37B86-EA5E-11DE-80E9-0013722F8DEC";
							break;
						case "Intv":
							newGuid = "B7BF673E-EA5E-11DE-9C4D-0013722F8DEC";
							break;
						case "Str":
							newGuid = "B7C8F092-EA5E-11DE-8D7D-0013722F8DEC";
							break;
						case "Uns":
							newGuid = "B7D4DC4A-EA5E-11DE-867C-0013722F8DEC";
							break;
						case "Lit":
							newGuid = "B7E0C7F8-EA5E-11DE-82CC-0013722F8DEC";
							break;
						case "Obs":
							newGuid = "B7EA5156-EA5E-11DE-9F9C-0013722F8DEC";
							break;
						case "Per":
							newGuid = "B7F63D0E-EA5E-11DE-9F02-0013722F8DEC";
							break;
						case "Ana":
							newGuid = "82290763-1633-4998-8317-0EC3F5027FBD";
							break;
					}
					if (newGuid != null)
						DataMigrationServices.ChangeGuid(domainObjectDtoRepository, dto, newGuid, recDtos.Concat(overlayDtos));
				}
			}

			DomainObjectDTO recTypesDto = domainObjectDtoRepository.GetDTO(recTypesGuid);
			DataMigrationServices.ChangeGuid(domainObjectDtoRepository, recTypesDto, "D9D55B12-EA5E-11DE-95EF-0013722F8DEC", overlayDtos);
			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #6
0
		public void PerformMigration(IDomainObjectDTORepository repoDto)
		{
			DataMigrationServices.CheckVersionNumber(repoDto, 7000041);

			var dtoLexDb = repoDto.AllInstancesSansSubclasses("LexDb").First();
			var xeLexDb = XElement.Parse(dtoLexDb.Xml);
			var guidComplexTypes = GetGuidValue(xeLexDb, "ComplexEntryTypes/objsur");
			var guidVariantTypes = GetGuidValue(xeLexDb, "VariantEntryTypes/objsur");
			BuildStandardMaps(guidComplexTypes, guidVariantTypes);
			var extraTypes = new List<LexTypeInfo>();
			var unprotectedTypes = new List<LexTypeInfo>();
			foreach (var dto in repoDto.AllInstancesSansSubclasses("LexEntryType"))
			{
				var xeType = XElement.Parse(dto.Xml);
				// ReSharper disable PossibleNullReferenceException
				var guid = xeType.Attribute("guid").Value;
				// ReSharper restore PossibleNullReferenceException
				string name;
				if (m_mapGuidName.TryGetValue(guid, out name))
				{
					m_mapGuidName.Remove(guid);
					m_mapNameGuid.Remove(name);
					var xeProt = xeType.XPathSelectElement("IsProtected");
					if (xeProt == null)
					{
						unprotectedTypes.Add(new LexTypeInfo(dto, xeType));
					}
					else
					{
						var xaVal = xeProt.Attribute("val");
						if (xaVal == null || xaVal.Value.ToLowerInvariant() != "true")
							unprotectedTypes.Add(new LexTypeInfo(dto, xeType));
					}
				}
				else
				{
					extraTypes.Add(new LexTypeInfo(dto, xeType));
				}
			}
			foreach (var info in unprotectedTypes)
			{
				var xeProt = info.XmlElement.XPathSelectElement("IsProtected");
				if (xeProt != null)
					xeProt.Remove();
				info.XmlElement.Add(new XElement("IsProtected", new XAttribute("val", "true")));
				info.DTO.Xml = info.XmlElement.ToString();
				repoDto.Update(info.DTO);
			}
			if (m_mapGuidName.Count > 0)
				FixOrAddMissingTypes(repoDto, extraTypes);
			FixOwnershipOfSubtypes(repoDto);
			DataMigrationServices.IncrementVersionNumber(repoDto);
		}
Пример #7
0
        /// <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());
            }
        }
Пример #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Changes all StFootnotes to 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, 7000002);

			var footnotesToChangeClasses = new List<DomainObjectDTO>();
			foreach (var footnote in domainObjectDtoRepository.AllInstancesSansSubclasses("StFootnote"))
			{
				XElement footnoteEl = XElement.Parse(footnote.Xml);
				footnoteEl.Attribute("class").Value = "ScrFootnote";

				// Add the empty ScrFootnote element to the ScrFootnote
				footnoteEl.Add(new XElement("ScrFootnote"));

				// Update the object XML
				footnote.Xml = footnoteEl.ToString();
				footnote.Classname = "ScrFootnote";
				footnotesToChangeClasses.Add(footnote);
			}

			// Udate the repository
			var startingStructure = new ClassStructureInfo("StText", "StFootnote");
			var endingStructure = new ClassStructureInfo("StFootnote", "ScrFootnote");
			foreach (var changedPara in footnotesToChangeClasses)
				domainObjectDtoRepository.Update(changedPara,
					startingStructure,
					endingStructure);

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #9
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);
		}
Пример #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Looks for CmFile objects included in LangProject. If found, will look for CmFile in
		/// correct location and replace reference on CmPicture with that new CmFile.
		/// </summary>
		/// <param name="repoDto">
		/// Repository of all CmObject DTOs available for one migration step.
		/// </param>
		/// <remarks>
		/// 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, 7000033);
			var langProj = repoDto.AllInstancesSansSubclasses("LangProject").First();
			var langProjElement = XElement.Parse(langProj.Xml);
			var pictures = langProjElement.Element("Pictures");

			if (pictures != null && pictures.Elements().Count() > 1)
			{
				DomainObjectDTO folder = null;
				bool foundFiles = false;
				foreach (var x in pictures.Elements())
				{
					var xObj = repoDto.GetDTO(x.Attribute("guid").Value);
					if (xObj.Classname == "CmFolder")
					{
						// empty folders can just be removed
						var xObjElement = XElement.Parse(xObj.Xml);
						if (xObjElement.Element("Files") == null)
							DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, xObj, true);
						else if (folder == null)
							folder = xObj;
						else
							MoveFileReferences(repoDto, langProj, xObj, folder);
					}
					else
						foundFiles = true;
				}

				if (folder != null && foundFiles)
					RemoveInvalidFiles(repoDto, langProj, folder);

			}
			DataMigrationServices.IncrementVersionNumber(repoDto);
		}
        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);
        }
Пример #12
0
		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);
		}
Пример #13
0
        public void PerformMigration(IDomainObjectDTORepository repoDto)
        {
            DataMigrationServices.CheckVersionNumber(repoDto, 7000019);

            var viewsToDelete = new List <DomainObjectDTO>();

            foreach (var dtoView in repoDto.AllInstancesSansSubclasses("UserView"))
            {
                var xeView = XElement.Parse(dtoView.Xml);
                var xeApp  = xeView.Element("App");
                if (xeApp == null)
                {
                    continue;
                }
                var val = xeApp.Attribute("val");
                if (val == null)
                {
                    continue;
                }
                var guidApp = new Guid(val.Value);
                if (guidApp == m_guidNotebook || guidApp == m_guidListEditor)
                {
                    viewsToDelete.Add(dtoView);
                }
            }
            foreach (var dto in viewsToDelete)
            {
                DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, dto, false);
            }
            viewsToDelete.Clear();

            DataMigrationServices.IncrementVersionNumber(repoDto);
        }
Пример #14
0
        private void VerifyScriptureStylesUnchanged(IDomainObjectDTORepository repoDTO)
        {
            int cExternal = 0;
            int cInternal = 0;
            int cLangCode = 0;

            foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("ScrTxtPara"))
            {
                string sXml = dto.Xml;
                if (sXml.Contains(" namedStyle=\"External Link\""))
                {
                    ++cExternal;
                }
                if (sXml.Contains(" namedStyle=\"Internal Link\""))
                {
                    ++cInternal;
                }
                if (sXml.Contains(" namedStyle=\"Language Code\""))
                {
                    ++cLangCode;
                }
            }
            Assert.AreEqual(1, cExternal, "Scripture paragraphs retain External Link style reference");
            Assert.AreEqual(1, cInternal, "Scripture paragraphs retain Internal Link style reference");
            Assert.AreEqual(1, cLangCode, "Scripture paragraphs retain Language Code style reference");
        }
Пример #15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Delete all UserViews
        /// </summary>
        /// <param name="repoDto">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must remove DTOs from the repository.
        ///
        /// 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, 7000030);

            List <DomainObjectDTO> viewsToDelete = new List <DomainObjectDTO>();

            foreach (DomainObjectDTO dtoView in repoDto.AllInstancesSansSubclasses("UserView"))
            {
                XElement xeView = XElement.Parse(dtoView.Xml);
                XElement xeApp  = xeView.Element("App");
                if (xeApp == null)
                {
                    continue;
                }
                XAttribute val = xeApp.Attribute("val");
                if (val == null)
                {
                    continue;
                }
                viewsToDelete.Add(dtoView);
            }
            foreach (var dto in viewsToDelete)
            {
                DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, dto, false);
            }
            viewsToDelete.Clear();

            DataMigrationServices.IncrementVersionNumber(repoDto);
        }
Пример #16
0
        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);
        }
Пример #17
0
        private Dictionary <string, List <DomainObjectDTO> > CreateFileGuidToPictureMap(IDomainObjectDTORepository repoDto)
        {
            var map = new Dictionary <string, List <DomainObjectDTO> >();

            foreach (var picture in repoDto.AllInstancesSansSubclasses("CmPicture"))
            {
                // all TE pictures are unowned, so no need to look at those with owners
                if (repoDto.GetOwningDTO(picture) == null)
                {
                    var pictureElement     = XElement.Parse(picture.Xml);
                    var pictureFileElement = pictureElement.Element("PictureFile");
                    // FWR-3385: not sure how this could happen, but it has occurred in
                    // real data
                    if (pictureFileElement == null)
                    {
                        continue;
                    }
                    var objSurrogateElement = pictureFileElement.Element("objsur");
                    var fileGuid            = objSurrogateElement.Attribute("guid").Value;

                    List <DomainObjectDTO> list;
                    if (!map.TryGetValue(fileGuid, out list))
                    {
                        list          = new List <DomainObjectDTO>();
                        map[fileGuid] = list;
                    }
                    list.Add(picture);
                }
            }
            return(map);
        }
Пример #18
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Пример #19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Changes all StTxtParas that are owned by Scripture to be ScrTxtParas
		/// </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, 7000001);

			var parasToChangeClasses = new List<DomainObjectDTO>();
			foreach (var stTxtPara in domainObjectDtoRepository.AllInstancesSansSubclasses("StTxtPara"))
			{
				var paraOwner = domainObjectDtoRepository.GetOwningDTO(stTxtPara);
				if (paraOwner.Classname != "StText" && paraOwner.Classname != "StFootnote")
				{
					continue; // Paragraph is not owned by an StText or StFootnote (shouldn't ever happen)
				}

				var textOwner = domainObjectDtoRepository.GetOwningDTO(paraOwner);
				if (textOwner.Classname != "ScrBook" && textOwner.Classname != "ScrSection")
				{
					continue; // StText is not part of Scripture, don't change.
				}
				// Its one of the paragraphs that we care about. We just need to change the
				// class in the xml to be a ScrTxtPara and change the objectsByClass map.
				DataMigrationServices.ChangeToSubClass(stTxtPara, "StTxtPara", "ScrTxtPara");
				parasToChangeClasses.Add(stTxtPara);
			}

			// Udate the repository
			var startingStructure = new ClassStructureInfo("StPara", "StTxtPara");
			var endingStructure = new ClassStructureInfo("StTxtPara", "ScrTxtPara");
			foreach (var changedPara in parasToChangeClasses)
				domainObjectDtoRepository.Update(changedPara,
					startingStructure,
					endingStructure);

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #20
0
		/// ------------------------------------------------------------------------------------
		/// <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);
		}
Пример #21
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Changes all StFootnotes to 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, 7000002);

            var footnotesToChangeClasses = new List <DomainObjectDTO>();

            foreach (var footnote in domainObjectDtoRepository.AllInstancesSansSubclasses("StFootnote"))
            {
                XElement footnoteEl = XElement.Parse(footnote.Xml);
                footnoteEl.Attribute("class").Value = "ScrFootnote";

                // Add the empty ScrFootnote element to the ScrFootnote
                footnoteEl.Add(new XElement("ScrFootnote"));

                // Update the object XML
                footnote.Xml       = footnoteEl.ToString();
                footnote.Classname = "ScrFootnote";
                footnotesToChangeClasses.Add(footnote);
            }

            // Udate the repository
            var startingStructure = new ClassStructureInfo("StText", "StFootnote");
            var endingStructure   = new ClassStructureInfo("StFootnote", "ScrFootnote");

            foreach (var changedPara in footnotesToChangeClasses)
            {
                domainObjectDtoRepository.Update(changedPara,
                                                 startingStructure,
                                                 endingStructure);
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Пример #22
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);
        }
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Пример #25
0
        /// <summary>We update every instance of a Restriction in a LexEntry or a LexSense to change from AUni to AStr.</summary>
        private static void UpdateRestrictions(IDomainObjectDTORepository repoDto)
        {
            var xpathToRestrictionsElt = "//Restrictions";

            foreach (var entryOrSenseDto in repoDto.AllInstancesSansSubclasses("LexEntry").Union(repoDto.AllInstancesSansSubclasses("LexSense")))
            {
                ChangeMultiUnicodeElementToMultiString(repoDto, entryOrSenseDto, xpathToRestrictionsElt);
            }
        }
Пример #26
0
		/// ------------------------------------------------------------------------------------
		/// <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);
		}
Пример #27
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);
		}
Пример #28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change any CmFile filePaths to relative paths which are actually relative to the LinkedFilesRootDir
        /// </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, 7000028);

            var    langProjDto               = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            var    langProjElement           = XElement.Parse(langProjDto.Xml);
            var    linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
            string persistedLinkedFilesRootDir;

            if (linkedFilesRootDirElement == null)
            {
                persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, FdoFileHelper.ksLinkedFilesDir);
            }
            else
            {
                persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
            }
            var linkedFilesRootDir = LinkedFilesRelativePathHelper.GetLinkedFilesFullPathFromRelativePath(domainObjectDtoRepository.Directories.ProjectsDirectory,
                                                                                                          persistedLinkedFilesRootDir, domainObjectDtoRepository.ProjectFolder);
            //Get the Elements  for class="CmFile"
            var CmFileDtosBeforeMigration = domainObjectDtoRepository.AllInstancesSansSubclasses("CmFile");

            foreach (var fileDto in CmFileDtosBeforeMigration)
            {
                XElement cmFileXML          = XElement.Parse(fileDto.Xml);
                var      filePath           = cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value;
                var      fileAsRelativePath = LinkedFilesRelativePathHelper.GetRelativeLinkedFilesPath(filePath,
                                                                                                       linkedFilesRootDir);
                //If these two strings do not match then a full path was converted to a LinkedFiles relative path
                //so replace the path in the CmFile object.
                // (If fileAsRelativePath is null, we could not make sense of the path at all; it may be corrupt.
                // Certainly we can't improve it!)
                if (fileAsRelativePath != null && !String.Equals(fileAsRelativePath, filePath))
                {
                    cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value = fileAsRelativePath;
                    UpdateDto(domainObjectDtoRepository, fileDto, cmFileXML);
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Пример #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);
        }
Пример #30
0
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000065);

            // Cache all basic data properties for each class in the mdc.
            var mdc = domainObjectDtoRepository.MDC;
            var cachedBasicProperties = CacheBasicProperties(mdc);

            foreach (var kvp in cachedBasicProperties)
            {
                var className = kvp.Key;
                if (mdc.GetAbstract(mdc.GetClassId(className)))
                {
                    continue;                     // Won't find any of those as dtos.
                }
                var basicProps = kvp.Value;
                foreach (var dto in domainObjectDtoRepository.AllInstancesSansSubclasses(className))
                {
                    var rootElementChanged = false;
                    var rootElement        = XElement.Parse(dto.Xml);
                    foreach (var basicPropertyInfo in basicProps)
                    {
                        if (basicPropertyInfo.m_isCustom)
                        {
                            var customPropElement = rootElement.Elements("Custom").FirstOrDefault(element => element.Attribute("name").Value == basicPropertyInfo.m_propertyName);
                            if (customPropElement == null)
                            {
                                CreateCustomProperty(rootElement, basicPropertyInfo);
                                rootElementChanged = true;
                            }
                        }
                        else
                        {
                            var basicPropertyElement = rootElement.Element(basicPropertyInfo.m_propertyName);
                            if (basicPropertyElement == null && !SkipTheseBasicPropertyNames.Contains(basicPropertyInfo.m_propertyName) && !basicPropertyInfo.m_isVirtual)
                            {
                                CreateBasicProperty(rootElement, basicPropertyInfo);
                                rootElementChanged = true;
                            }
                        }
                    }
                    if (!rootElementChanged)
                    {
                        continue;
                    }

                    dto.Xml = rootElement.ToString();
                    domainObjectDtoRepository.Update(dto);
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Пример #31
0
		/// ------------------------------------------------------------------------------------
		/// <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);
		}
Пример #32
0
        /// <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());
            }
        }
Пример #33
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, 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);
        }
Пример #34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Change any CmFile filePaths to relative paths which are actually relative to the LinkedFilesRootDir
		/// </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, 7000028);

			var langProjDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
			var langProjElement = XElement.Parse(langProjDto.Xml);
			var linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
			string persistedLinkedFilesRootDir;
			if (linkedFilesRootDirElement == null)
			{
				persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, FdoFileHelper.ksLinkedFilesDir);
			}
			else
			{
				persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
			}
			var linkedFilesRootDir = LinkedFilesRelativePathHelper.GetLinkedFilesFullPathFromRelativePath(domainObjectDtoRepository.Directories.ProjectsDirectory,
				persistedLinkedFilesRootDir, domainObjectDtoRepository.ProjectFolder);
			//Get the Elements  for class="CmFile"
			var CmFileDtosBeforeMigration = domainObjectDtoRepository.AllInstancesSansSubclasses("CmFile");

			foreach (var fileDto in CmFileDtosBeforeMigration)
			{
				XElement cmFileXML = XElement.Parse(fileDto.Xml);
				var filePath = cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value;
				var fileAsRelativePath = LinkedFilesRelativePathHelper.GetRelativeLinkedFilesPath(filePath,
																								 linkedFilesRootDir);
				//If these two strings do not match then a full path was converted to a LinkedFiles relative path
				//so replace the path in the CmFile object.
				// (If fileAsRelativePath is null, we could not make sense of the path at all; it may be corrupt.
				// Certainly we can't improve it!)
				if (fileAsRelativePath != null && !String.Equals(fileAsRelativePath, filePath))
				{
					cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value = fileAsRelativePath;
					UpdateDto(domainObjectDtoRepository, fileDto, cmFileXML);
				}
			}

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #35
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);
        }
Пример #37
0
/// <summary>
        /// Change any RnGenericRecord whose status is oldStatus to be newStatus.
        /// </summary>
        private void ReassignStatuses(IDomainObjectDTORepository domainObjectDtoRepository, string oldStatus, string newStatus)
        {
            // We need to go through tha collection because we need to change all status 'Appproved' to 'Confirmed'
            foreach (var RnRecDto in domainObjectDtoRepository.AllInstancesSansSubclasses("RnGenericRec").ToArray())
            {
                var rnElement = XElement.Parse(RnRecDto.Xml);
                if (!UpdateStatusInElement(rnElement, oldStatus, newStatus))
                {
                    continue;
                }
                RnRecDto.Xml = rnElement.ToString();
                domainObjectDtoRepository.Update(RnRecDto);
            }
        }
Пример #38
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);
        }
Пример #39
0
        private static string ExtractPrimaryWsFromLangProj(IDomainObjectDTORepository dtoRepos, bool analysis)
        {
            const string defaultWs = "en";
            var          propName  = analysis ? "CurAnalysisWss" : "CurVernWss";
            var          langProj  = dtoRepos.AllInstancesSansSubclasses("LangProject").FirstOrDefault();

            if (langProj == null)             // We must be in a test! A real test that cares should have a LangProject element!
            {
                return(defaultWs);
            }
            var propString = XElement.Parse(langProj.Xml).Element(propName).Element("Uni").Value;

            return(propString.Split(' ')[0]);
        }
Пример #40
0
		public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
		{
			DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000065);

			// Cache all basic data properties for each class in the mdc.
			var mdc = domainObjectDtoRepository.MDC;
			var cachedBasicProperties = CacheBasicProperties(mdc);
			foreach (var kvp in cachedBasicProperties)
			{
				var className = kvp.Key;
				if (mdc.GetAbstract(mdc.GetClassId(className)))
					continue; // Won't find any of those as dtos.

				var basicProps = kvp.Value;
				foreach (var dto in domainObjectDtoRepository.AllInstancesSansSubclasses(className))
				{
					var rootElementChanged = false;
					var rootElement = XElement.Parse(dto.Xml);
					foreach (var basicPropertyInfo in basicProps)
					{
						if (basicPropertyInfo.m_isCustom)
						{
							var customPropElement = rootElement.Elements("Custom").FirstOrDefault(element => element.Attribute("name").Value == basicPropertyInfo.m_propertyName);
							if (customPropElement == null)
							{
								CreateCustomProperty(rootElement, basicPropertyInfo);
								rootElementChanged = true;
							}
						}
						else
						{
							var basicPropertyElement = rootElement.Element(basicPropertyInfo.m_propertyName);
							if (basicPropertyElement == null && !SkipTheseBasicPropertyNames.Contains(basicPropertyInfo.m_propertyName) && !basicPropertyInfo.m_isVirtual)
							{
								CreateBasicProperty(rootElement, basicPropertyInfo);
								rootElementChanged = true;
							}
						}
					}
					if (!rootElementChanged)
						continue;

					dto.Xml = rootElement.ToString();
					domainObjectDtoRepository.Update(dto);
				}
			}

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #41
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Change the property LangProject.ExtLinkRootDir to LangProject.LinkedFilesRootDir
		/// </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, 7000025);

			// 1. Change the property LangProject.ExtLinkRootDir to LangProject.LinkedFilesRootDir

			var langProjDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
			var langProjElement = XElement.Parse(langProjDto.Xml);
			var ExtLinkRootDirElement = langProjElement.Element("ExtLinkRootDir");
			if (ExtLinkRootDirElement != null)
				ExtLinkRootDirElement.Name = "LinkedFilesRootDir";
			UpdateDto(domainObjectDtoRepository, langProjDto, langProjElement);


			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #42
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Changes Chart 'missing' markers from invalid ConstChartWordGroup references to
        /// ConstChartTag objects with null Tag property.
        /// </summary>
        /// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for
        /// one migration step.</param>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000012);

            // 1) Select the ConstChartWordGroup class objects.
            // 2) Convert any with null BeginSegment reference to ConstChartTag objects with null Tag reference.
            var objsToChangeClasses = new List <DomainObjectDTO>();

            foreach (var cellPartDto in domainObjectDtoRepository.AllInstancesSansSubclasses("ConstChartWordGroup"))
            {
                var rtElement = XElement.Parse(cellPartDto.Xml);

                // Only migrate the ones that have no BeginSegment
                var wordGrp = rtElement.Element("ConstChartWordGroup");
                if (wordGrp.Element("BeginSegment") != null)
                {
                    continue;                     // Don't migrate this one, it has a BeginSegment reference!
                }
                // change its class value
                rtElement.Attribute("class").Value = "ConstChartTag";

                // Add the empty ConstChartTag element
                rtElement.Add(new XElement("ConstChartTag"));

                // Remove the old WordGroup element
                RemoveField(cellPartDto, rtElement, "ConstChartWordGroup");

                // Update the object XML
                cellPartDto.Xml       = rtElement.ToString();
                cellPartDto.Classname = "ConstChartTag";
                objsToChangeClasses.Add(cellPartDto);
            }

            // Update the repository
            var startingStructure = new ClassStructureInfo("ConstituentChartCellPart", "ConstChartWordGroup");
            var endingStructure   = new ClassStructureInfo("ConstituentChartCellPart", "ConstChartTag");

            foreach (var changedCellPart in objsToChangeClasses)
            {
                domainObjectDtoRepository.Update(changedCellPart,
                                                 startingStructure,
                                                 endingStructure);
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Пример #43
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);
		}
Пример #44
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);
		}
Пример #45
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);
		}
Пример #46
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Looks for CmFile objects included in LangProject. If found, will look for CmFile in
        /// correct location and replace reference on CmPicture with that new CmFile.
        /// </summary>
        /// <param name="repoDto">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// 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, 7000033);
            var langProj        = repoDto.AllInstancesSansSubclasses("LangProject").First();
            var langProjElement = XElement.Parse(langProj.Xml);
            var pictures        = langProjElement.Element("Pictures");

            if (pictures != null && pictures.Elements().Count() > 1)
            {
                DomainObjectDTO folder     = null;
                bool            foundFiles = false;
                foreach (var x in pictures.Elements())
                {
                    var xObj = repoDto.GetDTO(x.Attribute("guid").Value);
                    if (xObj.Classname == "CmFolder")
                    {
                        // empty folders can just be removed
                        var xObjElement = XElement.Parse(xObj.Xml);
                        if (xObjElement.Element("Files") == null)
                        {
                            DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, xObj, true);
                        }
                        else if (folder == null)
                        {
                            folder = xObj;
                        }
                        else
                        {
                            MoveFileReferences(repoDto, langProj, xObj, folder);
                        }
                    }
                    else
                    {
                        foundFiles = true;
                    }
                }

                if (folder != null && foundFiles)
                {
                    RemoveInvalidFiles(repoDto, langProj, folder);
                }
            }
            DataMigrationServices.IncrementVersionNumber(repoDto);
        }
Пример #47
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// FWR-2461 Data Migration: for links to files in TsStrings
        ///--turn paths into relative paths to the LinkedFiledRootDir where possible
        ///--create a CmFile for each link found in a TsString owned by a CmFolder)
        /// </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, 7000029);

            var    langProjDto               = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            var    langProjElement           = XElement.Parse(langProjDto.Xml);
            var    linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
            string persistedLinkedFilesRootDir;

            if (linkedFilesRootDirElement == null)
            {
                persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, FdoFileHelper.ksLinkedFilesDir);
            }
            else
            {
                persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
            }
            var linkedFilesRootDir = LinkedFilesRelativePathHelper.GetLinkedFilesFullPathFromRelativePath(domainObjectDtoRepository.Directories.ProjectsDirectory,
                                                                                                          persistedLinkedFilesRootDir, domainObjectDtoRepository.ProjectFolder);

            //-------------------------------------------------
            var             langProjectGuid             = langProjElement.Attribute("guid").Value;
            var             filePathsInTsStringsElement = AddFilePathsInTsStringsElement(langProjElement);
            DomainObjectDTO cmFolderDto;
            var             cmFolderXElement = MakeCmFolder(domainObjectDtoRepository, langProjectGuid, filePathsInTsStringsElement, CmFolderTags.LocalFilePathsInTsStrings,
                                                            out cmFolderDto);

            UpdateDto(domainObjectDtoRepository, langProjDto, langProjElement);
            //--------------------------------------------------
            var cmFolderGuid = cmFolderXElement.Attribute("guid").Value;

            var filePathsInTsStrings = ProcessExternalLinksRelativePaths(domainObjectDtoRepository, linkedFilesRootDir);

            foreach (var filePath in filePathsInTsStrings)
            {
                MakeCmFile(domainObjectDtoRepository, cmFolderGuid, cmFolderXElement, filePath);
            }

            //Now that all the CmFile references have been added to the CmFolder update it in the repository.
            UpdateDto(domainObjectDtoRepository, cmFolderDto, cmFolderXElement);

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
Пример #48
0
        /// <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
        }
Пример #49
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);
		}
Пример #50
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);
        }
Пример #51
0
		/// ------------------------------------------------------------------------------------
		/// <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);
		}
Пример #52
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// FWR-2461 Data Migration: for links to files in TsStrings
		///--turn paths into relative paths to the LinkedFiledRootDir where possible
		///--create a CmFile for each link found in a TsString owned by a CmFolder)
		/// </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, 7000029);

			var langProjDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
			var langProjElement = XElement.Parse(langProjDto.Xml);
			var linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
			string persistedLinkedFilesRootDir;
			if (linkedFilesRootDirElement == null)
			{
				persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, FdoFileHelper.ksLinkedFilesDir);
			}
			else
			{
				persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
			}
			var linkedFilesRootDir = LinkedFilesRelativePathHelper.GetLinkedFilesFullPathFromRelativePath(domainObjectDtoRepository.Directories.ProjectsDirectory,
				persistedLinkedFilesRootDir, domainObjectDtoRepository.ProjectFolder);

			//-------------------------------------------------
			var langProjectGuid = langProjElement.Attribute("guid").Value;
			var filePathsInTsStringsElement = AddFilePathsInTsStringsElement(langProjElement);
			DomainObjectDTO cmFolderDto;
			var cmFolderXElement = MakeCmFolder(domainObjectDtoRepository, langProjectGuid, filePathsInTsStringsElement, CmFolderTags.LocalFilePathsInTsStrings,
				out cmFolderDto);
			UpdateDto(domainObjectDtoRepository, langProjDto, langProjElement);
			//--------------------------------------------------
			var cmFolderGuid = cmFolderXElement.Attribute("guid").Value;

			var filePathsInTsStrings = ProcessExternalLinksRelativePaths(domainObjectDtoRepository, linkedFilesRootDir);

			foreach (var filePath in filePathsInTsStrings)
			{
				MakeCmFile(domainObjectDtoRepository, cmFolderGuid, cmFolderXElement, filePath);
			}

			//Now that all the CmFile references have been added to the CmFolder update it in the repository.
			UpdateDto(domainObjectDtoRepository, cmFolderDto, cmFolderXElement);

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #53
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Changes Chart 'missing' markers from invalid ConstChartWordGroup references to
		/// ConstChartTag objects with null Tag property.
		/// </summary>
		/// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for
		/// one migration step.</param>
		/// ------------------------------------------------------------------------------------
		public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
		{
			DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000012);

			// 1) Select the ConstChartWordGroup class objects.
			// 2) Convert any with null BeginSegment reference to ConstChartTag objects with null Tag reference.
			var objsToChangeClasses = new List<DomainObjectDTO>();
			foreach (var cellPartDto in domainObjectDtoRepository.AllInstancesSansSubclasses("ConstChartWordGroup"))
			{
				var rtElement = XElement.Parse(cellPartDto.Xml);

				// Only migrate the ones that have no BeginSegment
				var wordGrp = rtElement.Element("ConstChartWordGroup");
				if (wordGrp.Element("BeginSegment") != null)
					continue; // Don't migrate this one, it has a BeginSegment reference!

				// change its class value
				rtElement.Attribute("class").Value = "ConstChartTag";

				// Add the empty ConstChartTag element
				rtElement.Add(new XElement("ConstChartTag"));

				// Remove the old WordGroup element
				RemoveField(cellPartDto, rtElement, "ConstChartWordGroup");

				// Update the object XML
				cellPartDto.Xml = rtElement.ToString();
				cellPartDto.Classname = "ConstChartTag";
				objsToChangeClasses.Add(cellPartDto);
			}

			// Update the repository
			var startingStructure = new ClassStructureInfo("ConstituentChartCellPart", "ConstChartWordGroup");
			var endingStructure = new ClassStructureInfo("ConstituentChartCellPart", "ConstChartTag");
			foreach (var changedCellPart in objsToChangeClasses)
				domainObjectDtoRepository.Update(changedCellPart,
					startingStructure,
					endingStructure);

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #54
0
		public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
		{
			DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000039);

			foreach (var dto in domainObjectDtoRepository.AllInstancesSansSubclasses("LexEntryRef"))
			{
				var xElt = XElement.Parse(dto.Xml);
				var primaryLexemes = xElt.Element("PrimaryLexemes");
				if (primaryLexemes == null || primaryLexemes.Elements().Count() == 0)
					continue;
				var newElt = new XElement("ShowComplexFormsIn");
				foreach (var child in primaryLexemes.Elements())
				{
					newElt.Add(new XElement(child)); // clone all the objsur elements.
				}
				xElt.Add(newElt);
				dto.Xml = xElt.ToString();
				domainObjectDtoRepository.Update(dto);
			}

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
Пример #55
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete all UserViews
		/// </summary>
		/// <param name="repoDto">
		/// Repository of all CmObject DTOs available for one migration step.
		/// </param>
		/// <remarks>
		/// The method must remove DTOs from the repository.
		///
		/// 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, 7000030);

			List<DomainObjectDTO> viewsToDelete = new List<DomainObjectDTO>();
			foreach (DomainObjectDTO dtoView in repoDto.AllInstancesSansSubclasses("UserView"))
			{
				XElement xeView = XElement.Parse(dtoView.Xml);
				XElement xeApp = xeView.Element("App");
				if (xeApp == null)
					continue;
				XAttribute val = xeApp.Attribute("val");
				if (val == null)
					continue;
				viewsToDelete.Add(dtoView);
			}
			foreach (var dto in viewsToDelete)
				DataMigrationServices.RemoveIncludingOwnedObjects(repoDto, dto, false);
			viewsToDelete.Clear();

			DataMigrationServices.IncrementVersionNumber(repoDto);
		}
		private void VerifyStyleReferencesUpdated(IDomainObjectDTORepository repoDTO)
		{
			int cHyperlink = 0;
			int cWrtSysAbbr = 0;
			int cHyperUsed = 0;
			int cWSAUsed = 0;
			foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("StTxtPara"))
			{
				string sXml = dto.Xml;
				Assert.False(sXml.Contains(" namedStyle=\"External Link\""), "The External Link style should no longer be used");
				Assert.False(sXml.Contains(" namedStyle=\"Internal Link\""), "The Internal Link style should no longer be used");
				Assert.False(sXml.Contains(" namedStyle=\"Language Code\""), "The Language Code style should no longer be used");
				string sHyperlink = " namedStyle=\"Hyperlink\"";
				if (sXml.Contains(sHyperlink))
				{
					++cHyperlink;
					int idx = sXml.IndexOf(sHyperlink);
					while (idx > 0)
					{
						++cHyperUsed;
						idx = sXml.IndexOf(sHyperlink, idx + sHyperlink.Length);
					}
				}
				string sWSA = " namedStyle=\"Writing System Abbreviation\"";
				if (sXml.Contains(sWSA))
				{
					++cWrtSysAbbr;
					int idx = sXml.IndexOf(sWSA);
					while (idx > 0)
					{
						++cWSAUsed;
						idx = sXml.IndexOf(sWSA, idx + sWSA.Length);
					}
				}
			}
			Assert.AreEqual(3, cHyperlink, "The Hyperlink style should be used in three objects");
			Assert.AreEqual(4, cHyperUsed, "The Hyperlink style should be used four times");
			Assert.AreEqual(2, cWrtSysAbbr, "The Writing System Abbreviation style should be used in two objects");
			Assert.AreEqual(2, cWrtSysAbbr, "The Writing System Abbreviation style should be used twice");
		}
		private void VerifyStylesRenamedOrDeleted(IDomainObjectDTORepository repoDTO)
		{
			int cHyperlink = 0;
			int cWrtSysAbbr = 0;
			int cExternalLink = 0;
			int cInternalLink = 0;
			int cLanguageCode = 0;
			int cStrong = 0;
			int cBuiltIn = 0;
			int cCustom = 0;
			bool gotHeading3 = false;
			bool gotHeading5 = false;
			foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("StStyle"))
			{
				Assert.That(dto.Guid.ToUpper(), Is.Not.EqualTo("71B2233D-8B14-42D5-A625-AAC8EDE7503B"),
					"Heading 3 in LexDb duplicates one in LangProj and should have been deleted");
				if (dto.Guid.ToUpper() == "B82D12DE-EA5E-11DE-88CD-0013722F8DEC") // Keeper Heading 3
				{
					gotHeading3 = true;
					var h3Elt = XElement.Parse(dto.Xml);
					Assert.That(h3Elt.Element("Rules").Element("Prop").Attribute("fontFamily").Value, Is.EqualTo("Times New Roman"),
						"should transfer font family setting from lexDB version of heading 3 to lang proj");
					Assert.That(h3Elt.Element("Rules").Element("Prop").Attribute("fontsize").Value, Is.EqualTo("11000"),
						"should transfer font size setting from lexDB version of heading 3 to lang proj");
					Assert.That(h3Elt.Element("BasedOn").Element("objsur").Attribute("guid").Value.ToUpperInvariant, Is.EqualTo("B8238980-EA5E-11DE-86E1-0013722F8DEC"),
						"should transfer based-on information to corresponding style in langproj");
					Assert.That(h3Elt.Element("Next").Element("objsur").Attribute("guid").Value.ToUpperInvariant, Is.EqualTo("B8179DD2-EA5E-11DE-8537-0013722F8DEC"),
						"should transfer next information to corresponding style in langproj");
				}
				if (dto.Guid.ToUpper() == "44944544-DF17-4553-94B8-A5E13C3392C5") // keeper Heading 5
				{
					gotHeading5 = true;
					var h5Elt = XElement.Parse(dto.Xml);
					Assert.That(h5Elt.Element("BasedOn").Element("objsur").Attribute("guid").Value.ToUpperInvariant, Is.EqualTo("B8238980-EA5E-11DE-86E1-0013722F8DEC"),
						"should transfer based-on information to corresponding style in langproj");
					Assert.That(h5Elt.Element("Next").Element("objsur").Attribute("guid").Value.ToUpperInvariant, Is.EqualTo("B8179DD2-EA5E-11DE-8537-0013722F8DEC"),
						"should transfer next information to corresponding style in langproj");
				}
				string sXml = dto.Xml;
				string sName = GetStyleName(sXml);
				DomainObjectDTO dtoOwner = repoDTO.GetOwningDTO(dto);
				if (dtoOwner.Classname != "LangProject")
				{
					Assert.AreEqual(dtoOwner.Classname, "Scripture", "Either LangProject or Scripture owns the style");
					if (sName == "External Link")
						++cExternalLink;
					else if (sName == "Internal Link")
						++cInternalLink;
					else if (sName == "Language Code")
						++cLanguageCode;
				}
				else
				{
					Assert.AreNotEqual(sName, "External Link", "The External Link style should no longer exist");
					Assert.AreNotEqual(sName, "Internal Link", "The Internal Link style should no longer exist");
					Assert.AreNotEqual(sName, "Language Code", "The Language Code style should no longer exist");
					if (sName == "Hyperlink")
						++cHyperlink;
					else if (sName == "Writing System Abbreviation")
						++cWrtSysAbbr;
					else if (sName == "Strong")
						++cStrong;
					if (sXml.Contains("<BasedOn>") || sXml.Contains("<Next>"))
					{
						XElement xeStyle = XElement.Parse(sXml);
						ValidateStyleReference(repoDTO, xeStyle, "BasedOn");
						ValidateStyleReference(repoDTO, xeStyle, "Next");
					}
					switch (sName)
					{
						case "Normal":
						case "Numbered List":
						case "Bulleted List":
						case "Heading 1":
						case "Heading 2":
						case "Heading 3":
						case "Block Quote":
						case "Title Text":
						case "Emphasized Text":
						case "Writing System Abbreviation":
						case "Added Text":
						case "Deleted Text":
						case "Hyperlink":
						case "Strong":
						case "Dictionary-Normal":
						case "Classified-MainEntry":
						case "Classified-Item":
							Assert.IsTrue(IsBuiltInStyle(sXml), sName + " should be marked as built-in");
							++cBuiltIn;
							break;
						default:
							// "Heading 4" and "Dictionary-Custom" should pass through here, plus 7 more
							// created from direct formatting.
							Assert.IsFalse(IsBuiltInStyle(sXml), sName + " should not be marked as built-in");
							++cCustom;
							break;
					}
				}
			}
			Assert.That(gotHeading3, "should have kept the LangProj Heading3");
			Assert.That(gotHeading5, "should have kept the LangProj Heading4");
			Assert.AreEqual(1, cHyperlink, "The Hyperlink style should exist (once)");
			Assert.AreEqual(1, cWrtSysAbbr, "The Writing System Abbreviation style should exist (once)");
			Assert.AreEqual(1, cStrong, "The Strong style should exist (once)");
			Assert.AreEqual(1, cExternalLink, "The External Link style should exist (once) in the Scripture stylesheet");
			Assert.AreEqual(1, cInternalLink, "The Internal Link style should exist (once) in the Scripture stylesheet");
			Assert.AreEqual(1, cLanguageCode, "The Language Code style should exist (once) in the Scripture stylesheet");
			Assert.AreEqual(17, cBuiltIn, "There should be 17 built-in LangProject styles.");
			Assert.AreEqual(9, cCustom, "There should be 9 custom LangProject styles.");

		}
Пример #58
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, 7000018);

			// collect all writing system info
			var guidToWsInfo = new Dictionary<string, Tuple<string, DomainObjectDTO, XElement>>();
			foreach (DomainObjectDTO wsDto in domainObjectDtoRepository.AllInstancesSansSubclasses("LgWritingSystem").ToArray())
			{
				XElement wsElem = XElement.Parse(wsDto.Xml);
				XElement icuLocaleElem = wsElem.Element("ICULocale");
				var icuLocale = icuLocaleElem.Element("Uni").Value;
				string langTag = Version19LangTagUtils.ToLangTag(icuLocale);
				guidToWsInfo[wsDto.Guid.ToLowerInvariant()] = Tuple.Create(langTag, wsDto, wsElem);
			}

			// remove all CmSortSpec objects
			foreach (DomainObjectDTO sortSpecDto in domainObjectDtoRepository.AllInstancesSansSubclasses("CmSortSpec").ToArray())
				domainObjectDtoRepository.Remove(sortSpecDto);

			// remove SortSpecs property from LangProject
			DomainObjectDTO lpDto = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
			XElement lpElem = XElement.Parse(lpDto.Xml);
			XElement sortSpecsElem = lpElem.Element("SortSpecs");
			bool lpModified = false;
			if (sortSpecsElem != null)
			{
				sortSpecsElem.Remove();
				lpModified = true;
			}

			var referencedWsIds = new HashSet<string>();

			// convert all LangProject writing system references to strings
			if (ConvertRefToString(lpElem.Element("AnalysisWss"), guidToWsInfo, referencedWsIds))
				lpModified = true;
			if (ConvertRefToString(lpElem.Element("VernWss"), guidToWsInfo, referencedWsIds))
				lpModified = true;
			if (ConvertRefToString(lpElem.Element("CurAnalysisWss"), guidToWsInfo, referencedWsIds))
				lpModified = true;
			if (ConvertRefToString(lpElem.Element("CurPronunWss"), guidToWsInfo, referencedWsIds))
				lpModified = true;
			if (ConvertRefToString(lpElem.Element("CurVernWss"), guidToWsInfo, referencedWsIds))
				lpModified = true;
			if (lpModified)
				DataMigrationServices.UpdateDTO(domainObjectDtoRepository, lpDto, lpElem.ToString());

			// convert all ReversalIndex writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "ReversalIndex", guidToWsInfo, referencedWsIds);

			// convert all WordformLookupList writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "WordformLookupList", guidToWsInfo, referencedWsIds);

			// convert all CmPossibilityList writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "CmPossibilityList", guidToWsInfo, referencedWsIds);

			// convert all UserViewField writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "UserViewField", guidToWsInfo, referencedWsIds);

			// convert all CmBaseAnnotation writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "CmBaseAnnotation", guidToWsInfo, referencedWsIds);

			// convert all FsOpenFeature writing system references to strings
			ConvertAllRefsToStrings(domainObjectDtoRepository, "FsOpenFeature", guidToWsInfo, referencedWsIds);

			// convert all ScrMarkerMapping ICU locales to lang tags
			ConvertAllIcuLocalesToLangTags(domainObjectDtoRepository, "ScrMarkerMapping", referencedWsIds);

			// convert all ScrImportSource ICU locales to lang tags
			ConvertAllIcuLocalesToLangTags(domainObjectDtoRepository, "ScrImportSource", referencedWsIds);

			// convert all ICU locales to Language Tags and remove legacy magic font names
			foreach (DomainObjectDTO dto in domainObjectDtoRepository.AllInstances())
				UpdateStringsAndProps(domainObjectDtoRepository, dto, referencedWsIds);

			var localStoreFolder = Path.Combine(domainObjectDtoRepository.ProjectFolder, FdoFileHelper.ksWritingSystemsDir);

			// If any writing systems that project needs don't already exist as LDML files,
			// create them, either by copying relevant data from a shipping LDML file, or by
			// extracting data from the obsolete writing system object's XML.
			if (!string.IsNullOrEmpty(domainObjectDtoRepository.ProjectFolder))
			{
				foreach (Tuple<string, DomainObjectDTO, XElement> wsInfo in guidToWsInfo.Values)
				{
					if (referencedWsIds.Contains(wsInfo.Item1))
					{
						var ws = new Version19WritingSystemDefn();
						var langTag = wsInfo.Item1;
						ws.LangTag = langTag;
						var ldmlFileName = Path.ChangeExtension(langTag, "ldml");
						string localPath = Path.Combine(localStoreFolder, ldmlFileName);
						if (File.Exists(localPath))
							continue; // already have one.
						string globalPath = Path.Combine(DirectoryFinder.GlobalWritingSystemStoreDirectory, ldmlFileName);
						if (File.Exists(globalPath))
							continue; // already have one.
						// Need to make one.

						// Code similar to this was in the old migrator (prior to 7000043). It does not work
						// because the XML files it is looking for are in the Languages subdirectory of the
						// FieldWorks 6 data directory, and this is looking in the FW 7 one. No one has complained
						// so we decided not to try to fix it for the new implementation of the migration.

						//string langDefPath = Path.Combine(FwDirectoryFinder.GetDataSubDirectory("Languages"),
						//    Path.ChangeExtension(langTag, "xml"));
						//if (File.Exists(langDefPath))
						//    FillWritingSystemFromLangDef(XElement.Load(langDefPath), ws);
						//else

						FillWritingSystemFromFDO(domainObjectDtoRepository, wsInfo.Item3, ws);
						ws.Save(localPath);
					}
				}
			}
			foreach (Tuple<string, DomainObjectDTO, XElement> wsInfo in guidToWsInfo.Values)
			{
				// this should also remove all LgCollations as well
				DataMigrationServices.RemoveIncludingOwnedObjects(domainObjectDtoRepository, wsInfo.Item2, false);
			}

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}
		private void VerifyScriptureStylesUnchanged(IDomainObjectDTORepository repoDTO)
		{
			int cExternal = 0;
			int cInternal = 0;
			int cLangCode = 0;
			foreach (DomainObjectDTO dto in repoDTO.AllInstancesSansSubclasses("ScrTxtPara"))
			{
				string sXml = dto.Xml;
				if (sXml.Contains(" namedStyle=\"External Link\""))
					++cExternal;
				if (sXml.Contains(" namedStyle=\"Internal Link\""))
					++cInternal;
				if (sXml.Contains(" namedStyle=\"Language Code\""))
					++cLangCode;
			}
			Assert.AreEqual(1, cExternal, "Scripture paragraphs retain External Link style reference");
			Assert.AreEqual(1, cInternal, "Scripture paragraphs retain Internal Link style reference");
			Assert.AreEqual(1, cLangCode, "Scripture paragraphs retain Language Code style reference");
		}
Пример #60
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Changes the use of CmAgentEvaluation, so that instead of one evaluation per agent/target pair
		/// owned by Agent.Evauations and referring to the target, there are only two CmAgentEvaluations
		/// owned by each CmAgent in their Approves and Disapproves properties, and they are referred to
		/// by the new WfiAnalysis.Evaluations Reference Collection.
		///
		/// Specifically, for each CmAgent,
		/// - Create two CmAgentEvaluations, one owned in Approves and one in Disapproves.
		/// - For each item in Evaluations, if Accepted, add the appropriate Approves evaluation to
		///     the target of the evaluation, otherwise, add the appropriate Disapproves (if there is a target).
		/// - Delete the Evaluations.
		///
		/// As a side effect, since all existing CmAgentEvaluations are deleted, obsolete properties are removed.
		/// </summary>
		/// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for
		/// one migration step.</param>
		/// ------------------------------------------------------------------------------------
		public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
		{
			DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000013);

			// from guid of a WfiAnalysis to list of evaluations.
			var map = new Dictionary<string, List<string>>();
			foreach (var agentDto in domainObjectDtoRepository.AllInstancesSansSubclasses("CmAgent"))
			{
				var rtElement = XElement.Parse(agentDto.Xml);
				var agentElement = rtElement.Elements("CmAgent").First();
				// Create two new CmAgentEvaluations.
				var newApprovesEval = MakeEvaluation(agentDto.Guid, domainObjectDtoRepository, agentElement, "Approves");
				var newDisapprovesEval = MakeEvaluation(agentDto.Guid, domainObjectDtoRepository, agentElement, "Disapproves");
				var evaluations = agentElement.Elements("Evaluations").FirstOrDefault();
				if (evaluations != null)
				{
					foreach (var objsur in evaluations.Elements("objsur"))
					{
						var evalGuidAttr = objsur.Attribute("guid");
						if (evalGuidAttr == null) continue;

						var evalGuid = evalGuidAttr.Value;
						var obsoleteEvalDto = domainObjectDtoRepository.GetDTO(evalGuid);
						if (obsoleteEvalDto == null)
							continue; // defensive (RandyR says there is no need to be defensive, since the repos will throw an exception, if the guid ois not found.)
						var agentEvalElt = XElement.Parse(obsoleteEvalDto.Xml).Element("CmAgentEvaluation");
						if (agentEvalElt == null)
							continue; // paranoid! (Also, no need for paranoia, since the element *must* be present, or the object cannot be reconstituted.)

						// Delete/Remove the old evaluation.
						domainObjectDtoRepository.Remove(obsoleteEvalDto);

						var acceptedElt = agentEvalElt.Element("Accepted");
						bool accepted = false;
						if (acceptedElt != null)
						{
							var attr = acceptedElt.Attribute("val");
							if (attr != null)
								accepted = attr.Value.ToLowerInvariant() == "true";
						}

						var targetElt = agentEvalElt.Element("Target");
						if (targetElt == null)
							continue;
						var targetObjsur = targetElt.Element("objsur");
						if (targetObjsur == null)
							continue; // paranoid
						var targetGuidAttr = targetObjsur.Attribute("guid");
						if (targetGuidAttr == null)
							continue; // paranoid
						var targetGuid = targetGuidAttr.Value;
						List<String> evals;
						if (!map.TryGetValue(targetGuid, out evals))
						{
							evals = new List<string>();
							map[targetGuid] = evals;
						}

						evals.Add(accepted ? newApprovesEval.Guid : newDisapprovesEval.Guid);
					}
					evaluations.Remove();
				}
				agentDto.Xml = rtElement.ToString();
				domainObjectDtoRepository.Update(agentDto);
			}
			foreach (var kvp in map)
			{
				var analysisDto = domainObjectDtoRepository.GetDTO(kvp.Key);
				var analysisRtElt = XElement.Parse(analysisDto.Xml);
				var analysisElt = analysisRtElt.Element("WfiAnalysis");
				if (analysisElt == null)
					continue; // Paranoid
				var evals = new XElement("Evaluations");
				analysisElt.Add(evals);
				foreach (var eval in kvp.Value)
				{
					evals.Add(new XElement("objsur", new XAttribute("t", "r"), new XAttribute("guid", eval)));
				}
				analysisDto.Xml = analysisRtElt.ToString();
				domainObjectDtoRepository.Update(analysisDto);
			}

			DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
		}