jeudi 8 mai 2008

Objects and POO in .Net


Classes - objets
liste de clients héritant d'un SortedList


 
Objectif : Construire une liste de client fondée sur un SortedList, si vous avez travaillé le même exemple avec ArrayList comparez les codes construits.

 

Rappel du schéma interne d'un SortedList :  
( un SortedList = 2 tables  Keys et Values liées entre elles implantant un IDictionnary )




n est le nombre d'éléments présent dans le SortedList ( n = this.Count ).

Le couple ( une cellule de Keys , la cellule associée dans Values ) peut aussi être considéré comme un DictionaryEntry  = (Key ,Value), le SortedList peut alors être considéré aussi comme une collection d'objets de type DictionaryEntry :


Exercice, listeClient d'objets de type Client, fondée sur un SortedList :



Spécifications des méthodes à implanter :

Classe Client :

Un objet de type Client est identifié grâce à des champs publiques représentant son nom, son prénom et un numéro unique d'identification qui est attribué au client (l'adresse du client est facultative). Les deux surcharges du constructeur renseigneront les champs nom, prenom, idClient et adresse.


Classe listeClient :

Maintient à jour la liste de tous les clients à l'aide de méthodes.


Méthodes de la classe listeClient :
1°) 
void afficherListeClients() : affiche à la console la liste complète de tous les clients.
2°) 
void ajouterClient(Client person) : ajoute un client à la liste dans le cas où son identifiant n'est pas déjà existant dans la liste.
3°) 
void modifAdresseClient(string nomCli, string newAdr) : à partir d'un nom de client "string nomCli" cette méthode modifie l'adresse actuelle de ce client dans la liste.
4°) 
void supprimerClient(string nomCli)enlève de la liste, l'objet client à partir de son nom "string nomCli" s'il existe dans la liste.
5°) 
string requeteClientId(int idCli)renvoie sous forme d'une string toutes les informations connues sur un client de la liste(nom, prenom, identifiant, adresse) à partir de son numéro d'identification de client "int idCli".
6°) 
string requeteClientNom(string nomCli) : renvoie sous forme d'une string toutes les informations connues sur un client de la liste(nom, prenom, identifiant, adresse) à partir de son nom de client "string nomCli".
7°) Deux surcharges de l'indexeur de la classe listeClient, permettant de retrouver un objet Client de la liste l'un directe ( this[int id] ) l'autre associative ( this[string nom] ).

Classes Client et listeClient

 

using System;
using System.Collections;

    class Client
    {//-- enregistrement du type client
        public string nom, prenom, adresse;
        public int idClient; 

        //-- constructeurs :
       
public Client(string nom, string prenom, int id)
        {

       
}
        public Client(string nom, string prenom, string adresse, int id)
            : this(nom, prenom, id)    
        {
        }
    } 

    class listeClient : SortedList    {
        private const string mark = "***"

        //-- méthodes métier :
        public void afficherListeClients()
        {//-- liste des clients enregistrés:
        } 

        public string requeteClientNom(string nomCli)
        {//-- requête de recherche de client par nom dans la liste
        } 

        public void modifAdresseClient(string nomCli, string newAdr)
        {//-- modification si le client est présent
        }

        public void ajouterClient(Client person)
        {//-- ajout uniquement si numéro non déjà présent
        }

        public void supprimerClient(string nomCli)
        {//-- supprime uniquement si le client est présent
        }

        public string requeteClientId(int idCli)
        {//-- requête de recherche de client par identif client dans la liste
        }

        //-- indexeurs :
        public Client this[string nom]
        {//-- indexeur de requête Client par nom :Client("***","***",-1) si pas trouvé
            get

            {
            }
        }

        public Client this[int id]
        {//-- indexeur de requête Client par identif :Client("***","***",-2) 
         //   si pas trouvé.

            get
            {
            }
        }
    }

Chargez le programme à compléter avec la classe de test. (cliquez sur le lien)

Méthode Main, à utiliser pour tester les méthodes de la classe listeClient :

(identique à celle de la listeClient fondée sur ArrayList)

