/// <summary> /// Returns a string representation of the common grammatical list equivalent of the provided array. /// </summary> /// <param name="cultureInfo">The culture info.</param> /// <param name="array">The array.</param> /// <returns></returns> public static string GetGrammerForList(this CultureInfo cultureInfo, IEnumerable <string> list) { if (list == null) { throw new ArgumentNullException("list"); } var array = list.ToArray(); switch (cultureInfo.TwoLetterISOLanguageName) { default: switch (array.Length) { case 0: return(string.Empty); case 1: return(array[1]); case 2: return(StringEx.Axb(array[0], " and ", array[1])); } var b = new StringBuilder(); int maxArrayIndex = (array.Length - 1); for (int index = 0; index < array.Length; index++) { b.Append(array[index]); b.Append(index != maxArrayIndex ? ", " : ", and "); } return(b.ToString()); } }
protected override void Render(HtmlTextWriter w) { int beginYear = BeginYear; int currentYear = DateTime.Now.Year; string yearText = (beginYear > 0 ? beginYear.ToString(CultureInfo.InvariantCulture) : string.Empty); if (currentYear > beginYear) { yearText = StringEx.Axb(yearText, "-", currentYear.ToString(CultureInfo.InvariantCulture)); } Text = Text.Replace("{0}", yearText); base.Render(w); }
internal static void AddCssStyle(this TagBuilder tagBuilder, string id, string value) { string oldValue; var attributes = tagBuilder.Attributes; if (attributes.TryGetValue("class", out oldValue)) { attributes["style"] = StringEx.Axb(id, ":", value) + "; " + oldValue; } else { attributes["style"] = StringEx.Axb(id, ":", value); } }
public HtmlBuilder RenderImageButton(string url, string alt, string commandEvent, Nparams args) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } _writeCount++; string onClickEvent = null; if (args != null) { var imageAttrib = args.Slice <Nparams>("image"); if (args.HasValue()) { onClickEvent = args.Slice <string>("onclick"); if (args.HasValue()) { AddAttribute(args, null); } } if (imageAttrib != null) { AddAttribute(imageAttrib, null); } } _textWriter.AddAttributeIfUndefined(HtmlTextWriterAttribute.Alt, (alt ?? string.Empty)); if (!string.IsNullOrEmpty(alt)) { _textWriter.AddAttributeIfUndefined(HtmlTextWriterAttribute.Title, alt); } _textWriter.AddAttributeIfUndefined(HtmlTextWriterAttribute.Src, url); if ((!string.IsNullOrEmpty(commandEvent)) || (!string.IsNullOrEmpty(onClickEvent))) { _textWriter.AddAttributeIfUndefined(HtmlTextWriterAttribute.Onclick, StringEx.Axb(onClickEvent, ";", commandEvent) + ";return(false);"); } _textWriter.AddAttributeIfUndefined(HtmlTextWriterAttribute.Type, "image"); _textWriter.RenderBeginTag(HtmlTextWriterTag.Input); _textWriter.RenderEndTag(); return(this); }
protected virtual SiteMapNode CreateSiteMapNodeFromDataReader(SiteMapNode parentNode, Dictionary <string, SiteMapNodeEx> nodes, List <VirtualNode> virtualNodes, List <AddProviderNode> addProviderNodes, PageOrdinal ordinal, IDataReader r, ref string hiddenRootTreeId) { if (r.IsDBNull(ordinal.TreeId)) { throw new ProviderException("Missing node ID"); } var treeId = r.GetString(ordinal.TreeId); if (nodes.ContainsKey(treeId)) { throw new ProviderException("Duplicate node ID"); } var visible = !r.Field <bool>(ordinal.IsHidden); var key = r.Field <int>(ordinal.Key); var uid = r.Field <string>(ordinal.Uid); var defaultTreeId = r.Field <string>(ordinal.DefaultTreeId); var type = r.Field <string>(ordinal.Type); var id = r.Field <string>(ordinal.Id); var name = r.Field <string>(ordinal.Name); var sectionId = r.Field <string>(ordinal.SectionId); //var attrib = r.Field<Nattrib>(ordinal.AttribStream); var attrib = BuildAttrib(r.Field <string>(ordinal.AttribStream)); // var pageDynamism = r.Field <string>(ordinal.PageDynamism); var lastModifyDate = r.Field <DateTime?>(ordinal.LastModifyDate); var virtualize = r.Field <string>(ordinal.Virtualize); // hidden branches if (!visible) { if (hiddenRootTreeId == null || !treeId.StartsWith(hiddenRootTreeId)) { hiddenRootTreeId = treeId; } } else if (hiddenRootTreeId != null) { if (treeId.StartsWith(hiddenRootTreeId)) { visible = false; } else { hiddenRootTreeId = null; } } // make url Action setRoute = null; SiteMapNodeEx node; switch (type) { case "X-AddProvider": addProviderNodes.Add(new AddProviderNode(virtualize, parentNode, x => { x.Title = name; var externalProvider = (x.Provider as StaticSiteMapProviderEx); if (externalProvider != null) { externalProvider.RebaseNodesRecurse(x, "/" + id); } })); return(null); case "X-Section": SiteMapVirtualNode virtualNode; node = virtualNode = new SiteMapSectionNode(_provider, uid, "/" + id, name); setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node); virtualNodes.Add(new VirtualNode(virtualNode, defaultTreeId)); break; case "E-Form": node = new SiteMapFormNode(_provider, uid, "/" + id, name); node.Set <SiteMapNodePartialProviderExtent>(new SiteMapNodePartialProviderExtent()); setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node); break; case "E-ListDetail": node = new SiteMapListDetailNode(_provider, uid, "/" + id, name); node.Set <SiteMapNodePartialProviderExtent>(new SiteMapNodePartialProviderExtent()); setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node); break; case "X-Link": id = StringEx.Axb(sectionId, "/", id); string linkUri; if (!attrib.TryGetValue("LinkUri", out linkUri)) { linkUri = "/"; } node = new SiteMapLinkNode(_provider, uid, "/" + id, name) { LinkUri = linkUri }; node.Set <Func <IDynamicNode, RouteData> >(nodeEx => { var linkNodeEx = (nodeEx as SiteMapLinkNode); if (linkNodeEx != null) { var context = HttpContext.Current; var query = context.Request.Url.Query; context.Response.Redirect(query.Length == 0 ? linkNodeEx.LinkUri : linkNodeEx.LinkUri + query); } return(null); }); break; case "X-Content": id = StringEx.Axb(sectionId, "/", id); node = new SiteMapPageNode(_provider, uid, "/" + id, name); setRoute = () => SetRouteInNode(_routeCreator.CreateRoutes(node, id, virtualize), node); break; default: throw new InvalidOperationException(); } node.Visible = visible; // map attrib if (attrib != null) { foreach (var attribKey in attrib.Keys) { node[attribKey] = attrib[attribKey]; } } // content var sectionNode = GetParentNodeFromDataReader(nodes, _rootNode, ordinal, r, true); node.Set <SiteMapNodeContentExtent>(new SiteMapNodeContentExtent { Shard = _connectShard, Key = key, TreeId = treeId, SectionNode = sectionNode, Sequence = _sequence++ }); var contentNode = (node as SiteMapPageNode); if (contentNode != null) { contentNode.LastModifyDate = lastModifyDate; contentNode.PageDynamism = pageDynamism; contentNode.PagePriority = null; } nodes.Add(treeId, node); // set route last so node values are populated before routes are determined. if (setRoute != null) { setRoute(); } return(node); }