« ImportByFormatDef (rtl) » : différence entre les versions
m (a renommé IntegrateByFormatDef (rtl) en ImportByFormatDef (rtl)) |
Aucun résumé des modifications |
||
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 à 08:14
<source lang="delphi">Procedure IntegrateByFormatDef(const aCodeFormat:string; const aData:TStrings; aRefObject:TitObject; const aLogLevel:FormatLogLevel);</source>
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
<source lang="delphi"> //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 dimport : %s'),[e.Message])); raise; end; end else ERule.Create(Format(_TP('Le format %s na pas été trouvé.'),[vFormatCode]));
end; </source>
Voir aussi:
{{#if:Développement DSM|
{{#if:Développement DSM|— Développement DSM |}} — Développement DSM —
|
{{#if:|— [[{{{1}}}]] |}} — Développement DSM —
}}