LoadFromStream(Stream: IIOStream);
LoadFromStream(Stream: System.IO.Stream);
Stream. Stream.
The LoadFromStream method loads the context from specified stream.
To save the context to the stream use the ILanerContext.SaveToStream method.
Executing this example requires a form containing:
A button with the Button1 identifier.
The LanerBox component.
The UiErAnalyzer component with the UiErAnalyzer1 identifier that is used as data source for LanerBox. Workbook of the time series database must be loaded to UiErAnalyzer1.
The document with the OBJ_CONTEXT identifier, that contains the saved context, must be present in repository.
Add references to the Metabase, Io, Fore system assemblies. Example is a handler of the OnClick event for the button.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Mb: IMetabase;
pContext: ILanerContext;
ContextObject, LanerObject: IMetabaseObjectDescriptor;
Stream: IIOStream;
Laner: ILaner;
Doc: IDocument;
MemStream: IMemoryStream;
Begin
Mb := MetabaseClass.Active;
// Context creation
pContext := New LanerContext.Create;
// Context loading from the stream
ContextObject := Mb.ItemById("OBJ_CONTEXT");
Doc := ContextObject.Edit As IDocument;
Stream := Doc.GetAsStream;
pContext.LoadFromStream(Stream);
// Start of workbooks loading to the context
pContext.BeginLoad;
// The first workbook loading
Laner := UiErAnalyzer1.ErAnalyzer.Laner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
// Loading the workbooks ,which the first book depends on
For Each LanerObject In Laner.Dependencies Do
Laner := LanerObject.Bind As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
End For;
// Loading the workbooks ,that depend on the first workbook
For Each LanerObject In Laner.Dependents Do
Laner := LanerObject.Bind As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner);
End If;
End For;
// Completion of the workbooks to context loading
pContext.EndLoad;
// Saving the context to stream
MemStream := New MemoryStream.Create;
pContext.SaveToStream(MemStream);
Doc.LoadFromStream(MemStream);
(Doc As IMetabaseObject).Save;
End Sub Button1OnClick;
After executing this example the context is loaded from the OBJ_CONTEXT document. After that the workbook, all the dependant books and the books the workbook depends on are added to the context. The resulting context is saved to the OBJ_CONTEXT document.
Executing this example requires a .NET form containing:
A button with the Button1 identifier.
The LanerBoxNet component.
The UiErAnalyzerNet component with the uiErAnalyzerNet1 identifier that is a data source for LanerBoxNet. Workbook of the time series database must be loaded to uiErAnalyzerNet1.
Example is a handler of the Click event for the button.
Imports Prognoz.Platform.Interop.Laner;
Imports System.IO;
Imports Prognoz.Platform.Interop.KeFore;
…
Private Sub button2_Click(sender: System.Object; e: System.EventArgs);
Var
Mb: IMetabase;
pContext: ILanerContext;
ContextObject, LanerObject: IMetabaseObjectDescriptor;
Stream: Stream;
Laner: ILaner;
Doc: IDocument;
MemStream: MemoryStream;
Begin
Mb := Self.Metabase;
// Context creation
pContext := New LanerContext.Create();
// Context loading from the stream
ContextObject := Mb.ItemById["OBJ_CONTEXT"];
Doc := ContextObject.Edit() As IDocument;
Stream := Doc.GetAsStream();
pContext.LoadFromStream(Stream);
// Start of workbooks loading to the context
pContext.BeginLoad();
// The first workbook loading
Laner := uiErAnalyzerNet1.ErAnalyzer.ErAnalyzer.Laner;
If Not Laner.IsInContext Then
pContext.Register(Laner As LanerFactory);
End If;
// Loading the workbooks ,which the first book depends on
For Each LanerObject In Laner.Dependencies Do
Laner := LanerObject.Bind() As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner As LanerFactory);
End If;
End For;
// Loading the workbooks ,that depend on the first workbook
For Each LanerObject In Laner.Dependents Do
Laner := LanerObject.Bind() As ILaner;
If Not Laner.IsInContext Then
pContext.Register(Laner As LanerFactory);
End If;
End For;
// Completion of the workbooks to context loading
pContext.EndLoad();
// Saving the context to stream
MemStream := New MemoryStream.Create();
pContext.SaveToStream(MemStream);
Doc.LoadFromStream(MemStream);
(Doc As IMetabaseObject).Save();
End Sub;
After executing this example the context is loaded from the OBJ_CONTEXT document. After that the workbook, all the dependant books and the books the workbook depends on are added to the context. The resulting context is saved to the OBJ_CONTEXT document.
See also: