Skip to content

Wrench in the Cog

Throwing a wrench into the cogs of a programmer's life

Archive

Tag: ASP.Net
Microsoft Visual Studio LightSwitch

Microsoft Visual Studio LightSwitch

Introduction

First, some shameless “me me me” information that adds some context to this post…

Seasoned software development professionals typically wait for a product to mature before adopting it as part of their developer tool set. Yes, I am a “seasoned” professional but that doesn’t mean that I am old, it just means that I have learned what it takes to effectively achieve my goals and objectives.

Over time I have developed a much greater appreciation for getting a better return on what I do. It would be nice to have an unlimited supply of both time and money so that I could mess around with and learn bleeding edge technologies, but I don’t. So what I do is build on my strengths to be the best at something that I am good at. That something is creating software using Microsoft based technologies. If I had the time to learn and use other technologies I absolutely would, but I don’t have the time.

Not withstanding that, I am not a dinosaur.?I do take the time to invest in my knowledge base and keep up to date on trends. If ?I recognize something new as having the potential of making a impact on the industry I’ll be sure to follow it more closely than others – especially if it makes it easier for me to achieve my own goals and objectives.

That is why I am writing this post.?Microsoft is introducing a simplified version of it’s Visual Studio development tool, and its name is?LightSwitch. LightSwitch has the potential to allow me to create business solutions in a fraction of the time it normally takes me. At the time of this post, LightSwitch is not even out in beta, so I don’t even have the tool yet. However the marketing gurus at Microsoft have planted the seed that has the potential to take on a viral context, good or bad, in the development world.

So, with an expectation that this is going to have an impact on the industry as well as me personally, I am going to try and follow along with the evolution of LightSwitch. This first post is going to explain a little about my understanding of LightSwitch and what it means to me as a developer. The goal of this and subsequent related posts is to 1) provide myself with a documented journal of my LightSwitch journey (because as a “seasoned” professional, my memory isn’t like it used to be), and 2) offer some insight and knowledge to like minded folk who may be on the same journey.

Here goes…

What is LightSwitch?

LightSwitch is a tool that will enable you to quickly create line-of-business (“LOB”) software applications. Using the Microsoft Visual Studio integrated development environment (“IDE”), LightSwitch pulls together a number of software development best practices into wizard like interfaces. The idea is to allow person to create a database driven application without writing a single line of code.

Doesn’t that sound like Access?

It is without doubt that pundits will raise a comparison of LightSwitch to Microsoft Access. ?At first glance, LightSwitch appears to be an evolution of the popular Microsoft Access desktop database application. Diving deeper, however, reveals that LightSwitch is much more. Both tools solve similar problems of rapidly developing database driven solutions. However LightSwitch provides a deeper set of offerings that give an application developer the flexibility to move beyond a constrained technology of Access based solutions.

Access offers a quick and easy to use, template driven database application development tool. LightSwitch does too, however LightSwitch has extension points that move the development of the application beyond a template created solution. Using a wizard like approach, LightSwitch steps you through the creation and definition of the data source(s) used for your project. With data sources in hand, LightSwitch then steps you through the workflow of creating the user interface components of your application. From simple detail data entry forms, to complex hybrid parent child detail forms with grids, LightSwitch presents you with wizard like dialogs that prompt you for your preferences. Using software development design best practices, LightSwitch uses your preferences to present user interface screens that would meet your requirements.

Does this sound similar to what Microsoft Access does? Yes, however LightSwitch moves beyond a critical constraint that Access solutions have – the requirement to have the Microsoft Access application, or its runtime components, already installed on the computer. As well, most of us have experience with the joys of creating or supporting network deployed multiuser Access solutions.

For an early look at the LightSwitch tool, checkout this blog entry titled Quickly Build Data-centric Business Applications with Visual Studio LightSwitch by Jay Schmelzer of the LightSwitch development team.

From an application development perspective, the workflow and process used in both has the same contextual use and feel. However where things are different are in the objectives for the delivery and deployment of the solution being developed. LightSwitch presents a greater breadth of?capabilities?for solution architecture and deployment objectives that Access has limitations on, such as scalability, extendability, and etc.

All That and a Bag of “No Lines of Code” Chips Too!

From a developer perspective, LightSwitch offers you all the goodness of best practice n-tier solution design – without having to write a single line of code.

