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.

Wednesday, May 19, 2010

Call chain that could be null at any step. Enter IfNotNull or Maybe.

It could be called IfNotNull or Maybe, currently i'm going with Maybe.

Project available at http://Maybe.codeplex.com

So we've all had to write code like

if(one==null) return null;
if(one.two==null) return null;
if(one.two.three==null) return null;
return one.two.three.four;

Now there's code to do it all in one fell swoop.

return one.Maybe(o=>o.two.three.four);

It also handles primitives not just classes:

return one.MaybeNullable(o=>o.two.three, t=>t.four);

Source

Inspired by:

http://blogs.msdn.com/alexj/archive/2008/03/03/maybe-there-is-more.aspx

and

http://blogs.developpeur.org/miiitch/archive/2008/02/29/vendredi-c-est-expression-tree.aspx

Some reading on the subject:

http://abdullin.com/journal/2009/10/6/zen-development-practices-c-maybe-monad.html

http://stackoverflow.com/questions/1196031/evil-use-of-maybe-monad-and-extension-methods-in-c

Note to self: Answer this once posted: http://stackoverflow.com/questions/854591/how-to-check-for-nulls-in-a-deep-lambda-expression/854619#854619

Tuesday, April 20, 2010

Javascript tooling

So I've been working with Javascript for a week or two now. I still loathe it. However I would not probably touch it at all were it not for


  • JQuery - Feels like a .net framework for javascript
  • JQueryUi - Ah a (ightweight custom control library
  • JQuerify - Inject jQuery onto pages that don't have it for making bookmarklets.
I've used Visual Studio 2010 Ultimate primarily for the script writing because of the code/syntax coloring and  built in (poor but still built in) {} () [] matching capabilities. Those aren't specific to Ultimate, or 2010 for all I know. 

For debugging scripts I've used
  • FireBug
  • Google Chrome's built-in developer tool bar (alot)
  • JsBin - online javascript collaborative debugger (seemed slightly buggy, but still worth it)
  • Javascript Lint - nice online static analyzer for syntax and other problems.
On top of those as base scripts to help with life
  • qTip - Nice jQuery plugin  tool tip script for web pages
  • Google's lovely api hosting content delivery network for jQuery, and jQueryUi.
    • Sidenote: apparently resizable, and who knows what else required I also reference "http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css"

Saturday, April 10, 2010

ClickOnce Bookmarklets...maybe click twice

I have a set of bookmarklets that go to my website, and actually use the current version of the bookmarklet. So the bookmarklet on the bar is just a pointer to a script out on my site. So I can update the bookmarklets to my heart's content without the end user having to do anything at all. Unless I move where the bookmarklets live on my site. So if your bookmarklet living space can be more permanent here's the cross domain bookmarklet injection code:

var e=document.createElement('script');

e.setAttribute(
'language', 'javascript');

e.setAttribute(
'token', '@testToken');

e.setAttribute(
'src', 'http://imaginarydevelopment.com/Sfc/Scripts/ClientScripts/AjaxXmlHttp.js');

document.body.appendChild(e);
void(0);

Notice the token code. That makes it so that in the child script I can pull in which user it is, and make posts to that user's account directly.

Friday, April 2, 2010

Macro Resources

So for any that live primarily never paying any attention to the fact that Visual Studio supports macros like me.  I thought in the spirit of my last post it would help to have some resources around other useful macros.

Additionally apparently macros can be auto triggered by 'Environment' Events such as solution open or close
Here's a nice list from the Stackoverflow community
  • Awesome Visual Studio Macros
    • Selected Text browser macros (whatever you have highlighted/selected in your code file)
      • google it
      • spellcheck the word
      • MSDN search
    • InsertNewGuidLiteral
    • AutoClose the start page when you open a solution
    • AutoOpen the start page when you close a solution
    • Automatic Build timer with every build to the output window
    • Dual monitor / Single monitor macro for switching back and forth on the fly
    • Outlining: Collapse to definitions but expand regions