Mono support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Mono Support Simple custom webpart using MonoX API 

Viewed 19224 time(s), 7 post(s) 2/23/2011 12:13:08 AMby Oli
Oli
1

Oli 2/23/2011 12:15:20 AM

Dear Mono,

I am a Tech Lead looking to spec your MonoX product in a large custom social network build. I like the look of your well dcoumented API but I need to quickly assertain the scope for doing a considerable amount of customisation.

I have downloaded MonoX, installed in on Windows 2008 / SQL Server 2008. I had no problems getting the sample project loaded in Visual Studio 2010 and I have the default project running on IIS 7.5. I have looked around the admin system. I have a good level of ASP.NET programming skill and I have a grasp of Web Parts and how to implement them (although havn't used them extensively until now).

It would be very helpful for me if you could walk me through the following simple scenario. From your answer i should be able to get an insight as to the rest of the work.

You currently have a ready made WebPart that will display the newest x number of Groups. What would your best-practice code be to demonstrate writing a webpart that displayed x number of Groups with the most menbers. From my inestigation so far I can guess at a number of possible routes through the API, but I am guessing it would be using the Group Repository, but its taking me too long to work out. This one example should give me the complete overview i need.

Thanks in advance,
Oli.
This content has not been rated yet. 
31 Reputation 4 Total posts
denis
2

denis 2/23/2011 7:40:13 PM

Hi Oli,
It depends on your goals - you may want to create a new, standalone GroupList Web part and use it as-is, or change the behavior of the default GroupList. In a latter case, you would create a new GroupList.ascx in your custom project that inherits from the existing MonoSoftware.MonoX.ModuleGallery.SocialNetworking.GroupList class. You can override BindData method in the Web part, or GetGroups method in the GroupRepository,  The GroupRepository doesn't currently has a method that would list groups sorted by the number of members (we cannot cover all custom scenarios out of the box), so you would have to do a bit of coding to get what you want. We could help you with that, depending on your data access strategy - we prefer using LLBLGen as the primary ORM in our projects, but you can use your own.
This content has not been rated yet. 
7141 Reputation 924 Total posts
Oli
3

Oli 2/24/2011 10:40:54 AM

Hi Denis,

Thanks for your reply. That's helpful and confirms what I had thought. Your API is extensive and fairly comprehensive - I would expect to be doing custom coding using the API to do things that are not built in stright out of the box. At the moment I am just 'feeling my way' through and trying to guage how steep the learning curve will be.

Before you came back with your post, I managed to write a Web Part which did what I wanted. Starting with a new web part, inheriting from your base part, I worked out that I had to include extra references in my VS2010 project not included by your sample project by default. I also had to find and learn how to use LLBLGen ORM Support Classes (something I am unfamiliar with, although I take your point that using this is optional).

After some hours or reading and a bit of trial and error I was able to write the following very basic bit of code which worked, all-be-it without any of the templating features of a common Web Part.

namespace ProjectName.Web.MonoX.ModuleGallery.SocialNetworking.Groups
{
    public partial class PopularGroupList : MonoSoftware.MonoX.BasePart
    {
        private int _listSize = 5;
        private string _header = string.Empty;
 
        public int ListSize
        {
            get { return _listSize; }
            set { _listSize = value; }
        }
 
        public string Header
        {
            get { return _header; }
            set { _header = value; }
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            string output = String.Empty;
             
            using (GroupRepository repo = GroupRepository.GetInstance())
            {
                int recordCount;               
                ISortExpression sorter = new SortExpression(SnGroupFields.MemberCount | SortOperator.Descending);
                 
                EntityCollection<SnGroupEntity> groups = repo.GetGroupCollection(null, sorter, null, 1, _listSize, out recordCount);
 
                if (!String.IsNullOrEmpty(_header))
                {
                    output += "<h3>" + _header + "</h3>";
                }
 
                foreach (SnGroupEntity group in groups)
                {
                    output += String.Format("<li>{0} ({1})</li>", group.Name, group.MemberCount.ToString());
                }
            }
 
            litPopularGroups.Text = output;
 
        }
    }
}

Now the next step would be to add in to my Web Part all the aspects of Templating and Paging. But this is already done in your NewGroupsList. Would you be able to help walk me through how to write my WebPart inheriting from this NewGroupsList, just overriding the DataBind() method?

Or have I got the wrong idea?

Thanks once again,
Oli.
This content has not been rated yet. 
31 Reputation 4 Total posts
denis
4

denis 2/24/2011 2:13:39 PM

Hi Oli,
The idea is OK. You have choosen one of the more complex parts for a start, but that's OK - you will pick up most of the knowledge you need by studying it.
Let me prepare a working example based on the NewGroupsList so we could discuss all the techniques used in it (binding, caching, paging, templating, repositories,...). I'll post the code here as soon as it is ready.
This content has not been rated yet. 
7141 Reputation 924 Total posts
Oli
5

Oli 2/24/2011 3:32:50 PM

Thank you so much. As you say, I think that would give me the grounding i need to get up to speed, so I appreciate your time.

Oli.
This content has not been rated yet. 
31 Reputation 4 Total posts
denis
6

denis 2/25/2011 10:17:27 PM

Hi Oli,
our discussion motivated one of my colleagues to publish a new blog post, and I didn't want to start a weekend before it is published :)
http://www.mono-software.com/Blog/post/Mono/93/Building-a-custom-Web-part/

Let's use Kristijan's tutorial as a starting point for further discussion. I think that it nicely captures the essential MonoX Web part building techniques.
Rated 5.00, 1 vote(s). 
7141 Reputation 924 Total posts
Oli
7

Oli 2/28/2011 8:28:35 AM

Hi Denis,

Thanks to you and Kristijan for providing a great tutorial. It certainly helps me a lot.
I'm working through it and I'll take the discussion forward from there.

Great work.

Oli.
This content has not been rated yet. 
31 Reputation 4 Total posts