The Visual Studio LightSwitch team at Microsoft have started a LightSwitch blog at http://blogs.msdn.com/b/lightswitch . There you’ll find the most recent happenings and talk from the development team themselves. It is at this blog where you can find a great article series that deep dives into the guts of a LightSwitch application. The first post in the series titled Anatomy of a LightSwitch Application is discusses the architecture of a LightSwitch application.

Of interest ?is how LightSwitch uses software architectural best practices in the creation of a LightSwitch solution. For example, a typical software solution architecture may be designed to include the following abstracted layers…

Example n-Tier Architecture

Example n-Tier Architecture (courtesy Microsoft)

Much like most of the solutions I create today, the architecture includes abstracted layers for presentation, business logic, and data. Today I build each of these tiers from scratch. I do leverage other tools for either the creation of, or further abstraction of, ?one or more of these layers. But most of the time the tools are used only for the creation of code that I can later modify to meet specific needs. For example, I find myself doing a lot of work in the business logic layer where there may be a lot of specialized business rule validation stuff.

None the less, there is still a lot of code writing. When something changes in either of the layers, something usually has to be updated in the other layers. Mapping user interfaces to data us a good example. That is where most of my time is spent. If something changes in a database, I need to make the necessary edits in the user interface to allow for a new or changed entity in a database.

So what does LightSwitch use for a application architecture? While flexible in the level of abstraction you what to actually deploy, let’s use the following typical 3-tier architecture for discussion…

LightSwitch 3-Tier Application Architecture (courtesy Microsoft)

As mentioned before, when I am working on a solution using Visual Studio, I had some work to do to create each of my layers. With LightSwitch, this is all done automagically. We’ll not quite, but from a developer perspective, it is like magic because we know the effort involved.

Most of my work is in manual creation and maintenance of these layers. LightSwitch should be able to do most of the work out that for me. If so, I can deliver solutions faster and conceptually, make money faster.

Source Code Control Freak.

I used to be a bit of a software development control freak. I liked to have as much access as I possibly could to source code. I’ve since learned that there are smarter people than me out there. If they come up with something that can do what LightSwitch is proposing to do, then I trust them. Notwithstanding, LightSwitch will allow you to still apply code using the Visual Studio IDE. This still gives me the comfort of having access at the code level to apply whatever custom scenarios I want. This makes my inner control freak feel better about using this new tool.

To really demonstrate this, I would need LightSwitch installed so I could create a video. Unfortunately the beta of LightSwitch is not scheduled to be released until August 23rd. So, in lieu of this, I’ll let other people smarter than me, like Jay Shmelzer, Group Program Manager at Microsoft with the Visual Studio team, demonstrate LightSwitch on Channel9

<Click here for Channel9 Video (embedded video code is not working for me)>

What’s in it for You!

I can’t tell you how many times I have downloaded and purchased tools that had promises of increasing my productivity, only to find that I would spend more time (which equals money) learning to use and integrate the tool. It takes way more time to get a return on these tools then many expect. For example, I use Infragistics and Telerik for many of my projects. I absolutely love these tools but they have taken me plenty of time to learn to use and integrate with my solutions – much more so than what I had originally expected. I will still use them, and probably use other tools too. The point is that I should have had a more realistic expectation of what it takes to use tools that promise better productivity. It is not magic – it takes time and effort.

So far, the marketing of LightSwitch seems realistic; no promises of a silver bullet to solve a software development problem, but rather a tool that will help developers get to a point of solution delivery sooner rather than later.

How many of your customers are using Access based, or other constrained technology solutions today? I have a large number of customers who have legacy applications that have matured well beyond their years. Some of these customers can’t even upgrade their enterprise systems because of the constraints of an aged line of business application. Sounds silly, but true, and I bet that you have some customers just like that. Using LightSwitch may make it easier for me to price out a more attractive solution as a replacement because it won’t take as long to build now.

Stay Tuned

Like I said before, I don’t take up to the latest and greatest development technologies until they are proven to be worth my while. LightSwitch seems to be something that may be worth my while so I am going to make an effort to watch how this tool evolves. If you want to tag along for the journey, I’d love to hear your thoughts and share some opinions and conversations with you.

As we move forward I’ll keep posting what I find and how I progress. Might be fun.

In the meantime, here are some resources for you to check out…

Cheers!

Popularity: 13% [?]

Doing this post because I need to make sure I remember how to do this.

In a project I am on I need to determine what T-SQL is being executed by LINQ to SQL statements. I need this because there is a routine that I want to reuse, which uses a T-SQL statement to build and export a DataTable as an Excel file. This is all done via the web, so the output is actually streamed as a response to the users browser.

