ICustomObjectResolver.WriteFromStream

Fore Syntax

WriteFromStream(Stream: IIOStream);

Fore.NET Syntax

WriteFromStream(Stream: System.IO.Stream);

Parameters

Stream. The stream, from which data for write is obtained.

Description

The WriteFromStream method writes data to custom object from the stream.

Comments

To read data from the custom object to the stream, use the ICustomObjectResolver.ReadToStream method.

Fore Example

Executing the example requires that the file system contains the C:\CustomObjData.pefx update file. This file must contain a custom object, in which any data is written. It is also required to have the C:\From.txt text file containing data that must be written to custom object.

Add links to the IO, Metabase system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    Update: IMetabaseUpdate;
    Progress: MyUpdateProgress;
Begin
    // Get current repository
    Mb := MetabaseClass.Active;
    // Create an update
    Update := Mb.CreateUpdate;
    // Load update parameters from file
    Update.LoadFromFileNF("C:\CustomObjData.pefx");
    // Create an object that implements events that occur during update
    Progress := New MyUpdateProgress.Create;
    // Perform update
    Update.ApplyEx(Progress, Null);
End Sub UserProc;

// Class that implements events that occur during update
Class MyUpdateProgress: UpdateProgress
    // Event that occurs after applying custom object update,
    // but before it is saved to repository
    Sub OnAfterApplyCustomObject(Resolver: ICustomObjectResolver);
    Var
        StreamR, StreamW: IFileStream;
    Begin
        // Create a stream related with the text file C:\To.txt
        StreamR := New FileStream.Create("C:\To.txt", FileOpenMode.Create, FileShare.DenyNone);
        // Read data from custom object to the stream related with file
        Resolver.ReadToStream(StreamR);
        // Create a stream related with the text file C:\From.txt
        StreamW := New FileStream.Create("C:\From.txt", FileOpenMode.Read, FileShare.DenyNone);
        // Write data to custom object from the stream related with files
        Resolver.WriteFromStream(StreamW);
    End Sub OnAfterApplyCustomObject;
    
End Class MyUpdateProgress;

After executing the example the C:\CustomObjData.pefx update is applied. Use the stream to load data from the custom object in the update to the C:\To.txt file, and data from the C:\From.txt file is written to the object.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Public Shared Sub Main(Params: StartParams);
Var
    Mb: IMetabase;
    Update: IMetabaseUpdate;
    Progress: MyUpdateProgress;
Begin
    // Get current repository
    Mb := Params.Metabase;
    // Create an update
    Update := Mb.CreateUpdate();
    // Load update parameters from file
    Update.LoadFromFileNF("C:\CustomObjData.pefx", UpdateLoadMode.ulmReplace);
    // Create an object that implements events that occur during update
    Progress := New MyUpdateProgress.Create();
    // Perform update
    Update.ApplyEx(Progress, Null);
End Sub;

// Class that implements events that occur during update
Public Class MyUpdateProgress: IMetabaseUpdateProgress
    // Event that occurs after applying custom object update,
    // but before it is saved to repository
    Sub OnAfterApplyCustomObject(Resolver: ICustomObjectResolver);
    Var
        StreamR, StreamW: IFileStream;
    Begin
        // Create a stream related with the text file C:\To.txt
        StreamR := New FileStream.Create();
        StreamR.Create("C:\To.txt", FileOpenMode.frCreate, FileShare.frDenyNone);
        // Read data from custom object to the stream related with file
        Resolver.ReadToStream(StreamR As System.IO.Stream);
        // Create a stream related with the text file C:\From.txt
        StreamW := New FileStream.Create();
        StreamW.Create("C:\From.txt", FileOpenMode.frRead, FileShare.frDenyNone);
        // Write data to custom object from the stream related with files
        Resolver.WriteFromStream(StreamW As System.IO.Stream);
    End Sub OnAfterApplyCustomObject;
    
    Public Sub OnProgress(Data: IMetabaseUpdateProgressData);
    Begin
    End Sub;
    
    Public Sub OnError(Data: IMetabaseUpdateProgressData; Var Ignore: Boolean);
    Begin
    End Sub;
    
    Public Sub OnAskConstraintsHandling(Node: IMetabaseUpdateNode; Details: String; Var Handling: UpdateDataConstraintsHandlingType);
    Begin
    End Sub;
    
    Public Sub OnAskReflectRights(Var Cancel: Boolean);
    Begin
    End Sub;
    
    Public Sub OnContext(Context: IMetabaseUpdateContext);
    Begin
    End Sub;
    
    Public Sub OnResolve(Node: IMetabaseUpdateNode; Resolver: IMetabaseUpdateResolver);
    Begin
    End Sub;
    
    Public Sub OnSkip(Data: IMetabaseUpdateProgressData);
    Begin
    End Sub;
    
    Public Sub OnNullLinks(Node: IMetabaseUpdateNode; Links: IMetabaseUpdateNullLinks);
    Begin
    End Sub;
    
    Public Sub OnBeforeCustomObjectSaveToPef(Resolver: ICustomObjectResolver);
    Begin
    End Sub;
End Class MyUpdateProgress;

See also:

ICustomObjectResolver