Friday, August 20, 2010

Visual Studio find and replace with regular expressions totally sucks.

The syntax for regular expressions in Visual studio's find and replace option are incredibly convoluted.

I wanted to replace all instances of width in a style sheet with something that was variable based.

so width:75px; would become width:@(width=75)px;

This syntax is using the new Razor view engine and the result is we set a local variable and render it to the page in a nice terse expression. Combined with:

left:@(leftStart+width)px;

we now have the beginning of a nice sliced row of images. Where all the things on a particular row would incrementally build, and then on the next row, I can reset leftStart.

This was the syntax for finding all lines of an html document and capturing the width:
width\:{[0-9]+}

And the syntax for the replacement?
width\:\@(width=\1)

I understand that c# syntax uses a ton of the same conflicting symbols, but... could you guys make something like rexexpal so that we can iteratively solve for the expressions we need?

Wednesday, August 18, 2010

WPF DataGrid Row-level styling

It took me a very long time to figure out how to do this. The following code takes a WPF (and probably silverlight) datagrid and changes the row foreground color based on a single property in that row.

<DataGrid AutoGenerateColumns="True"  Name="dgProjects" >
    <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=HasProblems}" Value="True">
                            <Setter Property="Foreground" Value="Red"/>
                        DataTrigger>
                    Style.Triggers>
                   
                Style>
            DataGrid.RowStyle>
DataGrid>

Monday, August 16, 2010

Vs Add-in solution explorer context menus with a little MEF

My first MEF success. I wrote a visual studio add-in context menu for solution explorer where you can right click a project (or solution file for all projects) so that it:



  • reads the project file checking several problem areas 
    • hint paths
    • copy local
    • pre/post build events
    • target framework version
  • then makes a backup copy
  • cleans those local customizations
  • invokes msbuild to make sure it still builds
  • brings up the Source control commit dialog
  • restores your local customizations that we don't want in the source.
I used MEF so that the UI was not hard coded into the add-in. It  was amazingly simple. While I was developing a solution someone was nice enough to post on stackoverflow telling me you can't hydrate static properties. Which I did.

Thursday, July 15, 2010

Bookmarklet: Change the page title

So on some sites, when you get a new ajax message (think facebook, gmail, or maybe meebo) the new message indicator never goes away in the page title on your tabs. Also some titles aren't nearly as clear on your tabs as to what they are, so you can use this to set the title on your tabs to the domain of the page.


So this is what I've come up with as a nice bookmarklet to clear the title without having to reload the page.

javascript:void(function(){document.title=document.domain;}())

or if you like you can set it to document.location

Tuesday, June 29, 2010

Recent POC experiments

What's a POC? - POC

I don't learn details very well, I learn why or why not. So I keep a base of code to refer back to the details and how to repeat something that I haven't done enough times to memorize. I also try to keep a thorough history of sites which helped me reach the conclusion in case I forget some of the why, or miss a few hows on things I didn't need at the time.

Progress:

  • Asp.net Profile provider
    • I've successfully configured and used the default functionality here in asp.net Mvc2
      • I would love to figure out how to enable some items to be for even anonymous visitors and the rest for authenticated users only.
  • VSTO - outlook add in
    • Outlook 2007 for whatever reason does not allow you to add rules involving distribution groups
      • I wrote an add-on (far from release quality) that gets around that and has a WPF window with a WPF data-grid to sort mail involving distribution groups into proper folders.
  • WPF - this leads me of course to the fact I've now done my first WPF window
  • VS2010 Add-in
    • The process of unloading the project, then editing the project file to look at what hint path a reference has was a pain. In my position I need to check for the presence of bad paths. I wrote an add-in that will open the project file without unloading it, and report back if there are any of these bad paths present.
  • VS2010 - Guidance Package migrated from vs2008 to a .vsix extension.
    • We have a guidance package that just barely qualifies as such to help developers create new components for our incredibly huge (443 projects, not counting testing projects) application. It generates 4 projects for every component (common, control(s), service, test).
      • I converted it to a .vsix and made many improvements such as adding a default form instead of just the existing user control for components that have a full form pop or dialog.
      • I added class file template projects (both the .cs and the designer.cs) for adding another user control or dialog
  • MsBuild tasks- We do not have a solution file for our 443 project application! We build the projects individually then assemble them together. Our build process involves CC.net, 2 huge build scripts, no custom logger, a .net app to generate/build locally,  and a lot of spaghetti Msbuild code.
    • I wrote a build task that takes the app's logic and my own Linq to XML to generate a proper build order on the fly by reading in the ITaskItem[] for all the project files, and comparing the list of assembly names against project references (intra-component references in our project depend on all dependencies going to 1 of 2 special folders instead of direct project references)
    • The next step was generating a project file that has the items in the right order already, with additional convenient message output.
    • I've been thinking of trying to generate a solution file or making the projects reference each other for MSBuild auto-dependency-detection and build ordering, but I've not hit enough dead-ends the way I'm currently going.
  • Entity Framework - I've made 2 poor attempts or perhaps good attempts that failed to use EF4.0 in the same way I'm used to with Linq to SQL.