Brad Abrams on RIA Services with EF

clock November 19, 2009 06:26 by author jamesstill

Abrams basically walked through a typical RIA Services app and most of it is familiar to anyone who has studied the RIA Services documentation and walkthrough. However there were several new things specific to VS2010 and the new bits.

RIA Services is now built on top of WCF. Yep, it's a first-class citizen on the stack right next to Workflow Services and Data Services. Brad Abrams said his goal with RIA was to force n-tier dev and to get people into the 21st century. :) That's why (and I'm translating here, he didn't say this) RIA is a prescriptive framework following the 80/20 rule rather than something totally open ended like the vanilla ASP.NET web project template.

The project template is now out of the box in VS2010/.NET 4.0. Also, there's a design view for XAML now. In fact, all the SL controls are on the toolbox and you don't have to edit the XAML at all. My first impulse is one of repulsion -- however, I realize that this is a great time saver for doing a first cut on layout and wiring up controls. You can always go into the XAML and tweak it later.

with a DataGrid and Pager control RIA does not go grab all nn number of rows from the database and bind it to the grid like in early ASP.NET. It takes advantage of LINQ and gets only the rows for the current page. That data is cached locally so if user clicks back arrow to go back to page 1 it's there.

No more XAML exploring. VS2010 has a Document Outline toolbar that shows a visual representation
of the nodes and their hierarchy.

No more rebuilding the RIA Service in order to push the gs file down to the SL client. Changes are reflected right away.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Microsoft PDC09 Keynote Address

clock November 17, 2009 05:09 by author jamesstill

Microsoft announced the new bits at PDC keynote today. The theme? Cloud, cloud, and more cloud. The Azure platform goes into production on Jan 1. In beta through the next several months are new cloud platform tools: AppFabric (previously code named "Dublin") and Endpoint. From what I understand AppFabric provides a unified hosting environment for WCF and Workflow, SQL Azure database caching, and can be configured right in IIS. Endpoint seems to be a discovery service for web services all over the world. You can search it and get all the information you need to consume that data in your application. It probably uses the REST protocol. Microsoft showed a pretty cool demo with the NASA web service that involved showing 3D landscapes of pictures taken by the Mars Rover. You could do a serious mashup in a .NET app with Endpoint.

The CIO of the U.S. government gave a little pep talk about cloud computing. He said the Obama Administration is committed to the cloud and is actively migrating to it now. Honestly, will Multnomah County really spend $3.5 million to build a new DC? Next year, Azure will offer totally configurable VMs in any flavor you want. We could run all of the county DC virtualized on Azure. New apps would plug right in to the cloud environment and legacy stuff could be put on configurable virtual servers in WinOS 2003, 2008, whatever.

Oh and Visual Studio 2010 with .NET Framework 4.0 will be released sometime in Q1 or Q2. The beta is out now and there was some cool stuff in it. You can drag a code pane over to your other monitor, debugging is beefed up, and unit tests write themselves at run time. Other stuff but it went pretty fast.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Visual Studio 2008: Unable to create the Web site

clock July 4, 2009 08:04 by author jamesstill

After a brief foray into Windows 7 Beta just to check it out I took my laptop back to Vista 64-bit, wiping everything out in the process to get a clean slate. Many moons ago, when first installing Vista, it took me about 3 minutes before I disabled the UAC. This time I'm trying hard not to disable it. (You know, best practices about not developing as a sysadmin and all of that.) Now I'm running into security issues that I'm forced to address rather than bypass. In the end this is a good thing. Here's the latest: In VS2008 I right-clicked on the solution and chose Add > New Web Site. Then I picked the WCF Service template and changed the location to HTTP. This tells VS to create a new virtual application beneath the Default Web Site (in my case c:\inetpub\wwwroot) but I got the error: "Unable to creat the Web site 'http://localhost/Foo' because I was not running Visual Studio in an administrator context. The solution is to run VS as an administrator (you can create a shortcut of devenv.exe and under the Advanced tab toggle "Run as administrator") in order to add the web site. Then save and close and go back in under your logged in credentials.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


STORM! ORM Mapper Beta Launch

clock March 28, 2008 02:59 by author jamesstill

I'm happy to announce that SquareWidget in partnership with the good folks at FlishHorse have launched the Strongly-Typed Object Relational Mapper (STORM) Beta. Download it now and take it for a spin. What is STORM? It's an add-in into Visual Studio 2005. What does it do? It's an OR mapper. It's a code generator. And there are no third-party black box assemblies or other wackiness. We've used Subsonic, NHibernate, and many other ORM tools and we came to the conclusion that it's no fun writing and maintaining a bunch of XML scripts. And we also didn't like creating custom templates like in CodeSmith. We're lazy. So we made a tool that's trivial to use.

Here's how easy it would be to STORM an ASP.NET web application:

  1. fire up VS and create a new web app
  2. add a Web.config file to the project
  3. right-click anywhere in the code window or on the solution root and choose Storm To > Configure Storm
  4. Fill in the four required fields, notably the connection string to your SQL Server database and click Save
  5. right-click and choose Storm All! and it will do its thing. 

 

