CustomLinker: IMsDimCustomLinker;
CustomLinker: Prognoz.Platform.Interop.Ms.IMsDimCustomLinker;
The CustomLinker property determines the custom dimension linking mechanism
The custom mechanism must be implemented as a class that inherits all methods from IMsDimCustomLinker.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a modeling problem with the PROBLEM_MULTIDIMITERATOR identifier. This problem must calculate a metamodel containing only multidimensional iterator. The repository must also contain a time series database with the TSDB_STAT identifier containing the INDICATOR attribute that is a link to the dictionary.
Add links to the Cubes, Dimensions, Metabase, Ms, Rds system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
Problem: IMsProblem;
MM: IMsMetaModel;
Iterator: IMsCalculationChainMultiDimIterator;
IterDim: IMsDimIteratorDimension;
Links: IMsDimIteratorLinks;
DSLinked: IRubricator;
Attributes: IMetaAttributes;
dimLinked: IDimInstance;
IDimLink: IMsDimIteratorLink;
ml: MLinker;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace("PROBLEM_MULTIDIMITERATOR", MsKey).Bind As IMsProblem;
// Get metamodel calculated by the problem
MM := Problem.EditMetaModel;
// Get multidimensional iterator
Iterator := MM.CalculationChain.Item(0) As IMsCalculationChainMultiDimIterator;
// Get links iterator's first dimension
IterDim := Iterator.Dimensions.Item(0);
Links := IterDim.Links;
// Remove existing links
Links.Clear;
// Get the TSDB_STAT time series database
DSLinked := mb.ItemById("TSDB_STAT").Bind As IRubricator;
// Get dictionary on which the INDICATOR attribute is based
Attributes := DSLinked.Facts.Attributes;
dimLinked := Attributes.FindById("INDICATOR").ValuesObject.Open(Null) As IDimInstance;
// Add dictionary as a related dictionary
IDimLink := Links.Add(dimLinked);
// Determine data source of related dimension
IDimLink.Dimension.Stubs.Add(DSLinked As IVariableStub);
// Specify consumer attribute
IDimLink.DestinationAttribute := dimLinked.Attributes.FindById("NAME").Attribute;
// Display name of controlling dimension in the console window
Debug.WriteLine("Controlling dimension: " + IDimLink.Owner.Name);
// Create custom mechanism of dimension linking
ml := New MLinker.Create;
Links.CustomLinker := ml;
// Create problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings;
Calculation := Problem.Calculate(CalcSettings);
// Perform calculation
Calculation.Run;
End Sub UserProc;
// Class that implements custom linking mechanism
Public Class MLinker: Object, IMsDimCustomLinker
Public Function ResolveLink(Source: IMsDimIteratorDimension; Destination: IMsDimIteratorDimension;
CurrentSelection: IDimSelectionSet; Var SkipCustomLink: boolean): integer;
Var
i: Integer;
Begin
SkipCustomLink := False;
Debug.WriteLine("Data source: " + Source.Name);
Debug.WriteLine("Data consumer: " + Destination.Name);
Debug.WriteLine("Selection:");
Debug.Indent;
For i := 0 To CurrentSelection.Count - 1 Do
Debug.Write(CurrentSelection.Item(i).Dimension.Name + ": ");
Debug.WriteLine(CurrentSelection.Item(i).ToString);
End For;
Debug.Unindent;
Return 1;
End Function ResolveLink;
End Class MLinker;
After executing the example a custom linking mechanism is applied to the multidimensional iterator. The console window displays information about linked dictionaries.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Rds;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
Problem: IMsProblem;
MM: IMsMetaModel;
Iterator: IMsCalculationChainMultiDimIterator;
IterDim: IMsDimIteratorDimension;
Links: IMsDimIteratorLinks;
DSLinked: IRubricator;
Attributes: IMetaAttributes;
dimLinked: IDimInstance;
IDimLink: IMsDimIteratorLink;
ml: MLinker;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
Begin
// Get current repository
mb := Params.Metabase;
// Get modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace["PROBLEM_MULTIDIMITERATOR", MsKey].Bind() As IMsProblem;
// Get metamodel calculated by the problem
MM := Problem.EditMetaModel;
// Get multidimensional iterator
Iterator := MM.CalculationChain.Item[0] As IMsCalculationChainMultiDimIterator;
// Get links iterator's first dimension
IterDim := Iterator.Dimensions.Item[0];
Links := IterDim.Links;
// Remove existing links
Links.Clear();
// Get the TSDB_STAT time series database
DSLinked := mb.ItemById["TSDB_STAT"].Bind() As IRubricator;
// Get dictionary on which the INDICATOR attribute is based
Attributes := DSLinked.Facts.Attributes;
dimLinked := Attributes.FindById("INDICATOR").ValuesObject.Open(Null) As IDimInstance;
// Add dictionary as a related dictionary
IDimLink := Links.Add(dimLinked);
// Determine data source of related dimension
IDimLink.Dimension.Stubs.Add(DSLinked As IVariableStub);
// Specify consumer attribute
IDimLink.DestinationAttribute := dimLinked.Attributes.FindById("NAME").Attribute;
// Display name of controlling dimension in the console window
System.Diagnostics.Debug.WriteLine("Controlling dimension: " + IDimLink.Owner.Name);
// Create custom mechanism of dimension linking
ml := New MLinker.Create();
Links.CustomLinker := ml;
// Create problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings();
Calculation := Problem.Calculate(CalcSettings);
// Perform calculation
Calculation.Run();
End Sub;
…
// Class that implements custom linking mechanism
Public Class MLinker: Object, IMsDimCustomLinker
Public Function ResolveLink(Source: IMsDimIteratorDimension; Destination: IMsDimIteratorDimension;
CurrentSelection: IDimSelectionSet; Var SkipCustomLink: boolean): System.UInt32;
Var
i: Integer;
Begin
SkipCustomLink := False;
System.Diagnostics.Debug.WriteLine("Data source: " + Source.Name);
System.Diagnostics.Debug.WriteLine("Data consumer: " + Destination.Name);
System.Diagnostics.Debug.WriteLine("Selection:");
System.Diagnostics.Debug.Indent();
For i := 0 To CurrentSelection.Count - 1 Do
System.Diagnostics.Debug.Write(CurrentSelection.Item[i].Dimension.Name + ": ");
System.Diagnostics.Debug.WriteLine(CurrentSelection.Item[i].ToString("", ",", False));
End For;
System.Diagnostics.Debug.Unindent();
Return 1;
End Function ResolveLink;
End Class MLinker;
See also: