begin process at 2012 02 11 04:03:59
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > IMPLÉMENTATION DU TYPE GUID AVEC MICROSOFT AJAX

IMPLÉMENTATION DU TYPE GUID AVEC MICROSOFT AJAX


 Information sur la source

Note :
Aucune note
Catégorie :Divers Classé sous :guid, atlas, microsoftajax, identifiant, uniqueidentifier Niveau :Initié Date de création :18/04/2007 Date de mise à jour :18/04/2007 20:29:56 Vu :4 977

Auteur : jesusonline

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note


 Description

Un Guid est un numéro unique. En .net il existe le type System.Guid qui est décrit sur la msdn ici : http://msdn2.microsoft.com/en-us/library/system.gu id.aspx

J'ai réécrit ce type coté client en utiliser le framework Microsoft Ajax Library.

Source

  • Type.registerNamespace('CS');
  • CS.Guid = function(value){
  • this._tabs = [];
  • if (value.match('^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$')){
  • this._tabs[0] = value.substring(0, 8).toUpperCase();
  • this._tabs[1] = value.substring(9, 13).toUpperCase();
  • this._tabs[2] = value.substring(14, 18).toUpperCase();
  • this._tabs[3] = value.substring(19, 23).toUpperCase();
  • this._tabs[4] = value.substring(24, 36).toUpperCase();
  • } else if (value.match('^{[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}}$')){
  • this._tabs[0] = value.substring(1, 9).toUpperCase();
  • this._tabs[1] = value.substring(10, 14).toUpperCase();
  • this._tabs[2] = value.substring(15, 19).toUpperCase();
  • this._tabs[3] = value.substring(20, 24).toUpperCase();
  • this._tabs[4] = value.substring(25, 37).toUpperCase();
  • } else if (value.match('^\\([A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}\\)$')){
  • this._tabs[0] = value.substring(1, 9).toUpperCase();
  • this._tabs[1] = value.substring(10, 14).toUpperCase();
  • this._tabs[2] = value.substring(15, 19).toUpperCase();
  • this._tabs[3] = value.substring(20, 24).toUpperCase();
  • this._tabs[4] = value.substring(25, 37).toUpperCase();
  • } else if (value.match('^[A-Za-z0-9]{32}$')){
  • this._tabs[0] = value.substring(0, 8).toUpperCase();
  • this._tabs[1] = value.substring(8, 12).toUpperCase();
  • this._tabs[2] = value.substring(12, 16).toUpperCase();
  • this._tabs[3] = value.substring(16, 20).toUpperCase();
  • this._tabs[4] = value.substring(20, 32).toUpperCase();
  • }else {
  • throw Error.format(Sys.Res.formatInvalidString);
  • }
  • }
  • CS.Guid.prototype = {
  • toString : function(format){
  • switch(format){
  • case 'N' :
  • return String.format('{0}{1}{2}{3}{4}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
  • break;
  • case 'B' :
  • return String.format('{{{0}-{1}-{2}-{3}-{4}}}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
  • break;
  • case 'P' :
  • return String.format('({0}-{1}-{2}-{3}-{4})', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
  • break;
  • case 'D' :
  • case '' :
  • case null :
  • case undefined :
  • return String.format('{0}-{1}-{2}-{3}-{4}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
  • break;
  • default :
  • throw Error.format(Sys.Res.formatInvalidString);
  • break;
  • }
  • }
  • }
  • CS.Guid.registerClass('CS.Guid');
  • CS.Guid.empty = new CS.Guid('00000000-0000-0000-0000-000000000000');
  • CS.Guid.newGuid = function(){
  • var d = new Date();
  • var end = d.getTime().toString();
  • for(var i = end.length; i < 32; i++){
  • end += Math.floor(Math.random()*16).toString(16);
  • }
  • return new CS.Guid(end);
  • }
            Type.registerNamespace('CS');
            
            CS.Guid = function(value){
                this._tabs = [];
                
                if (value.match('^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$')){
                    this._tabs[0] = value.substring(0, 8).toUpperCase();
                    this._tabs[1] = value.substring(9, 13).toUpperCase();
                    this._tabs[2] = value.substring(14, 18).toUpperCase();
                    this._tabs[3] = value.substring(19, 23).toUpperCase();
                    this._tabs[4] = value.substring(24, 36).toUpperCase();
                } else if (value.match('^{[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}}$')){
                    this._tabs[0] = value.substring(1, 9).toUpperCase();
                    this._tabs[1] = value.substring(10, 14).toUpperCase();
                    this._tabs[2] = value.substring(15, 19).toUpperCase();
                    this._tabs[3] = value.substring(20, 24).toUpperCase();
                    this._tabs[4] = value.substring(25, 37).toUpperCase();                    
                } else if (value.match('^\\([A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}\\)$')){
                    this._tabs[0] = value.substring(1, 9).toUpperCase();
                    this._tabs[1] = value.substring(10, 14).toUpperCase();
                    this._tabs[2] = value.substring(15, 19).toUpperCase();
                    this._tabs[3] = value.substring(20, 24).toUpperCase();
                    this._tabs[4] = value.substring(25, 37).toUpperCase();                    
                } else if (value.match('^[A-Za-z0-9]{32}$')){
                    this._tabs[0] = value.substring(0, 8).toUpperCase();
                    this._tabs[1] = value.substring(8, 12).toUpperCase();
                    this._tabs[2] = value.substring(12, 16).toUpperCase();
                    this._tabs[3] = value.substring(16, 20).toUpperCase();
                    this._tabs[4] = value.substring(20, 32).toUpperCase();                    
                }else {
                    throw Error.format(Sys.Res.formatInvalidString);
                }
            }
            
            CS.Guid.prototype = {
                toString : function(format){
                    switch(format){
                        case 'N' :
                            return String.format('{0}{1}{2}{3}{4}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
                            break; 
                            
                        case 'B' :
                            return String.format('{{{0}-{1}-{2}-{3}-{4}}}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
                            break;
                            
                        case 'P' :
                            return String.format('({0}-{1}-{2}-{3}-{4})', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);
                            break;
                        
                        case 'D' :
                        case '' :
                        case null :
                        case undefined : 
                            return String.format('{0}-{1}-{2}-{3}-{4}', this._tabs[0], this._tabs[1], this._tabs[2], this._tabs[3], this._tabs[4]);                         
                            break; 
                            
                        default : 
                            throw Error.format(Sys.Res.formatInvalidString);
                            break;
                    }
                }
            }
            
            CS.Guid.registerClass('CS.Guid'); 
            
            CS.Guid.empty = new CS.Guid('00000000-0000-0000-0000-000000000000');
            CS.Guid.newGuid = function(){
                var d = new Date(); 
                var end = d.getTime().toString(); 
                for(var i = end.length; i < 32; i++){
                    end += Math.floor(Math.random()*16).toString(16); 
                }
                return new CS.Guid(end); 
            }

 Conclusion

Contrairement à un vrai guid, le numéro n'est pas forcément unique (un guid est généré aléatoirement en prenant en compte la date, l'adresse mac de la carte réseau et d'autres paramètre) et on peut facilement connaitre l'heure de la création d'un guid. Mais dans la plupart des cas ce type nous suffit largement côté client.


 Historique

18 avril 2007 20:29:56 :
correction d'une boulette

 Sources du même auteur

Source avec Zip CHRONOMÈTRE MESURANT LA DURÉE D'UNE FONCTION
Source avec Zip Source avec une capture GADGET POUR VISTA : CPU GRAPH
FUNCTION.WAITFOR : ATTENDRE UNE CONDITION AVANT D'EXECUTER U...
DESORGANISÉ UN TABLEAU : LA MÉTHODE SORT
FONCTION GETELEMENTSBYCLASS

 Sources de la même categorie

COLONNES ADAPTABLES EN HAUTEUR par dronoide
Source avec Zip VECTEURS ET MATRICES: OUTILS GRAPHIQUES UTILES par william voirol
Source avec Zip Source avec une capture HTML5 PLAYER par kazma
Source avec Zip Source avec une capture SCROLLBAR PERSONNALISABLE par kazma
Source avec Zip INFO BULLE par RudiRatlos

Commentaires et avis

Commentaire de stfou le 18/04/2007 16:33:50

Pour info à ceux qui ne connaissent pas, GUID >> Global Unique Identifiant (Identifiant Unique au monde)

Commentaire de stfou le 18/04/2007 16:34:40

Sinon, super :) enfin quelque chose qui innove !

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Connaitre l'identifiant de session Windows [ par sebast105 ] Bonjour tout le monde,je d&#233;veloppe actuellement un script (JavaScript) et je souhaiterai r&#233;cup&#233;rer l'identifiant avec lequel l'utilisat ATLAS dans les gadgets [ par kerad ] Question rapidos, j'ai pas eu le temps de v&#233;rifier alors je me permets de demander direct sur le forum...Avec les gadgets, y'a moyen d'utiliser A URGENT!!Recupere identifiant coché [ par sensoide ] Bonjourj'ai un formulaire avec plusieurs checkbox.Je souhaiterais savoir comment fair pour recupérer l'identifiant de la premiere et seulement la prem Création d'un jar exécutable [ par Douniz ] Bonjour, tout d'abord j'espère que j'ai posté dans le bon forum sinon je m'en excuse, je suis un nouveau autant sur le site que dans la programmation.


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,326 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales