ICubeAttachmentManager.EditAttachments

Syntax

EditAttachments(Iterator: IMatrixModelIterator): ICubeAttachmentsEdited;

EditAttachments(Iterator: Prognoz.Platform.Interop.ForeSystem.IMatrixModelIterator): Prognoz.Platform.Interop.Cubes.ICubeAttachmentsEdited;

Parameters

Iterator. Iterator of matrix with attachments.

Description

The EditAttachments method opens list of attachments for edit.

Example

Executing the example requires that the repository contains a standard cube with the STD_CUBE identifier. Facts binding is set up in cube to store attachments. Dictionary, into which attachments are saved, has additional attribute with the OBJ_KEY identifier in its structure. The cube has an integer data type, it has also attribute of link to repository object. There is data or attachments in cube by any coordinates. The document with the DOC identifier must be created in repository and the file system must contain the C:\File.txt file.

Add links to the Cubes, Dal, Dimensions, Fore, IO, Matrix, Metabase system assemblies. In Fore.NET add links to the ForeIO, ForeSystem, KeFore assemblies too.

Sub UserProc;
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    Dest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    Exec: ICubeInstanceDestinationExecutor;
    Mat: IMatrix;
    MatEx: IMatrixEx;
    Ite: IMatrixIterator;
    ExecResult: ICubeExecuteResult;
    Manager: ICubeAttachmentManager;
    Ats: ICubeAttachmentsEdited;
    At: ICubeAttachmentEdited;
    NameAttributeKey, FileNameAttributeKey, UrlAttributeKey, TimeStampKey, AttachmentKey, ObjKey: Integer;
    FStream: IFileStream;
    Doc: IMetabaseObjectDescriptor;
    Sto: ICubeInstanceStorage;
    i: integer;
