本文整理汇总了C#中IDomainObjectDTORepository.TryGetOwner方法的典型用法代码示例。如果您正苦于以下问题:C# IDomainObjectDTORepository.TryGetOwner方法的具体用法?C# IDomainObjectDTORepository.TryGetOwner怎么用?C# IDomainObjectDTORepository.TryGetOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDomainObjectDTORepository
的用法示例。
在下文中一共展示了IDomainObjectDTORepository.TryGetOwner方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveZombies
private static void RemoveZombies(
IDomainObjectDTORepository dtoRepos,
IList<DomainObjectDTO> allDtos)
{
var count = allDtos.Count;
var legalOwnerlessClasses = new HashSet<string>
{
// Start at 7.0
"LangProject", // Started as no owner allowed.
"ScrRefSystem", // Started as no owner allowed.
"CmPossibilityList", // Started as required owner. // Optionally unowed 7000010. Required owner re-added and removed again by 7000020.
"CmPicture", // Started as no owner allowed. Optionally unowed by 7000019
//"UserView", // Started as no owner allowed. Removed in 7000031
//"LgWritingSystem", // Started as no owner allowed. Removed in 7000019
"WfiWordform", // none 7000001
"PunctuationForm", // Added to model in 7000010. Added 'none' between 7000010 and 7000011
"LexEntry", // 7000028
// Initial release: 7.0.6 at DM 7000037
//"VirtualOrdering", // 7000040 (added class in 7000038. Added 'none' with no model change number between 39 and 40).
// Release 7.1.1 at DM 7000044
// Release 7.2.x at DM 7000051 (51 added in 7.2 branch.)
// Release 7.3.x at DM 70000xx
};
if (dtoRepos.CurrentModelVersion >= 7000040)
legalOwnerlessClasses.Add("VirtualOrdering");
if (dtoRepos.CurrentModelVersion >= 7000059)
legalOwnerlessClasses.Add("Text");
var goners = new List<DomainObjectDTO>(count);
// Key is guid of owner. Value is set of guids it owns.
// In one very large project that ran out of memory, it had 1281871 dtos, and
// 115694 of them owned more than one other dto. So we'll guess that 1/10th
// of the total count is a reasonable estimate for the capacity of ownerMap.
var ownerMap = new Dictionary<DomainObjectDTO, HashSet<string>>(count/10);
foreach (var currentDto in allDtos)
{
DomainObjectDTO owningDto;
if (dtoRepos.TryGetOwner(currentDto.Guid, out owningDto))
{
if (owningDto == null)
{
if (dtoRepos.CurrentModelVersion >= 7000060 && !legalOwnerlessClasses.Contains(currentDto.Classname))
goners.Add(currentDto); // Not allowed to be unowned, so zap it.
continue;
}
// Has owner, but does owner know that it owns it?
HashSet<string> ownees;
if (!ownerMap.TryGetValue(owningDto, out ownees))
{
ownees = GetOwnees(owningDto.XmlBytes);
// Cache it only if it's really useful to do so.
if (ownees.Count > 2)
ownerMap[owningDto] = ownees;
}
if (ownees.Contains(currentDto.Guid.ToLowerInvariant()))
continue;
// Current dto is a zombie, so remove it, and everything it owns.
goners.Add(currentDto);
}
else
{
// Current dto is a zombie, so remove it, and everything it owns.
goners.Add(currentDto);
}
}
ownerMap.Clear();
foreach (var goner in goners)
{
RemoveIncludingOwnedObjects(dtoRepos, goner, false);
}
}
示例2: ValidateStyleReference
private void ValidateStyleReference(IDomainObjectDTORepository repoDTO, XElement xeStyle, string sRefName)
{
XElement xeOnly = null;
XElement xeObjsur = null;
foreach (XElement xeRef in xeStyle.Descendants(sRefName))
{
Assert.IsNull(xeOnly, sRefName + " should appear only once in an StStyle object");
xeOnly = xeRef;
foreach (XElement xeLink in xeRef.Descendants("objsur"))
{
Assert.IsNull(xeObjsur, "objsur should appear only once in a " + sRefName + " field");
xeObjsur = xeLink;
XAttribute xa = xeObjsur.Attribute("guid");
Assert.IsNotNull(xa, sRefName + "/objsur must have a guid attribute");
DomainObjectDTO dto;
Assert.IsTrue(repoDTO.TryGetValue(xa.Value, out dto), sRefName + " must point to a valid object");
Assert.AreEqual("StStyle", dto.Classname, sRefName + " must point to a style");
DomainObjectDTO dtoOwner;
Assert.IsTrue(repoDTO.TryGetOwner(xa.Value, out dtoOwner), sRefName + " must point to a style with a valid owner");
Assert.AreEqual("LangProject", dtoOwner.Classname, sRefName + " must point to a style owned by LangProject");
}
Assert.IsNotNull(xeObjsur, "objsur should appear once in a " + sRefName + " field");
}
}
示例3: ChangeInvalidGuid
private void ChangeInvalidGuid(IDomainObjectDTORepository repoDto, LexTypeInfo info,
string name, string guidStd)
{
var xaGuid = info.XmlElement.Attribute("guid");
if (xaGuid == null)
throw new Exception("The object does not have a guid -- this is impossible!");
xaGuid.SetValue(guidStd);
var guidBad = info.DTO.Guid;
if (!m_mapBadGoodGuids.ContainsKey(guidBad))
m_mapBadGoodGuids.Add(guidBad, guidStd);
var className = info.DTO.Classname;
repoDto.Remove(info.DTO);
info.DTO = new DomainObjectDTO(guidStd, className, info.XmlElement.ToString());
repoDto.Add(info.DTO);
// Fix the owning reference (but only if it's one of the two lists, because otherwise
// it might be contained in a LexTypeInfo that hasn't yet been processed).
var bad = String.Format("guid=\"{0}\"", guidBad);
var good = String.Format("guid=\"{0}\"", guidStd);
var bad2 = String.Format("guid='{0}'", guidBad); // probably pure paranoia...
var good2 = String.Format("guid='{0}'", guidStd);
DomainObjectDTO dtoOwner;
if (repoDto.TryGetOwner(info.DTO.Guid, out dtoOwner) && dtoOwner.Classname == "CmPossibilityList")
{
dtoOwner.Xml = dtoOwner.Xml.Replace(bad, good).Replace(bad2, good2);
repoDto.Update(dtoOwner);
}
// Fix any references from LexEntryRef objects.
foreach (var dtoRef in repoDto.AllInstancesWithSubclasses("LexEntryRef"))
{
var xml = dtoRef.Xml;
if (xml.Contains(guidBad))
{
dtoRef.Xml = xml.Replace(bad, good).Replace(bad2, good2);
repoDto.Update(dtoRef);
}
}
m_mapNameGuid.Remove(name);
m_mapGuidName.Remove(guidStd);
}
示例4: FixOwnershipOfSubtypes
private void FixOwnershipOfSubtypes(IDomainObjectDTORepository repoDto)
{
var types = repoDto.AllInstancesWithSubclasses("LexEntryType");
var cFixedFirst = 0;
foreach (var dto in types)
{
var xml = dto.Xml;
var fFixed = false;
foreach (var badGuid in m_mapBadGoodGuids.Keys)
{
if (xml.Contains(badGuid))
{
var bad = String.Format("guid=\"{0}\"", badGuid);
var good = String.Format("guid=\"{0}\"", m_mapBadGoodGuids[badGuid]);
xml = xml.Replace(bad, good);
var bad2 = String.Format("guid='{0}'", badGuid);
var good2 = String.Format("guid='{0}'", m_mapBadGoodGuids[badGuid]);
xml = xml.Replace(bad2, good2); // probably pure paranoia...
fFixed = true;
}
}
if (fFixed)
{
dto.Xml = xml;
repoDto.Update(dto);
++cFixedFirst;
}
var cFixed = 0;
foreach (var dtoSub in repoDto.GetDirectlyOwnedDTOs(dto.Guid))
{
DomainObjectDTO dtoOwner;
if (!repoDto.TryGetOwner(dtoSub.Guid, out dtoOwner) || dtoOwner != dto)
{
// we have a broken ownership link -- fix it!
var xeSub = XElement.Parse(dtoSub.Xml);
var xaOwner = xeSub.Attribute("ownerguid");
if (xaOwner == null)
xeSub.Add(new XAttribute("ownerguid", dto.Guid));
else
xaOwner.Value = dto.Guid;
dtoSub.Xml = xeSub.ToString();
repoDto.Update(dtoSub);
++cFixed;
}
}
}
}
示例5: VerifyEntryTypeOwners
/// <summary>
/// Verify that every LexEntryType points back to a valid owner after migration, and that
/// the owner points to the LexEntryType.
/// </summary>
/// <param name="repoDto"></param>
private static void VerifyEntryTypeOwners(IDomainObjectDTORepository repoDto)
{
foreach (var dto in repoDto.AllInstancesWithSubclasses("LexEntryType"))
{
DomainObjectDTO dtoOwner;
Assert.IsTrue(repoDto.TryGetOwner(dto.Guid, out dtoOwner), "All entry types should have valid owners!");
DomainObjectDTO dtoOwnedOk = null;
foreach (var dtoT in repoDto.GetDirectlyOwnedDTOs(dtoOwner.Guid))
{
if (dtoT == dto)
{
dtoOwnedOk = dtoT;
break;
}
}
Assert.AreEqual(dto, dtoOwnedOk, "The owner should own the entry type!");
}
}