ICubeAttachmentManager.SupportWriteAttachmentsByCoord

Syntax

SupportWriteAttachmentsByCoord(Coord: IMatrixModelCoord): Boolean;

Parameters

Coord. Coordinate in matrix with attachments.

Description

The SupportWriteAttachmentsByCoord method checks whether list of attachments by specified matrix coordinate with attachments can be changed.

Comments

The list of attachments can be changed, if the current coordinate contains facts binding to the field to store attachments.

The method returns True, if list of attachments can be changed and False, if list of attachments is unavailable 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, and Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    Dest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    Exec: ICubeInstanceDestinationExecutor;
    Mat: IMatrix;
    MatEx: IMatrixEx;
    Ite: IMatrixIterator;
    Coord: IMatrixCoord;
    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;
    Coord := Mat.CreateCoord;
    Coord.Item(
0) := 0;
    
//...
    //Create Coord by other dimensions
    //...
    Ite.PutCoord(Coord);
    
If Manager.SupportWriteAttachmentsByCoord(Coord) 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;

On executing the example the resulting cube matrix will be calculated and manager to work with attachments will be obtained. The iterator to navigate by matrix and coordinate in matrix will be created. Three different attachments will be created by coordinate. 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