Steven Nagy .NET

Tuesday, 28 August 2007

Another Vista Gadget Competition

Today I got the MSDN Flash and it noted there is an Australia wide competition for a Vista Gadget.

http://www.si-mi.com/ArtistDetail.aspx?id=871

Having come 2nd in the QLD competition, naturally I am interested in entering this competition as well. Some of the runner up prizes include Vista Ultimate (value $800, or so they say).

The closing date is 31st October (2 months away) and is open to anyone aged 12 to 30 in Australia only. Now here's the interesting bit. The company hosting the competition (Si-Mi) actually on-sells media that people upload, taking a cut for themselves. This means that you will not only be entering a competition, but uploading a potential money-maker as well! Apparently you earn 70% of the profit when your item is sold.

Contestants must set a price for their gadgets upon upload. Winners of the contest will partly be decided based
upon the amount of money made from uploads. Any profit made from selling sidebar gadgets as a result of this
competition remains the property of the entrant as per Si-Mi terms and conditions.

How cool is that! So lets revise:

  • You could win Vista Ultimate from your gadget, or more
  • You could get earnings from the gadget you upload
  • You will learn how to write sidebar gadgets

So what do you need? Well, just a good idea of course!

But if that's not enough, here's some resources for building gadgets.

http://msdn2.microsoft.com/en-us/library/ms723694.aspx
http://microsoftgadgets.com/Build/
http://gallery.live.com/devcenter.aspx
http://www.justfuckinggoogleit.com/?q=vista%20gadget

Technorati Tags: , , ,

Wednesday, 22 August 2007

Properties in .Net 3.5 - Updated!

Note: This article was updated, see "Amendment" at bottom.

When writing properties previously, you might do something like this:

private string _name;
public string Name
{
        get { return _name; }
        set { _name = value; }
}

(Note: the reasons for using a property over just a public field can vary; components need properties for design time support for example)

Well now you can short hand this in .Net 3.5 as follows:


public string Name { get; set; }

This is neat. At first it might confuse you... "I'm not going to inherit from this class!". You can also do this:

 

public string Name { get; private set; }

Which means your class can have a public getter but can only be set internally. If you only ever want your class to change the value and have external classes only querying the value, this works great.

However, the problem I ran up against today was that I had a base abstract class that I was inheriting from. I only wanted the sub classes to have getters, and have the ability to set the value privately.


public abstract string Name { get; }

I still wanted the implementing class to be able to privately set the value. However, this causes a build error:

public override string Name { get; private set; }

This is because I can not implement a setter in an override (the abstract declaration dictates the contract, and that was for a getter only). So, I had no option but to implement the old method of having a private setter:

private string _name;
public override string Name
{
    get { return _name; }
}

And then just set the _name field privately. Naturally its no big deal because without the new shortcut code I still would have had to implement it this way, but it would be nicer visually if I could have found a way to do it in one line.

AMENDMENT!

A co-worker suggested the following, which I tested and works great:

public abstract class test
{
    public abstract string Name { get; protected set; }
}

public class Tester : test
{
    public override string Name { get; protected set; }
}

This means you can maintain the easy read syntax. Happy days!

 

Technorati Tags: , ,


 

 


 

Friday, 10 August 2007

SurfWatch Demo Video

You might remember the Vista Gadget competition I entered into. Well Marty from Microsoft has demanded requested that all winners make a video about their gadget. So I did, and you can download it on the SurfWatch download page. Apparently Microsoft will put them all together for a DVD about Vista Gadgets, so it will be nice to have my work "in print" so to speak. The only other time my name ended up in print was for some research I did at QUT. I helped write an article that was published in the field of collaborative education.

Nothing much else of interest is going on. Everyone is at Tech.Ed so the gossip coming out of Microsoft is all about that. I'm not there unfortunately, but I wish I was. My timing in changing jobs wasn't perfect and I failed to make it a condition of my acceptance of the position. Oh well, I'll try to make up for it next year by attending both Remix and Tech.Ed.

Technorati Tags: , , , , ,

Tuesday, 7 August 2007

Provider Model In .Net 2.0/3.0

The .Net Framework provides a model for us to create providers for a set of pre-existing services, or for creating our own provider services. The provider we are probably most familiar with is the membership provider. This article from 4guysfromrolla.com is a great place to start with membership and roles. Using this provider allows us to just plonk a login control onto a form and not write any code to create a fully secure site. We can have ASP.NET create a bunch of tables for security in a database of our choosing (see part 3 of above article) and in Web.Config specify what role a user needs to access a folder/file. .Net does the rest!

But there comes a time when we might decide that we don't want our members in a database, or we want a different database schema, or even a different vendor (eg Oracle). This is where the provider model comes in.

So lets say we want to store users in our own database schema, in an Access database. We need to write our own Membership provider by inheriting from:
System.Web.Security.MembershipProvider

In doing so we are forced to override some methods that provide the implementation for our provider. For example, we need to override the following method to update a user:
public abstract void UpdateUser (MembershipUser user);

Once we have implemented our provider, we just need to tell the application to use that provider. We use the same Web.Config entries mentioned in the above article to do this. For example:

<membership defaultProvider="AccessMemberProvider">       
        <providers>
          <add
            name="AccessMemberProvider"
            type="Snagy.AccessMemberProvider"
            connectionStringName="MyConnection"
            applicationName="StevesTestApp"
            />
        </providers>
 </membership>

Essentially you can use the provider model for anything you want. Out of the box, .Net's membership, roles, profiles, site maps, session state, web part personalisation, and web events are all supplied via a provider model. In all cases .Net gives you at least 1 or 2 providers to use, mostly around SQL Server or Active Directory. However you can create your own provider and do anything you want. You can also create your own provider services if you so desire.

For a great article to get started on providers and writing your own, check out this Microsoft documentation.

Technorati Tags: , , , ,