/// <summary> /// Call method of given class using provided arguments. /// </summary> /// <param name="class_name">Class name</param> /// <param name="args0">Constructor args</param> /// <param name="method_name">Method name</param> /// <param name="args">List of arguments</param> /// <returns>Result of method execution</returns> public static Object CallMethod(String class_name, TArrayList args0, String method_name, TArrayList args) { Type type = Type.GetType(class_name.Replace('/', '.')); Type[] types0 = GetTypes(args0); System.Reflection.ConstructorInfo constructorInfo = type.GetConstructor(types0); Object doObject = constructorInfo.Invoke(args0.ToArray()); Type[] types = GetTypes(args); System.Reflection.MethodInfo methodInfo = type.GetMethod(method_name, types); if (methodInfo != null) { if (args != null && args.Size() > 0) { return(methodInfo.Invoke(doObject, args.ToArray())); } else { return(methodInfo.Invoke(doObject, null)); } } else { return(null); } }
private static Type[] GetTypes(TArrayList args) { Type[] types = args != null && args.Size() > 0 ? new Type[args.Size()] : new Type[0]; if (types.Length > 0) { for (int n = 0; n < args.Size(); n++) { types[n] = args[n].GetType(); if (args[n] is String) { int result; if (int.TryParse((String)args[n], out result)) { types[n] = typeof(int); args[n] = result; } } } } return(types); }
/// <summary> /// Call static method of given class using provided arguments. /// </summary> /// <param name="class_name">Class name</param> /// <param name="method_name">Method name</param> /// <param name="args">List of arguments</param> /// <returns>Result of method execution</returns> public static Object CallStaticMethod(String class_name, String method_name, TArrayList args) { Type type = Type.GetType(class_name.Replace('/', '.')); System.Reflection.MethodInfo methodInfo = type.GetMethod(method_name); if (args != null && args.Size() > 0) { return(methodInfo.Invoke(null, args.ToArray())); } else { return(methodInfo.Invoke(null, null)); } }
/// Execute main logic for Menu block public override void Execute() { var publicPages = new TArrayList(); var bookmark = (String)null; if (this.context.Contains("Name_Category")) { bookmark = CAT("#", Config.NAME_ITEMS, "_by_", this.context["Name_Category"]); } publicPages.Add("Home"); publicPages.Add("home"); if (this.context.IsMobile) { publicPages.Add(Config.NAME_ITEMS); publicPages.Add("items"); if (Config.SHOW_BOTTOM && this.context.Contains("Name_Category")) { publicPages.Add(CAT("By ", this.context["Name_Category"])); publicPages.Add(bookmark); //publicPages.Add("RSS Feeds"); //publicPages.Add("#read_rss_feeds"); } publicPages.Add("Sources"); publicPages.Add("sources"); } else { publicPages.Add(CAT("Browse ", Config.NAME_ITEMS)); publicPages.Add("items"); if (Config.SHOW_BOTTOM && this.context.Contains("Name_Category")) { publicPages.Add(CAT(Config.NAME_ITEMS, " by ", this.context["Name_Category"])); publicPages.Add(bookmark); publicPages.Add("Read RSS Feeds"); publicPages.Add("#Read_RSS_Feeds"); } publicPages.Add("Sources"); publicPages.Add("sources"); } var menuItems = new TArrayList(); for (int n = 0; n < publicPages.Size(); n += 2) { var row = new THashtable(); var title = STR(publicPages[n + 0]); var page = STR(publicPages[n + 1]); var href = (String)null; if (EQ(page, "home")) { href = Config.TOP_DIR; } else { if (EQ(page.Substring(0, 1), "#")) { href = page; } else { href = this.GetLink(Config.INDEX_PAGE, "?p=", null, page); } } row["[#Link]"] = href; row["[#LinkText]"] = title; row["[#Prefix]"] = n != 0 ? " • " : " "; menuItems.Add(row); } var prepare = new THashtable(); prepare["[#MenuItems]"] = menuItems; this.Write("menu", prepare); }
/// <summary> /// Execute template processing. /// </summary> /// <param name="template">Template in form of the list of lines.</param> /// <param name="hash">Data for merging with template.</param> /// <returns>Resulting content.</returns> private String ProcessTemplate(TArrayList template, THashtable hash) { if (this.context.IsMobile) { if (hash == null) { hash = new THashtable(); } hash["[#Is_Mobile]"] = 1; } var trimLine = true; var trimEnd = EOL; var ifMode = 0; var repeatMode = 0; var ifBuf = new TArrayList(); var repeatBuf = new TArrayList(); var ifWhat = ""; var repeatWhat = ""; var content = ""; for (int n = 0; n < template.Size(); n++) { var line = (String)template[n]; var lineNoComments = TrimComments(line); //, BLANK(this.context.Api)); //TODO if (ifMode > 0) { if (lineNoComments.IndexOf("#if") == 0) { ifMode++; } if (lineNoComments.IndexOf("#end if") == 0) { if (ifMode == 1) { var not = (ifWhat.IndexOf("!") == 0); var eq = (ifWhat.IndexOf("==") != -1); var neq = (ifWhat.IndexOf("!=") != -1); var processFlag = false; if (not == true) { if (!hash.ContainsKey(ifWhat.Substring(1))) //TODO { processFlag = true; } } else { if (eq) { String[] ifWhatArray = Strings.Split("==", ifWhat); String ifWhat1 = ifWhatArray[0]; String ifWhat2 = ifWhatArray[1]; if (hash.ContainsKey(ifWhat1) && EQ(hash[ifWhat1], ifWhat2)) { processFlag = true; } } else if (neq) { String[] ifWhatArray = Strings.Split("!=", ifWhat); String ifWhat1 = ifWhatArray[0]; String ifWhat2 = ifWhatArray[1]; if (hash.ContainsKey(ifWhat1) && !EQ(hash[ifWhat1], ifWhat2)) { processFlag = true; } } else if (hash.ContainsKey(ifWhat)) { processFlag = true; } } if (processFlag) { content += ProcessTemplate(ifBuf, hash); } ifBuf = new TArrayList(); } else { ifBuf.Add(line); } ifMode--; } else { ifBuf.Add(line); } } else if (repeatMode > 0) { if (lineNoComments.IndexOf("#repeat") == 0) { repeatMode++; } if (lineNoComments.IndexOf("#end repeat") == 0) { if (repeatMode == 1) { if (hash.ContainsKey(repeatWhat)) { var rows = (TArrayList)hash[repeatWhat]; for (int r = 0; r < rows.Size(); r++) { content += ProcessTemplate(repeatBuf, (THashtable)rows[r]); } hash.Remove(repeatWhat); } repeatBuf = new TArrayList(); } else { repeatBuf.Add(line); } repeatMode--; } else { repeatBuf.Add(line); } } else { if (lineNoComments.IndexOf("#if") == 0) { ifMode = repeatMode > 0 ? 2 : 1; ifWhat = lineNoComments.Substring(4).Trim(); } else if (lineNoComments.IndexOf("#repeat") == 0) { repeatMode++; repeatWhat = lineNoComments.Substring(8).Trim(); repeatBuf = new TArrayList(); } else { if (trimLine) { line = line.Trim(); line += trimEnd; } content += line; } } } var result = FormatTemplate(content, hash); return(result); }
/// <summary> /// Add standard categories (from DB) to current item. /// </summary> /// <param name="dsCategories">DataSet with categories (pre-loaded from DB).</param> /// <param name="lang">Input language.</param> /// <returns>Number of added categories.</returns> public int AddStandardCategories(DataSet dsCategories, String lang) { //if (BLANK(this.description)) // return; var categoryTags = new TArrayList(); if (!BLANK(this.category)) { categoryTags.AddAll(Strings.Split(", ", this.category)); } for (int n1 = 0; n1 < dsCategories.GetSize(); n1++) { var oCategory = dsCategories.GetRow(n1); var rssAllowedKey = STR(oCategory["s_CatId"]); var name = STR(oCategory["s_Name"]); var filterValue = STR(oCategory["s_Filter"]); String[] filterChunks = Strings.Split("~", filterValue); String[] includeChunks = SIZE(filterChunks) > 0 ? Strings.Split("\\|", filterChunks[0]) : Strings.EmptyArray(); String[] excludeChunks = SIZE(filterChunks) > 1 ? Strings.Split("\\|", filterChunks[1]) : Strings.EmptyArray(); var includeFlag = false; for (int n2 = 0; n2 < SIZE(includeChunks); n2++) { var includeChunk = includeChunks[n2]; //Regex.Escape(includeChunks[n2]); if (Regex.IsMatch(this.title, includeChunk, RegexOptions.IgnoreCase)) { includeFlag |= true; break; } if (!BLANK(this.description) && Regex.IsMatch(this.description, includeChunk, RegexOptions.IgnoreCase)) { includeFlag |= true; break; } } for (int n3 = 0; n3 < SIZE(excludeChunks); n3++) { var excludeChunk = excludeChunks[n3]; //Regex.Escape(excludeChunks[n3]); if (Regex.IsMatch(this.title, excludeChunk, RegexOptions.IgnoreCase)) { includeFlag &= false; break; } if (!BLANK(this.description) && Regex.IsMatch(this.description, excludeChunk, RegexOptions.IgnoreCase)) { includeFlag &= false; break; } } if (includeFlag) { categoryTags.Add(name); } } if (categoryTags.Size() == 0) { return(0); } //TODO //TArrayList uniqueCategories = this.NormalizeList(categoryTags, lang); //category = String.Join(", ", uniqueCategories); this.category = Strings.Join(", ", (String[])categoryTags.ToArray( typeof(String) )); return(categoryTags.Size()); }