AnkhSVN 2.0 Released - How’s it look?

11 07 2008

When I first started using Subversion full time for all of my personal projects, I stuck with the VisualSVN server and AnkhSVN as a Visual Studio client.  Both were free, easy to install, and easy to use.

However, after a few weeks, the AnkhSVN client could almost be called “annoying.”  It trampled over the existing SCC plugins for SourceSafe (for work) and made a mess out of several of my project uploads.  I ended up going back to using TortioiseSVN and doing everything through Explorer.

When AnkhSVN 2.0 was released, I figured I’d give it another shot.

The site claims quite a bit—including several unique additions:

  • Pending changes window; subversion status and commands available in one place
  • Full support for Visual Studio 2005 and 2008; AnkhSVN is now a SCC package instead of just an addin
  • Better log viewer
  • Merge support
  • Property editor
  • AnkhSVN now supports most project types previously unsupported via the SCC api
  • All solution explorer actions (rename, copy&paste, drag&drop) keep subversion history now
  • Enhanced build process and setup
  • Automatic check for updates
  • And last but certainly not least end user documentation

All of those look great—especially the SCC package and changes window.  But how does it compare once installed?

After installation and starting up VS2008, everything looks normal.

Brief Look

Pending Changes Window

The new pending changes window is FANTASTIC—much improved over the old 1.x versions.  I did run into a snafu when trying to resize the window where the scrollbars didn’t update on the screen; however, I’m not sure if it’s a VSS or AnkhSVN issue.

SCC Package

Under Options > Source Control, AnkhSVN shows up just like it should.

What does boggle me is that all of the Subversion commands and menus are available no matter what—even when the VSS SCC is enabled.  It still has the stink of VSS and SVN trying to step on one another (“pick me! control your project with me! no, I’m better! pick me!”).

Log/History Viewer

I really like the new history viewer.  It’s clean and easy to read; however, if you change the options at the top—there doesn’t appear to be a way to “change it back” and see the history again, close the view and review.

Annoyances

  • Opening a project from Subversion (File > Subversion > Open from Subversion) will open a project just fine, copy it down, but never opens it.  You have to go back and open the solution after it’s created the local structure.  Not huge, but annoying.
  • When viewing history; you cannot view the history of a single file (that I’ve found) in the Repository Explorer. 

I’m still planning to give it a whirl for the next couple of weeks and see what happens.  Hopefully over a couple weeks I’ll have more time to code—it’s been a busy July so far!





Catching Async Postbacks from Server Controls

11 07 2008

In my current project, I created a custom server control that presented the user with questions and answers—they select the answer and move on.

However, a requirement was that the user could push a button and “select all”.  Unfortunately, DropDownList objects are not as easy to select as, say, a CheckBox.  In addition, all controls are dynamically generated—I knew the IDs, but couldn’t specify the Async trigger in the MasterPage’s Script Manager.

I could, however, find the name of the control and do a bit of magic with it.

Here’s how:

First, in your server control, check to see if a ScriptManager control is even present.  For this example, I’m leaving out the try/catches—so we’ll assume that it’s there.

private ScriptManager _scriptManager;

Then, in OnInit (or OnLoad, depending on your controls):

_scriptManager = ScriptManager.GetCurrent(Page);

GetCurrent fetches the current AJAX ScriptManager control from the context you specify—in this case, the current Page object.

Now we’re ready to consume the ScriptManager.  First, we ensure that it’s not null AND, most importantly, that the line of code is being hit during an Async Postback.  Regular postbacks, for the point of updating an UpdatePanel don’t matter to us.

if (_scriptManager != null && _scriptManager.IsInAsyncPostBack)

{

var fromWhere =

_scriptManager.AsyncPostBackSourceElementID;

The ScriptManager’s AsyncPostBackSourceElementID (seriously, can we get longer field names?) provides just that, a hashed heirarchy of the control that caused the Async Postback.  For this to work, it’s important to remember that you must either have ChildrenAsTriggers set to True or have explicitly registered your dynamic control with the ScriptManager.

The hashed output looks like the standard ASP.NET control heirarchy:

ctl00_pbph_tc_ctl01_selectallbutton_123

In this case, when I dynamically created my button, I named it “selectallbutton_{id}” to make it easy to find AND store the information I need in this Select All step.

if (fromWhere.Contains(selectallbutton_”))

       {

var id =

fromWhere

.Substring(fromWhere.IndexOf(‘_’) + 1)

.ConvertTo<int>();

       MyMethod(id);

}

The full code block looks like:

_scriptManager = ScriptManager.GetCurrent(Page);

if (_scriptManager != null && _scriptManager.IsInAsyncPostBack)

{

var fromWhere =

_scriptManager.AsyncPostBackSourceElementID;

 

       if (fromWhere.Contains(selectallbutton_”))

       {

var id =

fromWhere

.Substring(fromWhere.IndexOf(‘_’) + 1)

.ConvertTo<int>();

       MyMethod(id);

}

}

Now my dynamically created button’s Click event is caught during the Async postback (inside an UpdatePanel), validated, and my custom method is executed—in this event, taking the “id” that was part of the Button’s ID and modifying other controls on the page accordingly.





Wrapping TabPanel Tabs With A Simple CSS Change

10 07 2008

The last few weeks have been filled with taking an old ASP legacy application and updating it to ASP.NET.  Fun stuff and not to challenging.

However, a “feature” of the AJAX Control Toolkit’s TabContainer finally hit a nerve.  In the past, I’ve ignored the fact that I couldn’t “wrap” the tabs or set how many rows of tabs to create.  I chalked it up to an annoyance and designed applications with this in mind.

After hunting through the Control Toolkit’s source code, the problem is simple.  There’s a line in the CSS explicitly telling it not to wrap.

Well, recompiling the toolkit can get annoying and hurts mobility of your applications—it’s no fun to bundle “custom” copies for a simple styling change.

.ajax__tab_header

{

    white-space: normal !important;

}

That will override the nowrap that is built into the Toolkit’s CSS.

Hopefully, someday, this will be a boolean property on the TabContainer control.





Ready for ReSharper 4.0.1 Nightly Builds?

8 07 2008

I swear that they don’t sleep at JetBrains.  Sleep is good!  :)

Fresh off of ReSharper 4.0’s great EAP and full release, they’re hard at work for ReSharper 4.0.1.  According to Confluence, there’s already been almost 220 bug fixes (as per build 907). 

As usual, caution should be used when evaluating an EAP product (e.g. not on your one-and-only production workstation), but it looks like another great opportunity to kick in some feedback for ReSharper.

You can find the nightly builds here.





ReSharper 4.0 - Cool Features

13 06 2008

There are quite a few new features to ReSharper 4.0 that are great, but it’s the little things that really can impress and speed up usage.  A few of my favorites are below.

camelHumps. :)

ReSharper now supports Go To > and statement completion according to camel casing.  If you’re like me, you tend to write normal sentences in camel case—it’s just habit.

Using the camel casing, it picks up the variable I just created, not the class.

Lambda support.

I’ve become addicted to the simplicity of lambdas—they express intent and you can read them like sentences.  ReSharper 4 does an excellent job of digging into the anonymous type and pulling up IntelliSense information.

ResponseChoicesController()

.SelectOne(x =>

x.IsDefault &&

x.ResponseTypeId == responseTypeId)

From the ResponseChoicesController, select one that meets the requirements that IsDefault is true and ResponseTypeId is equal to the specified responseTypeId.  To me, and I’m sure I’m odd, that is easier to read than the “written” LINQ code.

Convert Static to Extension.

This is FANTASTIC for revamping existing code to take full advantage of the .NET 3.5 Framework.  I’ve been working on a project the past few weeks to migrate a .NET 2.0 project using Enterprise Library 3 up to 3.5 and LINQ-to-SQL and this addition has been fantastic to move data and business logic into controllers and the LINQ data context.

 





Deep Copy Cloning of LINQ Entity Objects - Not Deep Enough

5 06 2008

Yesterday, I wrote about a great IL solution to deep copying LINQ objects.  Unfortunately, it’s not quite deep enough. :(

The problem lies in the entity sets related to LINQ objects.  For example, in what I’m working on, the Report object contains Marks (grades) based on a foreign key relationship.  The previously discussed IL cloning method copies the records, but because it doesn’t generate new primary keys for those, it throws:

“An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext.  This is not supported.”

I’ve tried zeroing out the PK fields just as I did with the report object iself—no dice.  Removing the Marks (by setting them equal to either null or new EntitySet<Mark>()) and no dice.

The only way I think I can get around it would be to break the FK relationship, clone the report (which would return a new Id), and then copy each of the Marks objects separately with some sort of loop (similar to below):

foreach (var mark in

new MarksController().SelectAll(oldReport.Id))

{

var newMark = new Mark {

              IndicatorId = mark.IndicatorId,

ReportId = newReport.Id,

             ResponseChoiceId = mark.ResponseChoiceId

});

}

That defeats the purpose though… ugh.

Back to the drawing board!

Tags: , , , ,




ReSharper 4.0 is now RC!

5 06 2008

The first RC for ReSharper 4.0 is out—pick it up! Nice!





Deep Copy Cloning of LINQ Entity Objects

4 06 2008

Unfortunately, there’s no real slick way (built into LINQ) to clone LINQ entity objects. 

My need was simple:  Take a record, duplicate it, change a few select values, and then dump it back into the data source to generate a new primary key.

But I couldn’t find a good way to get a deep copy using ICloneable and sure as heck didn’t want to do it manually. 

After a bit of searching, I came across a great blog posting that discussed using direct IL to make deep copies of objects.  The blog post looked promising.  As the author explains, “[t]he basic thing that it does is, create a DynamicMethod, get the ILGenerator, emit code in the method, compile it to a delegate, and execute the delegate.”  Sounds simple enough.

NOTE: Check out the blog post (here) for the full source code; the modifications I made are mostly domain specific—the implementation works great as it is.

I added the method into the GenericController that I use to implement LINQ and the results were brillant!

// Clone the entity based on the original report.

var newReport = this.Clone(SelectOne(originalReportId));

           

// Remove the ID to make it generate a new primary key.

newReport.Id = 0;

           

//  Change the necessary information.

newReport.EnteredBy = enteredBy;

newReport.Quarter = quarter;

 

// Insert the imported report into the system and save changes.

Insert(newReport, true);

 

// Now that the imported report has a primary key, return it.

return newReport;

Because .Clone is a virtual method of my Controller’s base class (public virtual T Clone<T>(T entity)), it applies to any type that I happen to pass into it.  In the code example above, this Import method is in the ReportsController and SelectOne returns a Report object, so Clone generates a clone based on the constructor and fields of that type.  Implementation with any other LINQ controller works just the same—excellent for reuse.

Since an integer primary key, Id in the code above, cannot be null, setting it to zero (0) will force the SQL processor to generate a new primary key when the record is entered into the database—which is exactly what we want.

Very pleased with the implementation of this and how slick (and quickly) it works.

Tags: , , , ,




Using the CLR Profiler with VS2008 Web Projects

13 05 2008

Download CLR Profiler for .NET 2.0 Framework.

The CLR profiler is great; it’s sweet to be able to see where memory is allocated and how well objects are disposed of (and whether or not I missed something that GC just isn’t catching). 

The form is pretty easy to use, but there’s a bit of a trick for VS 2008 web application profiling when using the built-in Web Development Server.

NOTE:  This isn’t anything like the ANTS Profiler (which I wish I had a license for, but don’t).  ANTS will tell you where code slowdowns are and more, this simply returns back histographs of object usage, memory, and the stack/heap.  Still very useful none the less.

Here’s how to get started:

1. Download the CLR profiler (see the link at the beginning of this article or click here).

2. Extract the profiler into a directory (it defaults to C:\CLRProfiler); it will extract two directory structures (binaries, source) and a readme document.

3. To start using the application immediately, browse into the Binaries directory and execute the CLRProfiler. 

Use the x86 version. I haven’t been able to get the x64 version to work correctly (even though I’m on a x64 machine) when profiling .NET web applications ala the built-in web development server.

4. Under File > Set Parameters, modify the “Command Line” to reflect the parameters required to start the built-in web development server.  After the parameters have been set, click OK.

Usually, you have a Port parameter and a Path parameter.  Here’s an example:

/port:1234 /path:“J:\Projects\Work\Current\ERC\web\”

5. Click ‘Start Application’.  A browse window will open.  Visual Studio 2008’s web development server is located in the Common Files directory.

%CommonProgramFiles%
    \Microsoft Shared\DevServer\9.0
or
%CommonProgramFiles(x86)
    \Microsoft Shared\DevServer\9.0

6. After selecting the WebDev.WebServer.Exe application file, your server will kick off with the parameters you set.

Now you’re ready to open up a web browser, begin browsing around, and evaluate your application.  When finished, click the ‘Kill Application’ button on the Profiler or simply close the WebServer application.





Visual Studio 2008 and .NET 3.5 SP1 Beta

13 05 2008

The blogs are abuzz this morning after the first beta release of the VS2008 and .NET 3.5 SP1.   Download it here.

In my opinion, this isn’t a service pack—this is a new version!

There are quite a few bug fixes (what you normally associate with a service pack), but also a huge list of new additions and improvements.

From Somasegar:

Traditionally our service packs address a range of issues found both through customer and partner feedback as well as our own internal testing.  While this service pack holds true to that theme and delivers updates for these types of issues, it also builds on the tremendous value that Visual Studio 2008 and .NET Framework 3.5 deliver today and enables an improved developer experience by adding a number of additional components that cover a range of highly requested customer features. For example, the service pack is the first release for Visual Studio 2008 that delivers full support for SQL Server 2008 and the ADO.NET Entity Framework.

I’ve posted a few links at the end of the post to the more extensive sources right now, take a look and get ready for the plunge.

So, what am I most excited about?

  • ADO.NET Entity Framework – I’m hoping that the “real” release motivates Oracle to develop provides for the entity framework and my dream of LINQ-esque connections to Oracle will be realized.
  • ASP.NET Routing Engine – As the MVC framework gets closer to a production reality, it’s very motivating to see the underpinnings already in place.
  • VS2008 Performance Improvements – Anything has to be an improvement. :(
  • JavaScript Code Formatting – Sweet, now if I can only get JavaScript intellisense to work. :(
  • LINQ Debug Support – Very nice, love seeing the generated SQL right there at debug time.

There are also lots of updates to WCF and WPF.  Hopefully this summer I’ll have more time to use these .NET 3.0 technologies and maybe be a bit more excited. ;)

Visual Studio 2008 GUI/Tools

The Web Developer Tools team has released a comprehensive list of designer bug fixes, IIS templates and modules, formatting changes, intellisense upgrades, and more on their blog.

MVC and URL Routing

Phil Haack details the effects of the URL routing changes on the MVC Preview releases as well as how it affects the upcoming Preview 3.

Everything

ScottGu, as always does an excellent job tying everything up together—designer, framework, and tooling.

Now, if ReSharper 4.0 would EVER get to RTW before we’re ready to VS2009, it’d be super!