Sign In

Navigation

On This Page

Motion Detection With Silverlight and Native Extensions for Silverlight
TCSLUG – Presentation Materials
New Html Agility Pack Versions and Features
Html Agility Pack 1.4.0 Released
Silverlight Window Navigation in Safari
VS2010 New Website Template Updates
C# 4.0 Named Parameter Dangers
VS2010 Extensions Followup
PDC ‘09 Predictions
The overloaded .NET developer
Uninstalling VS2010 beta 1 – Work Around
HTML Agility Pack - Contributor
The Case for Partial Properties
Recovering Mozilla Weave Passphrase
Speeding up the ASP Development Webserver in Firefox
Twin Cities User Groups and Events
Sorry for the Silence
Getting Started with Visual Studio 2010 Extensions
Small Basic Materials
Twin Cities Code Camp Presentation

Archive

<January 2012>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

Categories

Blogroll

Contact

Send mail to the author(s) Email Me
MCPD
MCTS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way


Copyright ©  2012
 Creative Commons License
This work by Jeff Klawiter is, unless explicitly stated in the article,  available under the Creative Commons Attribution 3.0 United States License.

Pick a theme:
# Wednesday, July 27, 2011
by Jeff Klawiter - Wednesday, July 27, 2011 1:17:59 PM (Central Standard Time, UTC-06:00)

While a little late, here are is the source code and the slide deck for my recent talk at the Twin Cities Silverlight User Group.

SLMotionDetector.zip

This includes a solution with the source code for the common MotionDetection library, a silverlight application with OOB capabilities, a Windows Phone 7 app and a failed WPF attempt.

You will need the Windows Phone 7 Mango Beta 2 SDK to run the WP7 project. This does include compiled versions of the NESL libraries. The source can be found at http://archive.msdn.microsoft.com/nesl/Release/ProjectReleases.aspx?ReleaseId=5519

This code is provided as-is. It comes with no support and complete with "Works on My Machine" credentials. I have removed the certificates used for signing the libraries, you may need to create your own to run the app out of browser. I have not taken the time to clean up the code or remove commented out old code..

Comments [0] #      C# | C# 4.0 | Silverlight | wp7  |  kick it on DotNetKicks.com Shout it
# Tuesday, July 20, 2010
by Jeff Klawiter - Tuesday, July 20, 2010 5:04:59 PM (Central Standard Time, UTC-06:00)

As promised I’m posting the finished projects from my Silverlight Templating presentation at the Twin Cities Silverlight Users Group today.

This includes the slide deck, the Watermark Text Box and Dynamic Themes project.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Saturday, June 05, 2010
by Jeff Klawiter - Saturday, June 05, 2010 6:17:49 PM (Central Standard Time, UTC-06:00)

Recently I have added 4 new projects to SVN for Html Agility Pack.

  1. HAPLight: a Silverlight implementation
  2. HAPCompact: a .NET CF 3.5 version
  3. HAP for .NET 4.0: taking advantage of DynamicObject.
  4. Unit Tests

All of these are works in progress and should be considered in alpha stages thus no binary releases for them yet. To use them you’ll need to download them from SVN. http://htmlagilitypack.codeplex.com/SourceControl/list/changesets

HAPLight

Bringing Html Agility Pack to Silverlight was relatively simple, thanks to Silverlight supporting XPATH and XpathNavigator. There have been two losses so far, HtmlCmdLine and HtmlWeb. HtmlWeb is a big loss and I don't plan on leaving it that way. Silverlight requires all web requests to be Asyncronous which HtmlWeb surely is not. So at some point I will be making a version of HtmlWeb that exposes Asynchronous methods for downloading pages and returning them as HtmlDocuments. For now you can do this yourself without much code using WebClient.DownloadstringAsync()

HAPCompact

Again making a port of Html Agility Pack to .NET CF wasn't too difficult. One of the biggest issues is .NET CF has no XPathNavigator support. There are no good free implementations and I don't expect there ever will be. So HAPCompact will need to rely on using LINQ to Objects. This project needs to be built with Visual Studio 2008. Unfortunately VS2010 did not include any .NET compact framework support. I've been trying to look into a way of taking advantage of VS2010's multi-targeting to add back in compilation support. I have many projects at work that are in .NET CF 2.0 and 3.5.

Html Agility Pack for .NET 4.0

.NET 4.0 shipped with the Dynamic Language Runtime included. C# was updated in turn to include a dynamic typing system. I thought it would be interesting to see if HAP could take advantage of these features to dynamically access HtmlNodes and HtmlAttributes.  This project so far is a partial class that makes HtmlNode inherit from DynamicObject. This may change later to have it just implement an interface instead. The advantage of this is you can access first level child nodes and attributes without . Something like documentElement.Html.Body.Div to get the first <div> on the page.

In C# to use these features you need to indicate the object is dynamic. Simply assigning the node to a variable typed as dynamic will suffice. I had hoped to use @ for getting attributes but found that it is completely lost so to access attributes a prefix of _ is needed. Here are some examples taken from the unit tests:

[Test]
public void TestGetAttribute()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("<html><body class=\"asdfasd\"><p>asdf asdf sdf</p></body></html>");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body._Class;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf<HtmlAttribute>(item);
}

[Test]
public void TestGetMember()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("<html><body><p>asdf asdf sdf</p></body></html>");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf<HtmlNode>(item);
}

Other ideas I’m having with this is to introduce some kind of domain specific language for doing more specific accessing like documentElement.Html.Body.First_Div or documentElement.Html.Body.ById_Header . This will be limited of course due to lack of symbols that could be used.

Unit Tests

I’ve begun adding Unit Tests to Html Agility Pack. This will be a long process to even approach a good code coverage percentage. There is quite a bit of code in the library and some of it could use a good refactoring. So as I’m writing unit tests I may be doing some refactoring as well. Along with this may come some introductions of breaking changes with some of the methods or properties within the API. Thus this next version may be 2.0.

# Friday, May 07, 2010
by Jeff Klawiter - Friday, May 07, 2010 6:01:55 PM (Central Standard Time, UTC-06:00)

Today I finally was able to get some time to get Html Agility Pack 1.4.0 released.

This latest release brings many subtle new features and many bug fixes. While it doesn’t attack some of the major pain points (as when joining the project I was not aware of them) it does bring HAP into the modern age for .NET. Gone are the .NET 1.0 ArrayLists and most of the HashTables. In are Generic lists and functions that return IEnumerable that mimic LINQ to XML. Things like Descendants() and Ancestors(). These new functions serve as an alternative to using XPATH.

Among the new LINQ compatible features 1.4.0 brings with it

  • Support for Medium Trust environments
  • Updates to Charset detection and the ability to override it
  • Many bug fixes
  • Ability to preserve tags original case when writing out the HtmlDocument
  • A new sister program HAPExplorer for browsing the HtmlDocument tree and searching said tree
  • Large cleanups and optimizations of the underlying code. Utilizing Resharper and Code Metrics the underlying code is in better shape than it was before. There is still a long way to go but it is a start.
  • Added a new Xpath property to HtmlNode that will get the direct path to that particular node. Easy to find via HAPExplorer
  • MSDN like CHM documentation

Download Html Agility Pack 1.4.0 Now!

I had hoped to release this a long time ago but I got piled up with one rush project after the next. When I wasn’t at work working I was at home working or delving deep into the guts of Silverlight.

HAP’s Past

Html Agility Pack was originally created by Simon Mourrier while he was at Microsoft as a System.Xml look-alike for parsing HTML documents. At that time extremely malformed HTML was the standard across the web. HTML 3.01 still had a good share of web pages out there. While we had tools like Dreamweaver popping up it was still very common to see unclosed <li> and <option> tags. HAP was a godsend. Converting HTML to XML was (and still can be) a pain. As such in those times HAP was set to by default handle the non-standard HTML browsers let slide by in those days.

HAP’s Present

These days the web has come quite a long way with many people pushing for standards and people actually taking them seriously. XHTML came to pass as a default for many HTML editors. Finding sites with horrendous non-conforming HTML is not as likely. Yes there’s still very ugly HTML (loads of tables) but it is still closer to standard than it was then. HAP in recent years has been showing some weaknesses. While I wouldn’t really call them weaknesses others might. It is more in the perception of what people expect HAP to do and what it really does.

HAP’s parsing engine is extremely efficient and can be very flexible when it comes to when tags can be closed. The problem is no one realizes this due to lack of documentation and examples. Also the location of the list of tags and their defaults is not in an easily discoverable position. This has lead to many discussion posts all ending with basically the same outcome, remove this tag or that tag from the list. This list, fyi, is HtmlNode.ElementsFlags. From a parser perspective this list is very handy and efficient, from an end users perspective it can be a bit of a nightmare to work with.

HAP’s Future

I originally joined the project to update it for my own purposes. I hate Xpath (personal reasons) and love LINQ. I had done so much work to update HAP to support LINQ I wanted to share it. I have since abandoned the VS Extension I was working on that I was going to use HAP for. I do not intend to abandon HAP. That being said it might be a bit until a new update is out. I do have a bunch of ideas on how to address the ElementFlags situation. Among these are building in some defaults for different (X)HTML specs, creating a fluent interface for adding them, making them able to be loaded from a config and things like that. Along with that there are many parts of HAP that are now implementing features that have been added to .NET in the last 7 years. The HtmlWeb class does quite a bit that WebClient handles now.

Another space I want HAP to tackle is Silverlight. I know it is being used in the Facebook Silverlight Client (just check it’s end user license).  With Silverlight 4 they have added Xpath support. HAP does need to slim down if it were to be ported to SL. 130KB is quite heavy for a Silverlight dll. Plus HAP isn’t compatible with async web calls.

Another thing HAP needs desperately is Unit Testing. Coming up with a testing suite is quite a challenge, there will need to be quite a bit of refactoring to really do it properly.

Another interesting idea I had with HAP is now with .NET 4.0 and the Dynamic keyword and Expando objects we could have quite a bit of fun. Access attributes and child tags as if they were properties on the node? It could be done and would be an interesting endeavor

