What you need to change for the program to work

Mar 30, 2011 at 8:38 AM

Hi together,

today i have donwloaded the project and it didn`t work like allready written here. I checked the code and whoever want`s to get it running needs to change the function GetAvailableForums to the following:


//Visual C# 2008 - .net 3.5 - Any CPU
        public AvailableForumData GetAvailableForums(bool forceRefresh)
        {
            AvailableForumData result = Persister.GetData("availableForums");

            lock (m_lock)
            {
                try
                {

                    if (result == null || forceRefresh)
                    {
                        result = new AvailableForumData();
                        string url = Configuration.AvailableForumsUrl;
                        WebRequest request = HttpWebRequest.Create(url);
                        WebResponse response = request.GetResponse();
                        //string categoryRegex = "
  • (.+?)<"; string categoryRegex = "\\r\\n\\s+

    (.+?)<"; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string text = sr.ReadToEnd(); foreach (var m in Regex.Matches(text, categoryRegex, RegexOptions.Singleline ).OfType()) { AvailableForumCategory category = new AvailableForumCategory { CategoryName = HttpUtility.HtmlDecode(m.Groups[1].Value) }; string block = Regex.Escape(m.Value); string inner = Regex.Match(text, block + "(.+?)(category box|$)", RegexOptions.Singleline).Groups[1].Value; foreach (var f in Regex.Matches(inner, "

  • (.+?)<.+?", RegexOptions.Singleline).OfType()) { AvailableForum forum = new AvailableForum(); forum.ForumLongName = HttpUtility.HtmlDecode(f.Groups[2].Value); // forum.ForumShortName = Regex.Match(f.Groups[1].Value, "http://social.msdn.microsoft.com/Forums/.+?/(.+?)/", RegexOptions.Singleline).Groups[1].Value; forum.ForumShortName = Regex.Match(f.Groups[1].Value, "/Forums/.+?/(.+?)/", RegexOptions.Singleline).Groups[1].Value; category.AvailableForums.Add(forum); } result.Categories.Add(category); } } SaveAvailableForums(result); } } catch { return null; } } return result; }
  •  

    Mar 30, 2011 at 8:40 AM

    The code really looks ugly, i try again:

            public AvailableForumData GetAvailableForums(bool forceRefresh)
            {
                AvailableForumData result = Persister.GetData<AvailableForumData>("availableForums");
    
                lock (m_lock)
                {
                    try
                    {
    
                        if (result == null || forceRefresh)
                        {
                            result = new AvailableForumData();
                            string url = Configuration.AvailableForumsUrl;
                            WebRequest request = HttpWebRequest.Create(url);
                            WebResponse response = request.GetResponse();
                            //string categoryRegex = "<li class=\"category box\"><h2><a.+?>(.+?)<";
                            string categoryRegex = "<li\\sclass=\"category\\sbox\">\\r\\n\\s+<h2><a.+?>(.+?)<";
                            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                            {
                                string text = sr.ReadToEnd();
                                
                                foreach (var m in Regex.Matches(text, categoryRegex, RegexOptions.Singleline ).OfType<Match>())
                                {
                                    AvailableForumCategory category = new AvailableForumCategory { CategoryName = HttpUtility.HtmlDecode(m.Groups[1].Value) };
                                    string block = Regex.Escape(m.Value);
                                    string inner = Regex.Match(text, block + "(.+?)(category box|$)", RegexOptions.Singleline).Groups[1].Value;
    
    
                                    foreach (var f in Regex.Matches(inner, "<li class=\"forum\".+?.+?<a href=\"(.+?)\">(.+?)<.+?</li>", RegexOptions.Singleline).OfType<Match>())
                                    {
                                        AvailableForum forum = new AvailableForum();
                                        forum.ForumLongName = HttpUtility.HtmlDecode(f.Groups[2].Value);
                                        // forum.ForumShortName = Regex.Match(f.Groups[1].Value, "http://social.msdn.microsoft.com/Forums/.+?/(.+?)/", RegexOptions.Singleline).Groups[1].Value;
                                        forum.ForumShortName = Regex.Match(f.Groups[1].Value, "/Forums/.+?/(.+?)/", RegexOptions.Singleline).Groups[1].Value;
                                        category.AvailableForums.Add(forum);
                                    }
    
                                    result.Categories.Add(category);
                                }
                            }
                            SaveAvailableForums(result);
                        }
                    }
                    catch
                    {
                        return null;
                    }
                }
    
                return result;
                
            }