Wednesday, April 26, 2006

Using Atlas on existing site

I have been playing with Atlas for ASP.NET April CTP for the last couple of days.

I quite like it so far, It is really easy to use if you are starting a new site, but not quite so easy if you are converting an existing site.

You have to do the following:

  • Install the Atlas CTP from Here

  • Open your existing solution and copy "Microsoft.Web.Atlas.dll" to the Bin directory of your solution.
    The default location for the dll is "C:\Program Files\Microsoft ASP.NET\Atlas\v2.0.50727\Atlas"

  • Add the following code to your web.config:

    Copy these elements as children of the <configuration> element:


      <configSections>
    <sectionGroup name="microsoft.web"
    type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
    <section name="converters"
    type="Microsoft.Web.Configuration.ConvertersSection"/>
    </sectionGroup>
    </configSections>

    <microsoft.web>
    <converters>
    <add
    type="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>
    <add
    type="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>
    <add
    type="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>
    </converters>
    </microsoft.web>

    Copy (or integrate) these elements as children of the <system.web> element:


        <pages>
    <controls>
    <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
    <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
    </controls>
    </pages>

    <!-- ASMX is mapped to a new handler so that proxy javascripts can also be served. -->
    <httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
    </httpHandlers>
    <httpModules>
    <add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>
    </httpModules>


  • Start Programming!



In my case I just added an <atlas:UpdatePanel> around a couple of edit-inplace DataGrids.
Update Panels are quite good, they also allow updating based on triggers. For example you may want to update based on a selection on a DropDownList so you would:

<atlas:UpdatePanel runat="server" ID="Update1" mode="Conditional">
<ContentTemplate>
.....
</ContentTemplate>
<Triggers>
<atlas:ControlValueTrigger ControlID="DropDownList1" PropertyName="SelectedValue" />
</Triggers>
</atlas:UpdatePanel>




The only server control I would like (and I understand the security reasons) would be an atlas:FileUpload control.
As Scott Guthrie puts it "File-Uploads are a somewhat weird element in HTML -- since they are by-design non-scriptable (for security reasons, to avoid someone writing client-side script to maliciously upload a file from a browser).
As such, you'll need to be a little careful with how you use them with Atlas (or other Ajax frameworks)."

However, it would be cool if they had an atlas enabled FileUpload control, that you could tie in with an atlas:UpdateProgress control to give user feedback that the file is still updating. You can't do this at the moment, as the UpdateProgress fires before the FileUpload code, so any value in the FileUpload is cleared by a PostBack before you have a chance to do anything with it.

Any comments on how to get around this welcome!

Wednesday, April 19, 2006

Why you shouldn't believe everything you read on the Internet

This is a great reason to not believe everything you read on the Internet. I don't know anything much Java, but I do know a thing or two about .NET and most of the items on that list are plain wrong.

Here are a few of the more defamatory ones (with my comments):

"An Abundance of Experienced practioners. Nobody seems to know how to write .NET programs well and that's giving .NET a bad name"

I know a fair few .NET developers - C#, VB, Delphi and even COBOL. I can assure you they know what they're doing.

"Industrial Strength Collection Classes - The .Net libraries look like they were designed by high-school students, First year CompSci? students at best."

The writer obviously hasn't heard of Anders Hejlsberg who would be in my all time top 10 Software Architects.

"More Languages - The JVM is more "common" than the CLR."

This to me seems to be two seperate points, but I'll take the "More Languages" argument. Here's a list of .NET languages off the top of my head: C++, C#, VB, COBOL, Object Pascal (Delphi), Python, J#

"Sane Coding Conventions - I don't know what's worse Hungarian notation or .NET coding conventions."

Surely sanity is in the eye of the beholder. I like the .NET conventions, plus Intellisense and sensible names in the class library mean I know the the difference between a namespace, class or method name.

"EmbeddedDevices - Java inside small packages."

If you don't count PocketPC's or SmartPhones as Embedded Devices.

"Comprehensive RDMS Driver Support - Can you find a ADO.NET driver for an open source database?"

MySQL
PostgreSql
Firebird

"Leads In Software Process Best Practices. Most best practices in software development are done in Java shops."

This is clearly wrong. I myself and most of the .NET developers I know use some or all of Patterns, n-tier design, Unit Testing. I don't think SoftDev best practice is limited to Java.

"Affordable Industrial Grade IDEs"

SharpDevelop, WebMatrix, Visual Studio Express are all free. Borland Developer Studio professional is about $300US.

I could go on but I won't. There is a challenge out by the original author to make an anti-list of why .NET is better than Java. I would love to but don't know enough about Java.
Besides, I would rather spend my time programming in .NET - its much more rewarding...

Wednesday, April 12, 2006

Gradient Fills

Gradient fills. Sure they look great, but they are everywhere these days. It seems bad taste to have a single color on your web site. If it isn't a dark to light or light to dark color blend then it's, like, so last week man.

Geez even Ford Motor Company have been at it. The solid blue oval has been replaced with a gradient blue oval.

As fads go, I don't think it's a bad one, but I think in a few years, with the benefit of hindsight, gradient fill will be as cringe worthy as paisley ties and 70's flares.

You heard it here first!

Monday, April 10, 2006

SQL Server 2005 Merge Replication

