You are currently browsing the category archive for the ‘IT’ category.

I was able to attend DDD South West (www.dddsouthwest.com) over the weekend held in Bristol. The conference is a free one day event open to all but mainly focusing on elements available on the .NET platform. It’s a great way of being able to hear some excellent speakers talk on areas that they are passionate about and who you would not normally be able to see.

Sessions that I attended included:
- .NET Collections Deep Dive by Gary Short (http://garyshortblog.wordpress.com/)
- No More Passwords by Jimmy Skowronski (http://jimmylarkin.net)
- Performance and Scalability, the Stack Exchange Way by Marc Gravell(http://marcgravell.blogspot.co.uk/)

———————————————————————————————-
.Net Collections Deep Dive
A session convincing us that there is more to .NET collections than just lists.

Lists:
- AddRange is better than Add inside a loop as it cuts down on the number of Array.Copys needed to be called when adding new items and expanding the underlying array (this really comes into effect when adding more that 10000 elements to a list).Alternatively you can set the capacity of the list when constructing to reduce this further
- Using a list initiator and specifying the elements within the list eg new list {item1, item2} is the same as calling Add multiple times
- List.Remove performs an IndexOf before calling List.RemoveAt so if you know where in the list your item is just call RemoveAt initially.
- List.Sort uses QuickSort as it’s underlying sort algorithm. This is the fastest sort algorithm for general purpose sorting as it is (nlogn) for best and average case but (n to the power of n) for worst case. What’s the worst case? An already sorted list – better to call List.Randomise before calling sort to remove this problem.
- List disadvantages: Add, Insert, Remove all O(n) operations

Linked List
- Double linked so that each element is linked to the element before and after it
- Add, Insert, Remove all O(1) operations however O(n) on lookups

Dictionary
- Performance depends on the result of Key.GetHashCode. If you are using your own objects for the key you need to implement this method yourself. Also need to override Equals method to prevent hashcode collision as every key in a dictionary must be unique.

Lookup
- Keys do not have to be unique
- Can be created using lists of tuples and converted to lookups

Collection Version Numbers
Every regular collection has a version number, this is the element that prevents you from iterating over a collection that you are changing. This traditionally causes problems in multi threaded environments due to thread locking and updating. Concurrent Collections have been created to solve this.

Concurrent Collections
- New collections in .NET 4.0
- Implements IProducerConsumerCollections which provides the methods TryAdd and TryTake
- TryAdd: attempts to add item to collection and returns boolean result
- TryTake: attempts to remove item from collection and returns item
- Blocking collections: uses Add and Take. TryAdd and TryTake also available with timeouts

Summary
- List: good general purpose collection. Construct to size if possible, prefer AddRange to Add. Be aware of issues with QuickSort (Google QuickSort killers for scernios)
- LinkedList: fast insert/remove
- Dictionary: fast lookup
- Lookup: multi key values
- Concurrent Collections: thread safety

————————————————————————————————-

No More Passwords – or how to use OAuth

Most public access websites that you come across that want you to interact with them all seem to have some sort of account creation area. While it’s probably fine to have a separate account on Google and Amazon it gets really tiresome when you are trying to download a software demo or take part in a forum. Especially when you consider the amount of passwords that you have to remember and the amount of media stories when hackers manage to get lists of account details from insecure  sites.

Fortunately OAuth presents an opportunity to hold an account with a provider eg OpenId, Facebook, Twitter, Google, LiveId, and then use those credentials across multiple websites to bring your existing account details with you.

To incorporate this into your own sites .NET provides a series of libraries under WebMatrix.Security that allows you to add providers with only a few lines of code. LiveId, Facebook, Twitter and YahooOpenId all come out of the box but Google can be easily added.

The steps involved are to register your site with the individual provider who will give you a token that you can add to your global.asax page and then the call on your site to perform the login is as simple as OAuthWebSecurity.RequestAuthentication(provider, postbackUrl).

One of the items of data that comes down with the request is a unique id representing the user that can then be stored in the application database allowing for persistence of settings/data etc. For our public facing customers there should no longer be a need to roll our own account management system.

Jimmy has provided a demo of how this can be achieved and as his presentation was a website you will be able to get the full notes at http://jimmylarkin.net/post/2012/05/27/DDD-South-West-OAuth-Session.aspx

————————————————————————————————-
Performance and Scalability, the Stack Exchange Way

Marc started out by explaining that the traditional answer to performance issues of throw another server at it doesn’t work for websites for the vast majority of the time- highlighted by StackOverflow’s own experiences where they serve up seven million page views a month and their servers are only running at 10% CPU capacity.

He also noted that IIS profiling doesn’t always show where the issues lie and for that you need something reporting within the code. This is how MiniProfiler was born- an open source profiler for MVC and ASP.NET websites that allows you to tag regions of code and report on the timings within them. It can even go to the database level and report on the SQL that was actually called- handy for Entity Framework and Linq statements.

It’s also lightweight so unlike other profilers it can be left to run in a production environment and only enabled when needed. The website effectively shows its usage so check out http://miniprofiler.com/ for more details.

The second tool that Marc showed was Dapper (http://code.google.com/p/dapper-dot-net/) which is a  lightweight mapping tool that is very effective for sites with large reads. This was created when the StackOverflow team noticed that some Entity Framework calls took 400ms to run instead of the standard 4ms and the issue turned out to be the mapping process between SQL results and custom objects within code.

I believe that both of these tools would provide benefits both to new and existing projects within and should be investigated further.

————————————————————————————————-

Presenters at DDD events are normally very good at making their presentation content available on their blogs so it would be worth checking out the agenda at http://www.dddsouthwest.com/Agenda/tabid/55/Default.aspx and looking up any of the speakers whose sessions catch your interest.

If any of these has captured your interest in attending DDD events, the next one that I know of is DDD Reading on Sat 1st Sept though DDD North is about to announce it’s call for speakers. Keep an eye on the official DDD site at http://developerdeveloperdeveloper.com for more details.

We were trying to figure out a way of having a dynamically encoded database name in our sql queries for a series of reports working off two databases. We needed to have the second database on a different server and we wanted to replicate this on our development environment as well as making deployment easier.

After spending a while looking into dynamic sql queries (not a great idea) and report parameters I decided to have another look at linked servers.

Linked servers are a means in SQL Server (probably exist in other db worlds- haven’t researched) of connecting two servers so that you can access database objects from one server within queries hosted in another.

To set them up:

  1. Go to “Server Objects” of the database server where the linked server will be added and right click on “Linked Servers”. Select “Add New Linked Server”.
  2. In the “General” tab, add a name for the new linked server in the “Linked Server” field.
  3. Select “Other data source”and for “Provider” select “Microsoft OLE DB for SQL Server”
  4. For “Product Name” type in “SQLOLEDB”
  5. In the “Data Source” field, enter the IP address of the server to be linked (this can be local)
  6. “Catalog” is the name of the database on the linked server and is optional (db2 in my case)
  7. Go to the “Security” tab and select “Be made using this security context”. Type in the remote login and credentials. Naturally set this to be a user with only the necessary permissions and not all.

Credit to http://www.jensbits.com/2010/11/10/create-linked-server-sql-server-2008/ on the creation of linked servers

Where this becomes powerful is that you can set the datasource to be the local machine name or ip so in effect you can link a server to itself. This works brilliantly for development as we can set our sql query using the linked server name and have it configured to multiple environments without touching the code.

To use a linked server in code you prefix the tablename with the name of the linked server so

select * from database.dbo.table becomes

select * from linkedservername.database.dbo.table

This works out to be quite a tidy implementation. Hope it helps someone else out there.

To find all the user tables that contain a particular column name run the following command on the relevant database:

SELECT name FROM sysobjects WHERE xtype='U' and id IN( SELECT id FROM syscolumns
WHERE name like '%COLUMN NAME%' )

I had the pleasure of attending a workshop by Scott Guthrie this week where he discussed the MVC (Model, View, Controller) design pattern within asp.net and the new additions to the .net framework coming with the release of C# 4.0 and Visual Studio 2010.

The first session on MVC raced by and before anyone in the audience had noticed two hours had passed by. The content was aimed at people who had never seen the MVC pattern before and brought us from a brief definition through to creating a full website. One of the highlights of this pattern for me was the ability to fully control the html output of the site as well as applying validation to the Model layer of the site and having that carry through to all aspects of the application including client side validation.

The second session focused on the soon to be released .net 4.0 framework and Visual Studio 2010. There are a lot of really interesting features being released not least the inclusion of jquery and a lot of editor improvements. An audible gasp went up from the audience when Scott demoed a new multiline selection and editing feature.

Overall it was a fantastic workshop to hear of new approaches to application development and something that I believe we will hear a lot more of..

The two sessions were videoed and I believe will be available from the Channel 9 website soon. In the meantime here’s videos from the Netherlands branch of the tour:

http://channel9.msdn.com/posts/matthijs/Scott-Guthrie-ASPNET-MVC-2/

http://channel9.msdn.com/posts/matthijs/Scott-Guthrie-Visual-Studio-2010-and-NET-Framework-40/

When Goto doesn’t go when you want it to

When working with server side events I have found it common to reroute the workflow to a different activity within the workflow. Perhaps a user has decided to end the workflow and I want to send them to an End Workflow activity first. I would normally use the following code to do this:

K2.GotoActivity("NameOfActivity"); 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }However to my surprise instead of the workflow moving to straight to that activity what actually happens is that the pointer linking the end of the current activity to the next changes to point to the activity entered in the GotoActivity code above. This means that if you have additional server events and potentially client events within the activity listed below the code containing the Goto they will still be processed leading to all sorts of errors further down the line.

The solution for me was to set a flag once the Goto had been called to skip out any further code execution. Messy but safer than allowing the code to execute. One to watch out for in your own code.

I had a situation where I needed to email a user from within the workflow process using a mail event with a dynamically built url generated from a stringtable entry detailing the start of a url and a datafield value containing a reference id in the email body. I found that no matter what way I concatenated the two values together or added href anchor tags to the body of the email, the email would be received showing the link but without it formatting itself as a hyperlink.

The resolution to this was to concatenate the values together along with the html tags in a server side code event and store this value in a datafield before the mail event item was reached.

The code ended up being:

K2.ProcessInstance.DataFields["Hyperlink"].Value = 
string.Format("<a href="{0}{1}">{0}{1}</a>", K2.StringTable["UrlString"],
 K2.ProcessInstance.DataFields["Identifier"].Value);

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Hope this helps someone else out there.

I got hit with this error last week when an IPC event that I was using within my workflow to kick off another workflow process failed to start. It turns out that I had forgotten to give my child process start permissions within the K2 server. As soon as I did this it started working for me.

It seems like such a small error but took way too long to find a solution as there was only a couple of forum posts with the same error as me but without a solution so I can’t be the only one out there having problems with it. Here’s hoping that the next person with the error will stumble across this post rather than searching in vain.

Last night as previously mentioned I attended the Best of PDC event hosted by NIMTUG at the Welly Park Hotel. It was the first nimtug event since April and it was great to see so many people there, especially those well remembered from previous events. As is by now tradition we stayed for a good while once Martha’s excellent talk had finished, discussing the current IT situation in Belfast and I ended up back home at 1am this morning. Well worth it though and a huge thank you to Martha, Damien and Simon for putting the event together.

The Northern Ireland Technology Users Group, or NIMTUG for short, are holding its next event on Monday 1st Decemeber in the Wellington Park hotel in Belfast. The session will cover a range of topics from LA’s PDC event earlier this year. Further details and registration can be found on the nimtug site.

Twitter

Follow

Get every new post delivered to your Inbox.