CSharpFeeds - All your C# feeds in one place.

Sponsors

Tuesday, February 06, 2007

CS Dev Guide: Referrals

by Keyvan Nayyeri via Keyvan Nayyeri on 2/6/2007 7:57:25 PM

A while back I was working on a custom control to deploy it to my blog but didn't finish it.  Today I worked on it again and may add it to this blog after installing first Beta version of Community Server 2007.  This control is about referrals.

What is a referral?  Yes, you know!  So I can jump into describing available APIs to work with referrals in Community Server.

CommunityServer.Components.Referral and CommunityServer.Components.ReferralSet classes and CommunityServer.Components.Referrals factory have the main role in working with referrals.

there is also a CSJob to store referral data on a regular basis.  This means that referral information won't be stored immediately and it takes time to store them by a CSJob (ReferralsJob).

In database there are two tables named cs_Referrals and cs_Urls that are used to store referral URLs in conjunction with cs_Posts table.  cs_Referral has a relationship with cs_Urls and cs_Posts.  URL of referral is stored in cs_Urls and other information about it are stored in cs_Referrals.

Referral is a class with following properties and no method:

  • Hits: Integer value of the number of hits from the referral.
  • LastDate: DateTime value of when the last hit is come to site from referral.
  • PostID: Integer value of post identifier that this referral belongs to it.
  • ReferralID: An integer value as identifier of referral.
  • SectionID: Integer value of section identifier where this referral and its corresponding post are located.
  • SettingsID: Integer value of SettingsID for current application.
  • Title: A string value as the title of URL.  Normally it's equal to URL.
  • Url: String value of referral's URL.
  • UrlID: Integer value of URL's identifier.
  • ViewPostUrl: A URL to quickly view the post.  You can find these URLs when you're viewing referrals page in blog.

ReferralSet is another class with four properties that are listed below.  It's actually a container to keep a list of Referral objects.

  • PageIndex: Integer value of page index number (starts from 0).
  • PageSize: Integer value of page size.
  • Referrals: An ArrayList of Referral objects.
  • TotalRecords: Integer value of total number of referral objects in ReferralSet.

Referrals is a method factory that helps you to work with referrals.  It's like a queue that keeps tracked data for referrals.  Some of its methods are important for default Community Server implementation (to add referrals to queue and other operations) so they're not very common in custom developments and I give a short description about one common methods.

GetReferrals() gets a Referral object and two integer values as page size and page index and returns a ReferralSet for the post.  Post is specified via its PostID in incoming Referral object.  Therefore you can use this method to get a list of referrals for a post.

In below code I want to get a list of referrals for the post that is being viewed by user to show it somewhere so GetFilteredReferrals() function doesn't get any parameter but returns an ArrayList of referrals.  It tries to filter referrals and exclude referrals from some search engines.  By default Community Server provides some APIs to filter incoming referrals before storing them into database but as it stores all referrals from search engines and doesn't apply any filter to them, I should filter them here.

ArrayList GetFilteredReferrals()

{

    CSContext context = CSContext.Current;

 

    ArrayList results = new ArrayList();

 

    Referral r = new Referral();

    r.PostID = context.PostID;

    r.SectionID = context.SectionID;

    r.SettingsID = context.SettingsID;

 

    ReferralSet referralSet = Referrals.GetReferrals(Referrals, 100, 0);

 

    foreach (Referral referral in referralSet)

    {

        if (!(referral.Url.Contains("search.") || referral.Url.Contains("google.")

            || referral.Url.Contains("search.yahoo") || referral.Url.Contains("search.live.com")

            || referral.Url.Contains("technoarti.com")))

            results.Add(referral);

    }

    return results;

}

Now playing: Eminem - Lose Yourself

email it!bookmark it!digg it!

Original Post: CS Dev Guide: Referrals

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us