I have spent the last hour or so gettng Merge Replication working on SQL Server 2005 - connecting to a PocketPC. It was working fine but I moved the SQL Server on to a different box and couldn't exactly remember how to set it back up.

Here are the steps I used to get it going.

1. Install SQL Server 2005
2. Restore the database into the new SQL Server Instance
3. Create a new login for the database
4. Install SQL Server Mobile 2005 tools – this installs the server tools for creating IIS virtual directory etc
5. Register the dll sqlcesa30.dll in the directory you have created for the IIS virtual dir – the wizard doesn’t do this
6. When you create the Publication – make sure it is for Merge Replication and the Snapshot is stored in the same folder as the folder created above. Make sure the user rights have rights to the SQL Agent and the database you want to merge
7. Create a snapshot – Open the replication monitor to see if has worked. If you are backing up a database from another server - you may have to revalidate the snapshot as well.
8. Yay - If has worked – if not the see troubleshooting below


C# Code to Sync Data (appologies for the formatting - I cant seem to work out how to get the tabs to stay once the code has posted)

public static void SyncData()
{
SqlCeReplication repl = null;

try
{
   // Set the Replication object.
   repl = new SqlCeReplication();

   repl.InternetUrl = "http://[computer-name]/[iisAlias]/sqlcesa30.dll";
   repl.Publisher = "[publisher name]";
   repl.PublisherDatabase = "[database name]";
   repl.PublisherLogin = "[login]";
   repl.PublisherPassword = "[password]";
   repl.Publication = "[pub name];
   repl.SubscriberConnectionString = "Data Source='\\[dbname].sdf'";
   repl.Subscriber = "[sub name]";

   // Create the Local SSCE Database subscription.
   if (!System.IO.File.Exists(@"\[dbname].sdf"))
   {
      repl.AddSubscription(AddOption.CreateDatabase);
   }
   // Synchronize to the instance of SQL Server 2005 to populate the Subscription.
   repl.Synchronize();
   MessageBox.Show("Data is Syncronized");
}

catch (SqlCeException ex)
{
// Use your own error handling routine to show error information.
MessageBox.Show(ex.Message);
}

finally
{
// Dispose of the Replication object.
repl.Dispose();
}
}

*** Change the [xxxxxx] to whatever the names are for you ****

Use the above code in your PDA app to synchronize to the publication. Change the InternetURL to be whatever the IIS name is (usually computer name) and the name of the virtual dir alias you made in step 4.

Login and Password are self explanatory. Subscriber conn str is where the database will be synced to.

TROUBLE SHOOTING

There are a number of errors that could occur.

Open the location of the IIS virtual dir in your web browser – it should say “Sql Server Agent 3.0”. If it doesn’t then the dll hasn’t been registered properly. Try re registering using regsvr32.

If there is a reconciling error, make sure all the usernames and passwords are correct and the snapshot is going into the folder that the IIS alias points too. Look at the Replication Monitor for error information. Usually you can work through the errors from there.

Monday, April 03, 2006

If I ruled the world

I am working for "the man" at the moment. I was a contractor for 3 years before that. It was hard fitting into someone else's way of doing things for a start, but I have found a routine that works.

The biggest problem for me is that I am the "IT Guy" at work. Everyone else does something else, so of course if there is any computer or technical issue I get the call. It doesn't really bother me, but I am hired as a developer first and foremost, and when you are working something through in your head, being interrupted by some insignificant problem in Excel can be annoying.

The other problem is I am lumped in with the admin staff in an open plan office. I have always worked in my own office throughout my professional programming career. I think it is good to have interaction with others, but it is also important to have a quiet place to go. Most people realise that a shut door means do not disturb. You just can't do that in an open plan office.

Anyway, this got me thinking, what makes a good office environment? One day I want to run my own company with employees (minions) to do my bidding. Here are the golden rules that would apply for dev's in my company:



  • Developers to get their own office, or place they can call their own if they need a quiet moment.

  • Working on Friday afternoons will be optional - I mean how much gets done on a Friday arvo anyway?

  • Once a week dev team meetings

  • All dev leads to talk to their devs on a one to one basis every day to discuss issues and other ideas. The quieter members of a team don't always get their ideas across at team meetings - usually they would be more comfortable tabling things on a one to one basis

  • Dev's could work from home for at least 50% of the week, if and only if it suits their team

  • No 8 hour day / 40 hour week.
    Not that anyone in the IT world does a 40 hour week, but it's non sensical to me to set an arbitrary amount of hours that someone is required to do per day or week. People in my team will, at their Monday morning team meetings, set the work they expect to achieve for the week. Once that is done, they may go. Obviously the work would have to be sensible and signed off by a team lead.

  • Flexi time.
    Some people are morning people, some people prefer to code in the middle of the night. My dev's will decide themselves when they want to come in.

  • Don't feel like it, Don't
    It sort of fits with the above point, but I have had days when I wake up and just don't feel inspired to code. I may be tired or need a break - whatever the reason, I am just not going to get any useful coding done that day. As an employer I would rather that if employees are having days like that, they don't bother coming in.


All of the above may sound like a bit of a fantasy, and I'm sure there would need to be a few kinks ironed out. The main problem would be if a team member needed to talk to another team member and they weren't available. Having said that, with instant communication available almost anywhere on the planet, that shouldn't be a problem.

Hopefully, I will get a chance to put my ideal world into practice.