Showing posts with label User groups. Show all posts
Showing posts with label User groups. Show all posts

Tuesday, 29 May 2012

DDDSW Roundup and Resources

On Saturday 26th I presented Defensive Programming 101 at DDD Southwest. As you may or may not be aware, the Developer Developer Developer or DDD brand of events are free one day events for the community by the community. Speakers submit their sessions and the attendees decide which ones they would like to see. The sessions with the most votes make it into the conference.

This was my fourth DDD event as I have been lucky enough to present at DDD Scotland twice and DDD North. This time at DDDSW, I got the pre-lunch slot, so to be fair to the attendees, I usually speed up a bit so that they can get out for lunch a wee bit earlier and skip the queues.

DDD Southwest was very well organised, with plenty of food, good facilities and good technical gear on site. This makes your job when you are presenting a lot easier. They even managed to sort out some amazing weather for the event and even so there was still in excess of 300 people at the event. My thanks again to the organisers, for minding us and making sure we had a great conference experience.

Thanks again to those who made it to my session and as promised, here is a list of the resources slide (which as always gets skipped at the end because there is way too many links on it)

Resources Slide 1

Resources Slide 2

As I said in my talk, many thanks to Troy Hunt for his kind permission on using some of the information on the ELMAH configuration errors which is detailed here

Sunday, 24 October 2010

Talks in November

6560.image_5F00_2DC376B7I am off down to Ireland in November thanks to Microsoft Ireland and I will be doing some talks for the Microsoft Technology User Groups around the country. All of the sessions are free, but registration is required so that we can track numbers and make sure we have seats for everyone.

Currently the Thursday slot is open if one user group wants to chime in an take it.

The current schedule is as follows

Thursday, 8 April 2010

Dynamic User Controls – Part 5 – Refactoring the code

The previous post dealt with getting the user controls to be dynamic with both addition and removal methods for the controls. In this post we will look at doing code reduction and making the code reusable with a minimum amount of effort. We created only one type of user control in the previous set of examples, but it is easy to image a situation where you would be creating more than one type type of control and in this scenario it would be handy not to have to write a massive amount of code for each control but use generic methods.
So that is what we are going to do in this post, some good old fashioned code refactoring. First we will look at the interface that is being used by user control and how it can be made generic. The original code for the interface is as follows
We can change the interface to a generic type like so

We will now change our existing PersonControl to use this new interface. The existing code is like this

And to implement the new interface we change it to the following

It is a simple as that. Any new control we want to use should use the new interface and whichever entity it is being used to represent.

We will now take a look at the method that enumerates the repeater items for the items values. Before we had this code

If we take a look at the code, we can make it generic by supplying a reference the type of entity in the list we want to return and also the name of the placeholder control and the repeater we want to use as parameters to a method. So by applying that logic we end up with this code.

As you can see now we have a nice reusable method. But we can further change this code and use some LINQ to replace the foreach statement. It will now look like this

To use the method we would replace the List<Person> CurrentPersonList as follows

Now we will look at changing the methods that add items to the repeater. Again we will take a look at the original code that was used in the last post.

If we look at what we could do here, we could change the code so that we supply the entity type that we want to use along with the current list of items, and the repeater that want to bind to. There is one slight additional change we need to do and that is when you use a generic method to create a new instance of a type, you must specify in the method declaration, the new constraint.

We can now replace the contents of the AddPerson method the the following

We look at the ItemCommand method which can generic the same way we have refactored the AddItem methods. The original code looks like this

Again we will look at the code and see what is reusable. If we supply the RepeaterItemEventArgs, a generic list of items and the repeater to bind to. So with that we end up like this

To use the method in the RemovePerson event, we change the contents of the repeater ItemCommand method to

Now the final piece of the puzzle is to change the ItemCreated event and the ItemLoad events. We can merge the ItemLoad into the ItemCreated event using a lambda expression. So the two methods before we start look like this.

If you use the lambda operator => we can merge the the ItemLoad and ItemCreated events into one method.

Now that we have it merged we can refactor this method into a generic method. We can replace the entity parts and if we pass in the name of the placeholder control and the path of the control to load as well as the RepeaterItemEventArgs we can re-use the method.

And there we have it, the code distilled down so that we can reuse certain methods if we have more than one repeater with different type of controls. So that is the end of the series of posts on dynamic controls. You can get the code bits from the post in the series

Friday, 2 April 2010