I welcome anyone that has input on where they want to see HAP go or want to join the project. Right now I don’t have the power to add any new developers but we can make our case to Simon to add new people on.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Saturday, April 24, 2010
by Jeff Klawiter - Saturday, April 24, 2010 3:50:26 PM (Central Standard Time, UTC-06:00)

There is a “bug” with Silverlight in Safari when trying to do window navigation. Both HtmlPage.PopupWindow and HtmlPage.Window.Navigate will not work on Safari due to plugin limitations. This makes doing something like using AddThis’ API rather hard to do cross browser. Chris Idzerda over at Vertigo had posted a partial solution a while back but it had the drawback of needing to always have more html along with your silverlight app. I decided to take his solution and make it a bit more automatic.

Chris’ solution involved having certain HTML exist on the page already that Silverlight can call. While this works, I hate having to dictate more and more things that need to be on the page. Below is his solution

public static void  OpenBrowser(string url)
{
  if(HtmlPage.BrowserInformation.UserAgent.Contains("Safari"))
  {
    HtmlElement anchor= HtmlPage.Document.GetElementById("externalAnchor");
    anchor.SetProperty("href", url);
    HtmlElement button= HtmlPage.Document.GetElementById("externalButton");
    button.Invoke("click", null);
  }
 else
    HtmlPage.Window.Navigate(new Uri(url, UriKind.RelativeOrAbsolute), "_blank");
}
<a  id="externalAnchor" style="display:none;"></a>
<input id="externalButton" type="button" onclick="window.open(document.getElementById('externalAnchor').href)" style="display:none;" />

My idea was to take his html and dynamically create it via Silverlight’s Html bridge. (Note this will only work if the xap is on the same domain or “enablehtmlaccess” is set to true for the plugin). To do this is fairly straight forward. Below is my code (with the exception handling simplified)

if (HtmlPage.BrowserInformation.UserAgent.ToLower().Contains("safari"))
{
    try
    {
        if (HtmlPage.IsEnabled)
        {
            var anchor = HtmlPage.Document.CreateElement("a");
            anchor.Id = "externalAnchor";
            anchor.SetStyleAttribute("display", "none");
            HtmlPage.Document.Body.AppendChild(anchor);

            var button = HtmlPage.Document.CreateElement("input");
            button.Id = "externalButton";
            button.SetAttribute("type", "button");
            button.SetAttribute("onclick", "window.open(document.getElementById('externalAnchor').href)");
            button.SetStyleAttribute("display", "none");
            HtmlPage.Document.Body.AppendChild(button);
        }
    }
    catch (Exception e)
    {
        OnError(e.Message);
    }
}

So starting off only if we are in Safari do we even need to run the code. I opted to run this code when my AddThis component is first loaded. If we have access to the HtmlPage we new up anchor and button elements. This generates the exact same HTML that Chris’ did in his example. After this his function from above just works :). It’s a fairly straightforward fix. I hope that soon MS will be able to get SL to support popup/navigation in Safari. I’m sure it has something to do with their plugin api.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Thursday, November 05, 2009
by Jeff Klawiter - Thursday, November 05, 2009 9:05:51 PM (Central Standard Time, UTC-06:00)

I went to create my first new website with Visual Studio 2010 the other day and was quite surprised with what I found.

image

In all versions prior to 2010 a new website would just get you a Default.aspx and the corresponding language codebehind file. This changes quite a bit with 2010. You actually will now be presented with a full website ready to go. Complete with a Master page, account login and more.

image

Digging in Further yields some nice little nuggets. First off the Site.Master isn’t just a blank master page with a ContentPlaceHolder. It actually contains a relatively decent CSS layout with LoginView and Menu controls.

image

Along with the Site.Master the site comes with Default.aspx, About.aspx and an entire directory dedicated to authentication. The Account directory is set up to handle all the most common authentication scenarios: Login, Register and Password Recovery. Furthermore these pages include actual code in the codebehind.

One thing however that it is missing is the database to authenticate with. If you are planning to use your own membership provider or an external database you just need to set it up in the web.config. If you’d like to just use an sqlexpress database you can use the ASP.NET Website Administration Tool to do this for you. This tool was added in .NET 2.0 and the current version doesn’t seem to have changed much. To generate the ASPNETDB.MDF SQLExpress database. Just click on the Tool and World icon in the Solution Explorer.

image
Another way to access this tool is via the ASP.NET Configuration command under the Website menu.

image

The best way to have it set up the database is to click on the “Use the security Setup Wizard..” link. This will take you through setting up the database, roles, users and locked down directories.

Beyond the account code the site comes with jQuery 1.3.2, it’s minified version and the Visual Studio Intellisense file. Unfortunately the jQuery files are not referenced by default in the master page or any of the other pages. I would have loved to have either an example usage or at least a reference to the file. To add jQuery it’s just a simple addition to the master file. After that just force VS to update its javascript intellisense using Ctrl+Shift+j

image

