Accueil > > > IMPLÉMENTATION DU TYPE GUID AVEC MICROSOFT AJAX
IMPLÉMENTATION DU TYPE GUID AVEC MICROSOFT AJAX
Information sur la source
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
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Connaitre l'identifiant de session Windows [ par sebast105 ]
Bonjour tout le monde,je développe actuellement un script (JavaScript) et je souhaiterai récupérer l'identifiant avec lequel l'utilisat
ATLAS dans les gadgets [ par kerad ]
Question rapidos, j'ai pas eu le temps de vé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
|
Derniers Blogs
[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|