Suddenelfilio\’s Weblog

Icon

Passionate about .net

XAML and WPF Coding Guidelines

I was looking around for some coding guidelines (.net in general) and I found the following for xaml and wpf by paul stovell. It’s a nice compilation of guidelines. Would be nice though to have it in a pdf form so I can add it to my collection ๐Ÿ˜‰ 

PaulStovell.NET ยป XAML and WPF Coding Guidelines

Filed under: Uncategorized

Great video about Silverlight

I had some free time on my hands at home and I was looking for some information about SilverLight. This session demonstrates building a rich interactive application using Silverlight. We cover how to use Microsoft Visual Studio to create applications, how to create UI using XAML markup and code, how to build a custom control, how to retrieve data from a Web service, and how to manipulate data with XML and LINQ.

This video is about the following features:

  • Http Networking + XML
  • Web Services
  • LINQ
  • HTML Integration
  • Mac Debugging (really nice one !!!)

Video downloads:
WMV | Zune | iPod | PSP | MPEG-4 | 3GP

Or go to the original page @ http://silverlight.net/Learn/learnvideo.aspx?video=144

Filed under: Uncategorized

Installing Infragistics NetAdvantage 2006 volume 3 on vista

For those of you that tried it might have noticed some error saying:

“Cannot find %sysdrive%\inetpub\wwwroot” 

You can solve this problem by changing a registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp

Change the value from: %systemdrive%\inetpub\wwwroot
to: c:\inetpub\wwwroot

and your installation will work. At least mine did ๐Ÿ˜‰

Filed under: Uncategorized

Easy way to setup SSL for testing on IIS

If you want to test SSL on IIS 6.0 you need to go through the hassle of creating a certificate and configuring IIS to allow SSL connections.

You can avoid all this with a simple execution of a small program called SelfSSL. SelfSSL is a program that creates and installs a local certificate and configures IIS for SSL.

Here are the steps to follow:

  1. Download the IIS 6.0 Resource toolkit from Microsoft MSDN Downloads.
  2. Install the toolkit.
  3. Open a command prompt (Start -> Run -> cmd -> [ENTER])
  4. Go to the following path: C:\Program Files\IIS Resources\SelfSSL
  5. Execute the program SelfSSL with the following command: SelfSSL.exe /T
    The /T option adds the self-signed certificate to “Trusted Certificates”
    list. The local browser will trust the self-signed certificate
    if this flag is specified.

Happy SSL-ing ๐Ÿ˜‰

Filed under: Uncategorized

Update your feeds

Just a small reminder to update your feed subscription to this blog if you have any. I changed hosting for the blog so the feed url is different as well.

greetings

Filed under: Blog

Babysteps: LINQ To SQL

Okay I had some free time to spend on LINQ  To SQL and because I’m working on a new personal project for the future (God only knows if I’ll ever finish it ๐Ÿ˜‰ ). I need in my database a table “Countries”. Because I don’t want to create a script to load this table  and I certainly don’t want to fill it manually I started looking for a web service that could provide me the data I need. I want to keep the country’s Name and its ISO code.
For this I found a web service on http://www.oorsprong.org [WSDL] which does exactly what I need.

The web service has got a web method – ListOfCountryNamesByCode – that returns all the countries with their ISO codes. Just perfect! ๐Ÿ˜€

Knowing where to get the data, we need to create the table that holds the data I’m getting from the web service. For this I only need a very basic table:

CREATE TABLE

[dbo].[Countries]
(
[ID] [int]
NOT NULL IDENTITY(1, 1),
[ISO] [nvarchar] (3)
NULL,
[Name] [nvarchar] (50)
NULL,
[InsertDate] [datetime]
NULL
) ON [PRIMARY]

Okay I admit maybe it’s not the best table structure ever, but it will do the trick.

So now the table is ready to store the data gotten from the web service all we need is to get the data.

First thing you need is to add a LINQ To SQL Mapping file (dbml file). Doing this is very simple. Just click somewhere in the solution explorer’s related project and select “Add new item”.

add new item - LINQ to SQL

 From the list you can select LINQ To SQL Classes. When the dbml file is created you just drag-n-drop the tables from the server explorer onto the designer’s surface.

dbml designer

That’s all you need to do for the object relational mapping for the Countries table. Also notice that when you drop the Countries table onto the surface of the designer it is smart enough to rename the autogenerated object to Country because it will represent the Country entity that is stored in the Countries table.

Next you need to fetch the countries using the web service. So just add a web service reference to your project, create an instance and call the necessary method, in this case it’s the ListOfCountryNamesByCode which will return an array of tCountryCodeAndName instances.

org.oorsprong.webservices.CountryInfoService serv = 
new org.oorsprong.webservices.CountryInfoService(); org.oorsprong.webservices.tCountryCodeAndName[] countries =
serv.ListOfCountryNamesByCode();

To work with the generated Country entity you will first need to create a database context. The designer already generated all the necessary code for you. All you need to do is create an instance like this:

CountryTableDataContext db = new CountryTableDataContext();

Be honest it couldn’t be much easier ๐Ÿ˜‰

The instace db contains a property called Countries which is a Linq table for Country entities. Because we have a type difference from what is returned by the web service and what needs to get stored in the database we will convert the array of tCountryCodeAndName instances to an IEnumerable of Country entities. For this we can use the LINQ to Objects technology together with anonymous typing and object initialization expressions.

 var ctr = from c in countries
           select new Country() { ISO = c.sISOCode, 
Name = c.sName, InsertDate = DateTime.Now };

As you can see we don’t define the type of ctr it will be implicitly defined as whatever is returned from the LINQ query. The part after the equals sign is the same as writing a foreach statement.
The second part of the code is where we create a new Country instance and assign it’s values using object initialization expressions. For example the Country entity has got an ISO property so you can say ” new Country() { ISO = c.sISOCode} ” to assign it the value of the property sISOCode on the tCountryNameAndCode instance c.

In C# 2.0 the previous code would look like this:

 List<Country> countryList = new List<Country>();
  foreach (tCountryCodeAndName c in countries)
  {
      Country ctr = new Country();
      ctr.ISO = c.sISOCode;
      ctr.Name = c.sName;
      ctr.InsertDate = DateTime.Now();

      countryList.Add(ctr);
  }

Of course there are some other techniques in the new way of coding that I didn’t explain like local type inference, lambda expression (behind the scenes)…

Now that we have got an IEnumerable of Country entities “ctr” we can add them to the database context very easily:

db.Countries.AddAll(ctr);

That’s it, just do this last line of code below and all the countries with their respective ISO code will be stored nicely in the database. Isn’t that cool ?!?

db.SubmitChanges();

If you have any questions on this post you can use the comment option to contact me about this.

Filed under: .net 3.5, LINQ, Visual Studio .Net "Orcas",