Rarely do I start out a website this way these days, most my sites I start are powered by one CMS or another. Besides those times I’ve been trying to use ASP.NET MVC more these days. I still use the default webforms site when I need to get something up and running quick with some basic data controls. I recently did a website for planning a family reunion. I could have saved myself a half an hour or so getting just the base of the site set up.

# Tuesday, October 27, 2009
by Jeff Klawiter - Tuesday, October 27, 2009 10:04:59 AM (Central Standard Time, UTC-06:00)

C# 4.0 introduces many new languages features, one of them being named parameters. Instead of passing parameters to a method or constructor in the sequence they are declared you can pass them in as a name/value pair.

//method signature
public SearchData(string searchText, SearchOptions SearchOption, int limit, int skip)

//Calling it the normal way
obj.SearchData("foo",mySearchOptions,10,20);

//Calling it with Named Parameters
obj.SearchData(limit: 10, skip: 20, searchText: "foo", SearchOption: mySearchOptions);

As you can see it is nice that now when passing parameters your code becomes more self documenting. You know what parameter is being assigned to what. Combine this with default/optional parameters it can make your code more clear and concise.

The problem comes when refactoring code. I hope you noticed something wrong about the second parameter in the method signature. While technically sound it fails naming guidelines. Say this was a third party library you were using and they discovered this and fixed it in the next revision. When you update to the new library you will get a compiler error. This is because the named parameters are Case Sensitive. Below is an example of just this

//New method signature
public SearchData(string searchText, SearchOptions searchOption, int limit, int skip)

//This will remain working
obj.SearchData("foo",mySearchOptions,10,20);

//This will now result in a compiler error
obj.SearchData(limit: 10, skip: 20, searchText: "foo", SearchOption: mySearchOptions);

Now I’m not saying you should never use Named Parameters. You should keep in mind if you are using code that is not your own you may be increasing your development debt. Also take into account where the code comes from. If you are doing Office development, I say go for it. Microsoft is very aware of implications of this and will no doubt do their due diligence when updating the Primary Interop Assemblies.

I also am hoping that Visual Studio 2010 will have refactoring support when renaming a parameter like that. I just tried in Beta 2 and did not get any such support. Maybe Resharper will catch it.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Monday, October 26, 2009
by Jeff Klawiter - Monday, October 26, 2009 12:15:10 PM (Central Standard Time, UTC-06:00)


Thanks to all those who came to my talk. When I first planned to give the talk Beta 1 had been out for a little while and I was working on my own extension. There was news that Beta 2 was no longer accepting bugs (beginning of august) and it was probably due that month. I thought that’d give me a couple months time to give the talk on Beta 2. But as we all know now, it took much longer to get Beta 2 out the door and it landed at the worst time.

When Beta 2 came out, 3 days before my talk, I set up a Windows 7 Bootable VHD up to install it and test my code, just in case I wasn’t able to get anything working and had to use Beta 1 for the talk instead. As I started trying out all the extensions I had I was almost ready to just use Beta 1 since none of them worked. As I got further into trying to use Beta 2 I realized some large fundamentals of all the extensions I was going to show had changed. Classes were removed, new classes introduced, easier ways of declaring your extension. The changes were big enough that I felt I would be doing a disservice to people by showing them the Beta 1 examples. I would rather show 1 working extension in Beta 2 than cause confusion by showing 5 in Beta 1.

Aside from the SDK changes in Beta 2 there were interface, feature and performance changes that I felt important to show. Beta 1 was much slower all around. There were new features in the Extension VSIX Manifest Editor and changes to the VSIX manifest itself. Also there were new templates included.

In the end I’m glad I used Beta 2 instead of Beta 1. While I was missing my examples of adding menu items, commands, doing search and replace in the editor, I was able to show real world working code that anyone going out and downloading Beta 2 after my talk would be able to implement. If I had another week or two between Beta 2 and the talk I would have had all of them.

I’d like to know your thoughts, I’m not above being criticized as long as the dialog is civil. I want to be a better speaker a better person. I know I’m not the most witty or animated, but I love to code and I love to share my knowledge.

Here’s links to some of the resources. The first sample code you can find below, The second two samples shown were from the Codeplex editor examples. I had more hand rolled examples but they didn’t work in Beta 2 but I ran out of time in getting them working.

Where Button Marker
WhereMarker.zip

Editor Examples on Codeplex
http://editorsamples.codeplex.com/

Visual Studio Extensibility on MSDN
http://msdn.microsoft.com/en-us/vsx/default.aspx

Black Editor Colors
JeffKlawiterBlackColoring.zip

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Friday, October 23, 2009
by Jeff Klawiter - Friday, October 23, 2009 12:01:27 PM (Central Standard Time, UTC-06:00)

Disclaimer: These are solely my personal opinion and thoughts of what will be unveiled during PDC this year.

Windows Mobile 7

With the current rumors that WM7 will beta in Nov it’s a no brainer that it will be unveiled at PDC. I’m expecting a major UI update, rewritten graphics system and more integration with .NET CF. The .NET CF team has been rather silent on their blog for a while now and that’s normally a sign of big things to come. I have a inkling that the new UI will be WPF based. Since Silverlight Mobile is WPF, this would give a great chance to make WPF a full UI framework for windows mobile

