Bring your hard drive to Community Night
If you are coming to tomorrow’s community night, you want to bring your hard drive along because I will have some stuff to fill it up with:
- Visual Studio 2010 & TFS 2010 Service Pack 1 Beta Bits
- Over 8Gb of DevExpress videos (csv list below) which has something for everyone:
- If you use any of their tools or components there is plenty of short videos on using features in them.
- If you like to learn from experts they have great videos where they interview people like Jeff Atwood, Richard Blewitt, Sara Ford and Tim Heuer.
- Maybe you just want some less technical learning’s so how about, learning the GTD methodology or the science of making great user interfaces!
- The Silverlight fire starter keynote in HD, so if you care about the future of Silverlight this is a much see video.
Plus I hear that some prizes may be given away at the events too
Pulled Apart - Part XIV: DevExpress
Note: This is part of a series, you can find the rest of the parts in the series index.
I make no attempt to hide my love for a company called DevExpress which produces enhancements for Visual Studio and additional controls for WinForms, ASP.NET Web Forms, ASP.NET MVC, WPF & Silverlight.
When I started with Pull I used mostly the standard WinForm controls and over time have changed it be almost 100% DevExpress controls for a number of reasons:
- Rudi Grobler, Silverlight expert sits across the partition from me and loves to point out how ugly standard WinForms is compared to Silverlight. DevExpress helps me make my applications look MUCH better.
- Every line of code has a cost to it and the value of that line of code decreases overtime. So standing on the shoulders of giants means my cost of development is MUCH less. This also means I focus on the business aspects and not on the UI aspects.
- There is a lot of parity between DevExpress controls over different platforms, so if I want to change platform (for example to Silverlight) then I know the feature set will be close, lot’s of code could be reused.
Below is the first public version of Pull, which uses just DevExpress GroupBoxes, the rest is all WinForms:
versus the UI currently in development (for the January 2011 release) where only the status bar and web browser control are not from DevExpress! I think you will agree it looks way better now, plus there are many new features there (like filtering grids) which were not supported previously.
Grid Extensions
For the January 2011 release we switched to the DevExpress grids, which meant a lot of code needed to be changed (or just deleted) and I ended up writing a few extensions for the grids which I believe may be of use to other people:
Return a collection selected items
Rather than working with a collection of selected rows, this allows you to get the values of the selected rows:
public static IEnumerable<T> SelectedItems<T>(this ColumnView view) where T : class { foreach (int selectedRowHandle in view.GetSelectedRows()) { T item = view.GetRow(selectedRowHandle) as T; yield return item; } }
Select a collection of items
The grid normally lets you select a single row or a continuous range, however often I want to provide a list of item values and have the rows which match those values selected:
public static void SelectRows<T>(this GridView view, IList<T> selectedItems) where T : class { foreach (T selectedItem in selectedItems) { for (int counter = 0; counter < view.DataRowCount; counter++) { T item = view.GetRow(counter) as T; if (item == selectedItem) { view.SelectRow(counter); } } } }
Layouts and Strings
You can persist the layout of the grid to a stream, the registry or XML file. However I have a settings file and I would like to save and restore the layout from strings so I can easily add it to my settings file:
public static string SaveLayoutToString(this GridView view) { MemoryStream gridStream = new MemoryStream(); view.SaveLayoutToStream(gridStream, OptionsLayoutBase.FullLayout); gridStream.Position = 0; using (StreamReader reader = new StreamReader(gridStream)) { return reader.ReadToEnd(); } } public static void RestoreLayoutFromString(this GridView view, string layout) { if (!string.IsNullOrWhiteSpace(layout)) { using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(layout))) { stream.Position = 0; view.RestoreLayoutFromStream(stream, OptionsLayoutBase.FullLayout); } } }
Enum + Grid + Images = Headache
I have an enum for the podcast state and rather than show the text, which is the default, I want to show an image on the cell. However this is not the easiest thing to figure out since there is no designer support for this
However you can do most of this in the designer and then only need one line of code per enum value
.
Step 1
Set the Column Edit property of the column to an ImageComboxBoxEdit:
Step 2
On the ImageComboBoxEdit editor settings set the small images (and/or large images) property to the image list which contains the items you want to show.
It is important that you know the position (or index) of image in the image list.
Step 3
Now all you need to do is add the item values for the editor in code using the Items.Add method, which takes an ImageComboBoxItem. That class has some overloads which accept an Object for the value and here you can put in the enum value. Once this is done it all works fantastically.
You’ll note in the demo code below that I have an image index of –1 for the first item, this is so that no image is shown!
editor.Items.Add(new ImageComboBoxItem("None", PodcastState.None, -1)); editor.Items.Add(new ImageComboBoxItem("Downloading", PodcastState.Downloading, 0)); editor.Items.Add(new ImageComboBoxItem("Pending", PodcastState.Pending, 1)); editor.Items.Add(new ImageComboBoxItem("New Episodes", PodcastState.NewEpisodes, 3)); editor.Items.Add(new ImageComboBoxItem("Error", PodcastState.Error, 2));
Visual Studio Service Pack 1 - Beta: Field Guide
Brian Harry announced the availability of the service pack 1 beta which is fantastic news for all developers. This post is a field guide of me doing the installs.
Before that I wanted to point out a few key things included in this SP:
- This can installed in production – this beta includes a “go live” license so it is supported and upgrades to the RTM of the SP will be supported.
- This includes over 80 hotfixes for between 800 and 1000 bugs and many new features. For a full list see the link above, but here is a brief list:
- Silverlight 4 tool support!
- Unit testing can target the 3.5 framework now.
- IntelliTrace support for 64bit and SharePoint!
- Performance Wizard for Silverlight!
- HTML 5 support
- IIS Express support
- SQL Compact Edition 4 Tooling
Details on the last three can be found on Hanselman’s blog.
- Some third party systems may break with this, at this time known ones are:
- ASP.NET MVC 3 RC 1 – this will be fixed in the next update.
- Visual Studio Async CTP – this will break completely! No news, yet, on when it will be fixed.
The Process
For me there are three files you need to get:
- Update for .NET 4
- Update for Visual Studio
- Update for Team Foundation Server (not covered in this post)
Step 1
Install the .NET 4 update first – this took on my machine 24 minutes to do. It is important to note that I did shutdown Visual Studio first but I had some other applications open, including Pull which is .NET 4.
At the end of the process I needed to restart!
This step is no specifically needed as the VS SP will include this automatically, however I personally like the idea of doing it manually and making sure .NET 4 apps continue to work before I continue to the VS install.
Step 2
On to the Visual Studio install which after a few minutes tells you what will be updated and then, tells you that it wants to download 490Mb!
What I had done was to download the smaller installer version (less than 1Mb) which means it first figures out what is needed and then downloads the rest. This is great for some people as the download size is less, however since I live in South Africa (read: bandwidth is a luxury) and I work with 300+ other developers it is better for me to get the “DVD” labelled one which is bigger (in my case 103Mb bigger) but contains everything in one go so it can be shared easily and the bandwidth hit just once!
Step 3
We re-join the action a while later (when the “DVD” edition downloaded, approx. 1 hour 21 min later) we start process again and this time the download size is 0Mb
This took 29 min to process (remember this is without the download) this install and success!
Notes
I haven’t found anything in the many extensions I use daily that has broken! In particular my favourites all work
- CodeRush still working!
- Ghost Doc 2.5 still works.
- I did have one of the help extensions installed and VS just handled that fine (ie.e. no conflict with the new help viewer).
- SQLite development tools
- Power Command for VS
- Pro Power Tools for VS
- WoVS Quick Add Reference
CommNight December - Some interesting events
In the middle of the company parties, you should take one night off to do some fantastic learning and networking at CommNight (Community Night) on the 14th December! You can read about all the details on the Microsoft DPE Blog.
There are two groups which I want to highlight which will be at CommNight:
S.A. Developer
S.A. Developer is a user group for developers and in December will be hosting the following topics:
- Tool of the month: This short (10min to 15min) session is where someone can present their favourite developer focus tool or add-on.
- Unit Testing WPF & Silverlight – Tools & Techniques: Silverlight and WPF can be used to create truly immersive UI experiences for users. Testing these UI components and the logic around it can become complex – especially when using frameworks like PRISM. Join us in this session as we take a look at a few tools and techniques that can be used when unit testing WPF and Silverlight applications.
Really looking forward to this session!
Information Worker
Information Worker is a user group for those in the IW space, not just developers but everyone even people who job just involves Excel and Outlook! This month we are looking at:
- Lync – Microsoft’s Unified Communication System
- Windows Phone 7 – What does this give the IW user? Things like Office and SharePoint integration will be discussed
T4 Cheat sheets!
I’ve been spending a lot of time working on two things recently: T4 (Text Template Transformation Toolkit) and Windows Phone 7. Part of my work around T4 included creating some cheat sheets to make it easier to get to grips with it!
There is now three posters available (High res PDF’s below or on the DRP site):
General Overview
This provides a high level overview of the various components in T4.
@template detail
The @template directive has a lot of options and this sheet provides detail on those.
Examples
This sheet provides usage examples of various aspects directives in T4.
You can see my time with Windows Phone 7 leaking into these two as I loosely designed them around the Metro UI design guideline that Windows Phone 7 uses. Interestingly for me is that Metro seems to work fantastically well for cheat sheets as these are some of the nicest and easiest to grok sheets I’ve ever done.
Windows Phone 7 Training Event
Rudi Grobler, known for his love of WPF, Silverlight and Windows Phone 7, has organised a FREE training event focused on Windows Phone 7! This event will run on the 5th Feb 2011 but space is VERY VERY limited.
The idea is to give you key information via presentations, learning via hands on labs and fun via playing with REAL devices!
You can get all the details and register at: http://sadev.wufoo.com/forms/windows-phone-7-jump-start-feb-2011/
More details about the event will be announced over the coming weeks so follow Rudi’s blog for more!
Tech·Ed Africa 2010 - Slides, scripts and demos for my talks
Tech·Ed Africa 2010 ended on Wednesday and it was a great event. Thanks to everyone who came to my sessions and came up to me after and between sessions to chat. I felt very honoured to be able to meet and share with you :D
This post is for those who want the slides or demo information. I have completed versions of the demos below (in the zip file) and the script for each demo which gives you the step by step process I used (in the docx file).
APS302 – Intro to Workflow Services and Windows Server AppFabric
Other content for this session:
APS309 – Windows Server AppFabric Caching What it is and When you should use it
Other content for this session:
APS310 – WCF Made Easy with .NET 4 and Windows Server AppFabric
Other content for this session:
Upload files to SharePoint using OData!
I posted yesterday about some pain I felt when working with SharePoint and the OData API, to balance the story this post cover some pleasure of working with it – that being uploading a file to document library using OData!
This is really easy to do, once you know how – but it’s the learning curve of Everest here which makes this really hard to get right, as you have both OData specialisations and SharePoint quirks to contend with. The requirements before we start is we need a file (as a stream), we need to know it’s filename, we need it’s content type and we need to know where it will go.
For this post I am posting to a document library called Demo (which is why OData generated the name of DemoItem) and the item is a text file called Lorem ipsum.txt. I know it is a text file, which means I also know it’s Content Type is plain/text.
The code, below, is really simple and here are what is going on:
- Line 1: I am opening the file using the System.IO.File class, this gives me the stream I need.
- Line 3: To communicate with the OData service I use the DataContext class which was generated when I added the service reference to the OData service and passed in the URI to the OData service.
- Line 8: Here I create a DemoItem - remember in SharePoint everything is a list or a list item, even a document which means I need to create the item first. I set the properties of the item over the next few lines. It is vital you set these and set them correctly or it will fail.
- Line 16: I add the item to the context, this means that it is being tracked now locally – it is not in SharePoint yet. It is vital that this be done prior to you associating the stream.
- Line 18: I associate the stream of the file to the item. Once again, this is still only happening locally – SharePoint has not been touched yet.
- Line 20: SaveChanges handles the actual writing to SharePoint.
using (FileStream file = File.Open(@"C:\Users\Robert MacLean\Documents\Lorem ipsum.txt", FileMode.Open)) { DataContext sharePoint = new DataContext(new Uri("http://<sharepoint>/sites/ATC/_vti_bin/listdata.svc")); string path = "/sites/ATC/Demo/Lorem ipsum.txt"; string contentType = "plain/text"; DemoItem documentItem = new DemoItem() { ContentType = contentType, Name = "Lorem ipsum", Path = path, Title = "Lorem ipsum" }; sharePoint.AddToDemo(documentItem); sharePoint.SetSaveStream(documentItem, file, false, contentType, path); sharePoint.SaveChanges(); }
Path Property
The path property which is set on the item (line 12) and when I associate the stream (line 18, final parameter) is vital. This must be the path to where the file will exist on the server. This is the relative path to the file regardless of what SharePoint site you are in for example:
- Path: /Documents/demo.txt
- Server: http://sharepoint1
- Site: /
- Document Library: Documents
- Filename: demo.txt
- Path: /hrDept/CVs/abc.docx
- Server: http://sharepoint1
- Site: /hrDept
- Document Library: CVs
- Filename: abc.docx
Wrap-up
I still think you need to still look at WebDav as a viable way to handle documents that do not have metadata requirements, but if you have metadata requirements this is a great alternative to the standard web services.
Cannot add a Service Reference to SharePoint 2010 OData!
SharePoint 2010 has a number of API’s (an API is a way we communicate with SharePoint), some we have had for a while like the web services but one is new – OData. What is OData?
The Open Data Protocol (OData) is a Webprotocol for querying and updating data that provides a way tounlock your data and free it from silos that exist in applicationstoday. OData does this by applying and building upon Webtechnologies such as HTTP, Atom PublishingProtocol (AtomPub) and JSON toprovide access to information from a variety of applications,services, and stores.
The main reason I like OData over the web services is that it is lightweight, works well in Visual Studio and works easily across platform, thanks to all the SDK’s.
SharePoint 2010 exposes these on the following URL http(s)://<site>/_vti_bin/listdata.svc and you can add this to Visual Studio to consume using the exact same as a web service to SharePoint, right click on the project and select Add Service Reference.
Once loaded, each list is a contract and listed on the left and to add it to code, you just hit OK and start using it.
Add Service Reference Failed
The procedure above works well, until it doesn’t and oddly enough my current work found a situation which one which caused the add reference to fail! The experience isn’t great when it does fail – the Add dialog closes and pops back up blank! Try it again and it disappears again but stays away.
If you check the status bar in VS, you will see the error message indicating it has failed – but by this point you may see the service reference is listed there but no code works, because the adding failed.
If you right click and say delete, it will also refuse to delete because the adding failed. The only way to get rid of it is to close Visual Studio, go to the service reference folder (<Solution Folder>\<Project Folder>\Service References) and delete the folder in there which matches the name of your service. You will now be able to launch Visual Studio again, and will be able to delete the service reference.
What went wrong?
Since we have no way to know what went wrong, we need to get a lot more low level. We start off by launching a web browser and going to the meta data URL for the service: http(s)://<site>/_vti_bin/listdata.svc/$metadata
In Internet Explorer 9 this just gives a useless blank page but if you use the right click menu option in IE 9, View Source, it will show you the XML in notepad. This XML is what Visual Studio is taking, trying to parse and failing on. For us to diagnose the cause we need to work with this XML, so save it to your machine and save it with a .csdl file extension. We need this special extension for the next tool we will use which refuses to work with files without it.
The next step is to open the Visual Studio Command Prompt and navigate to where you saved the CSDL file. We will use a command line tool called DataSvcUtil.exe. This may be familiar to WCF people who know SvcUtil.exe which is very similar, but this one is specifically for OData services. All it does is take the CSDL file and produce a code contract from it, the syntax is very easy: datasvcutil.exe /out:<file.cs> /in:<file.csdl>
Immediately you will see a mass of red, and you know that red means error. In my case I have a list called 1 History which in the OData service is known by it’s gangster name _1History. This problem child is breaking my ability to generate code, which you can figure out by reading the errors.
Solving the problem!
Thankfully I do not need 1 History, so to fix this issue I need to clean up the CSDL file of _1History references. I switched to Visual Studio and loaded the CSDL file in it and begin to start removing all references to the troublemaker. I also needed to remove the item contract for the list which is __1HistoryItem. I start off by removing the item contract EntityType which is highlighted in the image along side.
The next cleanup step is to remove all the associations to __1HistoryItem.
Finally the last item I need to remove is the EntitySet for the list:
BREATH! RELAX!
Ok, now the hard work is done and so I jump back to the command prompt and re-run the DataSvcUtil tool, and it now works:
This produces a file, in my case sharepoint.cs, which I am able to add that to my project just as any other class file and I am able to make use of OData in my solution just like it is supposed to work!
Come and hang out with me at Tech·Ed Africa 2010!
Tech·Ed Africa 2010 is less than a month away and it is a massive conference where all things IT Pro and developer are discussed. It is a great conference, filled with networking (read: beer), wonderful sessions and great prizes!
I will be attending as a speaker again this year so I thought I would share what I will be talking about, however before I get to that I want to talk about a wonderful prize I am giving away.
Certain MVP’s got given some Visual Studio 2010 Ultimate licenses to give away, and I was lucky enough to get three of those. Each license is values at $11600!! I will be giving these away at the community lounge as part of a fun game! Details of the game will be available at the lounge at the event.
Back to my shameless promotion Tech·Ed has two types of sessions Breakout Sessions where I get up on stage and present and demo for about an hour and Whiteboard Sessions which are interactive discussion sessions. I am lucky to have a few of each. Note: this is all subject to change.
Breakout Sessions
Intro to Workflow Services and Windows Server AppFabric
Windows Workflow Foundation 4 (WF4) provides a flexible, declarative programming model and a brand new runtime architecture that makes it easily accessible for .NET developers. What that means for developers is that WF4 can make it easier to put together your application logic, encapsulate complex control flow logic, and abstract complex programming tasks. WF4 also composes nicely with Windows Communication Foundation (WCF) for writing declarative workflow services that support content-based message correlation and long-running duplex conversations. When you combine the framework features with the new AppFabric capabilities in Windows Server to host and manage your workflows and services , you have a comprehensive workflow solution in Windows. In this session we will look at examples of how you can use WF4 in your application and service development to speed your development and simplify complex tasks, as well as how to build powerful, manageable workflow services with WF, WCF and AppFabric. Come find out how this powerful, testable framework can help you and your development team take programming to the next level.
WCF Made Easy with Microsoft .NET Framework 4 and Windows Server AppFabric
Windows Communication Foundation (WCF) is a flexible and powerful platform for building service-oriented applications, and with that flexibility comes some complexity. As of .NET Framework 4 – configuring, securing, hosting and managing WCF services has never been easier! WCF 4 and Windows Server AppFabric come together to help developers and IT administrators overcome the complexity. Come find out how much easier it is to configure WCF services in .NET 4 including alignment with the Microsoft ASP.NET configuration model and a reduced configuration footprint. Also learn Windows Server AppFabric features for the IT administrator, finally making it easier for IT administrators to easily access settings they care about such as security and throttling features; providing control over the hosting lifecycle of WCF services; and giving new visibility into faults, exceptions, and tracing and diagnostics features to help you manage your service deployments in production un-intrusively.
Windows Server AppFabric Caching: What It Is and When You Should Use It
The distributed in-memory caching capabilities of Windows Server AppFabric will change how you think about scaling your Microsoft .NET-connected applications. Come learn how the distributed nature of the cache allows large amounts of data to be stored in-memory for extremely fast access, how AppFabric’s integration with Microsoft ASP.NET makes it easy to add low-latency data caching across the Web farm, and discover the unique high availability features of AppFabric which will bring new degrees of scale to your data tier.
Whiteboard Sessions
Web Service Interop
This is a panel discussion on web service interop with myself, Nabeel Prior (Microsoft BizTalk Expert), Anton Delsink and Ryan Crawcour (BizTalk Expert from New Zealand).