EditAttachments(Iterator: IMatrixModelIterator): ICubeAttachmentsEdited;
Iterator. Iterator of matrix with attachments.
The EditAttachments method opens list of attachments for edit.
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;
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(Null) As 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;
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: