LINQ Project

31. December 2006 07:10 by Mrojas in General  //  Tags:   //   Comments (0)
These project extends the VB and C# languages with query, set and transforms operations. It adds a native syntax for those operations.

 

The idea of the LINQ project is to make data manipulation part of the language constructs. Lets see these VB examples for LINQ:

 

The following examples associates the Customer class to the Customer table. Just adding the Column Tag before a field, maps it to a table column.

 

    <Table(Name:="Customers")> _

    Public Class Customer

        <Column(Id:=True)> _

        Public CustomerID As String

       

        <Column()> _

        Public City As String

       

    End Class

To access the database you do something like:

' DataContext takes a connection string

Dim db As DataContext = _
        New DataContext("c:\...\northwnd.mdf")

      'Get a typed table to run queries

      Dim Customers As Table(Of Customer) = db.GetTable(Of Customer)()

      'Query for customers from London

        Dim q = _

          From c In Customers _

          Where c.City = "London" _

          Select c

 

      For Each cust In q

          Console.WriteLine("id=" & Customer.CustomerID & _

              ", City=" & Customer.City)

      Next

 

You just create a DataContext and create typed object that will relate dot the relational tables. I think this is awesome!!

 

It is even nicer if you create a strongly typed DataContext

 

    Partial Public Class Northwind

        Inherits DataContext

        Public Customers As Table(Of Customer)

        Public Orders as Table(Of Order)

        Public Sub New(connection As String)

            MyBase.New(connection)

 

Your code gets cleaner like the following:

    Dim db As New Northwind("c:\...\northwnd.mdf")

 

    Dim q = _

        From c In db.Customers _

       Where c.City = "London" _

        Select c

     

      For Each cust In q

          Console.WriteLine("id=" & Customer.CustomerID & _

              ", City=" & Customer.City)

      Next

 

 

These project will start a lot of exciting posibilities. I recommed you have a look at’: http://msdn.microsoft.com/data/ref/linq/

 

 

 

Thin Clients or Rich Clients

31. December 2006 06:26 by Mrojas in General  //  Tags:   //   Comments (0)

This is an old topic but I always like to give some thoughts on this idea.  I really think that in the future everything will run from the internet. Internet is becoming another basic need just as electricity, water, gas and telephone. The appearance of new technologies makes it easy to have Internet even in remote places like beaches and mountains.

Rich Clients have been defended because it was said that not a lot of interactivity could be produced by thin clients. It has also been said that powerful interfaces (with complex gadgets, etc) could be produced in a web interface. I think that Flash, and AJAX have shown that despite all believes it is possible. There are still more technologies that will come. But the easier deployment and the fact that you can use your web applications everywhere even from a cell phone in a taxi cub.

 

I also love phases like “If you ask an engineer the time, he'll tell you how to build a clock.”. Web interfaces are simple and easy to learn look at blogs like Jon Galloway http://weblogs.asp.net/jgalloway/archive/2003/09/27/29446.aspx and Microsoft's Inductive User Interface (IUI) initiative it seams like more people is starting to think in this way.

ASP to ASP.NET

29. December 2006 07:14 by Mrojas in General  //  Tags:   //   Comments (0)

Migrating ASP to ASP.NET

 

Surpinsingly for me. I found that some friends were working on migrating an ASP classic site to ASP.NET. I was impressed to see that there are still sites in ASP classic at ALL!!!!

ASP.NET 2.0 provides so much improvements, you cannot even debug in ASP. ASP.NET 2.0 has better performance and easier to deploy. There is even Intellisense! These days is hard for me not assuming that all IDEs provide the developer aids like that.

 

Also migrating simple ASP classic code to ASP.NET is not that hard.

Let’s see a simple ASP classic page like:

 

<%

Dim objConn

Dim objRS

Set objConn = Server.CreateObject(“ADODB.Connection”)

Set objRS = Server.CreateObject(“ADODB.Recordset”)

objConn.ConnectionString = “DRIVER=(SQL Server);server=…”

objConn.Open()

objRS.Open “SELECT * from Items”, objConn

Do While Not objRS.EOF

     Response.Write CStr(objRS(“ID”)) + “ – “ + objRS(“Description”) + “<br>”

     objRS.MoveNext

Loop

objConn.Close

%>

 

Migrates easily to:

 

<%@ Page aspcompat=true Language=”VB” AutoEventWireUp=”false” CodeFile=”Default.aspx.vb” >

<%

Dim objConn

Dim objRS

Set objConn = Server.CreateObject(“ADODB.Connection”)

Set objRS = Server.CreateObject(“ADODB.Recordset”)

objConn.ConnectionString = “DRIVER=(SQL Server);server=…”

objConn.Open()

objRS.Open (“SELECT * from Items”, objConn)

Do While Not objRS.EOF

     Response.Write (CStr(objRS(“ID”).Value) + “ – “ + objRS(“Description”).Value + “<br>”)

     objRS.MoveNext

Loop

objConn.Close

 

%>

 

These are the task to do:

  1. Remove SET
  2. Any method in ASP.NET requires its parameters to go inside parenthesis
  3. ASP.NET does not have default properties so elements as objRS(“ID”) must be changed to objRS(“ID”).Value and objRS(“Description”) to objRS(“Description”).Value
  4. you must add the aspcompat=true property to the page because of the apartment threading issues
  5. You should change statements like Dim objRS to Dim objRS as Object it is not an error but it will help you make your code more clear.

 

You can also download the Migration Assitant from ASP to ASP.NET from:

http://www.asp.net/DownloadWizard.aspx?WizardTarget=AspToAspNetMigrationAssistant

 

Starting with the internationalization bla bla (Part Two)

27. December 2006 10:50 by Mrojas in General  //  Tags:   //   Comments (0)
Ok enough theory. To start using the internationalization stuff lets start with a simple Form.

Open  the Visual Studio IDE. And Start a Windows Forms project. And then create a simple Form. Add some labels and buttons and set their captions. Once you do that and finish the initial creation of the form, go to the properties pane and change the Localizable property to true and assign the desired value in the Language property. The Visual Studio designer will save the changes in additional resource files whose names will look like <FormName>.<culture>.resx

Once you finish the texts, sizes, positions for the first culture and save it. The IDE creates the resource file for that culture. If you want to create a resource file for another language just change the Form property and assign the text for this new language.

 

You can not only assign personalized translations for each region but also the position and size of components. This is useful because in some languages the buttons might need to be bigger because the labels could be bigger.

 

All this work is supported by the .NET resource managers. System.Resources.ResourceManager class.

 

I recommend you also using String Resource Tools like the ones at: http://www.codeplex.com/ResourceRefactoring

 

These tools makes it even easier the task of moving all your strings to resource files:

 

Taking an application to the whole world (Series 1 of 3)

27. December 2006 03:59 by Mrojas in General  //  Tags:   //   Comments (0)

Recently I was asked by some fellows some help to make a new version of their VB6 application in Spanish, but at the end we end up migrating the application to VB.Net and taking advantage of the .NET internationalization features.

 

VB6 did not provided and out-of-box support for multiple cultures, but the .NET framework provides the developer with utilities to create applications that allow users in multiple regions use their applications according to their “Culture”.

 

The .Net Framework is able to handle different cultures. These “cultures” are used to localize certain aspects of the application for particular geographic zones.

When an application is not created with any cultural considerations it is said to use a Neutral Culture. It implies that independent of the machine configuration it will behave and display components in the same way.

 

The Culture is assigned automactically using the machine settings or it can be altered programmatically. You can use the property System.Globalization.CultureInfo.CurrentUICulture for that purpose.

 

Cultures have two elements: language and region. For example for Argentina where Spanish is spoken la culture will be es-AR (es is for Spanish: ESpañol and AR for Argentina)

 

If no information is found at all for an language then the neutral culture is used.

 

The information for user display is handler in assemblies usually called “satellite assemblies” which are loaded depending on the culture of the environment where the application is executed.

 

Is .NET hotter that Java

21. December 2006 11:44 by Mrojas in General  //  Tags: ,   //   Comments (0)
This is a very controversial topic. Recently I have seen several blogs that state that the VB6 Programmers are moving to other platforms like PHP or Java instead of VB.NET
For example see:
Number of VB Developerts Declining in US
By Steve Graegert
“They’re also leaving VB.NET; which is down by 26%. This means Java now holds the market penetration lead at 45% (with developers using Java during some portion of their time), followed by C/C++ at 40%, and C# at 32%.”

I also remember an Article I read in 2005 in JDJ (Java Developers Journal) that expressed that C# was a language created similar to C++ to aid the C++ programmers move to the .NET Framework, argument that I do not share.

I have no evidence but I do not feel that it is that way. I'm am a Java Developer too. And both platforms have their merits. C# is a nice language, very similar to Java and C++ no doubt but it deserves its own place. Visual Studio has still a path to follow. But VS2005 provides some useful refactorings and the incredibly awaited feature that allows you to edit the code that you're running :)

Maybe the 1.0 and 1.1 frameworks were not enterprise ready, but 2.0 and 3.0 frameworks are an excellent improvent.

Java as well had to go thru a lot of JDK releases. They have just released the 1.6 and what about the J2EE releases, the Java Enterprise Beans fiasco. You can confirm that by looking at the rise of POJO (Plain Old Java Object) frameworks like spring.

In general everything requires time to grow. I think that Java has been more time in the market and it has finally provided mechanisms that allow the development of enterprise services "easier" and it is giving it momentum.

.NET components industry is common, there are lots of components and somethings are easier. So I'll wait some time, maybe a couple of year to really find out which is the hotter platform.

Invoke a WebService that needs Windows Authentication

1. December 2006 10:22 by Mrojas in General  //  Tags:   //   Comments (0)

Passing client credentials to a Web service using Windows authentication

Sometimes a Web Service is under a configuration that requires Windows Authentication. It is not a problem for .NET, all you need to do is set your environment to send the client credentials.
  1. First Create a Reference to a Web Service:





To do that just go to the references of your project and add a Web Reference. Type the URL of your web service. This will find your Web Service Reference and you can update it. This will generate the proxy code you need to access your webservice.

If you try to call your webservice with a call like:

WebReference.MyService pService = new WebReference.MyService ();
pService.doStuff("A", "B");

You’ll get a HTTP 404 forbidden access exception.

Now to send the user and password to call your service write some code like the following:

WebReference.MyService pService = new WebReference.MyService ();
pService.Credentials = new System.Net.NetworkCredential("user", "password");
pService.doStuff("A", "B");

You can also send the domain name as part of the parameter to the NetworkCredential class:

pService.Credentials = new System.Net.NetworkCredential("user", "password","domain");

It will be even better to have your user and password not in your code but in the configuration file for your program. You can then use the AppSettings class to access those properties.

ToolTip with Images

1. December 2006 06:30 by Mrojas in General  //  Tags:   //   Comments (0)

The Tooltips that comes out of the box for winforms do not support images on them. This is a simple class that allows you to add Images and Text to your ToolTips

using System;

using System.Windows.Forms;

using System.Collections.Generic;

using System.Text;

using System.Drawing;

namespace CustomControls

{

class ToolTipWithImage : Control

{

private Image _img;

private Control _ctl;

private Timer _timer;

string _imgfilename;

string _tiptext;

public String TipText

{

get { return _tiptext; }

set { _tiptext = value; }

}

public String ImageFile

{

get

{

return _imgfilename;

}

set

{

if (_imgfilename == value)

{

}

else

{

_imgfilename = value;

try

{

_img = Image.FromFile(_imgfilename);

this.Size = new Size(_img.Width + 70, _img.Height);

}

catch

{

_img = null;

}

}

}

}

public ToolTipWithImage()

{

this.Location = new Point(0, 0);

this.Visible = false;

_timer = new Timer();

_timer.Interval = 1000;

_timer.Tick += new EventHandler(ShowTipOff);

}

public void SetToolTip(Control ctl)

{

_ctl = ctl;

ctl.Parent.Controls.Add(this);

ctl.Parent.Controls.SetChildIndex(this, 0);

ctl.MouseMove += new MouseEventHandler(ShowTipOn);

}

protected override void OnPaint(PaintEventArgs e)

{

if (_img != null)

{

e.Graphics.DrawImage(_img, 0, 0);

e.Graphics.DrawString(TipText, this.Font, Brushes.Black, _img.Width, 0);

}

}

public void ShowTipOn(object sender, MouseEventArgs e)

{

if (!this.Visible)

{

_timer.Start();

this.Left = _ctl.Left + e.X + 100;

this.Top = _ctl.Top + e.Y;

this.Visible = true;

}

}

public void ShowTipOff(Object sender, EventArgs e)

{

_timer.Stop();

this.Visible = false;

}

}

 

}

 

To use it just do something like

ToolTipWithImage timg = new ToolTipWithImage();

timg.TipText = "Hello";

timg.ImageFile = @"C:\Hello.gif";

timg.SetToolTip(btnOk);

Safe Migration to VB.NET

27. November 2006 05:44 by Mrojas in General  //  Tags:   //   Comments (0)
    My colleague Juan Pastor forward us an interesting link. It was called "Safe Migration to VB.NET". By Phillip Munce.
He provides an interesting point of view of how to address a migration. He's approach is based on the Agile Development strategies.
Mainly he states that a good way to address a migration project is developing a set of Unit Test cases. For which you could use either NUnit or the Visual Studio Team System.
In that way is easier to establish a measure that let's you know when the project is migrated if it meets the original application test cases.
He also sees it as an oportunity to document and improve maintability for the application.
Here at Artinsoft we also give special attention to testing and the establishment of the test case scenarios because they are our main tool to determine the "Functional Equivalence"
 of the application being migrated which is the goal of most of our clients.
Testing is not always appreciated by developers but as applications grow and maintability becomes complicated, it is harded and harder to keep track that new functionality and patches do not destroy the rest of your application.
Take a look at Phillips Blog here.

Creating a Scheduled job in ORACLE

22. November 2006 06:41 by Mrojas in General  //  Tags:   //   Comments (0)

This is easily done with the Oracle 10g interface, there is a nice article that explains that in at this address

However sometimes you don't have access to the Administrative UI. Is there another way to create or schedule jobs?

Sure just use the he DBMS_SCHEDULER package.

There are several things you should do:

1. GRANT CREATE JOB TO MYUSER;

2. ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;

3. Create Scheduler Program:

BEGIN
   DBMS_SCHEDULER.CREATE_PROGRAM(
      program_name=>'MYUSER.PROGRAM1',
      program_action=>'begin
         INSERT INTO TABLE1
         SELECT * FROM TABLE2;
         end;',
      program_type=>'PLSQL_BLOCK',
      number_of_arguments=>0,
      comments=>'Loads a table from another',
      enabled=>TRUE);
END;

 4. Create a schedule program:

BEGIN
   sys.dbms_scheduler.create_schedule( 
      repeat_interval =>   
         'FREQ=DAILY;INTERVAL=2;BYHOUR=18;BYMINUTE=0;BYSECOND=0',
      start_date => 
         to_timestamp_tz('2006-11-22 US/Eastern', 'YYYY-MM-DD TZR'),
      comments => 
         'Schedule for periodic loads',
      schedule_name => '"MYUSER"."DOLOADS"');
END;

 

5. And finally link both together to create a JOB:

BEGIN
   sys.dbms_scheduler.create_job(
      job_name => '"MYUSER"."JOB1"',
      program_name => 'MYUYSER.PROGRAM1',
      schedule_name => 'MYUSER.DOLOADS',
      job_class => 'DEFAULT_JOB_CLASS',
      comments => 'Loads a table',
      auto_drop => FALSE,
      enabled => TRUE);
END;

At least this is how I did it. This is just a quick summary of the following article:http://www.oracle.com/technology/oramag/oracle/04-jul/o44tech_dba.html