static void Main(string[] args)
{

            listeClient cci = new listeClient();
            cci.ajouterClient(new Client("renoir", "rené", 20));
            cci.ajouterClient(new Client("Lizt", "Franzt", "12 rote strasse 1245 Köln",8));
           
cci.ajouterClient(new Client("Thomson", "major", " 1st flowers street 00258 Maidstone",47));
           
cci.ajouterClient(new Client("Puccini", "Vittorio", 75));
            cci.ajouterClient(new Client("Strauss", "Johan", "62  Kirsh Platz 80065 Wien",109));
            cci.afficherListeClients();
            Console.WriteLine("Requête puccini : "+cci.requeteClientNom("Puccini"));
            Console.WriteLine("Requête idClient=1 : " + cci.requeteClientId(1));
            Console.WriteLine("Requête idClient=8 : " + cci.requeteClientId(8)); 
           
cci.ajouterClient(new Client("Wayne", "John", 75));
            cci.ajouterClient(new Client("Wayne", "John","Fort Alamo new Mexico",23));
           
cci.afficherListeClients();
            Console.ReadLine();
     
}

 

--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server

mercredi 7 mai 2008

Web deployment of .Net project

That's strong
 

The power of Web Deployment for Winforms

When I've to deploy a Windows Form application, usually 99% of the times I create a setup package by using Visual Studio .NET and its Setup Project: here you can create a single .msi package or multiple packages by using cabinets files (.cab) (useful if you want to deploy your application via multiple media).

With .NET 2.0 you have the possibility to use the ClickOnce technology to deploy your application. ClickOnce basically allows you to deploy Windows-based applications to a desktop by placing the application files on a Web or file server accessible to the client and providing the user with an URL. When the user clicks the link, the application files are downloaded to the user's machine and executed.

The program are executed in a secure sandbox provided by .NET code access security (CAS). When a new version of the application is deployed to the server, it can be automatically detected by connected clients, and the update can be downloaded and applied in a variety of ways based on optional deployment settings.

The .NET Framework 1.1 also includes a possibility to deploy applications in a way similar to this, a way that is not so known and used but that it's really powerful (I've choosed to use it for my last project): the Web Deployment.

But what is it? It's essentially a zero-touch deployment model that allows you to install a .NET application simply by going via browser to the proper URL where there is the application's executable file. What is wonderful is that the web server not needs to have the .NET Framework installed (it could be also a non Microsoft web server) but it's the local system's copy of the .NET Framework that handles the installation.

When you go to the proper url, the assemblies are downloaded and maintained in a download cache (unique for each user) and the installation and execution of the application uses a zone-based security model.

You can check the security zone settings simply by using the .NET Framework Configuration tool, as you can see in the figure below (I'm sorry for the italian language of my system ). Obviously, you can customize the security settings of these zones as you want, but it's not recommended.

If you're developing Windows Forms applications with .NET 1.1 and your deployment scenario is an Intranet network, I recommed this way to to: by using it, you don't require to have a distribution method to all your users. You save time and you're sure that all receives the correct version.



--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server

lundi 5 mai 2008

The reason for the challenge

Introduction

The Artical provides base for fresh C# and java developers

Features of C# absent in Java

  • C# includes more primitive types and the functionality to catch arithmetic exceptions.
  • Includes a large number of notational conveniences over Java, many of which, such as operator overloading and user-defined casts, are already familiar to the large community of C++ programmers.
  • Event handling is a "first class citizen"—it is part of the language itself.
  • Allows the definition of "structs", which are similar to classes but may be allocated on the stack (unlike instances of classes in C# and Java).
  • C# implements properties as part of the language syntax.
  • C# allows switch statements to operate on strings.
  • C# allows Anonymous methods providing closure functionality.
  • C# allows iterator that employs co routines via a functional-style yield keyword.
  • C# has support for output parameters, aiding in the return of multiple values, a featured shared by C++ and SQL.
  • C# has the ability to alias namespaces.
  • C# has "Explicit Member Implementation" which allows a class to specifically implement methods of an interface, separate to its own class methods. This allows it also to implement two different interfaces which happen to have a method of the same name. The methods of an interface do not need to be "public"; they can be made to be accessible only via that interface.
  • C# provides integration with COM.
  • Following the example of C and C++, C# allows call by reference for primitive and reference types

Features of Java absent in C#

  • Java's strictfp keyword guarantees the result of floating point operations remain the same across platforms.
  • Java supports checked exceptions for better enforcement of error trapping and handling.

Philosophical differences between the languages

  • There are no unsigned primitive numeric types in Java. While it is universally agreed that mixing signed and unsigned variables in code is bad, Java's lack of support for unsigned numeric types makes it somewhat unsuited for low-level programming.
  • C# does not include checked exceptions. Some would argue that checked exceptions are very helpful for good programming practice. Others, including Anders Hejlsberg, chief C# language architect, argue that they were to some extent an experiment in Java and that they haven't been shown to be worthwhile [1] [2].
  • C#'s namespaces are more similar to those in C++. Unlike Java, the namespace does not specify the location of the source file. (Actually, it's not strictly necessary for a Java source file location to mirror its package directory structure.)
  • C# includes delegates, whereas Java does not. Some argue that delegates complicate the method invocation model, because they are handled through reflection, which is generally slow. On the other hand, they can simplify the code by removing the need to declare new (possibly anonymous) classes to hook to events.
  • Java requires that a source file name must match the only public class inside it, while C# allows multiple public classes in the same file.
  • C# allows the use of pointers, which some language designers consider to be unsafe, but certain language features try to ensure this functionality is not misused accidentally. Pointers also greatly complicate technologies such as Java's RMI (Remote Method Invocation), where program objects resident on one computer can be referenced within a program running on an entirely separate computer. Some have speculated that the lack of memory pointers in Java (substituted by the more abstract notion of object references) was a nod towards the coming of grid computing, where a single application may be distributed across many physical pieces of hardware.
  • C# supports the goto keyword. This can occasionally be useful, but the use of a more structured method of control flow is usually recommended.
  • C# has true multi-dimensional arrays, as well as the array-of-arrays that is available to Java (which C# calls jagged arrays). Multi-dimensional arrays are always rectangular (in the 2D case, or analogous for more dimensions), whereas an array-of-arrays may store rows (again in the 2D case) of various lengths. Rectangular arrays may speed access if memory is a bottleneck (there is only one memory reference instead of two; this benefit is very dependent on cache behavior) while jagged arrays save memory if it's not full but cost (at the penalty of one pointer per row) if it is. Rectangular arrays also obviate the need to allocate memory for each row explicitly.
  • Java does not include operator overloading, because abuse of operator overloading can lead to code that is harder to understand and debug. C# allows operator overloading, which, when used carefully, can make code terser and more readable. Java's lack of overloading makes it somewhat unsuited for certain mathematical programs. Conversely, .NET's numeric types do not share a common interface or superclass with add/subtract/etc. methods, restricting the flexibility of numerical libraries.
  • Methods in C# are non-virtual by default. In Java however, methods are virtual by default. Virtual methods guarantee that the most overridden method of an object will be called which is determined by the runtime. You always have to keep that in mind when calling or writing any virtual method! If the method is declared as non-virtual, the method to invoke will be determined by the compiler. This is a major difference of philosophy between the designers of the Java and .NET platforms.
  • Java 1.5's generics use type-erasure. Information about the generic types is lost when Java source is compiled to bytecode. .NET 2.0's generics are preserved after compilation due to generics support starting in version 2.0 of the .NET Common Language Runtime, or CLR for short. Java's approach allows Java 1.5 binaries to be run in the 1.4 JRE, at the cost of additional runtime typechecks.
  • C# is defined by ECMA and ISO standards, whereas Java is proprietary, though largely controlled through an open community process.
  • The C# API is completely controlled by Microsoft, whereas the Java API is managed through an open community process.
  • The .NET run-time allows both managed and unmanaged code, enabling certain classes of bugs that do not exist in Java's pure managed code environment but also allows interfacing with existing code.


--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server