Dynamic User Controls – Part 1 – Session Intro

I recently gave three talks around Ireland on this topic for the Irish Microsoft Technology User Group (MTUG). I travelled to Derry, Dublin and Cork over three days and met some great folks. I was also very lucky to be presenting on the same night as Adam Kinney from Microsoft which was an excellent chance for me to get some news on Silverlight and the new bits from MIX10. A big thanks to Alan Bradley, David Gargan and Joe Gill on the MTUG side and Martha Rotter and Enda Flynn from Microsoft for facilitating this and also making sure I got to where I was supposed to go.

As promised to all those who attended my talks I am posting the session as a series of blog posts along with the bits from the sessions. The bits can be downloaded in 3 versions

If you are using the Visual Studio 2010 RC version make sure to download the Designer patch for the RC. This version will also work with the Beta 2 version of Visual Studio 2010.

So on with the speaker bits. I am not putting the PowerPoint online as it does not contain anything other than pictures and some text and its pretty useless without the speaker notes. So I am going to instead to put the speaker notes in this blog post with the PowerPoint slides as images.

WhyDoYouWantDynamicControls

The first question you should be asking is why do you want user controls in the first place. And the answer is usually one of the following three options

  • You don’t know the number or type of controls that you will need until runtime. This is possibly the most common reason to use dynamic controls.
  • You have a large number of the same type of control that you need to add to the application and you don’t want to spend the time manually putting them onto the design surface. Most people will be familiar with this because I doubt you have ever manually created 100 list items in a DataList for example
  • And finally its because of an architectural decision such as a custom server control and you have no choice.

 

 

The next question is what is the different between static and dynamic controls. Well firstly static controls StaticVsDynamicControls 

  • Can be added to the design surface at design time
  • They can be programmed against with intellisense because they are in the .designer.cs file
  • And finally they survive post back and the page life cycle.

On the other hand dynamic controls

  • Dynamic controls are added to the page control tree at runtime
  • They cannot be programmed against using intellisense in the traditional way. You can declare an object of the type of control and bring it to your instance of the control and program against it in that way
  • Dynamic controls do not survive the post back unless you give them a place to stay. And that is the crux of the problem involving dynamic controls.

PostBack

 

Now that we know what the issue is how do we solve it. Normally when you are using dynamic controls you add the controls to a placeholder and this works ok to a point. A better way of doing it is to use a repeater with a placeholder in the ItemTemplate and use custom methods of the ItemCreated and ItemCommand events. There are a few good reasons for this.

  • You can databind your list to your repeater allowing to quickly create a lot of controls
  • You can make your controls have databinding properties.
  • You can use the fact that the repeater is IEnummerable to get the information in and out
  • The ItemCommand event allows you to handle events from your controls
  • And finally it gives you a way to easily store state by using the repeater.

 

 

So that was the intro part of the session. As you can see I didn’t use a lot of time in PowerPoint because I believe that developers learn better from seeing the code rather than from a slide deck. The next posts will be all on the code parts of the sessions.

If you want to learn more about the whole viewstate relationship with dynamic controls you can read Dave Reed‘s excellent blog posts on the subject. I would like to take this chance to thank him for his kind permission in allowing me to use some of his material for my sessions.

Friday, 12 March 2010

New Technology User Group in Norway – MTUG.NO

The Microsoft Technology User Group (MTUG) is now starting to get going in Norway. So for those of you who are into the Infrastructure and Operations side of the house, this is for you. The best thing is that is free! Check it out on MTUG.no

Currently active in Oslo and Trondheim, Stavanger and Haugesund are due to come on stream soon. If you fancy setting up one in your area, please contact Anders Borchsenius (twitter) to get more information.

The first meeting will be Tuesday 16th of March with a kickoff from Nick Voicu who will be doing a talk on Tips and Tricks for the best PKI Deployment. Nick is Senior Developer with the Windows Security and Identity team in Microsoft.

The Agenda for the night :

1800 - 1805 : Velkommen

1805 - 1820 : Introduksjon til MTUG

1830 - 2030 : Tips and tricks for making the best PKI deployment

An overview on the existing optimizations in Windows PKI Client that will help design and deploy a better PKI in your organization.

2030 - 2100 : Q&A samt sosial mingling utover kvelden

You can register for the event here.

For those developers among you there is also the Norwegian .NET User Groups which are running around the country. Again also free!