Export and Import of a Table MDM Dictionary in Fore.NET

Export and import schemes are child objects of a table MDM dictionary. The Fore language can be used to set up:

Example Description

Executing the example requires that the repository contains an MDM repository with the RDS identifier. This repository must contain a table MDM dictionary with the D_EXP_IMP identifier.

The example also requires a .NET form that contains:

Add links to the following namespaces:

Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Rds;

Clicking the Export button exports elements of the D_EXP_IMP dictionary to the text file C:\Data_out.txt. Export options are defined as follows:

Clicking the Import button imports data from the text file C:\Data_out.txt to the D_EXP_IMP dictionary.

Example execution order:

Result: after running export an import procedure the D_EXP_IMP dictionary will contain only first level elements.

Data Export Procedure

This procedure is a handler of the Click event for the ExpButton button.

Private Sub ExpButton_Click(sender: System.Object; e: System.EventArgs);
Var
    mb: IMetabase;
    rdsKey: uinteger;
    dictObj: IMetabaseObject;
    Dict: IRdsDictionary;
    sExport: IMetaRdsExportSchema;
    i: Integer;
    dictAts: IRdsAttributes;
    Attr: IRdsAttribute;
    attrMap: IRdsExportSchemaAttribute;
    dictSort: IRdsSortAttributes;
    dictFilter: IRdsDictionaryFilterConditions;
    Cond: IRdsDictionaryFilterCondition;
    textCons: IDtTextConsumer;
    dictInst: IRdsDictionaryInstance;
Begin
    mb := self.Metabase;
    // Get key of the MDM repository
    rdsKey := mb.GetObjectKeyById("RDS_70");
    // Get table MDM dictionary
    dictObj := mb.ItemByIdNamespace["D_EXP_IMP", rdsKey].Edit();
    Dict := dictObj As IRdsDictionary;
    // Create a new export scheme
    sExport := Dict.ExportSchemas.Add() As IMetaRdsExportSchema;
    // Bind dictionary attributes to the consumer fields
    dictAts := Dict.Attributes;
    For i := 0 To dictAts.Count - 1 Do
        Attr := dictAts.Item[i];
        attrMap := sExport.AddMapping();
        attrMap.Attribute := Attr;
        attrMap.FieldName := Attr.Id;
    End For;
    // Indicate, that the consumer must be cleared before export
    sExport.ClearBeforeExport := True;
    // Set sorting by the NAME attribute
    dictSort := sExport.SortAttributes;
    Attr := dictAts.FindById("NAME");
    dictSort.Add(Attr, True);
    // Add a filter: only first level elements are exported
    dictFilter := sExport.Filter;
    Attr := dictAts.FindById("PARENT_KEY");
    Cond := dictFilter.Add(Attr);
    Cond.Value := Null;
    Cond.Operation := RdsConditionOperation.rcoEqual;
    // Set up data consumer: text file
    textCons := New DtTextConsumer.Create();
    textCons.File := "c:\Data_out.txt";
    textCons.WriteHeader := True;
    textCons.DelimitedTextQualifier := "'";
    sExport.Consumer := textCons;
    // Save the dictionary
    dictObj.Save();
    // Export execution
    dictInst := dictObj.Open(NullAs IRdsDictionaryInstance;
    dictInst.ExportData(sExport);
End Sub;

After executing the procedure, the text file C:\Data_out.txt contains first level elements of the D_EXP_IMP dictionary, sorted by value of the NAME attribute.

Data Import Procedure

This procedure is a handler of the Click event for the ImpButton button.

Private Sub ImpButton_Click(sender: System.Object; e: System.EventArgs);
Var
    mb: IMetabase;
    rdsKey: uinteger;
    dictObj: IMetabaseObject;
    Dict: IRdsDictionary;
    sImport: IMetaRdsImportSchema;
    i: Integer;
    dictAts: IRdsAttributes;
    Attr: IRdsAttribute;
    attrMap: IRdsImportSchemaAttribute;
    textProv: IDtTextProvider;
    dictInst: IRdsDictionaryInstance;
Begin
    mb := self.Metabase;
    // Get key of the MDM repository
    rdsKey := mb.GetObjectKeyById("RDS_70");
    // Get table MDM dictionary
    dictObj := mb.ItemByIdNamespace["D_EXP_IMP", rdsKey].Edit();
    Dict := dictObj As IRdsDictionary;
    // Create a new import scheme
    sImport := Dict.ImportSchemas.Add() As IMetaRdsImportSchema;
    // Bind dictionary attributes to the provider fields
    dictAts := Dict.Attributes;
    For i := 0 To dictAts.Count - 1 Do
        Attr := dictAts.Item[i];
        attrMap := sImport.Mappings[Attr];
        attrMap.Attribute := Attr;
        attrMap.FieldName := Attr.Id;
    End For;
    // Specify import mode
    sImport.Mode := UpdateLoadMode.ulmReplace;
    // Set up data provider: text file
    textProv := New DtTextProvider.Create();
    textProv.File := "c:\Data_out.txt";
    textProv.RangeHasHeader := True;
    textProv.HeaderRow := 0;
    //textProv.RowDelimiter := "\r" + "\n";
    //textProv.DelimitedColumnDelimiter := "\t";
    textProv.DelimitedTextQualifier := "'";
    sImport.Source := textProv;
    // Save the dictionary
    dictObj.Save();
    // Run import
    dictInst := dictObj.Open(NullAs IRdsDictionaryInstance;
    dictInst.ImportData(sImport);
End Sub;

After executing the example data stored in the text file C:\Data_out.txt is imported to the D_EXP_IMP dictionary.

See also:

Examples