本文整理汇总了C#中IDomainObjectDTORepository.GetOwningDTO方法的典型用法代码示例。如果您正苦于以下问题:C# IDomainObjectDTORepository.GetOwningDTO方法的具体用法?C# IDomainObjectDTORepository.GetOwningDTO怎么用?C# IDomainObjectDTORepository.GetOwningDTO使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDomainObjectDTORepository
的用法示例。
在下文中一共展示了IDomainObjectDTORepository.GetOwningDTO方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformMigration
/// ------------------------------------------------------------------------------------
/// <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);
}
示例2: ChangeGuid
/// <summary>
/// Changes the GUID of the specified DTO. It updates the owner and all specified referrers to point to the new GUID.
/// </summary>
/// <param name="dtoRepos">The dto repos.</param>
/// <param name="dto">The dto.</param>
/// <param name="newGuid">The new GUID.</param>
/// <param name="possibleReferrers">The possible referrers.</param>
internal static void ChangeGuid(IDomainObjectDTORepository dtoRepos, DomainObjectDTO dto, string newGuid,
IEnumerable<DomainObjectDTO> possibleReferrers)
{
// if the DTO already has the new GUID, don't do anything
if (dto.Guid.ToLowerInvariant() == newGuid.ToLowerInvariant())
return;
XElement rtElem = XElement.Parse(dto.Xml);
rtElem.Attribute("guid").Value = newGuid;
dtoRepos.Add(new DomainObjectDTO(newGuid, dto.Classname, rtElem.ToString()));
foreach (DomainObjectDTO ownedDto in dtoRepos.GetDirectlyOwnedDTOs(dto.Guid))
{
XElement ownedElem = XElement.Parse(ownedDto.Xml);
ownedElem.Attribute("ownerguid").Value = newGuid;
UpdateDTO(dtoRepos, ownedDto, ownedElem.ToString());
}
var ownerDto = dtoRepos.GetOwningDTO(dto);
if (ownerDto != null)
UpdateObjSurElement(dtoRepos, ownerDto, dto.Guid, newGuid);
if (possibleReferrers != null)
{
foreach (DomainObjectDTO referrer in possibleReferrers)
UpdateObjSurElement(dtoRepos, referrer, dto.Guid, newGuid);
}
dtoRepos.Remove(dto);
}
示例3: RemoveIncludingOwnedObjects
/// <summary>
/// Remove <paramref name="goner"/> and everything it owns.
/// Be sure to include removing goner from its optional owning property.
/// </summary>
internal static void RemoveIncludingOwnedObjects(IDomainObjectDTORepository dtoRepos, DomainObjectDTO goner, bool removeFromOwner)
{
DomainObjectDTO gonerActual;
if (!dtoRepos.TryGetValue(goner.Guid, out gonerActual))
return; // Not in repos.
if (removeFromOwner)
{
var ownerDto = dtoRepos.GetOwningDTO(goner);
if (ownerDto != null)
{
var ownerElement = XElement.Parse(ownerDto.Xml);
var ownObjSurElement = (from objSurNode in ownerElement.Descendants("objsur")
where objSurNode.Attribute("t").Value == "o" && objSurNode.Attribute("guid").Value.ToLower() == goner.Guid.ToLower()
select objSurNode).FirstOrDefault(); // Ought not be null, but play it safe.
if (ownObjSurElement != null)
ownObjSurElement.Remove();
if (!RemoveEmptyPropertyElements(dtoRepos, ownerDto, ownerElement))
{
// No empty property elements removed, so we have to do the update.
UpdateDTO(dtoRepos, ownerDto, ownerElement.ToString());
}
}
}
foreach (var ownedDto in dtoRepos.GetDirectlyOwnedDTOs(goner.Guid))
RemoveIncludingOwnedObjects(dtoRepos, ownedDto, false);
dtoRepos.Remove(goner);
}
示例4: VerifyStylesRenamedOrDeleted
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");
//.........这里部分代码省略.........
示例5: FixOrAddMissingTypes
private void FixOrAddMissingTypes(IDomainObjectDTORepository repoDto, IEnumerable<LexTypeInfo> extraTypes)
{
foreach (var info in extraTypes)
{
var fChanged = false;
foreach (var xeAUni in info.XmlElement.XPathSelectElements("Name/AUni"))
{
var xaWs = xeAUni.Attribute("ws");
if (xaWs == null || xaWs.Value.ToLowerInvariant() != "en")
continue;
var name = xeAUni.Value;
string guidStd;
if (!m_mapNameGuid.TryGetValue(name, out guidStd))
continue;
// We need to change the guid of this dto from 'guid to 'guidStd
ChangeInvalidGuid(repoDto, info, name, guidStd);
}
var xeProt = info.XmlElement.XPathSelectElement("IsProtected");
if (xeProt == null)
{
info.XmlElement.Add(new XElement("IsProtected", new XAttribute("val", "true")));
fChanged = true;
}
else
{
var xaVal = xeProt.Attribute("val");
if (xaVal == null)
{
xeProt.Add(new XAttribute("val", "true"));
fChanged = true;
}
else if (xaVal.Value.ToLowerInvariant() != "true")
{
xaVal.SetValue("true");
fChanged = true;
}
}
if (fChanged)
{
info.DTO.Xml = info.XmlElement.ToString();
repoDto.Update(info.DTO);
}
}
if (m_mapNameGuid.Count > 0)
{
BuildNewTypeMaps();
var newTypes = new HashSet<DomainObjectDTO>();
foreach (var guid in m_mapGuidName.Keys)
{
// We need to create this LexEntryType!
var rgNewDtos = m_mapGuidNewDtos[guid];
foreach (var info in rgNewDtos)
{
var dto = new DomainObjectDTO(info.Guid, info.ClassName, info.Xml);
repoDto.Add(dto);
if (info.ClassName == "LexEntryType")
newTypes.Add(dto);
}
}
foreach (var dto in newTypes)
{
var dtoOwner = repoDto.GetOwningDTO(dto);
var xeOwner = XElement.Parse(dtoOwner.Xml);
XElement xePoss = null;
if (dtoOwner.Classname == "CmPossibilityList")
{
xePoss = xeOwner.Element("Possibilities");
if (xePoss == null)
{
xePoss = new XElement("Possibilities");
xeOwner.Add(xePoss);
}
}
else if (dtoOwner.Classname == "LexEntryType")
{
xePoss = xeOwner.Element("SubPossibilities");
if (xePoss == null)
{
xePoss = new XElement("SubPossibilities");
xeOwner.Add(xePoss);
}
}
if (xePoss != null)
{
var fNeeded = true;
foreach (var objsur in xePoss.Elements("objsur"))
{
var xaGuid = objsur.Attribute("guid");
if (xaGuid == null)
throw new Exception("missing guid in an objsur element");
if (xaGuid.Value.Equals(dto.Guid, StringComparison.OrdinalIgnoreCase))
{
fNeeded = false;
break;
}
}
if (fNeeded)
{
//.........这里部分代码省略.........
示例6: CheckNewSegment
private static XElement CheckNewSegment(IDomainObjectDTORepository dtoRepos, int beginOffset, DomainObjectDTO owningPara, XElement newSegmentObjSurElement, out DomainObjectDTO newSegmentDto)
{
newSegmentDto = dtoRepos.GetDTO(newSegmentObjSurElement.Attribute("guid").Value);
Assert.IsNotNull(newSegmentDto, "Missing new Segment DTO.");
var newSegmentElement = XElement.Parse(newSegmentDto.Xml);
// Make sure it is owned by the expected para.
Assert.AreSame(owningPara, dtoRepos.GetOwningDTO(newSegmentDto), "Wrong paragraph owner.");
var newSegmentInnerElement = newSegmentElement.Element("Segment");
Assert.IsNotNull(newSegmentInnerElement, "Missing new inner Segment Element in the new Segment object.");
Assert.AreEqual(beginOffset, int.Parse(newSegmentInnerElement.Element("BeginOffset").Attribute("val").Value));
return newSegmentInnerElement;
}
示例7: CheckNotes
private static void CheckNotes(IDomainObjectDTORepository dtoRepos, DomainObjectDTO newSegmentDto, ICollection noteGuids, XContainer newSegmentInnerElement, bool expectedToHaveNotes, int expectedNumberOfNotes)
{
// Check Nts.
var notesElements = newSegmentInnerElement.Elements("Notes");
if (!expectedToHaveNotes)
{
Assert.AreEqual(0, notesElements.Count(), "Had unexpected number of notes.");
return;
}
var objsurElements = notesElements.Elements("objsur");
Assert.AreEqual(expectedNumberOfNotes, objsurElements.Count(), "Wrong number of Notes.");
foreach (var objsurElement in objsurElements)
{
// Make sure the objsur guid is in 'noteGuids'.
var objsurGuid = objsurElement.Attribute("guid").Value;
Assert.Contains(objsurGuid, noteGuids);
// Make sure the objsur element is t="o" (owning).
var type = objsurElement.Attribute("t").Value;
Assert.AreEqual("o", type, "Not an owning property.");
// Make sure the owner of the objsur guid is the new Segment.
var noteDto = dtoRepos.GetDTO(objsurGuid);
Assert.AreSame(newSegmentDto, dtoRepos.GetOwningDTO(noteDto));
// Each Nt should have two alts.
var noteElement = XElement.Parse(noteDto.Xml);
var contentElement = noteElement.Element("Note").Element("Content");
Assert.IsNotNull(contentElement, "No Nt Content element.");
CheckAlternatives(contentElement, 2);
}
}
示例8: CreateFileGuidToPictureMap
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;
}
示例9: GetStTextGuidFromXfic
private static string GetStTextGuidFromXfic(IDomainObjectDTORepository dtoRepos, string xficGuid)
{
var dtoXfic = dtoRepos.GetDTO(xficGuid.ToLowerInvariant());
var paraGuid = GetBeginObjectGuid(dtoXfic.XmlBytes);
return dtoRepos.GetOwningDTO(dtoRepos.GetDTO(paraGuid.ToLowerInvariant())).Guid;
}
示例10: DeleteUnneededGoners
private static void DeleteUnneededGoners(IDomainObjectDTORepository dtoRepos,
IEnumerable<DomainObjectDTO> goners, ICollection<string> neededGoners)
{
// We have run out of memory during this data migration on large projects. (See
// FWR-3849.) One possible reason is that we can make 15000+ copies of LangProject
// as we slowly squeeze out the owning links to Annotations. So let's collect them
// all up at once, and remove them with a single change to the LangProject dto.
var dtoLangProject = dtoRepos.AllInstancesSansSubclasses("LangProject").FirstOrDefault();
if (dtoLangProject != null)
{
var xeLangProject = XElement.Parse(dtoLangProject.Xml);
var cAnn = xeLangProject.Descendants("objsur").
Where(t => (t.Attribute("t") != null && t.Attribute("t").Value == "o")).Count();
if (cAnn > 0)
{
var gonersInLangProject = new List<DomainObjectDTO>(cAnn);
foreach (var goner in goners)
{
DomainObjectDTO gonerActual;
if (!dtoRepos.TryGetValue(goner.Guid, out gonerActual))
continue; // Not in repos.
if (neededGoners.Contains(goner.Guid))
continue; // still need this in the repository.
var ownerDto = dtoRepos.GetOwningDTO(goner);
if (ownerDto != null && ownerDto.Guid == dtoLangProject.Guid)
gonersInLangProject.Add(gonerActual);
}
if (gonersInLangProject.Count > 0)
{
DataMigrationServices.RemoveMultipleIncludingOwnedObjects(dtoRepos,
gonersInLangProject, dtoLangProject);
gonersInLangProject.Clear();
// We don't try removing those from goners because that operation may
// involve a linear lookup in the list to find the object to remove.
// And RemoveIncludingOwnedObjects() checks whether the goner still
// exists before doing anything else.
}
}
}
// Remove old stuff.
foreach (var goner in goners)
{
if (neededGoners.Contains(goner.Guid))
continue;
DataMigrationServices.RemoveIncludingOwnedObjects(dtoRepos, goner, true);
}
}
示例11: AddSegmentAnalyses
//.........这里部分代码省略.........
var twficElementListForCurrentSegment = new List<byte[]>();
var twficMap = new Dictionary<string, byte[]>();
foreach (var twficKvp in from xficKvp in xficsForCurrentOldSegment
where GetAnnotationTypeGuid(xficKvp.Value) == DataMigrationServices.kTwficAnnDefnGuid
select xficKvp)
{
twficBeginOffsetListForCurrentSegment.Add(twficKvp.Key);
var twficGuid = GetGuid(twficKvp.Value);
twficGuidListForCurrentSegment.Add(twficGuid);
twficElementListForCurrentSegment.Add(twficKvp.Value);
twficMap.Add(twficGuid, twficKvp.Value);
}
var textTagElementsForCurrentSegment = new List<byte[]>();
foreach (var oldTextTagAnnElement in oldTextTags)
{
// Find the ones that are used in the current segment,
// and add them to textTagElementsForCurrentSegment.
var appliesToGuids = new List<string>();
foreach (var guid in GetAppliesToObjsurGuids(oldTextTagAnnElement))
{
if (twficGuidListForCurrentSegment.Contains(guid))
appliesToGuids.Add(guid);
}
if (appliesToGuids.Count() <= 0)
continue;
// Store them for a while.
textTagElementsForCurrentSegment.Add(oldTextTagAnnElement);
// Get the index of the First twfic in appliesToGuids collection (which may hold pfics)
// and the index of the Last twfic in appliesToGuids collection (which may hold pfics).
var beginIdx = 0;
for (var i = 0; i < appliesToGuids.Count(); ++i)
{
var currentXfixGuid = appliesToGuids[i].ToLower();
byte[] currentTwficElement;
if (!twficMap.TryGetValue(currentXfixGuid, out currentTwficElement))
continue;
beginIdx = xficsForCurrentOldSegment.IndexOfValue(currentTwficElement);
break;
}
var endIdx = 0;
for (var i = appliesToGuids.Count() - 1; i > -1; --i)
{
var currentXfixGuid = appliesToGuids[i].ToLower();
byte[] currentTwficElement;
if (!twficMap.TryGetValue(currentXfixGuid, out currentTwficElement))
continue;
endIdx = xficsForCurrentOldSegment.IndexOfValue(currentTwficElement);
break;
}
var owningStText = dtoRepos.GetOwningDTO(paraDto);
var newTextTagGuid = Guid.NewGuid().ToString().ToLower();
var newTextTagElement = new XElement("rt",
new XAttribute("class", "TextTag"),
new XAttribute("guid", newTextTagGuid),
new XAttribute("ownerguid", owningStText.Guid.ToLower()),
new XElement("CmObject"),
new XElement("TextTag",
new XElement("BeginSegment", DataMigrationServices.CreateReferenceObjSurElement(newSegmentGuid)),
new XElement("EndSegment", DataMigrationServices.CreateReferenceObjSurElement(newSegmentGuid)),
new XElement("BeginAnalysisIndex", new XAttribute("val", beginIdx)),
new XElement("EndAnalysisIndex", new XAttribute("val", endIdx)),
new XElement("Tag", DataMigrationServices.CreateReferenceObjSurElement(GetInstanceOfGuid(oldTextTagAnnElement)))));
// Add new DTO to repos.
var newTextTagDto = new DomainObjectDTO(newTextTagGuid, "TextTag", newTextTagElement.ToString());
dtoRepos.Add(newTextTagDto);
// Add new TextTag to owning prop on owner as objsur element.
var owningStTextElement = XElement.Parse(owningStText.Xml);
var innerStTextElement = owningStTextElement.Element("StText");
var tagsPropElement = innerStTextElement.Element("Tags");
if (tagsPropElement == null)
{
tagsPropElement = new XElement("Tags");
innerStTextElement.Add(tagsPropElement);
}
tagsPropElement.Add(DataMigrationServices.CreateOwningObjSurElement(newTextTagGuid));
// Tell repos of the modification.
owningStText.Xml = owningStTextElement.ToString();
dtoRepos.Update(owningStText);
}
// Remove current text tags from input list
foreach (var currentTextTagElement in textTagElementsForCurrentSegment)
oldTextTags.Remove(currentTextTagElement);
}
//else
//{
// // No xfics at all, so make sure para is set to be tokenized again.
// // Done globally for each Para in ProcessParagraphs
// //MarkParaAsNeedingTokenization(dtoRepos, paraDto, paraElement);
//}
return retval;
}