protected virtual string GetPropertyValueInternal( DynamicNode model, string propertyAlias, bool recursive ) { string strValue = ""; if ( model != null && !string.IsNullOrEmpty( propertyAlias ) ) { IProperty property = null; if ( !recursive ) { property = model.GetProperty( propertyAlias ); } else { DynamicNode tempModel = model; IProperty tempProperty = tempModel.GetProperty( propertyAlias ); if ( tempProperty != null && !string.IsNullOrEmpty( tempProperty.Value ) ) { property = tempProperty; } while ( property == null && tempModel != null && tempModel.Id > 0 ) { tempModel = tempModel.Parent; if ( tempModel != null ) { tempProperty = tempModel.GetProperty( propertyAlias ); if ( tempProperty != null && !string.IsNullOrEmpty( tempProperty.Value ) ) { property = tempProperty; } } } } if ( property != null ) { strValue = property.Value; } } return strValue; }
public HelperResult ApplyTemplate(DynamicNode node, string mode) { Func<DynamicNode, string, HelperResult> template; //if we are not in debug mode we should use the cached templates //please remember to restart your application if you do any template //changes in production (for files in App_Code this will happen automatically) if (!_debugMode) { var key = new CacheKey { NodeTypeAlias = node.NodeTypeAlias, Mode = mode }; if (_templatesCache.ContainsKey(key)) { template = _templatesCache[key]; } else { template = GetTemplate(node.NodeTypeAlias, mode); _templatesCache.Add(key, template); } } else { template = GetTemplate(node.NodeTypeAlias, mode); } return template(node, mode); }
private int createFolderScructure(DateTime dt, DynamicNode stream) { var names = new string[] {dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString()}; var cs = new ContentService(); var current = stream; var lookUp = true; foreach (var name in names) { if (lookUp) { var exists = current.Children.Where(x => x.Name == name).FirstOrDefault(); if (exists == null) { lookUp = false; var node = cs.CreateContent(name, current.Id, "Folder"); cs.SaveAndPublish(node); Thread.Sleep(2000); current = current.Children.Where(x => x.Name == name).FirstOrDefault(); } } else { var node = cs.CreateContent(name, current.Id, "Folder"); cs.SaveAndPublish(node); current = current.Children.Where(x => x.Name == name).FirstOrDefault(); } } return current.Id; }
public virtual string GetPropertyValue( DynamicNode model, string propertyAlias, Func<DynamicNode, bool> func = null ) { string rtnValue = ""; if ( model != null && !string.IsNullOrEmpty( propertyAlias ) ) { //Check if this node or ancestor has it DynamicNode currentNode = func != null ? model.AncestorOrSelf( func ) : model; if ( currentNode != null ) { rtnValue = GetPropertyValueInternal( currentNode, propertyAlias, func == null ); } //Check if we found the value if ( string.IsNullOrEmpty( rtnValue ) ) { //Check if we can find a master relation string masterRelationNodeId = GetPropertyValueInternal( model, Constants.ProductPropertyAliases.MasterRelationPropertyAlias, true ); if ( !string.IsNullOrEmpty( masterRelationNodeId ) ) { rtnValue = GetPropertyValue( new DynamicNode( masterRelationNodeId ), propertyAlias, func ); } } } return rtnValue; }
public virtual DynamicXml GetXmlPropertyValue( DynamicNode model, string propertyAlias, Func<DynamicNode, bool> func = null ) { DynamicXml xmlNode = null; string propertyValue = GetPropertyValue( model, propertyAlias, func ); if ( !string.IsNullOrEmpty( propertyValue ) ) { xmlNode = new DynamicXml( XElement.Parse( propertyValue, LoadOptions.None ) ); } return xmlNode; }
public static string GetBattleTagByNodeID(int id) { DynamicNode profile = new DynamicNode(id); string battletag = null; if(profile.NodeTypeAlias == BattleTagProfile.documentTypeAlias) { battletag = profile.Name; return battletag; } else { return battletag; } }
public static BlogPost Get(DynamicNodeContext nodeContext, int postId = -1) { if (postId == -1) { postId = GetBlogPostId(); } if (postId <= 0) { return GetEmptyPost(); } var post = new DynamicNode(postId); return MapToBlogPost(post); }
public static List<RelatedLink> GetRelatedLinks(string property, DynamicNode model) { var rlinks = new List<RelatedLink>(); if (string.IsNullOrEmpty(model.GetPropertyValue(property))) { return rlinks; } foreach (var item in (IEnumerable<dynamic>)JsonConvert.DeserializeObject(model.GetPropertyValue(property))) { var result = new RelatedLink(); result.Url = (bool)item.isInternal ? new DynamicNode(item["internal"]).Url : item.link; result.Target = (bool)item.newWindow ? "_blank" : null; result.Caption = item.caption; rlinks.Add(result); } return rlinks; }
/// <summary> /// The site map. /// </summary> /// <param name="renderModel"> /// The render model. /// </param> /// <returns> /// The <see cref="ActionResult"/>. /// </returns> public ActionResult SiteMapTemplate(RenderModel renderModel) { List<SiteMapViewModel> sitemapElements = new List<SiteMapViewModel>(); DynamicNode homepage = new DynamicNode(1089); if (homepage.GetProperty("showInSiteMap") != null && homepage.GetProperty("showInSiteMap").Value == "1") { sitemapElements.Add(new SiteMapViewModel { Url = homepage.Url, LastModified = homepage.UpdateDate }); } DynamicNodeList sitemapPages = homepage.Descendants( n => n.GetProperty("showInSiteMap") != null && n.GetProperty("showInSiteMap").HasValue() && n.GetProperty("showInSiteMap").Value == "1"); foreach (DynamicNode page in sitemapPages) { sitemapElements.Add(new SiteMapViewModel { Url = page.Url, LastModified = page.UpdateDate }); } return this.View("SiteMapTemplate", sitemapElements); }
protected void Page_Load(object sender, EventArgs e) { currentNode = new DynamicNode(Node.getCurrentNodeId()); heroPageUrl = "/profile/heroes/hero.aspx"; if (!Page.IsPostBack && !string.IsNullOrEmpty(Request.QueryString["id"])) { profile = new DynamicNode(Convert.ToInt32(Request.QueryString["id"])); //check if profile has heroes else show the download heroes panel if (!profile.Descendants(x => x.NodeTypeAlias == Hero.documentTypeAlias).IsNull()) { rViewHeroes.DataSource = profile.Descendants(Hero.documentTypeAlias); rViewHeroes.DataBind(); } else { } } }
public override object GetData(ITabContext context) { var plugin = Plugin.Create("Function", "Param", "Type"); try { string url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; int NodeId = 0; if (System.Web.HttpContext.Current.Request["glimpse7GetCheatSheet"] == "true") { return(UmbracoFn.showMethods(typeof(umbraco.MacroEngines.DynamicNode))); } if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request["glimpse7GetContentById"])) { Int32.TryParse(System.Web.HttpContext.Current.Request["glimpse7GetContentById"], out NodeId); } else if (umbraco.presentation.UmbracoContext.Current.PageId != null) { NodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value; } else { return(UmbracoFn.showMethodsValue(typeof(umbraco.MacroEngines.DynamicNode), "content")); } dynamic node = new umbraco.MacroEngines.DynamicNode(NodeId); return(UmbracoFn.showMethodsValue(node, "content")); } catch (Exception ex) { plugin.AddRow().Column(umbraco.presentation.UmbracoContext.Current.PageId); } return(plugin); }
public bool IsDescendantOrSelf(DynamicNode other) { var ancestors = this.AncestorsOrSelf(); return IsHelper(n => ancestors.Items.Find(ancestor => ancestor.Id == other.Id) != null); }
public HtmlString IsNotEqual(DynamicNode other, string valueIfTrue, string valueIfFalse) { return IsHelper(n => n.Id != other.Id, valueIfTrue, valueIfFalse); }
public bool IsNotEqual(DynamicNode other) { return IsHelper(n => n.Id != other.Id); }
private Dictionary <string, object> single(Node child, bool viseBarn) { if (child.NodeTypeAlias == "nettskypakker") { viseBarn = true; } var dynNodeData = new Dictionary <string, object>(); var barn = new List <object> { }; var Bilder = new List <object> { }; var Ikoner = new List <object> { }; var Filer = new List <object> { }; var Tjenester = new List <object> { }; var Nettskypakker = new List <object> { }; if (child.Children.Count > 0 && viseBarn) { var contentPages = ApplicationContext.Services.ContentService.GetChildren(child.Id).OrderBy(x => x.SortOrder).Where(page => page.Trashed == false && page.Published == true); foreach (var item in contentPages) { Node childNode = new Node(item.Id); barn.Add(single(childNode, false)); } dynNodeData["barn"] = barn; } if (child.GetProperty("bilder") != null) { string[] splitted = child.GetProperty("bilder").Value.ToString().Split(','); foreach (string split in splitted) { //var mediaId = Udi.Parse(split).ToPublishedContent(); var mediaId = Udi.Parse(split).ToPublishedContent(); var item_node = new umbraco.MacroEngines.DynamicNode(mediaId); var nyttBilde = new Dictionary <string, object>(); foreach (var verdi in item_node.PropertiesAsList) { if (verdi.Alias == "title" || verdi.Alias == "alt" || verdi.Alias == "src" || verdi.Alias == "umbracoWidth" || verdi.Alias == "umbracoHeight" || verdi.Alias == "umbracoExtension" || verdi.Alias == "createDate") { nyttBilde[verdi.Alias] = verdi.Value.Trim(); } } nyttBilde["x"] = 0; nyttBilde["y"] = 0; var med = Umbraco.Media(item_node.Id); Umbraco.Web.Models.ImageCropDataSet bilde = (Umbraco.Web.Models.ImageCropDataSet)med.umbracoFile; nyttBilde["src"] = bilde.Src; int x = Convert.ToInt32(Convert.ToDouble(nyttBilde["umbracoWidth"]) * 0.5); int y = Convert.ToInt32(Convert.ToDouble(nyttBilde["umbracoHeight"]) * 0.5); nyttBilde["x"] = x; nyttBilde["y"] = y; if (bilde.FocalPoint != null) { double dLeft = Convert.ToDouble(bilde.FocalPoint.Left); double dTop = Convert.ToDouble(bilde.FocalPoint.Top); nyttBilde["focalx"] = Convert.ToDouble(Math.Round((Decimal)dLeft, 2)); nyttBilde["focaly"] = Convert.ToDouble(Math.Round((Decimal)dTop, 2)); } Bilder.Add(nyttBilde); } dynNodeData["Media"] = Bilder; } if (child.GetProperty("ikon") != null) { string[] splitted = child.GetProperty("ikon").Value.ToString().Split(','); foreach (string split in splitted) { //var mediaId = Udi.Parse(split).ToPublishedContent(); var mediaId = Udi.Parse(split).ToPublishedContent(); var item_node = new umbraco.MacroEngines.DynamicNode(mediaId); var nyttBilde = new Dictionary <string, object>(); foreach (var verdi in item_node.PropertiesAsList) { if (verdi.Alias == "title" || verdi.Alias == "alt" || verdi.Alias == "urlName" || verdi.Alias == "src" || verdi.Alias == "umbracoWidth" || verdi.Alias == "umbracoHeight" || verdi.Alias == "umbracoExtension" || verdi.Alias == "createDate") { nyttBilde[verdi.Alias] = verdi.Value.Trim(); } } nyttBilde["x"] = 0; nyttBilde["y"] = 0; var med = Umbraco.Media(item_node.Id); Umbraco.Web.Models.ImageCropDataSet bilde = (Umbraco.Web.Models.ImageCropDataSet)med.umbracoFile; nyttBilde["src"] = bilde.Src; int x = Convert.ToInt32(Convert.ToDouble(nyttBilde["umbracoWidth"]) * 0.5); int y = Convert.ToInt32(Convert.ToDouble(nyttBilde["umbracoHeight"]) * 0.5); nyttBilde["x"] = x; nyttBilde["y"] = y; if (bilde.FocalPoint != null) { double dLeft = Convert.ToDouble(bilde.FocalPoint.Left); double dTop = Convert.ToDouble(bilde.FocalPoint.Top); nyttBilde["focalx"] = Convert.ToDouble(Math.Round((Decimal)dLeft, 2)); nyttBilde["focaly"] = Convert.ToDouble(Math.Round((Decimal)dTop, 2)); } Ikoner.Add(nyttBilde); } dynNodeData["ikoner"] = Ikoner; } if (child.GetProperty("vedlegg") != null) { string[] splitted = child.GetProperty("vedlegg").Value.ToString().Split(','); foreach (string split in splitted) { //var mediaId = Udi.Parse(split).ToPublishedContent(); var mediaId = Udi.Parse(split).ToPublishedContent(); var item_node = new umbraco.MacroEngines.DynamicNode(mediaId); var nyFil = new Dictionary <string, object>(); foreach (var verdi in item_node.PropertiesAsList) { if (verdi.Alias == "umbracoFile" || verdi.Alias == "umbracoExtension" || verdi.Alias == "createDate") { nyFil[verdi.Alias] = verdi.Value.Trim(); } } Filer.Add(nyFil); } dynNodeData["Filer"] = Filer; } if (child.GetProperty("tjenester") != null) { foreach (string uditjenestestring in child.GetProperty("tjenester").Value.ToString().Split(',')) { Tjenester.Add(single(new Node(Umbraco.GetIdForUdi(Udi.Parse(uditjenestestring))), false)); } dynNodeData["Tjenester"] = Tjenester; } // if (child.GetProperty("nettskypakker") != null) // { //foreach (string udipakkestreng in child.GetProperty("nettskypakker").Value.ToString().Split(',')) //{ // Nettskypakker.Add(single(new Node(Umbraco.GetIdForUdi(Udi.Parse(udipakkestreng))), false)); //} //dynNodeData["pakker"] = Nettskypakker; // } if (child.Parent != null) { dynNodeData["Parent"] = child.Parent.UrlName; } dynNodeData["NodeTypeAlias"] = child.NodeTypeAlias; dynNodeData["NodeName"] = child.Name; dynNodeData["url"] = child.UrlName; dynNodeData["NodeId"] = child.Id; dynNodeData["OpprettetDato"] = child.CreateDate.ToString("dd.MM.yyyy"); dynNodeData["OpprettetAv"] = child.WriterName; foreach (umbraco.NodeFactory.Property egenskap in child.Properties) { if (egenskap.Alias == "media") { } else if (egenskap.Alias == "tjenester") { } else { dynNodeData[egenskap.Alias] = egenskap.Value.Trim(); } } return(dynNodeData); }
public static dynamic GetNodeByNameRelative(DynamicNode model, string name) { return model.Descendants( x => string.Compare(x.Name, name, StringComparison.OrdinalIgnoreCase) == 0).Items.FirstOrDefault(); }
public static DynamicNode GetHomeNodeStrongTyped(DynamicNode model) { return model.AncestorOrSelf("Home"); }
public HtmlString IsAncestorOrSelf(DynamicNode other, string valueIfTrue, string valueIfFalse) { var descendants = this.DescendantsOrSelf(); return IsHelper(n => descendants.Items.Find(descendant => descendant.Id == other.Id) != null, valueIfTrue, valueIfFalse); }
/// <summary>Get URL by content item.</summary> public static string GetUrl(Object id) { var cmsItem = new DynamicNode(id); var url = GetUrl(cmsItem); return String.IsNullOrEmpty(url) ? null : url; }
private static BlogPost MapToBlogPost(DynamicNode post) { return new BlogPost { Id = post.Id, Author = GetAuthor(post.GetPropertyValue("uBlogsyPostAuthor")), Date = DateTime.Parse(post.GetPropertyValue("uBlogsyPostDate", DateTime.UtcNow.ToString("dd MMM yyyy"))).ToString("dd MMM yyyy"), Title = post.GetPropertyValue("uBlogsyContentTitle", "Sorry, nothing found").Wikify(), Summary = post.GetPropertyValue("uBlogsyContentSummary", "Sorry, nothing found").Wikify(), Content = post.GetPropertyValue("uBlogsyContentBody", "Sorry, nothing found").Wikify(), Image = GetImageUrl(post.GetPropertyValue("uBlogsyPostImage")) }; }
public static string GetTitle(this DynamicNode dynamicNode) { dynamic node = new DynamicNode(dynamicNode.Id); return Util.Coalesce(node.NavivationTitle.ToString(), node.PageTitle.ToString(), node.Name.ToString()); }
public static HelperResult Render(DynamicNode node, string mode = "") { return RazorScaffoldCore.Instance.ApplyTemplate(node, mode); }
private static string ReplaceUmbracoLinks(string macroTagString) { var regex = new Regex("{localLink:[0-9]+}", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); var matches = regex.Matches(macroTagString); foreach (Match match in matches) { var regexNum = new Regex(@"\d+"); var matchesNum = regexNum.Matches(match.ToString()); if (matchesNum.Count > 0) { DynamicNode node = new DynamicNode(matchesNum[0].Value); string url = node.Url; url = url.Remove(0, 1); macroTagString = macroTagString.Replace(match.ToString(), url); } } return macroTagString; }
public HtmlString IsDescendantOrSelf(DynamicNode other, string valueIfTrue, string valueIfFalse) { var ancestors = this.AncestorsOrSelf(); return IsHelper(n => ancestors.Items.Find(ancestor => ancestor.Id == other.Id) != null, valueIfTrue, valueIfFalse); }
public bool IsAncestorOrSelf(DynamicNode other) { var descendants = this.DescendantsOrSelf(); return IsHelper(n => descendants.Items.Find(descendant => descendant.Id == other.Id) != null); }
private DynamicNode getStream() { DynamicNode n = new DynamicNode(-1); return n.DescendantsOrSelf(StreamTypeAlias).FirstOrDefault(); }
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; }
/// <summary>Get URL by content item.</summary> public static string GetUrl(DynamicNode cmsItem) { return cmsItem != null ? cmsItem.Url : null; }
public static dynamic GetNodeByName(DynamicNode model, string name) { return GetHomeNodeStrongTyped(model).Descendants( x => string.Compare(x.Name, name, StringComparison.OrdinalIgnoreCase) == 0).Items.FirstOrDefault(); }
/// <summary> /// Returns the xml value of a property on the product. Will traverse the content tree recursively to find the value. Will also use the master relation property of the product to search master products. /// </summary> /// <param name="storeId">Id of the store.</param> /// <param name="model">The product as a DynamicNode.</param> /// <param name="propertyAlias">Alias of the property to find.</param> /// <param name="func">A function to filter the result.</param> /// <returns>The xml value of the property.</returns> public static DynamicXml GetXmlPropertyValue( long storeId, DynamicNode model, string propertyAlias, Func<DynamicNode, bool> func = null ) { return DynamicNodeProductInformationExtractor.Instance.GetXmlPropertyValue( model, propertyAlias, func ); }
public static DynamicNode GetNodeByNameStrongTyped(DynamicNode model, string name) { return (DynamicNode)GetNodeByName(model, name); }
public HtmlString IsEqual(DynamicNode other, string valueIfTrue) { return IsHelper(n => n.Id == other.Id, valueIfTrue); }