Silverlight 4

Becoming a staple of PDC and Mix, Silverlight has been on some extremely fast paced development. I’m expecting SL 4 to have webcam and microphone support. Along with more .NET 4.0 features like dynamic types and the DLR.

Silverlight Mobile

It has been talked about more than once, last PDC had quite a large demo for it. I expect it to be announced probably for Windows Mobile 6.5 and higher.

Windows 8

With Windows 7 out of the way, I think we may be teased with some of the ideas they have for Win8. There has been a lot of activity on linkedin related to it. Like 128bit support, which I’m expecting is probably Intel’s Itanium successor and not meant for desktop chips.

Blend 3 SP1

MS has already said that Blend 3 will get .NET 4.0 support in SP1 and it was expected to ship Q3. I think most of this update will only revolve around .NET 4 and nothing in the way of new killer features.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Wednesday, October 21, 2009
by Jeff Klawiter - Wednesday, October 21, 2009 4:51:23 PM (Central Standard Time, UTC-06:00)

I write this as I’m sitting here working on a .NET CF 2.0 project in Visual Studio 2005 while installing Visual Studio 2010 Beta 2 onto my laptop which is running windows 7 installed on a vhd file booted natively. I look at the list of components being installed with 2010 Beta 1 and I’m just left feeling inadequate. The one that really tipped it was Visual F# 1.0. F# has been out in for a while now and I’ve only seen talks on it. I haven’t written a line of code in it. I can also say the same for Work Flow and many other MS/.NET technologies.

I sat in on an interview today with a rock star programmer. His code sample he sent in to us was the best we’ve ever seen. He’s got strong ASP.NET (and MVC) skill along with HTML/CSS-fu. Then I ask the questions about what else he has done in .NET.. barely any WinForms, no compact framework, little WPF. I do not hold any of this against him, I know full well what it is like to try and keep up with things when your current job doesn’t entail them. Here at Sierra Bravo my job does entail them, sometimes. We do such a large variety of projects I’ve had to learn almost everything under the .NET sun and I still feel like I’m behind.

I’ve spent the last few months trying to write a talk on Visual Studio 2010 Extensions and I sure hope my talk goes well but I’m not optimistic. After getting into doing the extensions, hoping for a nice easy to use SDK as was promised, I found still a complex system of interfaces, attributes and unclear APIs. Mind you, it is still beyond  what was available in 2008. I also gave a talk on SQL CLR programming and have been working on learning ASP.NET MVC. Beyond that, reading a WPF certification book and hoping to one day expand my certifications passed the VS 2005 realm. I spend nearly every minute of my spare time reading, coding and learning.

Things I have done

  • .NET CF 1-3.5 (about 10 applications)
  • ASP.NET 1.1 – 3.5 (lost count of how many sites)
  • .NET WinForms 1.1 – 3.5 (about 20 applications)
  • Windows Services (around 10)
  • ASMX (lost count)
  • WCF ( a few)
  • SQL Server 2000-2008 (full and express)
  • SQL Reporting Services
  • SQL CLR
  • SharePoint integration (2)
  • Visual Studio Extensions (a few)
  • Command line Programs (20+)
  • Library development (HtmlAgilityPack, Sierra Bravo Connector aka PickDB)
  • TCP Client/Server protocols
  • Serial Port controlled vending machines
  • RFID integration
  • Surface
  • Silverlight 1.1-3.0
  • C# and VB.NET
  • Dabbled in XNA
  • Dabbled in MVC
  • Office Integration
  • LINQ to SQL, LINQ to Entities
  • T4 programming
  • Got MCTS WinForms/ASP.NET 2.0 and MCPD ASP.NET 2.0 certified

Things I still need more experience in, have yet to do, work with or even look at

  • TDD/DI/IoC – I’ve dabbled a bit but feel like I’m really falling behind with these dev patterns
  • Micro Framework
  • F#
  • Work Flow
  • TFS
  • Full WPF Application
  • Full Mono application
  • M/Oslo
  • Parallel Extensions
  • Tons of the new stuff in VS2010/.NET 4.0 (like the asp.net 4 features)
  • Write a LINQ provider

While the latter list seems small, I’m sure it will grow again. The first list covers 4 1/2 years of work. To me it is mind boggling that I’ve done so much and also a testament to how powerful the .NET framework is. In the PHP world there are a couple great frameworks these days but it has taken many many years to get to that point. Also PHP 6 is turning into PERL 6 with it being on the horizon for many years now. It also has the issue of only being a web language.

I really hope after VS2010 Microsoft slows down for a bit and waits until VS2015 or something. I’m not sure if I can keep up on this pace much longer. Some days I wish for a job where I’m working on a product, or in a slower paced project. Other days I think I’d go crazy if I was working on the same thing all the time. One thing is for certain, I need to start doing things outside of work again.

