ImportByFormatDef (rtl)

De Wiki1000
(Différences entre les versions)
Ligne 32 : Ligne 32 :
  
 
<source lang="delphi">
 
<source lang="delphi">
 +
//Procedure _doImport;
 +
var
 +
vFormatCode : String;
 +
vFormatIntegrationFichier : TFormatIntegrationFichier;
 +
vidxRem  : Integer;
 +
vTimeOrg : LongInt;
 +
vTimeInt : LongInt;
 +
vTimeLst : LongInt;
 +
vTimeCom : LongInt;
 +
vTrackingMode : Integer;
 
begin
 
begin
 +
  // Locate the format definition
 +
  // Recherche du format en dur
 +
  vFormatCode := 'INT_VIRNAT_160';
 +
  vFormatIntegrationFichier := TFormatIntegrationFichier.Find('(code=%1)','',true,[vFormatCode]);
 +
 +
  // Set logging mode
 +
  if estVerbeux then
 +
    vTrackingMode := Format_Log_Level_Verbose
 +
  else
 +
    vTrackingMode := Format_Log_Level_None;
 +
 +
  if Assigned(vFormatIntegrationFichier) then
 +
  begin
 +
  // Start a long transaction
 +
  ClassManager.BeginLongTran(1,'TImportRemiseBancaire');
 +
  try
 +
    CreerSessionImport;
 +
 +
    // Load the source file in a TStrings
 +
    ProgressMessage(Format(_TP('Chargement du fichier %s.'),[FichierImport]));
 +
    content.LoadFromFile(FichierImport);
 +
 +
    vTimeOrg := GetTickCount;
 +
    ProgressMessage(Format(_TP('Intégration du fichier %s.'),[FichierImport]));
 +
 +
    // Import the source file here
 +
    ImportbyFormatDef(vFormatIntegrationFichier.GetFileFormatNameRef,Content.Strings,self,vTrackingMode);
 +
 +
    vTimeInt := GetTickCount;
 +
    ProgressMessage(Format(_TP('Intégration en %s ms.'),[TickToString(vTimeInt-vTimeOrg)]));
 +
 +
    //A noter que si l'on ne veut pas garder les données -: vider la liste & rollback
 +
    ProgressMessage(Format(_TP('Ajout des %s remises dans la session.'),[IntToStr(ListeRemise.Count]));
 +
    vTimeLst := GetTickCount;
 +
    for vIdxRem := 0 to ListeRemise.Count-1 do
 +
      SessionImportation.ImportDonneeList.Addref(ListeRemise.Refs[vIdxRem]);
 +
 +
    listeRemise.Clear;
 +
    ProgressMessage(Format(_TP('Liste des données créées en %s ms.'),[TickToString(vTimeLst-vTimeInt)]));
 +
    ProgressMessage(_TP('Fermeture de la transaction.'));
 +
 +
    ClassManager.CommitlongTran;
 +
    vTimeCom := GetTickCount;
 +
    ProgressMessage(Format(_TP('Clôture transaction en %s Ms, sur un total de %s Ms.'),[TickToString(vTimeCom-vTimeLst),TickToString(vTimeCom-vTimeOrg)]));
 +
  except
 +
    ClassManager.RollBacklongTran;
 +
    ProgressMessage(Format(_TP('Erreur d''import : %s'),[e.Message]));
 +
    raise;
 +
  end;
 +
end
 +
else
 +
  ERule.Create(Format(_TP('Le format %s n''a pas été trouvé.'),[vFormatCode]));
 
end;
 
end;
 
</source>
 
</source>

Version du 28 juin 2011 à 10:14

Procedure IntegrateByFormatDef(const aCodeFormat:string; const aData:TStrings; aRefObject:TitObject; const aLogLevel:FormatLogLevel);

Cette méthode permet d'importer un fichier en utilisant un format.

aCodeFormat Code du format à utiliser pour l'import.
aData Contenu du fichier à importer.
aRefObject Objet racine tous les objets qui seront créés.
aLogLevel Niveau de journalisation.

Le journal généré se situe dans répertoire [container L1000]/logs

Trois niveaux de journalisation sont possibles :

  • Format_Log_Level_None
aucune trace
  • Format_Log_Level_Data_Errors
trace les erreurs d'accès au données (formule erronée...) utile pour la mise au point des nouveaux formats
  • Format_Log_Level_Verbose
trace l'exploration du fichier / du modèle (trace importante en taille) + Format_Log_Level_Data_Errors

Exemple

//Procedure _doImport;
var
 vFormatCode : String;
 vFormatIntegrationFichier : TFormatIntegrationFichier;
 vidxRem  : Integer;
 vTimeOrg : LongInt;
 vTimeInt : LongInt;
 vTimeLst : LongInt;
 vTimeCom : LongInt;
 vTrackingMode : Integer;
begin
  // Locate the format definition
  // Recherche du format en dur
  vFormatCode := 'INT_VIRNAT_160';
  vFormatIntegrationFichier := TFormatIntegrationFichier.Find('(code=%1)','',true,[vFormatCode]);
 
  // Set logging mode
  if estVerbeux then
    vTrackingMode := Format_Log_Level_Verbose
  else
    vTrackingMode := Format_Log_Level_None;
 
  if Assigned(vFormatIntegrationFichier) then
  begin
   // Start a long transaction
   ClassManager.BeginLongTran(1,'TImportRemiseBancaire');
   try
     CreerSessionImport;
 
     // Load the source file in a TStrings
     ProgressMessage(Format(_TP('Chargement du fichier %s.'),[FichierImport]));
     content.LoadFromFile(FichierImport);
 
     vTimeOrg := GetTickCount;
     ProgressMessage(Format(_TP('Intégration du fichier %s.'),[FichierImport]));
 
     // Import the source file here
     ImportbyFormatDef(vFormatIntegrationFichier.GetFileFormatNameRef,Content.Strings,self,vTrackingMode);
 
     vTimeInt := GetTickCount;
     ProgressMessage(Format(_TP('Intégration en %s ms.'),[TickToString(vTimeInt-vTimeOrg)]));
 
     //A noter que si l'on ne veut pas garder les données -: vider la liste & rollback
     ProgressMessage(Format(_TP('Ajout des %s remises dans la session.'),[IntToStr(ListeRemise.Count]));
     vTimeLst := GetTickCount;
     for vIdxRem := 0 to ListeRemise.Count-1 do
       SessionImportation.ImportDonneeList.Addref(ListeRemise.Refs[vIdxRem]);
 
     listeRemise.Clear;
     ProgressMessage(Format(_TP('Liste des données créées en %s ms.'),[TickToString(vTimeLst-vTimeInt)]));
     ProgressMessage(_TP('Fermeture de la transaction.'));
 
     ClassManager.CommitlongTran; 
     vTimeCom := GetTickCount;
     ProgressMessage(Format(_TP('Clôture transaction en %s Ms, sur un total de %s Ms.'),[TickToString(vTimeCom-vTimeLst),TickToString(vTimeCom-vTimeOrg)]));
   except
     ClassManager.RollBacklongTran;
     ProgressMessage(Format(_TP('Erreur d''import : %s'),[e.Message]));
     raise;
   end;
 end
 else
   ERule.Create(Format(_TP('Le format %s n''a pas été trouvé.'),[vFormatCode]));
end;

Voir aussi:

Développement DSMDéveloppement DSM





Whos here now:   Members 0   Guests 0   Bots & Crawlers 1
 
Outils personnels