An outlet for my obsession with technology
ASP.NET MVC
Spark with VB.NET Project Demo #2
Jun 3rd
Outline:
- Status of using spark in a VB.NET project
- Bugs from Spark Demo #1
- Strongly Typed Views
Toolset 2009
Jun 1st
Most of my work so far this year has been with one client. This client was a Java shop for quite some time and is pretty green to Microsoft. Also, they don’t seem to ever have had real success with building enterprise class systems. That’s not to say that they haven’t wrote very large and very complex systems. They have done it all with either the bare minimum in tooling or a incorrect implementation of the tooling.
In fact; one of their primary reasons for moving to .NET was to perform a tooling reset. They decided it was too hard to use technology like OR/M, DI, Messaging, and MVC. The figured that (straight from the horse mouth) “Webforms, ADO.NET and SQL” is all we need. I don’t even understand that statement…anyway…back to the tools
Of course I believe this is all based on the improper use of technology. As they say “Any tool can become a weapon if held properly”. unfortunately for me and future developers with this client. The technology that was so frond upon is the tool that….um…well…never mind.
All I am trying to say is that I’ve been pretty tied into some specific Microsoft technology most of the year. Most of the tools on this list had to pass through a standards committee meeting and some are still under the radar…Ok on with the tools!
Visual Studio 2008 (2005, Visual Basic, Dreamweaver)
Thankfully most of my work is new development so I spend a bulk of my time in Visual Studio 2008. Unfortunately is not TFS so my task tracking is handled outside….if at all. Also there are no productivity plug-ins available, I even asked if I could install my own…so no ReShaper or Visual SVN
ASP.NET 3.5 SP1 VB.NET
With most of my work new development I do get to keep up with the .NET version. I am REALLY looking forward to .NET 4 (its just 4 right?…I heard someone from MS flies out and you get your hand slapped if you call it 4.0)
ASP.NET MVC
Yeah! what more can I say.
ASP.NET MVC Futures
This one has not passed through the development standards committee yet but since I also sit on the committee I don’t think it will be much of a fight. Really I only use it for Html.RenderAction
WCF
The tooling is rough but the technology is solid. I am really happy with WCF and hope it infects my clients….but I feel that will stick with asmx for a few more YEARS….
EF
I am just not ready to fight for Nhibernate just yet…I have a new project starting around the 20th, as with every new project I try to push through one new technology. I think this one will finally get a OR/M.
I do like where MS is going with EF and look forward to EF 4, isn’t that what its called in .NET 4.0?, but as much as I work with EF 1 ….man its rough. I’ve often considered using Linq2Sql and building on top ala Rob Conery’s MVC Storefront.
AutoMapper
A convention-based object-object mapper.
AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up source to destination values. Currently, AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.
iTextSharp
iTextSharp is a port of the iText, a free Java-Pdf library.
Unity
The Unity Application Block (Unity) is a lightweight extensible dependency injection container with support for constructor, property, and method call injection.
MSTest (unit testing)
Still using the default unit testing framework. Right now I am really focused on getting more developers to write tests…anything…please. Really; there are no tests. Functional testing by non-technical people is NOT testing. Crap…I feel another post coming on…
LINQPad
I am a big fan of LINQ!
LINQPad lets you interactively query SQL databases in a modern query language: LINQ. Kiss goodbye to SQL Management Studio!
LINQPad supports everything in C# 3.0 and Framework 3.5:
- LINQ to Objects
- LINQ to SQL
- Entity Framework
- LINQ to XML
Spark View Engine
Spark is a view engine for Asp.Net Mvc and Castle Project MonoRail frameworks. The idea is to allow the html to dominate the flow and the code to fit seamlessly.
It should be noted that I am pretty new to spark and I am testing it in some personal projects to see if its worth bringing into a client. BUT the client has a strict VB only stance…so my testing will not only be standard spark stuff but doing so in a VB.NET MVC project….check out the videos.
jQuery
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
I am a JavaScript nut…primarrly jQuery and Dojo…really happy to see it in MVC because it was denied by my largest client until it started coming out of File->New Project…..Thanks Microsoft
jQuery Facebox w/ homegrown iframe support
Facebox is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote pages. It’s simple to use and easy on the eyes.
Bringing in modals was a lot of work; demos, meetings, documents, etc….we went with thickbox….I am using facebox with support for iframe content.
CruiseControl.NET
CruiseControl.NET is an Automated Continuous Integration server, implemented using the Microsoft .NET Framework. Again; under the radar…I have a ccnet server running on my desktop…
FxCop
FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements.
SVN
Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).
BUT…its 1.3.2….and it has pretty limited support for merges…..ugh…I think you get the picture by now….
WebSVN
WebSVN offers a view onto your subversion repositories that’s been designed to reflect the Subversion methodology. You can view the log of any file or directory and see a list of all the files changed, added or deleted in any given revision. You can also view the differences between two versions of a file so as to see exactly what was changed in a particular revision.
WebSVN offers the following features:
- Easy to use interface
- Customisable templating system
- Colourisation of file listings
- Blame view
- Log message searching
- RSS feed support
- and more…
And best of all….something about radar…
Feedreader
I use feedreader to monitor the RSS feeds from WebSVN. This way I know what is going on with my teams projects and other teams projects which my programs are dependant
SourceMonitor
SourceMonitor lets you see inside your software source code to find out how much code you have and to identify the relative complexity of your modules. For example, you can use SourceMonitor to identify the code that is most likely to contain defects and thus warrants formal review
- Collects metrics in a fast, single pass through source files.
- Measures metrics for source code written in C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML.
- Includes method and function level metrics for C++, C, C#, VB.NET, Java, and Delphi.
- Saves metrics in checkpoints for comparison during software development projects.
- Displays and prints metrics in tables and charts.
- Operates within a standard Windows GUI or inside your scripts using XML command files.
- Exports metrics to XML or CSV (comma-separated-value) files for further processing with other tools.
Conclusion
I am one stealthy developer…you would think that since I am on the committee that defines developer standards most of these items would be known, understood, or used…..or maybe you think I’m not demoing, teaching, preaching, or begging…well if you think that you don’t know me
I am shouting, arguing, and fighting…..ugh…
ASP.NET MVC New Project Replace Webforms with Spark
May 29th
Note: This demo is in VB.NET and based on my use of spark on a real project; I can say that this will be the first of a few Spark MVC for VB.NET developers. Spark uses C# in the views; I think its going to be a good way, for me at least, to keep up to speed with both syntax.
It seems that bootstrapping Spark in the global.asa (code in general) is not working for namespaces. I’ll have another post early next week about all my next steps but for now just know you need to add your namespaces to a _global.spark
This demo is the process of getting running with spark and replacing the webforms view engine in a new asp.net mvc project. From soup to nuts as they would say…I guess.
Links:
Spark Download:
http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27109
Spark Master Layout (Master Pages)
http://sparkviewengine.com/documentation/master-layouts
Project Source:
ASP.NET MVC new project with Spark view engine (coming soon)
A completely biased comparison of ASP.NET MVC and Webforms
May 15th
I have to admit I am total bias towards MVC but hear me out. I have yet to work in an organization that implements an OOP or even MVP when using WebForms. It’s all been directly bound controls to data readers/sets/tables. No object model, no business object layer, page_load is used and abused, etc. It can’t be stated enough that MVC will not save a project from the bullshit code that is forms over data crap but at least there is hope in the form of a tiny amount of guidance from Microsoft. </rant>
Introduction
In the .NET world the MVC pattern is relatively new but it has been the staple development architecture for Java and Ruby for over a decade. Most of the current the debate between what technology is “better” is argued from a developer’s point of view. While the technical underpinnings of a technology can often translate to the projects success; I feel that both WebForms and MVC are mature enough that most projects will do fine with either.
The technical debate does nothing for those who are trying to persuade their organization to consider ASP.NET MVC. What I am trying to present here is a list of decision points an organization can use when deciding on MVC vs. WebForms.
ASP.NET WebForms
Through the abstraction of HTML, CSS, and JavaScript; ASP.NET WebForms attempts to recreate the experience of developing a desktop application. The entire HTTP protocol is successfully abstracted away and developers are present with a faux statefulness that mimics desktop applications. Development teams are able to use a WYSIWIG style of development.
ASP.NET MVC
Out of the box ASP.NET MVC forces developers to understand HTML, CSS, and JavaScript. There is little to no abstraction which can be a double edged sword. On one hand your development team has access to the raw power of the markup & languages that make up the web. On the other; if your development team is not experienced with HTML, CSS, and JavaScript there might be a learning curve.
Decision Matrix
|
ASP WebForms |
ASP.NET MVC |
|
Your project is small and your team is not experienced with MVC |
Your project is large (experience with MVC not required) |
|
Your project requires many specific 3rd party vendor components |
Your project is not bound to 3rd party vendor components (The UI can still be very rich) |
|
Your project team is not comfortable with open-source libraries (expecially jQuery) |
Your project team is comfortable with open-source libraries (especially jQuery) |
|
Your customers requirements, possibly by contract, will not change during development |
Your customers requirements may change during development |
|
Your project will never be "extended" or have a feature "added" |
Your project maybe be "extended" or have features "added" |
|
Your project is mission critical and deserves the comfort provided by unit testing |
|
|
Your project is limited in maintenance hours |
|
|
Your project cares about HTML markup compliance |
Conclusion
I think that most projects will be able to succeed using either technology. The question is simply how much pain will you cause your developers? Will you stick with web forms and create an endless maintenance cycle? We know how much developers love maintenance programming. Or will you force them out of their comfort zone and make them learn something new for the sake of your project?
Html.RenderAction & object reference not set to an instance of an object
Apr 7th
Make sure you download the MVC futures from CODEPLEX not Microsoft.com
http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471
ASP.NET MVC SiteMap
Dec 3rd
Note: This code does not support caching or security trimming. It is simply a way to build something that compares to the .NET TreeView control using the MVC pattern.
Recently one of my clients had the "perfect storm" of requirements, restrictions, deadlines and policies that lead to the need to develop a MVC TreeView(ish) control.
Requirements:
- Database storage – Site administrations needed a simple interface into editing and I was not about to write something to update XML files.
- NOT use the SQL Service Broker for easy SQL caching support – Security concerns….I assume…I was never told why NOT but just NO.
- Support the MVC pattern – new projects where being developed using ASP.NET MVC
- Easy to implement and maintain
Design:
- With MS shipping jQuery it would be nice to use a jQuery plugin to render the tree
- Leverage existing technology – Exising project are using the SQL SiteMap Provider, hence, accompanying tables and stored procedures.
- Extend the ASP.NET MVC HtmlHelpers class
Note: I assume your application is currently setup to use the SQL SiteMap Provider…or at least the Table for the provider exists.
Step 1: Create a Stored Procedure that uses a CTE
Most of the heavy lifting happens here. As you can see, when viewing the full-size image, the results are ordered by "thePath". That makes parsing the results into a ordered list very easy.
1: WITH siteMapCTE(SYSID, ID, Parent,title,description,url,roles, level, thePath) AS (
2: SELECT SYSID, ID, Parent,title,description,url,roles, 1 as level, CONVERT(VARBINARY(MAX), ID) AS thePath
3: FROM aspnet_SiteMap WHERE Parent is NULL
4: UNION ALL
5: SELECT e.SYSID, e.ID, e.Parent,e.title,e.description,e.url,e.roles, c.level + 1, c.thePath + CONVERT(VARBINARY(MAX), e.ID) AS thePath
6: FROM aspnet_SiteMap e
7: INNER JOIN siteMapCTE c
8: ON e.Parent = c.ID
9: )
10: SELECT * FROM siteMapCTE ORDER BY thePath, title
Step 2: Create new HtmlHelper method
First off..Stephen Walther’s first ASP.NET MVC article was on writing html helpers using Extension Methods. I have his sample in a current project so it was a great place to drop in the new method.
<Extension()> _
Public Function ListBasedSiteMap(ByVal HtmlHelper As HtmlHelper, ByVal items As Object) As String
If items Is Nothing Then
Throw New ArgumentNullException("items")
End If
Dim builder As New StringBuilder()
Dim mPreviousLevel As Integer
Dim mUrl As String = String.Empty
builder.Append("<div class=""demo"" id=""testMap""><ul>")
For Each row As DataRow In items.Rows
If row.Item("url").ToString.Contains("~/") = True Then
mUrl = "/" & System.Configuration.ConfigurationManager.AppSettings("application.name") & "" & row.Item("url").ToString.Split("~/")(1)
Else
mUrl = row.Item("url").ToString
End If
If row.Item("level") = 1 Then
builder.AppendLine("<li id=""" & row.Item("id") & """ class=""open""><a href=""" & mUrl & """>" & row.Item("title") & "</a>")
ElseIf mPreviousLevel < row.Item("level") Then
'child
builder.AppendLine("<ul>")
builder.AppendLine("<li id=""" & row.Item("id") & """><a href=""" & mUrl & """>" & row.Item("title") & "</a>")
ElseIf mPreviousLevel = row.Item("level") Then
builder.AppendLine("<li id=""" & row.Item("id") & """><a href=""" & mUrl & """>" & row.Item("title") & "</a>")
ElseIf mPreviousLevel > row.Item("level") Then
'close level
builder.AppendLine("</li>")
builder.AppendLine("</ul>")
builder.AppendLine("<li id=""" & row.Item("id") & """><a href=""" & mUrl & """>" & row.Item("title") & "</a>")
Else
'parent ?
End If
added.Add(row.Item("id"))
mPreviousLevel = row.Item("level")
Next
builder.AppendLine("</ul></div>")
Return builder.ToString()
End Function
Oh…I pass the results in as a data table….you can change that to be whatever your passing….
Step 3: Get results to your view
How ever you like, get the data to the view. Again, I am using my own DAL and pass the results in as a Data Table
Step 4: Put the unordered list on the view
1: <%=Html.ListBasedSiteMap(ViewData("siteMap"))%>
Don’t forget to import the HtmlHelpers namespace…in your paper (I presume its a master page or the web.config)
1: <%@ Import Namespace="yourNameSpace.HtmlHelpers" %>
Break
Ok, at this point you should have an non-styled unordered list of SiteMap nodes that looks something like. All we have to do now is style, wire and go. As a matter of fact, the sitemap should work too!…it just looks like crap.
Step E: jsTree!
I’m not going to walk you through the process of wiring up your site to use jsTree but that is the next step. download, and put the files into your project, add the script and link tags for the javascript and css…modify the CSS as needed…
So maybe I did walk you through it…anyway.
Step VI: onload event….um…
I’m using dojo for this project with the exception of the TreeView so I leveraged dojo’s OOP and onload….this should work but its not tested.
1: var first = null;
2: $(function() {
3: tree1 = new tree_component();
4: tree1.init(jQuery("#testMap"), {
5: cookies: {
6: prefix: "sitemap",
7: opts: { path: '/' }
8: },
9: callback: {
10: onchange: function(NODE) {
11: if (!first) {
12: first = true;
13: } else { document.location.href = jQuery(NODE).children("a:eq(0)").attr("href"); }
14: }
15: }
16: });
17: });
Finish
Here is what I ended up with…
Again, I know…no caching…no security trimming but it works and you can allow management of the nodes from a web interface (of course you have to code that) … If anyone adds trimming please let me know…I don’t have a need now but I’d like to keep this all together in one place.
Top 10 ASP.NET MVC Links
Oct 12th
I started off to make a short list of the ASP.NET MVC sites I use often but it quickly turned into a top 10 list. That is until I realized I only visit 9 ASP.NET MVC related sites on a regular basis. So, here is my Top 9..That is until someone suggests another site worthy of my reading.
ASP.NET
http://www.asp.net/mvc/default.aspx?wwwaspnetrdirset=1
Blogs
http://www.hanselman.com/blog/
http://weblogs.asp.net/scottgu/
http://weblogs.asp.net/stephenwalther/
http://bradwilson.typepad.com/
CodePlex
ASP.NET on CodePlex
The ASP.NET MVC releases are posted under the ASP.NET umbrella project.
http://www.codeplex.com/aspnet
http://www.codeplex.com/MVCContrib/Wiki/View.aspx?title=Documentation&referringTitle=Home
Html.DropDownList and dojo.byId
Sep 16th
Ok, so maybe I’m doing it wrong..(that’s what she said)…and it would not be the first time.
dojo.byId(‘name’).value fails when using the Html Helper “Html.DropDownList” from ASP.NET MVC PR5 as seen below
1: <%'=Html.DropDownList("", "search_form_filter", ViewData())%>
Er..um…could it just be that dojo.byId does not return the display text when value is not explicitly defined in the dropdown…yeah..that’s probably it.
Html.RenderUserControl and ASP.NET MVC Preview 5
Sep 2nd
Html.RenderUserControl has been superceded by Html.RenderPartial
1: <% Html.RenderPartial("~/Views/Shared/MyControl.ascx") %>
2: <% Html.RenderPartial("MyControl") %>
You can specify the full path to your user control as in the first example. Or, if your user control is in the ~/Views/Shared folder, you can use the second example.
Notice that Html.RenderPartial does not produce a return..aka…the = is removed.
ASP.NET MVC and YOU
Sep 2nd
One of my largest clients is a forward thinker in terms of web application development. As such it’s a great place to introduce ASP.NET MVC. Surprisingly, it was received, by the Java Gurus with strong MVC roots, with a lukewarm reception. But I digress..ScottGu recently posted a small tidbit about ASP.NET MVC that I think needs a little more highlighting:
Important: If you don’t like the MVC model or don’t find it natural to your style of development, you definitely don’t have to use it. It is a totally optional offering – and does not replace the existing WebForms model. Both WebForms and MVC will be fully supported and enhanced going forward (the next release of ASP.NET WebForms will add richer URL routing features, better HTML markup/client-side ID/CSS support, and more). So if after reading the above post you think "hmm – that doesn’t feel natural to me", then both don’t worry, and don’t feel like you should or need to use it (you don’t).
— ScottGu