Comments [0] #      Rant  |  kick it on DotNetKicks.com Shout it
# Saturday, September 26, 2009
by Jeff Klawiter - Saturday, September 26, 2009 6:05:35 PM (Central Standard Time, UTC-06:00)

Today I was cleaning off my old laptop for my girlfriend to use. While trying to Uninstall Visual Studio 2010 Beta 1 I ran across an error. It was on the step trying to uninstall the “TFS Object Model”. The error said it was looking for “TFSObjectModel-x86_ENU.exe”, it asks for the install DVD but the exe is not on the disc at all. After some digging I found a way to get the uninstall to work.

The trick is to uninstall the component on it’s own. It’s called “Microsoft Team Foundation Server 2010 Beta 1 Object Model – ENU”

image

After uninstalling that I was able to run the VS2010 uninstall without a hitch.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Tuesday, September 15, 2009
by Jeff Klawiter - Tuesday, September 15, 2009 10:02:42 AM (Central Standard Time, UTC-06:00)

For a few months now I’ve been working on a VS2010 extension I’m calling Funky Search. It’s basic intent is to bring tag based search and replace functionality to Visual Studio. My first order of business when creating this extension was the need for an HTML Parsing Engine. I had used HTML Agility Pack (HAP from now on) in the past. One downside of it is that it uses XPATH for querying the HTML. While in it’s day XPATH was a decent solution for searching XML structures, there are better searching solutions available today namely LINQ.

I set out and updated HAP to have all of it’s Node and Attribute collections to inherit from IList<T> instead of implementing their own Enumerators. I then added many helper methods to mimic LINQ to XML. With this I could now work on creating dynamic LINQ statements to power my extension.

While working on this I got into the community of people using HAP and I came across a larger issue, it had not been updated in years and the creator and other developer on the project had seemed to abandon it. I sent many emails to the creator Simon Mourier (former MS employee, and current CTO of SoftFluent) over the summer with no reply. I finally found his work email and discovered he was on vacation until early September. I was finally able to get in contact with him today and he added me as a developer on the project.

This will mark the first time in about 5 years I’m a developer on an open source project. Before coming to Sierra Bravo I was huge into open source, also at that time MS had no free versions of Visual Studio. I was working as a PHP developer and had contributed to some small projects and even worked on part of the Mozilla project adding in an easier way to code-sign your Mozilla/Firefox extensions.

I’m looking forward to advancing HAP, fixing bugs and making it easier to use. It sits in a unique position as being the only freely available HTML parser that works. While it can be used for dubious purposes as a page scraper it can also be used for good. I’ve used it in the past where we had a client that had their hosting provider go out of business, their site was going to only be up for another day and we had no direct access to their database server. We had FTP access to get the code of the site and access to a readonly front end that displayed the contents of the tables in html with no export functionality. I wrote a scraper with HAP to get those tables and put them into an importable format. With it I was able to download and import their database and save their site.

# Monday, September 14, 2009
by Jeff Klawiter - Monday, September 14, 2009 4:18:17 PM (Central Standard Time, UTC-06:00)

With the advent of ASP.NET MVC 2.0 and the new templated helpers we’re once again having to write out our entire data objects. This is something that ORM tools like LINQ to SQL and LINQ to Entities were supposed to alleviate. Even better is we must now implement a class in 3 files.

Case in point: http://blog.pagedesigners.co.nz/archive/2009/08/06/asp.net-mvc-2-ndash-buddy-classes-for-your-models.aspx

The idea of “Partial Properties” follows the convention for Partial Classes and not Partial Methods. With Partial classes you can have the same class defined in two files. This is extremely helpful with extending generated code. With Partial Methods, one partial class file defines a method and another partial class file may if it choose implement that method. If the method is never implemented then the compiler completely throws away any code that may have referenced that method.

During a PDC talk Anders said that he couldn’t see a reason why we should implement Partial Properties but it’s becoming clear to me that we are starting to have the need.

Here’s the current situation:

  1. You create your models with LINQ to SQL or LINQ to Entities.
  2. You have no control over the auto-generated code so you implement partial classes for each class made in a separate file
  3. You need to annotate the properties in the generated classes so you then have to create a buddy class
  4. You take all the properties of the generated class and type them in and add attributes to them and thus mostly defeating the purpose of #1
//GeneratedClass.Designer.cs (the generated file)
public partial class GeneratedClass
{
	private string _name;
	public string Name
	{
		get{return _name;}
		set{_name = value;}
	}
}

//GeneratedClass.cs (your file)
[MetadataType(typeof(GeneratedClass_Metadata))]
public partial class GeneratedClass
{
	
}

//GeneratedClass.cs or GeneratedClass.Meta.cs (your other file)
public partial class GeneratedClass_Metadata
{
	[Required(ErrorMessage="Name Required")]
	public string Name{get;set;}
}

In the end you end up with 2-3 files and 3 implementations of your class. You also end up with the compiler generating more classes that their only use are for attributes.

With a “Partial Property” generated code could expose all of the public properties like so

