示例#1
0
        /// <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);
            }
        }
示例#2
0
        /// <summary>
        /// Normalize list of categories.
        /// </summary>
        public void NormalizeCategories()
        {
            if (BLANK(this.category))
            {
                return;
            }

            String[] categories = Strings.Split(", ", this.category);
            var      size       = SIZE(categories);

            if (size == 1)
            {
                return;
            }

            var categoryTags = new TArrayList();

            for (int n1 = 0; n1 < size; n1++)
            {
                String category1 = categories[n1];
                if (!categoryTags.Contains(category1))
                {
                    categoryTags.Add(category1);
                }
            }

            this.category = Strings.Join(", ", (String[])categoryTags.ToArray(
                                             typeof(String)
                                             ));
        }
示例#3
0
        /// <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));
            }
        }
示例#4
0
        /// <summary>
        /// Fetch info from RSS-feed.
        /// </summary>
        /// <param name="url">Feed url</param>
        /// <returns>Resulting array of items</returns>
        public static Object[] FetchRss(String url)
        {
            var items = new TArrayList();

            XmlDocument rssXmlDoc = new XmlDocument();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssXmlDoc.NameTable);

            nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

            // Load the RSS file from the RSS URL
            try {
                rssXmlDoc.Load(url);
            }
            catch (Exception ex1) {
                var matchCollection = Regex.Matches(ex1.Message, "'([^']+)' is an undeclared prefix. Line [0-9]+, position [0-9]+.");
                if (matchCollection.Count > 0)
                {
                    var prefix = matchCollection[0].Groups[1].Value;
                    try
                    {
                        var    client  = new System.Net.WebClient();
                        var    content = (new System.Net.WebClient()).DownloadString(url);
                        byte[] bytes   = Encoding.Default.GetBytes(content);
                        content = Encoding.UTF8.GetString(bytes);
                        //content = System.Text.Encoding.UTF8.GetBytes(content).ToString();
                        var pattern = CAT("<", prefix, ":[^>]+>[^<]+</", prefix, ":[^>]+>");
                        content = Regex.Replace(content, pattern, "");
                        rssXmlDoc.LoadXml(content);
                    }
                    catch (Exception ex2) {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }

            // Parse the Items in the RSS file
            XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

            // Iterate through the items in the RSS file
            foreach (XmlNode rssNode in rssNodes)
            {
                var item = new THashtable();

                XmlNodeList itemNodes = rssNode.SelectNodes("*");
                foreach (XmlNode itemNode in itemNodes)
                {
                    String name = itemNode.Name;
                    String text = itemNode.InnerXml;
                    if (text.StartsWith("<![CDATA["))
                    {
                        text = text.Replace("<![CDATA[", "").Replace("]]>", "");
                    }

                    if (name == "category")
                    {
                        if (item[name] == null)
                        {
                            item[name] = text;
                        }
                        else
                        {
                            item[name] += ", " + text;
                        }
                    }
                    else if (name == "dc:creator")
                    {
                        THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable();
                        dc["creator"] = text;
                        item["dc"]    = dc;
                    }
                    else if (name == "dc:date")
                    {
                        THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable();
                        dc["date"] = text;
                        item["dc"] = dc;
                    }
                    else
                    {
                        item[name] = text;
                    }
                }
                items.Add(item);
            }
            return(items.ToArray());
        }
示例#5
0
        /// <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());
        }