First, I need to get the T-SQL statement. For example, here is the LINQ to SQL that I normally run to return entities from my data context.

result = From d In _myContext.Drawings _
         Where d.Line.ProjectSpecification.ProjID = projectID _
?? ? ? ? Select d

The above works for most of the processing I need to do. I use the results for some EXTJS goodness via Coolite controls. But what I also want to do is leverage the already implemented LINQ to SQL queries to also send results to an Excel export routine I built.

So, rather than try and recreate the same query by hand crafting some T-SQL variables, I want to get the T-SQL used by the existing LINQ query.

Here is how;

Dim sSQL = _myContext.GetCommand(result).CommandText

<Update> Good thing I learn from my mistakes. While the above code will work when doing a simple query, it doesn’t quite work when adding parameters. In this case, the parameter is a project id. I received errors indicating that “@p0″ was not valid. Looking at the CommandText value, I saw that the SQL generated looked valid, however my project id value was not there. Instead, it was @p0. So, I simply added some logic to replace the parameter reference…

Dim sSQL = Replace(_myContext.GetCommand(result).CommandText, "@p0", projectID )

And presto, I have the T-SQL used by my LINQ query.

Just for giggles, here is how I implemented the export routine via ASP.Net…

First, I created ?a Exports.aspx page. Then I import the necessary namespaces…

Imports System.Collections.Generic
Imports System.Data.Linq
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Xml.Xsl
Imports System.IO

Then I craft some stuff in the page load event…

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Dim sessionSQL = Session("CustomReportBuilderSQL")
  Dim exportDT As DataTable = GetReportDataTable(sessionSQL)
  Dim exportFormat As String = Request.QueryString("exportFormat")
  Select Case exportFormat
    Case "CSV"
      ExportToSpreadsheet(exportDT, "test.csv")
    Case "XML"
      ExportToXML(exportDT, "test.xml")
    End Select
   Me.lblStatus.Text = "Export Complete!"
End Sub

I create a method that accepts my T-SQL variable and returns a DataTable.

Private Shared Function GetReportDataTable(ByVal SessionSQL As String) As DataTable
   Dim myConn As New SqlConnection(AssemblyNamespaceHere.My.MySettings.Default.FWLDConnectionString)
   myConn.Open()
   ' Create Data Adapter
   Dim da As New SqlDataAdapter(SessionSQL, myConn)

   ' Create and fill Dataset
   Dim ds As New DataSet
   da.Fill(ds, "CustomReportBuilderResults")

   ' Get Data Table
    Dim dt As DataTable = ds.Tables(0)
    Return dt
End Function

Then I create the export routines that stream the appropriate response back to the web browser…

Public Shared Sub ExportToSpreadsheet(ByVal table As DataTable, ByVal name As String)

  Dim context As HttpContext = HttpContext.Current
  context.Response.Clear()
  For Each column As DataColumn In table.Columns
    context.Response.Write(column.ColumnName & ",")
  Next
  context.Response.Write(Environment.NewLine)
  For Each row As DataRow In table.Rows
    For i As Integer = 0 To table.Columns.Count - 1
      context.Response.Write(row(i).ToString().Replace(",", String.Empty) & ",")
    Next
    context.Response.Write(Environment.NewLine)
  Next
  context.Response.ContentType = "text/csv"
  context.Response.AppendHeader("Content-Disposition", "attachment; filename=" & name)
  context.Response.End()

End Sub

Public Shared Sub ExportToXML(ByVal table As DataTable, ByVal name As String)

  Dim memStream As New MemoryStream()
  table.WriteXml(memStream)

  Dim bytearray() As Byte
  bytearray = memStream.ToArray
  memStream.Flush()
  memStream.Close()

  Dim context As HttpContext = HttpContext.Current

  context.Response.Clear()
  context.Response.AddHeader("Content-Length", bytearray.Length.ToString())
  context.Response.Write(bytearray)
  context.Response.Write(Environment.NewLine)
  context.Response.ContentType = "application/xml"
  context.Response.AppendHeader("Content-Disposition", "attachment; filename=" & name)
  context.Response.End()

End Sub

With all that, all that I have to do is 1) save the T-SQL statement as a session variable, and 2) pass the type of export I want as a variable in a query string to my Exports.aspx page.

Hope this helps.

Popularity: 5% [?]