Using ReSharper to adjust namespaces across multiple files
By James Fisk
I’m currently working on a project that has a large amount of files and projects, as you can imagine managing all those files and projects can get a little unwieldy. We as a team realised this, and decided to take some time out in order to reduce the amount of projects.
Now one of the tasks I was asked to do was to merge a number of the core projects into one project, this involved moving around 50+ files into the project that we were merging into. So, with my task assigned to me I gallantly completed the task by simply moving the required files into the project, and hey presto job done. Or was it?
As you may know that good development practice in .NET requires the developer to ensure that the namespace follows the directory structure from project root down to the file. Now moving the files was ok, but the job was half done, the namespaces did not match the dir structure of the files new location. Ok I thought, I’ll just update the namespaces, but there was a lot of files 50+ files. Ok I could just use find and replace, but that means I could screw it up because it requires my intervention.
What I needed was a addin that detects the incorrectly specified namespaces in the files, then when you have confirmed that you wish the files to be corrected, it’ll not only update the namespaces, and as a bonus it’ll update all the references, usings and clean up the code as well. Funny enough there is such an addin, and it’s called (drum role) Resharper.
What you can do is select the offending files in the solution, either by right clicking on the selected files, or by right clicking on a project or solution folder in the solution, and then by selecting the menu item Refactor->Adjust Namespaces, you’ll then be presented with a wizard detailing the files that have been detected, clicking next will start the process. After a while all the files and references will be updated, leaving you to save all the files afterwards (by default the wizards opens the files it has changed).
Now, this is just the tip of the iceberg regarding Resharper, it is a very powerful addin, not cheap, but well worth it in helping to speed up development, I recommend that you download the trial and give it a go, it supports VS 2008, VS 2010 and also VS 2003 as well.
Getting around the 260 chars path limit in Windows
By James Fisk
Just recently I’ve been creating projects in Visual Studio 2010 for SharePoint 2010. My projects where getting very deep in the filesystem, where the upshot of this is that the file path was getting very long. To my dismay if you try and deploy a SharePoint solution that contains very long paths (>260 char) it fails. Now in this day of age, that is not good.
Now i’ve been reading around and found that the limit is imposed by the WIN32 API, however, I know that NTFS supports file path lengths of 32K. Now that is one hell of a difference. When we hit this 260 char limit our first reaction is to shorten the file path somehow, but it does not seem right. Further reading finally led me to a way to get windows to allow file paths upto 32K.
To get windows to allow for path up to 32K you simply prepend the file path with \\?\ and away you go.
Ie copy \\?\c:\<Very long path> \\?\d:\<Very long path>
Now the thing is you can use it in your windows apps to support 32K path lengths and hey presto, a windows app that supports 32K.
Update :-
I found this snippet
The "\\?\" prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.
This was extracted from the MSDN.
So use it with caution.
Windows 7 God Mode
By James Fisk
Just found this nugget out, apparently you make windows 7 very customisable simply by doing the following :-
-
Create a new folder in c:\windows
-
Rename that folder to GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
- Now double click on the new god mode folder and have fun.
Using Typemock VS2010 Beta 2
By James Fisk
After installing TypeMock with VS2010 Beta 2 I found there was no integration in VS2010. This means that when you run your unit tests in your integrated unit test runner TypeMock would not kick in.
To workaround this use TMockRunner.exe with nunit as an external command like this :-
"c:\Program Files\Typemock\Isolator\5.4\TMockRunner.exe" "c:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\nunit-console.exe” "c:\Projects\Aberdovey2010\spikes\UnitTesting\Sample.Tests\bin\Debug\Sample.Tests.dll"
You will need to change the paths for your environment.
As mentioned this will need to executed outside the outside Visual Studio from batch file, or you could add the command as an external tool.
To do this got to menu Tools->Externel Tools…
This will bring up the following dialog box :-
Enter the title, location of the command, in this case TMockRunner.exe, and the arguments which should be, <nunit install path>nunit-console.exe <full path to TEST assembly>. Don’t forget to check the ‘User Output to window’ check box, which means all output from this command will go to the output window, simples. Have fun.
Mixing JQuery, SP2010 Client OM with the sand pit
By James Fisk
On a recent project we had set a requirement for the solution to run as a SharePoint 2010 Sandboxed solution, and needed to provide a much richer UI experience, so we decided to use JQuery and Client OM.
This presented me with few challenges, what helped was a deep dive into SharePoint 2010 with the first ever Combined Knowledge 2010 beta training course with Todd Bleeker and Gary Yeoman. Because I follow agile practices, I spiked this, what I mean by this is that a spike is a term used for researching a way of doing something, so that the team can estimate the story that requires this approach. After I completed my spike we were in a much better place to estimate the story, this post is my journey in trying to understand this problem.
Here is the code that this post discusses, please bear in mind that this is not production code.
First of all i set up myself with a VMWare image of SharePoint 2010 running on Windows Server 2008 SP2. I used these Instructions from Microsoft.
Once i got myself setup I then researched how I would go about making this happen. After googling for what seemed like and eternity I stumbled across this post from Lighting Tools, which enabled me to load javascript in a sandboxed solution.
So I set to work. I created a blank SharePoint 2010 project in Visual Studio 2010 and added a web part, don’t go for the visual web part they are not compatible with sandboxed solutions.
Don’t create a Visual Web Part in sandboxed solution as they are not compatible, mainly because visual web parts need physical files on the file system.
You then add this snippet of code to the web part cs file, as detailed in the post I mentioned earlier.
1: protected override void RenderContents(HtmlTextWriter writer)
2: {
3: string url = SPContext.Current.Site.RootWeb.Url;
4: writer.Write("<script language='javascript' type='text/javascript' src='" + url + "/SiteAssets/Assets/Start.js'></script>");
5: writer.Write("<script language='javascript' type='text/javascript'>Sys.loadScripts('" + url + "/SiteAssets/Assets/jquery-1.3.2.min.js');</script>");
6: writer.Write("<script language='javascript' type='text/javascript'>Sys.loadScripts('" + url + "/SiteAssets/Assets/jquery-ui-1.7.2.custom.min.js');</script>");
7: writer.Write("<script language='javascript' type='text/javascript'>Sys.loadScripts('" + url + "/SiteAssets/Assets/SandBox.js');</script>");
8: }
Notice the use of SPContext.Current.Site.RootWeb.Url, this is to ensure that the script always loaded from the root web, regardless of where the webpart running from.
This code is loading a javascript file (Start.js) that is from Microsoft’s AJAX library. This loads all the required functionality, such as the Sys namespace. I could have used the ‘Sys.require’ to load the required JQuery, but I wanted tight control over that instead.
Next the real magic happens, using the Sys.loadScripts function you ensure that one, and only one copy of the script you have selected is being loaded. Notice that the script are being loaded from a folder called /SiteAssets/Assets. This is a container in SharePoint that stores the script into the content database, very important if you want to use a Sandboxed solution.
Next I created a normal sitepage in SharePoint, which I used to load the web part and javascript. Once the site page was created I used SharePoint Designer 2010 to get hold of the contents of the page, it was easier that way because I’m lazy at typing, but you can use whatever method you want.
Remember the SiteAssets/Assets folder in the web part that loads the jquery and other javascript files. For this to work you need to create a module called ‘Assets’ and added all the required files for the module. Don’t forget to add the ‘URL’ attribute to the Elements.xml file to ensure the files get rendered from the correct location.
Now, I created another module, this time it is for the deployment of the sitepage that will contain the javascript loading web part, and your html that the javascript will interact with. In my case it was to mimic a white board that SCRUM teams use. In this UI you can drag and drop the story boxes from one swim lane to another. Dropping the story into a swim lane would update the stories’ status, this being ‘Not Started’, ‘In Progress’, ‘Verify’ or ‘Done’. The story status is stored in a SharePoint list.
Each swim lane is a div, which i had to mark as droppable by using jquery UI plugin.
1: $("#notStarted").droppable({
2: drop: function (event, ui) {
3: updateStoryStatus('notStarted', ui.draggable);
4: }
5: });
These 6 lines does quite a lot. I’m selecting a div with the ID ‘notStarted’, you use the ‘#’ notation to depict an ID. Then I enable the div to become droppable,that is to accept any draggable item. Droppable can handle upto five events, these being ‘activate’, ‘deactivate’, ‘over’, ‘out’, ‘drop’. For this I just concentrated on the event drop. When the event fires it uses an anonymous function, which then passes control over to another function that updates the stories’ status. The first parameter is obviously the status I want to set the dropped story, the second parameter is the object that was dropped, this is supplied by this rather curios syntax ‘ui.draggable’. This happens in the initialisation stage.
Initialisation stage
In the SandBox.js file I have all the custom code. This code handles the loading of all the stories from the story list on SP2010 and updated story status based on where the stories are dropped.
Now, one of the very first functions i call is the following :-
ExecuteOrDelayUntilScriptLoaded(start, "sp.js");
This line is very important, the reason why is that in order to use Client OM in javascript, you need the JS file ‘sp.js’. This JS framework allows me to load current SP context and start to query and update the SharePoint Lists and so forth. It is a limited framework that can only talk back to the SP server farm from whence sp.js is loaded from. This is for obvious security reasons. You might be wondering what the function ExecuteOrDelayUntilScriptLoaded is for. This function is used to ensure the that the function ‘start’ (starting point of my app) is only called when the file ‘sp.js’ is loaded, if not, then it can’t be guaranteed when the client om framework is loaded. Incidentally, the function ExecuteOrDelayUntilScriptLoaded should not be in a function, you want it to be called as soon as the ‘sandbox.js’ is loaded.
In order for the ExecuteOrDelayUntilScriptLoaded function to work you need to load the JS file this function is in the ‘init.js’, that is part of the ‘sp.js’. For the ‘sp.js’ to be loaded you need to include it into the ASPX page, like so :-
1: <script type="text/javascript">
2: <SharePoint:ScriptLink language="javascript" name="sp.js" LoadAfterUI="true" runat="server"/>
3: </script>
When the ‘Start’ function is called all the swim lanes are set as droppable, then the stories are loaded.
Loading the stories
This is where client OM really comes in to it’s own. Knowing I now have ‘sp.js’ loaded and ready I can start using client om. The first thing I had to do is load the context :-
context = new SP.ClientContext.get_current();
Now I have the equivalent to SPContext on the client side, now to load the story status list :-
this.site = context.get_web(); context.load(this.site); lists = site.get_lists(); displayAStory(lists.getByTitle('StoryStatus'));
Here I grab the current web, load that into the main context, retrieve all the lists, then retrieve the list called story status passing it to a function load displays all the stories and places them into the correct swim lane.
Display the stories
Once the correct list has been loaded all that remains is to load all the list items :-
1: function displayAStory(currentItem) {
2: var camlQuery = generateCAMLQuery('<View></View>');
3: this.listItems = currentItem.getItems(camlQuery);
4: context.load(listItems);
5:
6: context.executeQueryAsync(
7: Function.createDelegate(this, this.onQuerySucceeded),
8: Function.createDelegate(this, this.onFail));
9: }
First I needed to generate a CAMLQuery to put against the story list. The list items are then filtered against the CAML query, load that list into the context, finally execute the loading of story list asynchronously. With executeQueryAsync you supply two functions, the first one is called when the execute command was successful, the second is called when the command fails.
Successful ASync command
After the command has been executed and it was success, this function is called as a delegate by the executeQueryAsync method mentioned earlier :-
1: function onQuerySucceeded(sender, args) {
2: var itemCount = listItems.get_count();
3: for (i = 0; i < itemCount; i++) {
4: var item = listItems.itemAt(i);
5: if (item.get_item('Status') == "Not Started") {
6: $("#notStarted").append(generateStoryDivHTML(item));
7: }
8: if (item.get_item('Status') == "In Progress") {
9: $("#inprogress").append(generateStoryDivHTML(item));
10: }
11: if (item.get_item('Status') == "Verify") {
12: $("#verify").append(generateStoryDivHTML(item));
13: }
14: if (item.get_item('Status') == "Done") {
15: $("#done").append(generateStoryDivHTML(item));
16: }
17: }
18: $(".story").draggable({cursor:'crosshair'});
19: }
Here I simply loop over all the items in the list, looking at the status of the current story and placing it into the corresponding swim lane. The story is generated by creating a div.
Generating a Story box
To generate a story box I simply generate a DIV on fly inserting the story name.
1: function generateStoryDivHTML(item) {
2: return "<div class='story'><span id='StoryTitle'>" +
3: item.get_item('Title') +
4: "</span><input type='hidden' id='itemId' value='" +
5: item.get_id() +
6: "' </div>";
7: }
The story id is also added, but as a hidden field, this is used when the app wants to know which story should be updated after it has been dropped.
Update story status
In order to update the story I had to store the story ID in each story div, so that when the ui.draggable object is supplied I can grab the story id from a hidden input field here is the code that does that :-
1: function updateStoryItem(storyElement, newStatus) {
2: var storyId = storyElement.find('#itemId').attr('value');
3: var itemToUpdate = listItems.getById(storyId);
4: itemToUpdate.set_item('Status', newStatus);
5: itemToUpdate.update();
6: context.load(itemToUpdate);
7: context.executeQueryAsync(updateStoryStatusSucceed, onFail)
8: }
In here I grab the story id from the hidden field and then use it to grab the list item by it’s id. Then I take the ‘newStatus’ and update the item by column ‘Status’ with the ‘newStatus’. All that remains is to update the list, then load it into the current context and execute Async on the context in order to persist the changes.
Final thoughts
I know this has been a whirl wind overview of using jquery, client om in a sandboxed solution, and no doubt there might be a better way of achieving the same thing, but I’m still learning. Using AJAX based web apps is now easier in SP2010 with Client OM.
Speed might be an issue I have not done any performance testing on this, so that might raise a few issues. On the whole I hope this will help in some way to understand Client OM with Javascript.
21Apps and thee
By James Fisk
As you’ll no doubt be aware that i’ve joined forces with Andrew Woodward at 21Apps (www.21apps.com). I’ve worked with Andy for about two years, on and off on various projects, and found him to be passionate about Agile (SCRUM/XP) and since we share the same views and vision it seemed the logicial step to join forces and help others enjoy the benefits of Agile.
Sorry for the short, hopefully this blog will be updated on a regular basis. Ta Ta for now.
Scribing in planning games
By James Fisk
In our planning games we’re using the tried and tested approach of post it notes and white boards. However, we found that when we were writing the tasks out the team members were writing the tasks in silence, which meant knowledge sharing was not really taking place and the team members were really estimating on a task they had little or no say in. Which meant that sometimes, when we got into the iteration, one or more tasks didn’t seem to really fulfil the story and we were having to do extra work, at best, or, at worst, dump the story altogether.
So, a solution was needed. What the team did was come up with a scribing system. It’s quite simple, these are always the best ideas, a member of the team scribes (writes onto the whiteboard).
What happens is that a team member is chosen to scribe. That person writes down verbatim what the TEAM thinks will be the appropriate task(s) to deliver the story. The scribe does not guess the tasks, they do not make suggests, they are merely dictated to by the team. Once all the tasks are written then the team transfer the tasks onto post it notes and estimates.
We found that scribing forced the team to think about the tasks more, it also allowed the team to enter into a lively debate about the required task(s), thus spreading knowledge. Another added bonus scribing has is that things that may have been missed, were not, because whole team is writing the task collectively.
Try it, it’s nice. A word of warning though, we found that scribing on all stories we found that it’s causes the planning game to drag on a bit. So we only scribed on stories that appeared to be complicated, but to be honest that’s just us, try it for yourself and see how it helps then adjust accordingly.
One further note, is that the teams that use web based story and task tools, ie Version One, XP Planner, etc, maybe already be doing this. ie one person sits at the keyboard whilst the other team members tell the person what to type, so if your team are doing that then you are already benefiting from the scribing approach.
Happy scribing.
Planning poker cards
By James Fisk
Where I’m currently working we were finding that our planning games were becoming a bit strained. We found that when we came to estimating our stories we found that the estimates were a bit varied.
Now, we all know that if the estimations are very different in a planning game you stop to discuss why there are differences in the estimations. Once the reasoning why the estimations has been discussed, the team can then re-estimate with new knowledge and hopefully things should be more or less the same, if not repeat.
That was OK after a while, but what I mean by varied people were giving funny estimations like 12.5, 4.7 so on and so forth, and no matter now draconian we tried to make the estimation process these silly little estimations kept on cropping up, which slowed the estimation process down and just generally frustrated people.
What we needed was a predefined set of numbers that we can all use, where we can quickly show what our estimation is.
After a bit of searching I found the planning poker cards from Mountain Goat Software.
How you use them is quite interesting, each developer has a pack. In the pack consists of the following cards :-
- ? = I’m not playing
- 0
- 1/2
- 1
- 2
- 3
- 5
- 8
- 13
- 20
- 40
- 100
- ∞ = Greater than 100
When it comes to estimating the developers all hold up the cards at the same time, if they are mostly all the same the team goes with that estimation, however, if they are varied then the team quickly discuss the variances then re-estimate.
If the developer has no clue about the task the team is estimating they hold up the ? card, if however, they think this story is too huge they show the ∞ card, this is probably an indication that the story is one hell of an epic and really needs to be broken down. The numbering scale also helps to stop people giving silly estimates of small increments.
When you read around how to use the planning poker game cards, you’ll see that they are used mainly estimating stories, but we also use them for estimating the tasks as well, with great effect.
This may seem a bit unprofessional, but our team have found that it helps to speed up the planning games greatly. Firstly by introducing a strict numbering system, so we don’t get the x.something nonsense, and introducing an element of fun, and as we all know that time goes by much quicker when you are having fun.
Writing developer stories
By James Fisk
I’ve been working with a team for a while now who use XP. Writing user stories is OK and they are written very well, but writing developer stories posed a few problems.
The problem was this :-
We had a tendency, to actually write the story in such a way that presented the solution rather then the problem, and this seemed to cause problems and confusion.
Example of writing a bad developer story :-
As a developer I want to create a script that will run all DB scripts in succession so that I can easily refresh my development DB.
As you can see the solution is already presented in the story, not good. This is mainly because it’s not giving the development team the wiggle room to come up with a solution. The thing is the developer who wrote is giving his/her own take on the solution without consulting the rest of the team, thus not allowing for other team members, who might have a better solution, to present their contribution in the planning game.
So, what we need is to re-write the developer story in such a way that gives the team to reach a consensus on what is the best solution.
As a developer I want to address the issue of deploying the latest DB to my development DB with the minimum of fuss, so that I can start work sooner.
This is much better because it talks about the problem rather than the solution. Now, you might be saying that “Isn’t it how you write stories anyway?” and you’ll be right from a customer’s story writing point of view, but I think as with my team of developers, we know a little bit more about the system, which influences our story writing towards a solution rather than describing the problem.
Introducing……..
By James Fisk
I’m sorry, where you expecting a drum roll? No it’s just me James Fisk, I’m a developer of ten years plus specialising in ASP.NET, SharePoint,Spring.NET and Agile.
Hopefully this would be a regular place to dump my thoughts and so forth.
My company is called ‘Dititus’ it doesn’t mean anything I just thought it sounded good and it allowed me to get a .COM domain. You wouldn’t believe how differcult it is to get one those nowadays. Anyhoo the reason why I decided to call this blog ‘Spring loaded’ is because i’ve started to use Spring.NET a lot and it was also the first thing that popped into my head and I think that you’ll agree they are always the best type of titles.
I hope this blog will inform and stimulate, or at least, just humour. If I achieve any one of those I’ll be a happy man.
Thank you
James Fisk



July 15th, 2010