LoadFromStreamNF(Reader: IIOStream; Mode: UpdateLoadMode);
Reader. The stream, from which the update is loaded.
Mode. Method for loading objects to the update.
The LoadFromStreamNF method loads the update from stream.
Executing the example requires that the repository contains three different repositories. They have objects.
Add links to the IO, Metabase system assemblies.
Sub UserProc;
Var
Mb1, Mb2, Mb3: IMetabase;
Upd: WorkingWithUpdate;
Stream: IIOStream;
Begin
// ...
// Connect to three different repositories, initialize variables Mb1, Mb2, Mb3
// ...
// Create an update in the first repository
Upd.Initialize(Mb1, UpdSourceType._New);
Upd.AddObjectInUpdate(Mb1.ItemById("Obj1"));
// Save update to file
Upd.SaveToFile("D:\Upd1.pefx");
Upd.Flush;
//...
// Create an update in the second repository and restore it from file
Upd.Initialize(Mb2, UpdSourceType.File, "D:\Upd1.pefx");
Upd.AddObjectInUpdate(Mb2.ItemById("Obj2"));
// Save the obtained update to stream
Stream := Upd.AsStream;
Upd.Flush;
// ...
// Create an update in the third repository and restore it from stream
Upd.Initialize(Mb3, UpdSourceType.Stream, Stream);
Upd.AddObjectInUpdate(Mb3.ItemById("Obj3"));
// ...
// Further operations with the update
//...
Upd.Flush;
End Sub UserProc;
Enum UpdSourceType
_New = 1,
File = 2,
Stream = 3
End Enum UpdSourceType;
Class WorkingWithUpdate: Object
Shared _upd: IMetabaseUpdate;
Public Shared Sub Initialize(Mb: IMetabase; SourceType: UpdSourceType; UpdSource: Variant = Null);
Begin
// Initialize update depending on the selected acquisition method
_upd := Mb.CreateUpdate;
// Load from file or stream if such initialization type is selected
If (SourceType <> UpdSourceType._New) And Not IsNull(UpdSource) Then
Select Case SourceType
Case UpdSourceType.File:
_upd.LoadFromFileNF(UpdSource);
Case UpdSourceType.Stream:
_upd.LoadFromStreamNF(UpdSource, UpdateLoadMode.Insert);
End Select;
End If;
End Sub Initialize;
Public Shared Sub AddObjectInUpdate(RepoObject: IMetabaseObjectDescriptor);
Var
UFN: IMetabaseUpdateFolderNode;
UON: IMetabaseUpdateObjectNode;
Begin
UFN := _Upd.RootFolder;
UON := UFN.Add(MetabaseUpdateNodeType.Object) As IMetabaseUpdateObjectNode;
UON.Object := RepoObject;
UON.BoundType := MetabaseObjectUpdateBoundType.ById;
End Sub AddObjectInUpdate;
Public Shared Sub SaveToFile(FileName: String);
Begin
// Save update to file
_upd.SaveToFileNF(FileName);
End Sub SaveToFile;
Public Shared Function AsStream: IIOStream;
Var
Result: IIOStream;
Begin
Result := New MemoryStream.Create;
// Save update to stream
_upd.SaveToStreamNF(Result, Null);
Return Result;
End Function AsStream;
Public Shared Sub Flush;
Begin
// Clear update
_upd := Null;
End Sub Flush;
End Class WorkingWithUpdate;
Generally, the specified example displays how one common class can be used to work with the update in three different repositories. A new update is created in the first repository, the update is opened from file in the second repository, the update is loaded from stream in the third repository. One object from each repository is added to the update at each stage.
See also: