public MtpsNavigationNode( MtpsIdentifier subTreeId, MtpsIdentifier targetId, MtpsNodeCore parent = null, bool phantom = false, Guid? guid = null, string contentId = null, string alias = null, string title = null, IList<MtpsNodeCore> childLinks = null ) : base(subTreeId, targetId, title, parent, phantom) { Guid = guid; ContentId = contentId; Alias = alias; ChildLinks = null == childLinks ? EmptyChildrenCollection : new ReadOnlyCollection<MtpsNodeCore>(childLinks); }
public MtpsNodeCore(MtpsIdentifier subTreeId, MtpsIdentifier targetId, string title, MtpsNodeCore parent, bool phantom = false) { SubTreeId = subTreeId; TargetId = targetId; Title = title; Parent = parent; IsPhantom = phantom; }
private MtpsNavigationNode ToNavigationNode(MtpsNodeCore parent, MtpsNodeCore node) { if (null != node.SubTreeId) { var xmlElement = GetTocXmlElement(node.SubTreeId.AssetId, node.SubTreeId.Version, node.SubTreeId.Locale); if (null != xmlElement) return ToNavigationNode(parent, xmlElement); } Guid? guid = null; string contentId = null; string alias = null; if (null != node.TargetId) { Contract.Assume(!String.IsNullOrEmpty(node.TargetId.AssetId)); Contract.Assume(!String.IsNullOrEmpty(node.TargetId.Version)); Contract.Assume(!String.IsNullOrEmpty(node.TargetId.Locale)); var contentResponse = GetContentResponse(node.TargetId); contentId = contentResponse.contentId; var guidText = contentResponse.contentGuid; Guid guidValue; if (!String.IsNullOrEmpty(guidText) && Guid.TryParse(guidText, out guidValue)) { guid = guidValue; } alias = contentResponse.contentAlias; } return new MtpsNavigationNode( subTreeId: node.SubTreeId, targetId: node.TargetId, parent: parent, phantom: node.IsPhantom, guid: guid, contentId: contentId, alias: alias, title: node.Title, childLinks: null ); }
private MtpsNavigationNode ToNavigationNode(MtpsNodeCore parent, XmlElement xmlElement) { Contract.Requires(null != xmlElement); Contract.Ensures(Contract.Result<MtpsNavigationNode>() != null); var subTreeAssetId = xmlElement.Attributes["toc:SubTree"].Value; Contract.Assume(!String.IsNullOrEmpty(subTreeAssetId)); var subTreeVersion = xmlElement.Attributes["toc:SubTreeVersion"].Value; Contract.Assume(!String.IsNullOrEmpty(subTreeVersion)); var subTreeLocale = xmlElement.Attributes["toc:SubTreeLocale"].Value; Contract.Assume(!String.IsNullOrEmpty(subTreeLocale)); var subTreeId = new MtpsIdentifier(subTreeAssetId, subTreeVersion, subTreeLocale); var title = xmlElement.GetAttribute("toc:Title"); var targetAssetId = xmlElement.GetAttribute("toc:Target"); var targetLocale = xmlElement.GetAttribute("toc:TargetLocale"); var targetVersion = xmlElement.GetAttribute("toc:TargetVersion"); bool isPhantom; Boolean.TryParse(xmlElement.GetAttribute("toc:IsPhantom"), out isPhantom); ; var children = new List<MtpsNodeCore>(); foreach (var childElement in xmlElement.ChildNodes.Cast<XmlElement>()) { MtpsIdentifier childSubTree = null; var childSubTreeId = childElement.GetAttribute("toc:SubTree"); if (!String.IsNullOrEmpty(childSubTreeId)) { var version = childElement.GetAttribute("toc:SubTreeVersion"); Contract.Assume(!String.IsNullOrEmpty(version)); var locale = childElement.GetAttribute("toc:SubTreeLocale"); Contract.Assume(!String.IsNullOrEmpty(locale)); childSubTree = new MtpsIdentifier(childSubTreeId, version, locale); } MtpsIdentifier childTarget = null; var childTargetId = childElement.GetAttribute("toc:Target"); if (!String.IsNullOrEmpty(childTargetId)) { var version = childElement.GetAttribute("toc:TargetVersion"); Contract.Assume(!String.IsNullOrEmpty(version)); var locale = childElement.GetAttribute("toc:TargetLocale"); Contract.Assume(!String.IsNullOrEmpty(locale)); childTarget = new MtpsIdentifier(childTargetId, version, locale); } if (null != childSubTree || null != childTarget) { var childTitle = childElement.GetAttribute("toc:Title"); var childLink = new MtpsNodeCore(childSubTree, childTarget, childTitle, parent); children.Add(childLink); } } MtpsIdentifier targetId = null; Guid? guid = null; string contentId = null; string alias = null; if (!String.IsNullOrEmpty(targetAssetId)) { Contract.Assume(!String.IsNullOrEmpty(targetVersion)); Contract.Assume(!String.IsNullOrEmpty(targetLocale)); targetId = new MtpsIdentifier(targetAssetId, targetVersion, targetLocale); var contentResponse = GetContentResponse(targetId); contentId = contentResponse.contentId; var guidText = contentResponse.contentGuid; Guid guidValue; if (!String.IsNullOrEmpty(guidText) && Guid.TryParse(guidText, out guidValue)) { guid = guidValue; } alias = contentResponse.contentAlias; } return new MtpsNavigationNode( subTreeId: subTreeId, targetId: targetId, parent: parent, phantom: isPhantom, guid: guid, contentId: contentId, alias: alias, title: title, childLinks: children ); }
private IEnumerable<MtpsNavigationNode> SearchWithinGroup(string searchName, MtpsNavigationNode parent, MtpsNodeCore childLink) { Contract.Requires(!String.IsNullOrEmpty(searchName)); Contract.Requires(parent != null); Contract.Requires(childLink != null); Contract.Ensures(Contract.Result<IEnumerable<MtpsNavigationNode>>() != null); if (null == childLink.SubTreeId) return Enumerable.Empty<MtpsNavigationNode>(); var xmlElement = GetTocXmlElement(childLink.SubTreeId.AssetId, childLink.SubTreeId.Version, childLink.SubTreeId.Locale); if (null == xmlElement) return Enumerable.Empty<MtpsNavigationNode>(); var tocNode = ToNavigationNode(parent, xmlElement); return SearchChildren(searchName, parent, tocNode.ChildLinks); }
private IEnumerable<MtpsNavigationNode> SearchChild(string searchName, MtpsNavigationNode parent, MtpsNodeCore childLink) { Contract.Requires(!String.IsNullOrEmpty(searchName)); Contract.Requires(parent != null); Contract.Requires(childLink != null); Contract.Ensures(Contract.Result<IEnumerable<MtpsNavigationNode>>() != null); var tocNode = ToNavigationNode(parent, childLink); return SearchToc(searchName, tocNode); }
private string GetBestLocale(MtpsNodeCore node) { Contract.Requires(null != node); if (null != node.TargetId) { if (!String.IsNullOrEmpty(node.TargetId.Locale)) return node.TargetId.Locale; } if (null != node.SubTreeId) { if (!String.IsNullOrEmpty(node.SubTreeId.Locale)) return node.SubTreeId.Locale; } return Locale; }