CreateReferenceObjSurElement() static private method

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

            // (WRONG) The ExcludeAsHeadword element only appears when @val="true" and
            // it is to be replaced by DoNotShowMainEntryIn with a list of all publications.
            // NB: The above statement is simply not true (RBR).
            // FW 7 writes out all primitive data properties.
            // The FW 6-FW7 migrator doesn't add them,
            // but FW 7 writes them the next time an object gets changed.

            // Make the list of publications once
            var newElt = new XElement("DoNotShowMainEntryIn");

            IEnumerable <XElement> dtoPubList = null;

            // XPATH: rt[Name/AUni='Publications']/Possibilities/objsur
            foreach (var a_list in domainObjectDtoRepository.AllInstancesSansSubclasses("CmPossibilityList"))
            {
                var xList = XElement.Parse(a_list.Xml);
                if (xList.XPathSelectElement("Name[AUni='Publications']") == null)
                {
                    continue;
                }
                dtoPubList = xList.XPathSelectElements("Possibilities/objsur");
                if (dtoPubList != null && dtoPubList.Count() > 0)
                {
                    break;
                }
            }

            if (dtoPubList == null || dtoPubList.Count() == 0) // add the Publications list to the project
            {                                                  // This list is owned by LexDb
                var ieDtoLexDb = domainObjectDtoRepository.AllInstancesSansSubclasses("LexDb");
                Debug.Assert(ieDtoLexDb != null && ieDtoLexDb.Count <DomainObjectDTO>() == 1, "Project has no LexDb Dto or more than one");
                var    dtoLexDb    = ieDtoLexDb.First <DomainObjectDTO>();
                var    xNode       = XElement.Parse(dtoLexDb.Xml);
                var    ksguidLexDb = xNode.Attribute("guid").Value;
                var    nowStr      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                string xmlStrPub   =
                    "<rt guid=\"" + ksguidPubList + "\" class=\"CmPossibilityList\" ownerguid=\"" + ksguidLexDb + "\"><Name><AUni ws=\"en\">Publications</AUni></Name><DateCreated val=\"" + nowStr + "\" /><DateModified val=\"" + nowStr + "\" /><Depth val=\"1\" /><PreventChoiceAboveLevel val=\"0\" /><IsSorted val=\"True\" /><IsClosed val=\"False\" /><PreventDuplicates val=\"False\" /><PreventNodeChoices val=\"False\" /><UseExtendedFields val=\"False\" /><DisplayOption val=\"0\" /><ItemClsid val=\"7\" /><IsVernacular val=\"False\" /><WsSelector val=\"0\" /><ListVersion val=\"00000000-0000-0000-0000-000000000000\" /><Possibilities><objsur guid=\"" + ksguidMainDictionary + "\" t=\"o\" /></Possibilities></rt>";
                var dtoPub = new DomainObjectDTO(ksguidPubList, "CmPossibilityList", xmlStrPub);

                string xmlStrMD = "<rt guid=\"" + ksguidMainDictionary + "\" class=\"CmPossibility\" ownerguid=\"" + ksguidPubList + "\"><Name><AUni ws=\"en\">Main Dictionary</AUni></Name><Abbreviation><AUni ws=\"en\">Main</AUni></Abbreviation><SortSpec val=\"0\" /><DateCreated val=\"" + nowStr + "\" /><DateModified val=\"" + nowStr + "\" /><ForeColor val=\"0\" /><BackColor val=\"0\" /><UnderColor val=\"0\" /><UnderStyle val=\"0\" /><Hidden val=\"False\" /><IsProtected val=\"True\" /></rt>";
                var    dtoMD    = new DomainObjectDTO(ksguidMainDictionary, "CmPossibility", xmlStrMD);

                domainObjectDtoRepository.Add(dtoMD);
                domainObjectDtoRepository.Add(dtoPub);

                // Make xLexDb own dtoPub
                var xPts = xNode.Element("PublicationTypes");
                if (xPts == null)
                {                   // add one to LexDb
                    xPts = new XElement("PublicationTypes");
                    xPts.Add(DataMigrationServices.CreateOwningObjSurElement(ksguidPubList));
                    xNode.Add(xPts);
                }
                Debug.Assert(xPts != null, "LexDb has no PublicatonTypes and won't accept new ones.");
                dtoLexDb.Xml = xNode.ToString();
                domainObjectDtoRepository.Update(dtoLexDb);
                newElt.Add(DataMigrationServices.CreateReferenceObjSurElement(ksguidMainDictionary));
            }
            else
            {               // already had a publications list - add all to DoNotShowMainEntryIn
                foreach (var xElt in dtoPubList)
                {           // change the t attr to "r" reference instead of "o" own.
                    var xPubRef = new XElement(xElt);
                    xPubRef.SetAttributeValue("t", "r");
                    newElt.Add(xPubRef);
                }
            }
            foreach (var dto in domainObjectDtoRepository.AllInstancesSansSubclasses("LexEntry"))
            {
                // (WRONG) The ExcludeAsHeadword element only appears when @val="true" unless played with in a text editor
                // NB: The above statement is simply not true (RBR).
                // FW 7 writes out all primitive data properties.
                // The FW 6-FW7 migrator doesn't add them,
                // but FW 7 writes them the next time an object gets changed.
                var xElt       = XElement.Parse(dto.Xml);
                var exHeadword = xElt.Element("ExcludeAsHeadword");
                if (exHeadword == null)
                {
                    continue;
                }
                XAttribute XAval = exHeadword.Attribute("val");
                // It must be upper-case, since that is what is output.
                if (XAval.Value == "True")
                {                       // Add all publications from the list to this property
                    xElt.Add(new XElement(newElt));
                }
                exHeadword.Remove();                 // exHeadword.Value may be True, False or invalid
                dto.Xml = xElt.ToString();
                domainObjectDtoRepository.Update(dto);
            }
            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }