Contents tagged with ASP.NET MVC

  • SkyLog: My first end-to-end example on programming by composition

    I have completed my first end-to-end example as I am exploring the idea of programming by composition. SkyLog is an example on querying IIS Log files like what LogParser do, except:

    1. It is built on LINQ and thus can use the entire .net framework, not just the built-in functions of LogParser.
    2. It can use Parallel LINQ and thus uses multiple cores effectively.
    3. Any part of a query can be refactored into a function and thus reused.
    4. We just need to write the queries once and the queries can be used against one log file, a whole directory of log files, several servers, and in any storage, such as Azure Blog Storage.

    The running example are available at http://skylinq.azurewebsites.net/skylog. The example runs the query against some log files stored in Azure Blog Storage.

    image

    The queries in the example are from http://blogs.msdn.com/b/carlosag/archive/2010/03/25/analyze-your-iis-log-files-favorite-log-parser-queries.aspx.

    The queries look even simpler than what you normally write against LogParser or SQL Server:

    image

    That is because part of the queries were refactored into two reusable functions below. We cannot reuse part of query with LogParser. With SQL Server, we can create reusable units with View. With LINQ, we can reuse any part of the LINQ query.

    image

    Note that I used the memory efficient version of GroupBy written by me previously. The equivalent code using the GroupBy in LINQ is commented out.

    To run these reports, we just need records from the log files as IEnumerable<string>. To get them from a directory, the code would look like:

    image

    To get records from Windows Azure Blob Storage, the could would look like:

    image

    Lastly, we need to convert IEnumberable<string> to strongly-typed wrapper, IEnumerable<W3SVCLogRecord>, to be consumed by the reports:

    image

    I touched upon the idea of strongly-typed wrapper previously. The purpose of strongly-typed wrapper is to allow intelligence while minimize the garbage collection. The wrapper provides access to underlying data, but does not convert the data to a data-transfer-object.

    The front-end is a simple ASP.NET MVC page. Reports are exposed through ASP.NET Web API using the CSV formatter that I built previously. The visualization was built using D3.js. The code is so simple that we could think each line of the code as Javascript based widgets. If we desire more sophisticated UI, we could compose the UI with a different widget. We could even introduce a client-side template engine such as Mustache.js.

    image

    Even with simple example, there are enough benefits in it so that I probably would never need to use LogParser again. The example is fully built on LINQ to IEnumerable. I have not used any cool feature from IQueryable and Rx yet. As usually, the latest code is in http://skylinq.codeplex.com. Stay tuned for more fun stuff.

  • Gave 3 presentations at SoCal Code Camp (UCSD) today

    I gave 3 presentations at SoCal Code Camp today at University of California, San Diego.

    The first two presentations are co-presented with our summer intern Christopher Chen. Clicks the links below to download the power point.

    Creating an Orchard website on Azure in 60 minutes

    Customizing Orchard Websites without limit

    My source code can be found on github: https://github.com/aspcompiler/sdcodecamp

    Lastly, several people asked whether we can create mailing list to keep in touch. I created a Linkedin group called SoCal Orchard SIG. Welcome to join!

    My last talk was:

    Machine learning made simple

  • Running an intern program

    This year I am running an unpaid internship program for high school students. I work for a small company. We have ideas for a few side projects but never have time to do them. So we experiment by making them intern projects. In return, we give these interns guidance to learn, personal attentions, and opportunities with real-world projects.

    A few years ago, I blogged about the idea of teaching kids to write application with no more than 6 hours of training. This time, I was able to reduce the instruction time to 4 hours and immediately put them into real work projects. When they encounter problems, I combine directions, pointer to various materials on w3school, Udacity, Codecademy and UTube, as well as encouraging them to  search for solutions with search engines. Now entering the third week, I am more than encouraged and feeling accomplished. Our the most senior intern, Christopher Chen, is a recent high school graduate and is heading to UC Berkeley to study computer science after the summer. He previously only had one year of Java experience through the AP computer science course but had no web development experience. Only 12 days into his internship, he has already gain advanced css skills with deeper understanding than more than half of the “senior” developers that I have ever worked with. I put him on a project to migrate an existing website to the Orchard content management system (CMS) with which I am new as well. We were able to teach each other and quickly gain advanced Orchard skills such as creating custom theme and modules. I felt very much a relationship similar to the those between professors and graduate students. On the other hand, I quite expect that I will lose him the next summer to companies like Google, Facebook or Microsoft.

    As a side note, Christopher and I will do a two part Orchard presentations together at the next SoCal code camp at UC San Diego July 27-28. The first part, “creating an Orchard website on Azure in 60 minutes”, is an introductory lecture and we will discuss how to create a website using Orchard without writing code. The 2nd part, “customizing Orchard websites without limit”, is an advanced lecture and we will discuss custom theme and module development with WebMatrix and Visual Studio.

  • Fun with Orchard, Webmatrix, Git and Azure

    Why Orchard?

    Our company wants to convert an old html site to a content management system. We considered between Wordpress and Orchard and picked Orchard. This post strongly influenced us. It is ASP.NET MVC vs php. We are a .net shop. We thought it would be easier to do custom development with Orchard.

    Why Webmatrix?

    There are a few reason we used Webmatrix:

    1. Webmatrix works with Orchard very well. Many Orchard training materials use Webmatrix.
    2. Webmatrix is free. We have interns here working on Orchard. We do not have to consume a Visual Studio license.
    3. Webmatrix has an excellent story working with both Git and Azure.

    Why Git?

    We would like to have a version control system. Git is a free and open source distributed version control system. There are several free Git hosts, such as GitHub, Codeplex, and BitBucket. So we picked Git.

    Why Azure?

    We would like to have website that our entire team can see. Azure web site is an excellent option for us. It is very easy to host Orchard with an Azure website, either with Sql Compact Edition or with Azure SQL Database. Azure also integrates with Git very well.

    So how do they work together?

    Although it is possible to edit a Azure hosted web site directly with Webmatrix, we hosted out source code in Git because we need a source control system.

    It is very easy to work with Git from Webmatrix. One can use git with an existing site or open a site directly from git.

    The Sql Server migration solution in Webmatrix is amongst the easiest way to migrate a Sql CE database to Azure SQL Database.

    It is also fairly easy to setup an Azure website to pull source code from git directly and build the source code. Each time when we push a changeset to git, Azure is notified and it will automatically pull and build the website. For Orchard, the “built” is actually not more than an xcopy. We just need to embed a .deployment file in our source code. See David Haden’s post for more details.

  • Getting started with ASP.NET Web API quickly

    Web API is a feature of ASP.NET MVC 4. It is an API for writing REST web services. One might ask why we need another API. After all, we already have WCF Rest Service a few years ago. It is also fairly easy to return JSON from an ASP.NET MVC controller using JsonResult. For a long answer, it is best read ScottGu;s blog or the WCF site. The short answer is that Microsoft want a way to make it extremely easy to create REST services and to provide lots of features. ASP.NET MVC is the best place. Currently, the .Net REST/Json story is fragmented and there are several Json serializers in .Net. ASP.NET Web API represents the future, consolidated API for this feature.

    It is fairly easy to get started with ASP.NET Web API. For those who likes to watch video, Jon Galloway’s 6 short videos provides a very quick start and it takes only 24 minutes to watch them all. For those who like read and type, the ASP.NET site has 7 short chapters that can be read in an hour or two. Many bloggers are blogging the Web API. I would recommend Stephen Walter’s blog for a quick introduction. Finally, I strongly recommend looking into some of the samples.

  • Experimenting with ASP.NET 4.5 beta

    The next version of ASP.NET is 4.5. The official information is at http://www.asp.net/vnext.

    There are two ways to experiment with ASP.NET 4.5 beta. The first is to install Visual Studio 11 beta. The second way is to install ASP.NET MVC 4 beta on Visual Studio 2010 to experiment with a subset of the features. Visual Studio 11 beta contains .Net Framework 4.5 beta. .Net Framework 4.5 is a highly compatible in-place update of .Net Framework 4.0. If you uninstall .Net Framework 4.5 beta, you will have to reinstall .Net Framework 4.0. For this reason, I would suggest you to experiment with Visual Studio 11 beta on an experimental machine, perhaps on a Windows 8 consumer preview VHD.

    On the other hand, ASP.NET MVC 4 beta consists of a set of new assemblies that can run side-by-side with MVC 3. It also has a new set of templates for MVC 4 projects. The only thing that affects MVC 3 work is that it changes the intelligence for web pages (.cshtml and .vbhtml) to support web pages 2 features. You need to build your web application before you edit any .cshtml or .vbhtml pages to overcome a bug.

    The following features can be experimented with ASP.NET MVC 4 beta on VS 2010:

    Not part of ASP.NET MVC 4 beta, there is an exciting open source framework from the ASP.NET team called SignalR that be experimented in VS 2010. SignalR allows developing long polling Comet type of applications using .NET. The ASP.NET team has also created an open source chat application called JabbR as a case study.

    In future blogs, I will blog my experiment with each of these exciting new areas.

  • Teaching high school kids ASP.NET programming

    During the 2011 Microsoft MVP Global Summit, I have been talking to people about teaching kids ASP.NET programming. I want to work with volunteer organizations to provide kids volunteer opportunities while learning technical skills that can be applied elsewhere. The goal is to teach motivated kids enough skill to be productive with no more than 6 hours of instruction. Based on my prior teaching experience of college extension courses and involvement with high school math and science competitions, I think this is quite doable with classic ASP but a challenge with ASP.NET. I don’t want to use ASP because it does not provide a good path into the future. After some considerations, I think this is possible with ASP.NET and here are my thoughts:

    · Create a framework within ASP.NET for kids programming.

    · Use existing editor. No extra compiler and intelligence work needed.

    · Using a subset of C# like a scripting language. Teaches data type, expression, statements, if/for/while/switch blocks and functions. Use existing classes but no class creation and OOP.

    · Linear rendering model. No complicated life cycle.

    · Bare-metal html with some MVC style helpers for widget creation; ASP.NET control is optional. I want to teach kids to understand something and avoid black boxes as much as possible.

    · Use SQL for CRUD with a helper class. Again, I want to teach understanding rather than black boxes.

    · Provide a template to encourage clean separation of concern.

    · Provide a conversion utility to convert the code that uses template to ASP.NET MVC. This will allow kids with AP Computer Science knowledge to step up to ASP.NET MVC.

    Let me know if you have thoughts or can help.

  • System.ComponentModel.DataAnnotation talk at LA Code Camp

    Today, I gave a talk at LA code camp on using Validation Attributes in the System.ComponentModel.DataAnnoation namespace in the context of both ASP.NET MVC and other applications.

    Since .net 3.5 does not have a Validator class, I have supplied a Validator class in the attached code. In addition, I have also presented a data structure that can be constructed dynamically to stored the validation attributes for classes and properties, and a dynamic validator that consume the data structure.

    Validation.Zip