Begin
    MB := MetabaseClass.Active;
    CubeInst := MB.ItemById(
"STD_CUBE").Open(NullAs ICubeInstance;
    Dest := CubeInst.Destinations.DefaultDestination;
    
//Cube selection
    Sels := Dest.CreateDimSelectionSet;
    
For Each Sel In Sels Do
        Sel.SelectAll;
    
End For;
    Exec := Dest.CreateExecutor;
    Exec.IncludeAttachments := 
True;
    Exec.PrepareExecute(Sels);
    Exec.PerformExecute;
    Mat := Exec.Matrix;
    
//Resulting cube matrix
    MatEx := Mat As IMatrixEx;
    
If MatEx.AttachmentValueIndex < 0 Then
        Debug.WriteLine(
"AttachmentValueIndex <0. Aborted ");
        
Return;
    
End If;
    ExecResult := CubeClass.ExecuteResult(Mat);
    
//Manager to work with cube attachments
    Manager := ExecResult.CreateAttachmentManager;
    
//Matrix iterator
    Mat.ValueFlag := Mat.ValueFlag + 10;
    Ite := Mat.CreateIterator;
    Ite.Move(IteratorDirection.First);
    
If Manager.SupportWriteAttachments(Ite) Then
        Ats := Manager.EditAttachments(Ite);
        NameAttributeKey := Ats.Attributes.FindById(
"NAME").Key;
        FileNameAttributeKey := Ats.Attributes.FindById(
"FILE_NAME").Key;
        UrlAttributeKey := Ats.Attributes.FindById(
"URL").Key;
        TimeStampKey := Ats.Attributes.FindById(
"TIMESTAMP").Key;
        AttachmentKey := Ats.Attributes.FindById(
"ATTACHMENT").Key;
        ObjKey := Ats.Attributes.FindById(
"OBJ_KEY").Key;
        
//Create attachments
        //File
        At := Ats.AddNew;
        FStream := 
New FileStream.Create("C:\File.txt", FileOpenMode.Read, FileShare.DenyNone);
        At.Type := CubeAttachmentType.Value;
        At.AttributeValueByKey(AttachmentKey) := FStream;
        At.AttributeValueByKey(FileNameAttributeKey) := 
"File.txt";
        At.AttributeValueByKey(NameAttributeKey) := 
"File.txt";
        At.AttributeValueByKey(TimeStampKey) := DateTime.Now;
        
//Repository document
        At := Ats.AddNew;
        Doc := MB.ItemById(
"DOC");
        At.Type := CubeAttachmentType.Document;
        At.AttributeValueByKey(ObjKey) := Doc.Key;
        At.AttributeValueByKey(FileNameAttributeKey) := (Doc.Bind 
As IDocument).FileName;
        At.AttributeValueByKey(NameAttributeKey) := Doc.Name;
        At.AttributeValueByKey(TimeStampKey) := DateTime.Now;
        
//Link
        At := Ats.AddNew;
        At.Type := CubeAttachmentType.URL;
        At.AttributeValueByKey(UrlAttributeKey) := 
"http://localhost/";
        At.AttributeValueByKey(NameAttributeKey) := 
"localhost";
        At.AttributeValueByKey(TimeStampKey) := DateTime.Now;
        
//View attachments list
        For i := 0 To Ats.Count - 1 Do
            At := Ats.Edit(i);
            Debug.WriteLine(
"Key= " + At.Key.ToString +
                
" Name = " + (At As ICubeAttachment).AttributeValueByKey(NameAttributeKey) +
                
" Type = " + (At As ICubeAttachment).Type.ToString);
        
End For;
        
//Save changes
        Manager.Post(Ite, Ats);
        Sto := Dest.CreateStorage(CubeInstanceStorageOptions.Attachments);
        Sto.AttachmentManager := Manager;
        Sto.SaveMatrix(Mat, Mat.ValueFlag);
    
End If;
End Sub UserProc;

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.KeFore;
Imports Prognoz.Platform.Interop.ForeIO;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    Dest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    Exec: ICubeInstanceDestinationExecutor;
    Mat: IMatrix;
    MatEx: IMatrixEx;
    CubeCls: CubeClassClass = 
New CubeClassClass();
    Ite: IMatrixIterator;
    ExecResult: ICubeExecuteResult;
    Manager: ICubeAttachmentManager;
    Ats: ICubeAttachmentsEdited;
    At: ICubeAttachmentEdited;
    NameAttributeKey, FileNameAttributeKey, UrlAttributeKey, TimeStampKey, AttachmentKey, ObjKey: Uinteger;
    FStream: IFileStream = 
New FileStreamClass();
    Doc: IMetabaseObjectDescriptor;
    Sto: ICubeInstanceStorage;
    i: integer;
Begin
    MB := Params.Metabase;
    CubeInst := MB.ItemById[
"STD_CUBE"].Open(NullAs ICubeInstance;
    Dest := CubeInst.Destinations.DefaultDestination;
    
//Cube selection
    Sels := Dest.CreateDimSelectionSet();
    
For Each Sel In Sels Do
        Sel.SelectAll();
    
End For;
    Exec := Dest.CreateExecutor();
    Exec.IncludeAttachments := 
True;
    Exec.PrepareExecute(Sels);
    Exec.PerformExecute(
False);
    Mat := Exec.Matrix;
    
//Resulting cube matrix
    MatEx := Mat As IMatrixEx;
    
If MatEx.AttachmentValueIndex < 0 Then
        System.Diagnostics.Debug.WriteLine(
"AttachmentValueIndex <0. Aborted ");
        
Return;
    
End If;
    ExecResult := CubeCls.ExecuteResult[Mat];
    
//Manager to work with cube attachments
    Manager := ExecResult.CreateAttachmentManager();
    
//Matrix iterator
    Mat.ValueFlag := Mat.ValueFlag + 10;
    Ite := Mat.CreateIterator();
    Ite.Move(IteratorDirection.itdFirst);
    
If Manager.SupportWriteAttachments(Ite) Then
        Ats := Manager.EditAttachments(Ite);
        NameAttributeKey := Ats.Attributes.FindById(
"NAME").Key;
        FileNameAttributeKey := Ats.Attributes.FindById(
"FILE_NAME").Key;
        UrlAttributeKey := Ats.Attributes.FindById(
"URL").Key;
        TimeStampKey := Ats.Attributes.FindById(
"TIMESTAMP").Key;
        AttachmentKey := Ats.Attributes.FindById(
"ATTACHMENT").Key;
        ObjKey := Ats.Attributes.FindById(
"OBJ_KEY").Key;
        
//Create attachments
        //File
        At := Ats.AddNew();
        FStream.Create(
"C:\File.txt", FileOpenMode.frRead, FileShare.frDenyNone);
        At.Type_2 := CubeAttachmentType.catValue;
        At.AttributeValueByKey_2[AttachmentKey] := FStream;
        At.AttributeValueByKey_2[FileNameAttributeKey] := 
"File.txt";
        At.AttributeValueByKey_2[NameAttributeKey] := 
"File.txt";
        At.AttributeValueByKey_2[TimeStampKey] := DateTime.Now;
        
//Repository document
        At := Ats.AddNew();
        Doc := MB.ItemById[
"DOC"];
        At.Type_2 := CubeAttachmentType.catDocument;
        At.AttributeValueByKey_2[ObjKey] := Doc.Key;
        At.AttributeValueByKey_2[FileNameAttributeKey] := (Doc.Bind() 
As IDocument).FileName;
        At.AttributeValueByKey_2[NameAttributeKey] := Doc.Name;
        At.AttributeValueByKey_2[TimeStampKey] := DateTime.Now;
        
//Link
        At := Ats.AddNew();
        At.Type_2 := CubeAttachmentType.catURL;
        At.AttributeValueByKey_2[UrlAttributeKey] := 
"http://localhost/";
        At.AttributeValueByKey_2[NameAttributeKey] := 
"localhost";
        At.AttributeValueByKey_2[TimeStampKey] := DateTime.Now;
        
//View attachments list
        For i := 0 To Ats.Count - 1 Do
            At := Ats.Edit(i);
            System.Diagnostics.Debug.WriteLine(
"Key= " + At.Key.ToString() +
                
" Name = " + (At As ICubeAttachment).AttributeValueByKey[NameAttributeKey] +
                
" Type = " + (At As ICubeAttachment).Type.ToString());
        
End For;
        
//Save changes
        Manager.Post(Ite, Ats);
        Sto := Dest.CreateStorage(CubeInstanceStorageOptions.cisoAttachments);
        Sto.AttachmentManager := Manager;
        Sto.SaveMatrix(Mat, Mat.ValueFlag);
    
End If;
End Sub;

On executing the example the resulting cube matrix will be calculated and manager to work with attachments will be obtained. Iterator to navigate by matrix will be created. By the first available coordinate, three different attachments will be created. The information about all attachments that are available by the coordinate will be displayed to the development environment console. After that all changes will be saved to the cube.

See also:

ICubeAttachmentManager