private static Dictionary <string, SelfCertComplianceCountryCollection> fetchSelfCertData() { var data = new Dictionary <string, SelfCertComplianceCountryCollection>(); var complianceGroups = new DynamicNodeList(); var countryList = new DynamicNodeList(); if (fetchComplianceGroups(out complianceGroups)) { foreach (DynamicNode eachComplianceGroup in complianceGroups) { var complianceGroup = new SelfCertComplianceCountryCollection(); complianceGroup.Countries = new List <SelfCertCountry>(); complianceGroup.IsProf = isProfessionalComplianceGroup(eachComplianceGroup); var s = eachComplianceGroup.Name; if (eachComplianceGroup.HasDescendantsOfType("Country", out countryList)) { foreach (DynamicNode eachCountry in countryList) { if (eachCountry.SafeProperty("includeInSelf-Certification") == "1") { complianceGroup.Countries.Add(new SelfCertCountry { CountryName = eachCountry.Name, GermanCountryName = eachCountry.SafeProperty("de"), CountryNodeId = eachCountry.Id, IsActive = false }); } } } data.Add(eachComplianceGroup.Name, complianceGroup); } } return(data); }
public static DynamicNode Down(this DynamicNode context, string nodeTypeAlias) { if (string.IsNullOrEmpty(nodeTypeAlias)) { DynamicNodeList children = new DynamicNodeList(context.ChildrenAsList); return children.Items.First(); } else { return context.Descendants(nodeTypeAlias).Items.FirstOrDefault(); } }
public static int NumberOfBlogsByCreator(DynamicNodeList nodes, string name) { var nodeList = new DynamicNodeList(); foreach (DynamicNode dynamicNode in nodes) { if (dynamicNode.CreatorName == name) { nodeList.Add(dynamicNode); } } return nodeList.Items.Count; }
public object ConvertValueWhenRead(object inputValue) { var list = new DynamicNodeList(); var commaSeparated = inputValue as string; if (!string.IsNullOrEmpty(commaSeparated)) { var ids = commaSeparated.Split(new[] {','}); foreach (var dn in ids.Select(id => new DynamicNode(id))) { list.Add(dn); } } return list; }
private static bool fetchComplianceGroups(out DynamicNodeList complianceGroups) { DynamicNode settingsRoot; if (NodeFacade.settingsRoot(out settingsRoot)) { if (settingsRoot.HasDescendantsOfType("ComplianceGroup", out complianceGroups)) { return(true); } } complianceGroups = null; return(false); }
public static int NumberOfBlogsInMonth(DynamicNodeList nodes, string archiveDate) { var date = Convert.ToDateTime(archiveDate); var nodeList = new DynamicNodeList(); foreach (DynamicNode dynamicNode in nodes) { if (dynamicNode.CreateDate.Month == date.Month && dynamicNode.CreateDate.Year == date.Year) { nodeList.Add(dynamicNode); } } return nodeList.Items.Count; }
public static DynamicNodeList GetNodesByMonth(DynamicNodeList nodes, string archiveDate) { var date = Convert.ToDateTime(archiveDate); var nodeList = new DynamicNodeList(); foreach (DynamicNode dynamicNode in nodes) { if (dynamicNode.CreateDate.Month == date.Month && dynamicNode.CreateDate.Year == date.Year) { nodeList.Add(dynamicNode); } } return nodeList; }
public object ConvertValueWhenRead(object inputValue) { var list = new DynamicNodeList(); var commaSeparated = inputValue as string; if (!string.IsNullOrEmpty(commaSeparated)) { var ids = commaSeparated.Split(new[] { ',' }); foreach (var dn in ids.Select(id => new DynamicNode(id))) { list.Add(dn); } } return(list); }
/// <summary> /// Settings > Compliance Lists Folder > .Children /// </summary> /// <returns> /// Returns a DynamicNodeList which contains the DynamicNodes that represent the user compliance lists /// Each DynamicNode is a compliance list, which can be extracted using GetPropertyValue("compliance") /// </returns> private static DynamicNodeList getUserLists() { DynamicNode settingsRoot; DynamicNodeList complianceListFolder; DynamicNodeList userLists = new DynamicNodeList(); // returned if (NodeFacade.settingsRoot(out settingsRoot)) { if (settingsRoot.HasDescendantsOfType("ComplianceListsFolder", out complianceListFolder)) { userLists = complianceListFolder.First().Children; } } return(userLists); }
internal static DynamicNodeList ConvertSearchResultToDynamicNode(Examine.ISearchResults results) { var list = new DynamicNodeList(); var xd = new XmlDocument(); foreach (var result in results.OrderByDescending(x => x.Score)) { var item = new DynamicBackingItem(result.Id); if (item.Id == 0) continue; var node = (NodeFactory.Node)item.content; var examineResultXml = Umbraco.Core.XmlHelper.AddTextNode(xd, "examineScore", result.Score.ToString()); node.Properties.Add(new NodeFactory.Property(examineResultXml)); list.Add(new DynamicNode(item)); } return list; }
public static DynamicNode Down(this DynamicNode context, int number) { DynamicNodeList children = new DynamicNodeList(context.ChildrenAsList); if (number == 0) { return children.Items.First(); } else { DynamicNode working = context; while (number-- >= 0) { working = children.Items.First(); children = new DynamicNodeList(working.ChildrenAsList); } return working; } }
public static DynamicNodeList GetNodesByTag(DynamicNodeList nodes, string tagSearch) { var nodeList = new DynamicNodeList(); foreach (dynamic node in nodes) { if (node.HasProperty("Tags") && !String.IsNullOrEmpty(node.Tags)) { var tagsList = node.Tags.ToString().Split(','); foreach (var tag in tagsList) { if (tag.Trim().ToLower() == tagSearch.Trim().ToLower()) nodeList.Add(node); } } } return nodeList; }
public static bool HasDescendantsOfType(this DynamicNode node, string documentType, out DynamicNodeList descendants) { var nodes = node.Descendants(documentType); descendants = new DynamicNodeList(); if (nodes == null) { return(false); } else if (nodes.Count() == 0) { return(false); } else { descendants = nodes; return(true); } }
public static bool HasParentsOfType(this DynamicNode node, string documentType, out DynamicNodeList parents) { var nodes = node.Ancestors(documentType); parents = new DynamicNodeList(); if (nodes == null) { return(false); } else if (nodes.Count() == 0) { return(false); } else { parents = nodes; return(true); } }
public static DynamicNodeList GetNodes(DynamicNodeList nodes, string category) { var myNodeList = new DynamicNodeList(); foreach (dynamic dynamicNode in nodes) { var myCategories = dynamicNode.GetProperty("dwtBlogCategories").Value.ToString(); if (!String.IsNullOrWhiteSpace(myCategories)) { var myCategoryList = new List<string>(myCategories.Split(',')); if (myCategoryList.Any(x => x == category)) { myNodeList.Add(dynamicNode); } } } return myNodeList; }
public override bool TryGetMember(GetMemberBinder binder, out object result) { var name = binder.Name; //check the cache first! if (_cachedMemberOutput.TryGetValue(binder.Name, out result)) { return true; } result = null; //this will never be returned if (name.InvariantEquals("ChildrenAsList") || name.InvariantEquals("Children")) { result = GetChildrenAsList; //cache the result so we don't have to re-process the whole thing _cachedMemberOutput.TryAdd(binder.Name, result); return true; } if (binder.Name.InvariantEquals("parentId")) { var parent = n.Parent; if (parent == null) { throw new InvalidOperationException(string.Format("The node {0} does not have a parent", Id)); } result = parent.Id; _cachedMemberOutput.TryAdd(binder.Name, result); return true; } bool propertyExists = false; if (n != null) { bool recursive = false; if (name.StartsWith("_")) { name = name.Substring(1, name.Length - 1); recursive = true; } PropertyResult prop; if (!_cachedProperties.TryGetValue(binder.Name, out prop)) { prop = n.GetProperty(name, recursive, out propertyExists); // check for nicer support of Pascal Casing EVEN if alias is camelCasing: if (prop == null && name.Substring(0, 1).ToUpper() == name.Substring(0, 1) && !propertyExists) { prop = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)), recursive, out propertyExists); } } if (prop != null) { if (TryGetPropertyData(prop, out result)) { //cache the result so we don't have to re-process the whole thing _cachedMemberOutput.TryAdd(binder.Name, result); return true; } } //check if the alias is that of a child type var typeChildren = n.ChildrenAsList; if (typeChildren != null) { var filteredTypeChildren = typeChildren .Where(x => x.NodeTypeAlias.InvariantEquals(name) || x.NodeTypeAlias.MakePluralName().InvariantEquals(binder.Name)) .ToArray(); if (filteredTypeChildren.Any()) { result = new DynamicNodeList(filteredTypeChildren); //cache the result so we don't have to re-process the whole thing _cachedMemberOutput.TryAdd(binder.Name, result); return true; } } //lookup the property using reflection result = GetReflectedProperty(binder.Name); if (result != null) { _cachedMemberOutput.TryAdd(binder.Name, result); return true; } } //if property access, type lookup and member invoke all failed //at this point, we're going to return null //instead, we return a DynamicNull - see comments in that file //this will let things like Model.ChildItem work and return nothing instead of crashing if (!propertyExists && result == null) { //.Where explictly checks for this type //and will make it false //which means backwards equality (&& property != true) will pass //forwwards equality (&& property or && property == true) will fail result = new DynamicNull(); return true; } return true; }
private object ExecuteExtensionMethod(object[] args, string name, bool argsContainsThis) { object result = null; MethodInfo methodToExecute = ExtensionMethodFinder.FindExtensionMethod(typeof(IEnumerable<DynamicNode>), args, name, false); if (methodToExecute == null) { methodToExecute = ExtensionMethodFinder.FindExtensionMethod(typeof(DynamicNodeList), args, name, false); } if (methodToExecute != null) { var genericArgs = (new[] { this }).Concat(args); result = methodToExecute.Invoke(null, genericArgs.ToArray()); } else { throw new MissingMethodException(); } if (result != null) { if (result is IEnumerable<DynamicBackingItem>) { result = new DynamicNodeList((IEnumerable<DynamicBackingItem>)result); } if (result is IEnumerable<DynamicNode>) { result = new DynamicNodeList((IEnumerable<DynamicNode>)result); } if (result is DynamicBackingItem) { result = new DynamicNode((DynamicBackingItem)result); } } return result; }
public bool Where(string predicate) { //Totally gonna cheat here var dynamicNodeList = new DynamicNodeList(); dynamicNodeList.Add(this); var filtered = dynamicNodeList.Where<DynamicNode>(predicate); if (filtered.Count() == 1) { //this node matches the predicate return true; } return false; }
/// <summary> /// Checks if the owner list is null and attempts to create it if there is a parent. /// </summary> /// <returns>Successful if the owners list is not null, false if the owners list could not be created and remains null</returns> private bool EnsureOwnersList() { if (this.ownerList == null && this.Parent != null) { var list = this.Parent.ChildrenAsList.Select(n => new DynamicNode(n)); this.ownerList = new DynamicNodeList(list); } return this.ownerList != null; }
public override bool TryGetMember(GetMemberBinder binder, out object result) { var name = binder.Name; result = null; //this will never be returned if (name == "ChildrenAsList" || name == "Children") { result = GetChildrenAsList; return true; } bool propertyExists = false; if (n != null) { bool recursive = false; if (name.StartsWith("_")) { name = name.Substring(1, name.Length - 1); recursive = true; } var data = n.GetProperty(name, recursive, out propertyExists); // check for nicer support of Pascal Casing EVEN if alias is camelCasing: if (data == null && name.Substring(0, 1).ToUpper() == name.Substring(0, 1) && !propertyExists) { data = n.GetProperty(name.Substring(0, 1).ToLower() + name.Substring((1)), recursive, out propertyExists); } if (data != null) { result = data.Value; //special casing for true/false properties //int/decimal are handled by ConvertPropertyValueByDataType //fallback is stringT if (n.NodeTypeAlias == null && data.Alias == null) { throw new ArgumentNullException("No node alias or property alias available. Unable to look up the datatype of the property you are trying to fetch."); } //contextAlias is the node which the property data was returned from //Guid dataType = ContentType.GetDataType(data.ContextAlias, data.Alias); var dataType = GetDataType(data.ContextAlias, data.Alias); var staticMapping = UmbracoSettings.RazorDataTypeModelStaticMapping.FirstOrDefault(mapping => { return mapping.Applies(dataType, data.ContextAlias, data.Alias); }); if (staticMapping != null) { Type dataTypeType = Type.GetType(staticMapping.TypeName); if (dataTypeType != null) { object instance = null; if (TryCreateInstanceRazorDataTypeModel(dataType, dataTypeType, data.Value, out instance)) { result = instance; return true; } else { LogHelper.Warn<DynamicNode>(string.Format("Failed to create the instance of the model binder")); } } else { LogHelper.Warn<DynamicNode>(string.Format("staticMapping type name {0} came back as null from Type.GetType; check the casing, assembly presence, assembly framework version, namespace", staticMapping.TypeName)); } } if (RazorDataTypeModelTypes != null && RazorDataTypeModelTypes.Any(model => model.Key.Item1 == dataType) && dataType != Guid.Empty) { var razorDataTypeModelDefinition = RazorDataTypeModelTypes.Where(model => model.Key.Item1 == dataType).OrderByDescending(model => model.Key.Item2).FirstOrDefault(); if (!(razorDataTypeModelDefinition.Equals(default(KeyValuePair<System.Tuple<Guid, int>, Type>)))) { Type dataTypeType = razorDataTypeModelDefinition.Value; object instance = null; if (TryCreateInstanceRazorDataTypeModel(dataType, dataTypeType, data.Value, out instance)) { result = instance; return true; } else { LogHelper.Warn<DynamicNode>(string.Format("Failed to create the instance of the model binder")); } } else { LogHelper.Warn<DynamicNode>(string.Format("Could not get the dataTypeType for the RazorDataTypeModel")); } } else { //NOTE: Do we really want to log this? I'm not sure. //if (RazorDataTypeModelTypes == null) //{ // HttpContext.Current.Trace.Write(string.Format("RazorDataTypeModelTypes is null, probably an exception while building the cache, falling back to ConvertPropertyValueByDataType", dataType)); //} //else //{ // HttpContext.Current.Trace.Write(string.Format("GUID {0} does not have a DataTypeModel, falling back to ConvertPropertyValueByDataType", dataType)); //} } //convert the string value to a known type return ConvertPropertyValueByDataType(ref result, name, dataType); } //check if the alias is that of a child type var typeChildren = n.ChildrenAsList; if (typeChildren != null) { var filteredTypeChildren = typeChildren.Where(x => { List<string> ancestorAliases = GetAncestorOrSelfNodeTypeAlias(x); if (ancestorAliases == null) { return false; } return ancestorAliases.Any(alias => alias == name || MakePluralName(alias) == name); }); if (filteredTypeChildren.Any()) { result = new DynamicNodeList(filteredTypeChildren); return true; } } try { result = n.GetType().InvokeMember(binder.Name, System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null, n, null); return true; } catch { //result = null; //return false; } } //if property access, type lookup and member invoke all failed //at this point, we're going to return null //instead, we return a DynamicNull - see comments in that file //this will let things like Model.ChildItem work and return nothing instead of crashing if (!propertyExists && result == null) { //.Where explictly checks for this type //and will make it false //which means backwards equality (&& property != true) will pass //forwwards equality (&& property or && property == true) will fail result = new DynamicNull(); return true; } return true; }
public int Index() { if (this.ownerList == null && this.Parent != null) { var list = this.Parent.ChildrenAsList.Select(n => new DynamicNode(n)); this.ownerList = new DynamicNodeList(list); } if (this.ownerList != null) { List<DynamicNode> container = this.ownerList.Items.ToList(); int currentIndex = container.FindIndex(n => n.Id == this.Id); if (currentIndex != -1) { return currentIndex; } else { throw new IndexOutOfRangeException(string.Format("Node {0} belongs to a DynamicNodeList but could not retrieve the index for it's position in the list", this.Id)); } } else { throw new ArgumentNullException(string.Format("Node {0} has been orphaned and doesn't belong to a DynamicNodeList", this.Id)); } }
/// <summary> /// Returns string of tag and number to represent font strength /// </summary> /// <param name="nodes"></param> /// <returns></returns> public static string ReturnTagsString(DynamicNodeList nodes, string baseNodeUrl) { var tags = new List<String>(); foreach (dynamic node in nodes) { if (node.HasProperty("Tags") && !String.IsNullOrEmpty(node.Tags)) { var tagsList = node.Tags.ToString().Split(','); foreach (var tag in tagsList) { tags.Add(tag); } } } tags.Sort((x, y) => string.Compare(x, y)); var tagsAlreadyUsed = ""; var tagsTalliedAndScored = new List<String[]>(); var totalCountOfTags = 0; // Sort and Score all Tags foreach (var tag in tags) { if (!tagsAlreadyUsed.Contains(tag)) { tagsAlreadyUsed += tag; var tag1 = tag; var numberOfThisTag = tags.Count(tagCounter => tagCounter == tag1); totalCountOfTags += numberOfThisTag; tagsTalliedAndScored.Add(new String[] { numberOfThisTag.ToString(), tag.Trim() }); } } var tagCloudHtml = new List<String>(); for (var i = 0; i < tagsTalliedAndScored.Count; i++) { double tagPercentage = Convert.ToDouble(tagsTalliedAndScored[i][0]) / totalCountOfTags; var hrefStringBase = "<a href=\"{0}?tag={1}\">{1}</a>"; if (tagPercentage > .2) { var href = String.Format(hrefStringBase, baseNodeUrl, tagsTalliedAndScored[i][1]); tagCloudHtml.Add(String.Format("<span class=\"{0}\">{1}</span>", "Strength1", href)); } else if (tagPercentage > .15) { var href = String.Format(hrefStringBase, baseNodeUrl, tagsTalliedAndScored[i][1]); tagCloudHtml.Add(String.Format("<span class=\"{0}\">{1}</span>", "Strength2", href)); } else if (tagPercentage > .1) { var href = String.Format(hrefStringBase, baseNodeUrl, tagsTalliedAndScored[i][1]); tagCloudHtml.Add(String.Format("<span class=\"{0}\">{1}</span>", "Strength3", href)); } else if (tagPercentage > .05) { var href = String.Format(hrefStringBase, baseNodeUrl, tagsTalliedAndScored[i][1]); tagCloudHtml.Add(String.Format("<span class=\"{0}\">{1}</span>", "Strength4", href)); } else { var href = String.Format(hrefStringBase, baseNodeUrl, tagsTalliedAndScored[i][1]); tagCloudHtml.Add(String.Format("<span class=\"{0}\">{1}</span>", "Strength5", href)); } } var tagsHtmlString = tagCloudHtml.Aggregate("<div class=\"TagCloud\">", (current, r) => current + r); tagsHtmlString += "</div>"; return tagsHtmlString; }
/// <summary>Get an array of id's (comma delimited) matched items' property (alias).</summary> public static IList<string> GetIds(DynamicNodeList cmsItems, string propertyAlias, string[] tokens) { IList<string> items = new List<string>(); int cmsItemsCount = cmsItems.Items.Count; int tokensCount = tokens.Length; int i, j = 0; for(i = 0;i < cmsItemsCount;i += 1) { for(j = 0;j < tokensCount;j += 1) { if(BaseUtility.Equals(cmsItems.Items[i].GetProperty(propertyAlias).Value, tokens[j])) { items.Add(cmsItems.Items[i].Id.ToString()); } } } return items; }
public static int NumberOfMonthsArchive(DynamicNodeList nodes) { var monthsDifference = (DateTime.Now.Year * 12 + DateTime.Now.Month) - (nodes.Items.LastOrDefault().CreateDate.Year * 12 + nodes.Items.LastOrDefault().CreateDate.Month); return monthsDifference; }