//GeneratedClass.Designer.cs (the generated file)
public partial class GeneratedClass
{
	private string _name;
	public partial string Name
	{
		get{return _name;}
		set{_name = value;}
	}
}
//GeneratedClass.cs (your file)
public partial class GeneratedClass
{
	[Required(ErrorMessage="Name Required")]
	public partial string Name;
}

This may all be moot if we can at least get some tooling support for MetaDataType. We could use a Refactor –> Generate Buddy Class. This could auto-gen the metadata class for you so all you have to do is write the attributes in. Maybe even Class Diagram support?

Comments [0] #      C# | Rant  |  kick it on DotNetKicks.com Shout it
by Jeff Klawiter - Monday, September 14, 2009 1:16:03 PM (Central Standard Time, UTC-06:00)

I recently got a new laptop and was trying to get Mozilla Weave set up on it and I could not remember my passphrase. So I went to the site to see if I could recover it and could not. They will reset it and delete all of your data when you do. After that you have to resync from one of your working versions. My problem was that my only current working version was my desktop at work which was shut down due to me being on vacation.

Now today I’m back from vacation and I was wondering if there was some way to retrieve my passhprase. After searching my profile folder I realized, maybe they just use the password system built into FireFox. And sure enough there were two entries for weave.

image

After finding it in your list it just takes hitting “Show Passwords” to retrieve it. If you’re like me and have a Master Password set you will have to enter it again at this point.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Tuesday, July 21, 2009
by Jeff Klawiter - Tuesday, July 21, 2009 1:33:17 PM (Central Standard Time, UTC-06:00)

 

I recently was directed to a nice trick on how to make the Visual Studio Web Development (WebDev.WebServer.exe) server run faster when accessing it in FireFox. I’ve long noticed it seem to lag quite a bit compared to running in IE.

Basically there is something that goes wrong when FireFox tries to connected the server via IPv6. The trick is to just disable it. Unfortunately this disables it for all sites and may cause problems in the future as more places switch over to IPv6. But for now it should be just fine. Changing the setting is quite easy

 

Type in “about:config” in your address bar (get passed the “are you sure you want to do this” nag screen) and search for ipv6. You should find a settings like below

IPv6 About:Config

The setting network.dns.disableIPv6 should be set to True. All it takes is double-clicking on the setting to change it. The effects should be immediate.

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Thursday, July 09, 2009
by Jeff Klawiter - Thursday, July 09, 2009 11:18:02 AM (Central Standard Time, UTC-06:00)

I recently sent the list below to a colleague. I figured I should share it further.

This is a list of user groups I attend fairly regularly.

  1. .NET User Group
  2. Developers Guild 
    • Second Tuesday of the month
    • In depth talks on .NET, programming patterns, project patterns. Talks have been in depth azure, dependency injection/inversion of control
    • http://www.twincitiesdevelopersguild.com/
    • Held at New Horizons Mn in Edina
    • I may be giving a talk here this fall
  3. Languages User Group
    • Second Thursday of the month
    • Held at Magenic in Golden Valley
    • A new language or part of a language every month. Talks on java, lisp, creating your own language. The next one is going to be great, esoteric languages.. the languages that are made for fun
    • http://www.twincitieslanguagesusergroup.com/TCLUG/Default.aspx
  4. Silverlight/WPF Users Group
  5. XNA User Group
  6. Twin Cities Code Camp
    • Twice a year, sometime in spring and fall. Around March/October
    • Large free event that's all about code and is always full of great talks and cutting edge topics. It takes place on a Saturday and ends with tons of prizes, normally an Xbox 360 or two in the top prizes. (done by random name selection of attendees). I've been to everyone so far and I always come away feeling like it was worth it, something I have not been feeling after going to conferences that I paid for.
    • http://www.twincitiescodecamp.com/TCCC/Default.aspx
    • I'm giving a talk this fall on Visual Studio 2010 extensions. I gave a talk in the spring about Visual Studio Tips and Tricks
  7. Twin Cities Web Design:
    • Meetings don’t seem to be on a schedule,
    • Covers general web design things like JavaScript frameworks, CSS tools
    • Meets at Sierra Bravo
    • http://tcwebdesign.org/
  8. MySQL/Drizzle user group
Comments [1] #       |  kick it on DotNetKicks.com Shout it
# Wednesday, July 08, 2009
by Jeff Klawiter - Wednesday, July 08, 2009 1:26:33 PM (Central Standard Time, UTC-06:00)

 

I’ve been so busy working on things at and out of work I’ve fallen behind with updating my blog. I’ve got many things I want to blog about but finding time for putting one together is becoming difficult. Things I’ve been working on lately

  • Visual Studio Extension: I’m working on a VS 2010 extension that is going to be whole worlds of awesome for ASP.NET developers. Most of the work so far has been in getting the backend pieces in place for doing the actual “work” and figuring out where to get the things I need from Visual Studio.
  • ASP.NET MVC: I’ve been working on my first ASP.NET MVC site so I can start using it at work. I was reading the ASP.NET MVC book put out by the scotts and others. The first Chapter of the book covers creating a site from start to finish
  • Preparing for the WPF MCTS exam
  • Wrote a bunch of SQL CLR code
  • Testing Blend 3 and Sketchflow
  • Preparing a talk on VS2010 Extensions for Twin Cities Code Camp 7

 