Let me know what you think!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Fetching Connection Strings

clock December 27, 2007 04:49 by author jamesstill

Let's assume you wish to store your database connection string in the <connectionStrings> configuration section of Web.config. This is the best practice in my opinion because you can (and should) encrypt the section in production. Now you have two basic options:

(1) fetch the connection string at the UI level and pass it back to the data layer.

(2) remove the dependency altogether and let the data layer fetch it from Web.config

I've done it both ways. With option (1) you have a simple call to the ConfigurationManager:

string connectionString = ConfigurationManager.ConnectionStrings["FooBar"].ConnectionString;

 

Most people do this and it's quick and simple. If you don't want the coupling or you don't feel like parameter passing or you want your unit test assembly to be able to get a connection string without needing to reflect over the UI assembly, then option (2) involves creating a helper method that any assembly in your solution can call. Here's one that opens a config file from an explicit virtual root location and returns a string value that matches the passed in key:

public static string GetConnectionString(string connectionName) {
    string connectionString = string.Empty;
    // reading from explicit IIS virtual root alias name rather than "~"
    Configuration c = WebConfigurationManager.OpenWebConfiguration(@"\Widget");
    if (c != null) {
        ConnectionStringsSection section = c.GetSection("connectionStrings") as ConnectionStringsSection;
        foreach (ConnectionStringSettings css in section.ConnectionStrings) {
            if (css.Name.ToUpper().CompareTo(connectionName.ToUpper()) == 0) {
                connectionString = css.ConnectionString;
                break;
            }
        }
    }
    return connectionString;
} 

 

Then it's pretty simple to fetch a connection string from your DAL layer: 

string connectionString = GetConnectionString("FooBar");
SqlConnection cn = new SqlConnection(connectionString);

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Enumerate Application Settings

clock December 13, 2007 06:09 by author jamesstill

Here's my own solution to a problem that seems to plague a lot of .NET developers out there. The problem is how best to enumerate application settings stored in a section of an ASP.NET 2.0 app.config file at runtime. Let's suppose you have a settings file called Color.settings with the following key-value pairs:

BLU - Blue
BRO - Brown
GRN - Green
HAZ - Hazel

 

The designer stores those settings in app.config. It also creates the getters for each key and decorates them with the value:

[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Blue")]
public string BLU {
    get {
        return ((string)(this["BLU"]));
    }
}

 

In this way the Color class is strongly-typed and, given a code, makes it easy to fetch its value through the settings property:

string color = Color.Default.BLU;

 

But what if you don't know the key at design time? Fortunately, the singleton instance exposed by the Color.settings class implements ApplicationSettingsBase Properties. Reference System.Configuration and simply enumerate the SettingsPropertyCollection to find the value:

string key = "BLU";
string value = string.Empty;
foreach (SettingsProperty sp in Color.Default.Properties) {
    if (sp.Name.Equals(key)) {
        value = sp.DefaultValue.ToString();
        break;
    }
}

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Custom SiteMapProvider

clock December 13, 2007 05:55 by author jamesstill

Usually custom SiteMap providers are written because we're pulling our nodes from a source other than xml. Jeff Prosise's provider written for SQL Server is a classic example. But I had a case recently in which the out of the box XmlSiteMapProvider was just fine; my problem was that I needed to do some peculiar security trimming on the nodes. No problem, just add roles to the nodes and enable security trimming in Web.config for the provider right? Not exactly. The requirements were that the system had to ship with the ability to turn a major piece of functionality on or off in production. Let's call the functionality "ViewWidgets" and let's say there's an app setting in Web.config called "ViewWidgets" with value="false". That means, the web site should suppress the Widgets unless and until it is flipped to true. Then Widgets should be available to the end user. One way of implementing this would have been to set a generic role or override Web.config in a subfolder. But I wanted the webmaster to be able to flip the flag to true or false in Web.config where he was more comfortable working. The solution turns out to be pretty easy. Just derive a custom provider from XmlSiteMapProvider and override the Initialize method to trim the node based on the app setting:

[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class CustomSiteMapProvider : XmlSiteMapProvider {
 
    const string VIEW_WIDGET_KEY = "ViewWidgets";
 
    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes) {
        lock (this) {
            base.Initialize(name, attributes);
            bool viewWidget = Convert.ToBoolean(AppSettingHelper.GetAppSetting(VIEW_WIDGET_KEY));
            if (!viewWidget) {
                foreach (SiteMapNode childNode in base.RootNode.ChildNodes) {
                    if (childNode.ResourceKey.ToUpper().Equals("WIDGET")) {
                        base.RemoveNode(childNode);
                        break;
                    }
                }
            }
        }
    }
}

 

In this case I've encapsulated calls to AppSettings in an AppSettingHelper class. And of course you have to register your custom provider in the <system.web> section of Web.config. And that's about it.

Currently rated 4.0 by 3 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


About

SquareWidget LLC is an Oregon-based software development company that specializes in handcrafted .NET software solutions.

Search

Archive

Categories


Sign in