public QueryCustomization(XmlNode node) { XmlNode xcommon = node.SelectSingleNode("global"); ConfigExists = xcommon != null; if (xcommon != null) { GlobalTable = new GlobalRec(); Dictionary <string, TokenMapRec> maps = GlobalTable.tokenMaps; var xmaps = xcommon.SelectNodes("maps/map"); foreach (XmlNode xmap in xmaps) { bool glb = xmap.Attributes["globalize"] == null || xmap.Attributes["globalize"].Value.ToLower() == "true"; string toid = xmap.Attributes["to-resId"] == null || !glb ? null : xmap.Attributes["to-resId"].Value; string toname = xmap.Attributes["to"] == null ? "" : xmap.Attributes["to"].Value; if (toid == null) { maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToName = toname }); } else { maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToID = toid }); } } } XmlNodeList xdataSrcs = node.SelectNodes("datasource"); if (xdataSrcs == null) { return; } ConfigExists = true; foreach (XmlNode xdatasrc in xdataSrcs) { XmlNodeList xsets = xdatasrc.SelectNodes("set"); DataSourceRec rec = new DataSourceRec(); string src = xdatasrc.Attributes["name"].Value; MapTable.Add(src, rec); foreach (XmlNode xset in xsets) { string set = xset.Attributes["name"].Value; if (!IsValidSetName(src, set)) { continue; } Dictionary <string, TokenMapRec> maps = new Dictionary <string, TokenMapRec>(); rec.TokenMaps.Add(set, maps); var xmaps = xset.SelectNodes("maps/map"); foreach (XmlNode xmap in xmaps) { bool glb = xmap.Attributes["globalize"] == null || xmap.Attributes["globalize"].Value.ToLower() == "true"; string toid = xmap.Attributes["to-resId"] == null || !glb ? null : xmap.Attributes["to-resId"].Value; string toname = xmap.Attributes["to"] == null ? "" : xmap.Attributes["to"].Value; if (toid == null) { maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToName = toname }); } else { maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToID = toid }); } } // var lfilters = xset.SelectNodes("filters"); foreach (XmlNode nfiters in lfilters) { SetFilters setadminflts = new SetFilters(); setadminflts.AllowImplied = nfiters.Attributes["allow-implied"] == null || nfiters.Attributes["allow-implied"].Value.ToLower() == "true" ? true : false; List <TokenFilter> l = new List <TokenFilter>(); foreach (XmlNode n in nfiters.SelectNodes("filter")) { l.Add(getFilter(n, setadminflts.AllowImplied)); } setadminflts.Filters = l.ToArray(); var setfilters = new Dictionary <string, SetFilters>(); setfilters.Add(set, setadminflts); rec.TokenFiltersMap.Add(nfiters.Attributes["type"].Value, setfilters); } } } }
private void GetFilterSection(SetFilters setFilters, StringBuilder sb) { for (int i = 0; i < setFilters.Filters.Length; i++) { var filter = setFilters.Filters[i]; sb.Append(@" " + (i > 0 ? "else " : "") + @"if ("); switch(filter.Target) { case TokenMatchTarget.Sorting: sb.Append("!isquery && ("); break; case TokenMatchTarget.Filtering: sb.Append("isquery && ("); break; } switch(filter.Kind) { case TokenMatchKind.Equals: if (!filter.IsCaseSensitive) sb.Append("tk.TkName.toLowerCase() == '" + filter.FilterExpr + "'.toLowerCase()"); else sb.Append("tk.TkName. == '" + filter.FilterExpr + "'"); break; case TokenMatchKind.Contains: if (!filter.IsCaseSensitive) sb.Append("tk.TkName.toLowerCase().indexOf('" + filter.FilterExpr + "'.toLowerCase()) != -1"); else sb.Append("tk.TkName.indexOf('" + filter.FilterExpr + "') != -1"); break; case TokenMatchKind.StartsWith: if (!filter.IsCaseSensitive) sb.Append("tk.TkName.toLowerCase().indexOf('" + filter.FilterExpr + "'.toLowerCase()) == 0"); else sb.Append("tk.TkName.indexOf('" + filter.FilterExpr + "') == 0"); break; case TokenMatchKind.EndsWith: if (!filter.IsCaseSensitive) sb.Append("tk.TkName.length >= '" + filter.FilterExpr + "'.length && tk.TkName.toLowerCase().indexOf('" + filter.FilterExpr + "'.toLowerCase()) == tk.TkName.length - '" + filter.FilterExpr + "'.length"); else sb.Append("tk.TkName.length >= '" + filter.FilterExpr + "'.length && tk.TkName.indexOf('" + filter.FilterExpr + "') == tk.TkName.length - '" + filter.FilterExpr + "'.length"); break; case TokenMatchKind.Expression: sb.Append(string.Format(filter.FilterExpr, "tk.TkName")); break; case TokenMatchKind.Regex: sb.Append("tk.TkName.match(" + filter.FilterExpr + ")"); break; } switch (filter.Target) { case TokenMatchTarget.Sorting: case TokenMatchTarget.Filtering: sb.Append(")"); break; } sb.Append(@") return " + (filter.IsAllowed ? "true" : "false") + @";"); } sb.Append(@" else return " + (setFilters.AllowImplied ? "true" : "false") + @";"); }
public QueryCustomization(XmlNode node) { XmlNode xcommon = node.SelectSingleNode("global"); ConfigExists = xcommon != null; if (xcommon != null) { GlobalTable = new GlobalRec(); Dictionary<string, TokenMapRec> maps = GlobalTable.tokenMaps; var xmaps = xcommon.SelectNodes("maps/map"); foreach (XmlNode xmap in xmaps) { bool glb = xmap.Attributes["globalize"] == null || xmap.Attributes["globalize"].Value.ToLower() == "true"; string toid = xmap.Attributes["to-resId"] == null || !glb ? null : xmap.Attributes["to-resId"].Value; string toname = xmap.Attributes["to"] == null ? "" : xmap.Attributes["to"].Value; if (toid == null) maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToName = toname }); else maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToID = toid }); } } XmlNodeList xdataSrcs = node.SelectNodes("datasource"); if (xdataSrcs == null) return; ConfigExists = true; foreach (XmlNode xdatasrc in xdataSrcs) { XmlNodeList xsets = xdatasrc.SelectNodes("set"); DataSourceRec rec = new DataSourceRec(); string src =xdatasrc.Attributes["name"].Value; MapTable.Add(src, rec); foreach (XmlNode xset in xsets) { string set = xset.Attributes["name"].Value; if (!IsValidSetName(src, set)) continue; Dictionary<string, TokenMapRec> maps = new Dictionary<string, TokenMapRec>(); rec.TokenMaps.Add(set, maps); var xmaps = xset.SelectNodes("maps/map"); foreach (XmlNode xmap in xmaps) { bool glb = xmap.Attributes["globalize"] == null || xmap.Attributes["globalize"].Value.ToLower() == "true"; string toid = xmap.Attributes["to-resId"] == null || !glb ? null : xmap.Attributes["to-resId"].Value; string toname = xmap.Attributes["to"] == null ? "" : xmap.Attributes["to"].Value; if (toid == null) maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToName = toname }); else maps.Add(xmap.Attributes["from"].Value, new TokenMapRec { ToID = toid }); } // var lfilters = xset.SelectNodes("filters"); foreach (XmlNode nfiters in lfilters) { SetFilters setadminflts = new SetFilters(); setadminflts.AllowImplied = nfiters.Attributes["allow-implied"] == null || nfiters.Attributes["allow-implied"].Value.ToLower() == "true" ? true : false; List<TokenFilter> l = new List<TokenFilter>(); foreach (XmlNode n in nfiters.SelectNodes("filter")) l.Add(getFilter(n, setadminflts.AllowImplied)); setadminflts.Filters = l.ToArray(); var setfilters = new Dictionary<string, SetFilters>(); setfilters.Add(set, setadminflts); rec.TokenFiltersMap.Add(nfiters.Attributes["type"].Value, setfilters); } } } }