Upcoming Blog Articles

VS2010 Extensions Take 2
SQL CLR

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Saturday, May 23, 2009
by Jeff Klawiter - Saturday, May 23, 2009 1:43:05 PM (Central Standard Time, UTC-06:00)

I searched far and wide and was unable to find a good quick tutorial on getting  a Visual Studio 2010 extension up and running. There are a few things wrong in the verbiage used that can be quite confusing.

Obtaining the VS 2010 Beta 1 SDK

The first order of business is to get the Visual Studio 2010 Beta 1 SDK, which will add the new templates for creating an extension.

http://www.microsoft.com/downloads/details.aspx?FamilyID=d197feb6-ced5-40d4-949d-a51f02309ee8&displaylang=en

After downloading it and trying to install it you may run across an uncaught exception (like I did)
UnHandled Exception VS 2010 SDK Installer

The error lies in the Bootstrapper (setup.exe). Since the VsSDK_sfx.exe is a self-extracting zip archive you can use your favorite unzipping utility to get the contents. (or you can take the hard way and get the files in your temp folder after it’s been unzipped). I prefer to use WinRar, it makes it extremely easy
Extracting VSSDK To Folder

After this there are only 5 files extracting.
VS SDK Unzipped

We only care about 2 of them. vssdk.cab and vssdk.msi.
Launch the vssdk.msi . This is the main installer for the SDK. It gives little feedback and will auto close when it’s done installing.

Creating Your First VS2010 Extension Project

Launch Visual Studio 2010. In your New Projects dialog under <Your Language>/Extensibility you should now have “VSIX Project”
New VSIX Project

This project defines the basic extension for visual studio. Out of this you will be able to build your VSIX file for installation into Visual Studio.

After giving your new project a name you are given a barebones extension.
New VSIX Project in Solution Explorer

The Visual Studio Extension Manifest

First we’ll start off with an unfamiliar file, the extension.vsixmanifest file. This defines your extension, from title, to license agreement to pictures. While this file is a fairly simple XML file. The VS Team provided a nice interface for editing it.
image 

While most of the form is pretty self explanatory, there are some specific points to make

  • ID: This is your global ID for your extension. After you first publish your extension, it is probably a good idea to not change this.
  • Version: this can be viewed as your installer version. It may not necessarily mirror your dll versions.
  • Supported VS Editions: This is a big one and is also forward thinking. Here you can select from all the different versions of VS2010, including Express, Integrated and Isolated Shell. It can also be expanded later to include the next version of VS.

For more information on the vsixmanifest file, see the documentation http://msdn.microsoft.com/en-us/library/dd393700(VS.100).aspx

The last two pieces are where things get interesting. There hasn’t been much said about how extensible Extensions are in VS2010.

Under References you can create references to other VS2010 extensions that your extension may depend on. Clicking on the Add Reference button gives you this dialog.
image

You’re given the options to select an extension you already have installed, add an external VSIX package or manually define one and a URL to download it from. The URL part is the real beauty. When installing your Extension it has the ability to get the latest and greatest of an extension. You can of course limit it as well to certain version numbers to avoid breaking changes. This creates a lean, mean on demand Extension.

The Content editor doesn’t seem to be fully baked. Here you can add extra content into your vsix package and have it registered upon install.  One example is a registering a Project Template. I’ve borrowed an example from the Card Game Starter Kit .

image

 

The Code

You will find one lone code file in your new project. Here is the CS version

using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.VisualStudio.ExtensibilityHosting;

/// <summary>
/// Empty VSIX Project.
/// </summary>
namespace MyFirstVs2010Extension
{

}

Not much in there. This is where your imagination comes in

Here is where I’ll leave you to fend on your own for now. Navigating the Visual Studio SDK assemblies is another post all in itself.  You’ll find all assemblies you need under the Microsoft.VisualStudio namespace in your add references dialog. It is also possible to tie into Team System via the Microsoft.TeamSystem .

For some full source examples of VS 2010 Extensions, check out the Editor Samples on codeplex
http://editorsamples.codeplex.com/

# Friday, May 15, 2009
by Jeff Klawiter - Friday, May 15, 2009 4:31:39 PM (Central Standard Time, UTC-06:00)

I gave a talk on Microsoft Small Basic last night at the Twin Cities Languages User Group. I promised to post my materials and here they are.

The zip contains the powerpoint presentation file, the example programs and the example extension.

For the guy that asked about mp3s. It looks like they will work as long as the computer it’s running on has an mp3 codec installed (which is very unlikely).

Comments [0] #       |  kick it on DotNetKicks.com Shout it
# Tuesday, April 07, 2009
by Jeff Klawiter - Tuesday, April 07, 2009 11:12:30 AM (Central Standard Time, UTC-06:00)

Just a quick post here for the people that attended my presentation. Thank you for coming to listen to me blabber about snippets and little tips and tricks. I hope you found it of some use.

Comments [0] #       |  kick it on DotNetKicks.com Shout it