p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 (http://p2p.wrox.com/forumdisplay.php?f=264)
-   -   Articles/links that have TBH relevance (http://p2p.wrox.com/showthread.php?t=62892)

jimibt October 15th, 2007 07:22 AM

Articles/links that have TBH relevance
 
The idea of this thread is that articles or links are posted hi-lighting various techniques or tips that can be adapted for use in TBH to either make it more scalable, simpler or generally more elegant. I'll kick off with this article:

http://davidhayden.com/blog/dave/arc...erPattern.aspx

followed by code examples of it's use presently and proposed in TBH:

presently from BLL\Forums\Forum.cs:

        public static Forum GetForumByID(int forumID)
        {
            Forum forum = null;
            string key = "Forums_Forum_" + forumID.ToString();

            if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                forum = (Forum)BizObject.Cache[key];
            }
            else
            {
                forum = GetForumFromForumDetails(SiteProvider.Forums.GetFo rumByID(forumID));
                BaseForum.CacheData(key, forum);
            }
            return forum;
        }

proposed/amended:

        public static Forum GetForumByID(int forumID)
        {
            Forum forum = null;
            string key = "Forums_Forum_" + forumID.ToString();

            // get the cachedata upfront into an object
            object data = BizObject.Cache[key];
            if (BaseForum.Settings.EnableCaching && data != null)
            {
                // if test is passed, then set forum to typeof (Forum)data;
                forum = (Forum)data;
            }
            else
            {
                forum = GetForumFromForumDetails(SiteProvider.Forums.GetFo rumByID(forumID));
                BaseForum.CacheData(key, forum);
            }
            return forum;
        }

hope this makes sense. it certainly 'beats' the race condition and the if statement really only tests for cacheing being enabled as well as the data object not being null. if the condition is met, then the Forum forum object is set to the data object as type Forum.

one worth modifying and using throughout.

[edit] the url above is making the page very wide, i couldn't get the standard <a href="www.site.com">description</a> to work. any tips??

jimi

http://www.originaltalent.com

Maxxim October 15th, 2007 08:00 AM

It's a good point!

The first version was:

if (BaseForum.Settings.EnableCaching && BizObject.GetCacheData(key) != null)

But, and if you write:

if (BizObject.GetCacheData(key) != null && BaseForum.Settings.EnableCaching)

?

Did you tested if the first condition is FALSE, ASPNET will verify the second condition?

Maxxim October 15th, 2007 08:16 AM

:( I forgot the Null Check

I'll edit the last post


jimibt October 15th, 2007 08:36 AM

Max,

yes, no matter the order of the expressions within the brackets, both will be evaluated. however, if an exception were to occur on the 1st expression, then the second would not be evaluated.


jimi

http://www.originaltalent.com

jimibt October 15th, 2007 09:06 AM

Another little TIP. based on a question by trystanc on this forum, he asked about the thread safety of singleton patterns. after a bit of research, i came up with a minor change that addresses the failure in the TBH implementation. anyway, here's a link to the original thread, as well as my code changes below:

http://p2p.wrox.com/topic.asp?TOPIC_ID=65461

here's how my ForumsProvider (DAL\Provider\ForumsProvider.cs) 'intro' looks now:

namespace MB.TheBeerHouse.DAL
{
    public abstract class ForumsProvider : DataAccess
    {
        static private readonly ForumsProvider _instance = (ForumsProvider)Activator.CreateInstance(
                    Type.GetType(Globals.Settings.Forums.ProviderType) );

        static ForumsProvider() { }

        static public ForumsProvider Instance
        {
            get
            {
                return _instance;
            }
        }

        public ForumsProvider()
        {
            this.ConnectionString = Globals.Settings.Forums.ConnectionString;
            this.EnableCaching = Globals.Settings.Forums.EnableCaching;
            this.CacheDuration = Globals.Settings.Forums.CacheDuration;
        }
        // other code below unchanged

hope this makes sense.

jimi

http://www.originaltalent.com

Maxxim October 17th, 2007 06:25 PM

If someone wants to add Page Threads Links to BrowseThreads Page do follow the link on the bottom.
(This script can redirect too to last page!
If you want to go to the second page of thread127 you use ...showthread.aspx?threadid=127&pg=2
If you want to go to the last page of thread127 you use ...showthread.aspx?threadid=127&pg=last)

The result is:
http://img521.imageshack.us/img521/1...nkpagespm9.jpg

The script is:
http://p2p.wrox.com/topic.asp?TOPIC_ID=65938


ViagraFalls October 18th, 2007 04:49 AM

Jimi, I'd nominate your post where you described how to add threads to the breadcrumbs to be posted here, too :)

http://entropia-online.blogspot.com/

jimibt October 18th, 2007 04:51 AM

Quote:

quote:Originally posted by ViagraFalls
 Jimi, I'd nominate your post where you described how to add threads to the breadcrumbs to be posted here, too :)

http://entropia-online.blogspot.com/
Peter,

ermm - i can't remember that one :). could you add the link??

thanks !!

jimi

http://www.originaltalent.com

ViagraFalls October 18th, 2007 05:45 AM

Posted - 03/20/2007 : 4:53:20 PM Report Abuse


--------------------------------------------------------------------------------

TIP!!
========

quick tip (this may have been covered before but it bugged me for a few hours). to get the breadcrumbs to 'follow' from forum to threads, you have to do 2 things:

1. amend the web.sitemap as follows:

      <siteMapNode title="$Resources: SiteMap, Forum" url="~/ShowForums.aspx">
        <siteMapNode title="$Resources: SiteMap, Browse_Threads" url="~/BrowseThreads.aspx" />
        <siteMapNode title="$Resources: SiteMap, Thread" url="~/ShowThread.aspx" />
      </siteMapNode>

2. open the App_GlobalResources\SiteMap.resx and add a new entry:

name: Browse_Threads
Value: Browse Threads

thats it - rebake and your breadcrumbs should now be complete!! :)

Posted by jimi in this thread: http://p2p.wrox.com/topic.asp?TOPIC_...hichpage=1#top

http://entropia-online.blogspot.com/

jimibt June 4th, 2008 05:01 AM

found an interesting article re a project called 'velocity' which describes the 'next' big thing in layering the application architecture. basically, it's a kind of distributed 'super-cache' that sits between the business layer and the data access layer. does it sound familiar :D. anyway, i think the idea would be to have an actual cache layer between the BLL and DAL. you can read the 1st thoughts on it here:

http://blogs.msdn.com/velocity/archi...-velocity.aspx

[edit] plus followup on the initial blog:

http://blogs.msdn.com/velocity/archi...-followup.aspx

jimi

http://www.originaltalent.com


All times are GMT -4. The time now is 10:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.