// --------------------------- Cube Section --------------------------- // /// <summary> /// Calculates the number of cubes on this server /// </summary> /// <returns>Number of cubes on this server</returns> public int GetNumberOfCubes() { int viCubeCount = TM1API.TM1ObjectListCountGet(pool.handle, this.handle, TM1API.TM1ServerCubes()); int number = TM1API.TM1ValIndexGet(user.handle, viCubeCount); return(number); }
/// <summary> /// Calculates the number of Dimensions in the cube /// </summary> /// <returns>Number of dimensions in this cube</returns> public int getNumberOfDimensions() { int viDimCount = TM1API.TM1ObjectListCountGet(this.pool.handle, this.handle, TM1API.TM1CubeDimensions()); int number = TM1API.TM1ValIndexGet(server.user.handle, viDimCount); return(number); }
public Cube(Pool pool, Server server, Int32 handle) { this.pool = pool; this.server = server; this.handle = handle; int nameProp = TM1API.TM1ObjectPropertyGet(pool.handle, handle, TM1API.TM1ObjectName()); // WORKS!!!!!! this.name = TM1API.intPtrToString(server.user.handle, nameProp); dimensions = new List <Dimension>(); setDimensions(); }
public Server(Pool pool, string name, string client, string password) { this.pool = pool; this.user = pool.hUser; this.name = name; this.client = client; this.vServerName = TM1API.TM1ValString(pool.handle, name.Trim(), 0); this.vClientName = TM1API.TM1ValString(pool.handle, client.Trim(), 0); this.vPassword = TM1API.TM1ValString(pool.handle, password.Trim(), 0); cubes = new List <Cube>(); dimensions = new List <Dimension>(); }
//public TM1Type type { private set; get; } public Element(Pool pool, Server server, Int32 handle) { this.pool = pool; this.server = server; this.handle = handle; //this.TYPECONSOLIDATED = TM1API.TM1TypeElementConsolidated(); int nameProp = TM1API.TM1ObjectPropertyGet(this.pool.handle, this.handle, TM1API.TM1ObjectName()); // WORKS!!!!!! this.name = TM1API.intPtrToString(server.user.handle, nameProp); this.attributes = new List <Model.Attribute>(); setAttributes(); }
/// <summary> /// Iterates over all dimensions in this server /// and stores them in the dimensions List /// </summary> public void SetDimensions() { for (int i = 1; i <= GetNumberOfDimensions(); i++) { int hDim = TM1API.TM1ObjectListHandleByIndexGet(this.pool.handle, this.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValIndex(this.pool.handle, i)); if (TM1API.IsError(user.handle, hDim)) { throw new Exception(); } Dimension dim = new Dimension(this.pool, this, hDim); dimensions.Add(dim); } }
/// <summary> /// Iterates over all cubes on this server /// and stores them in the cubes List /// </summary> public void SetCubes() { for (int i = 1; i <= GetNumberOfCubes(); i++) { int hCube = TM1API.TM1ObjectListHandleByIndexGet(this.pool.handle, this.handle, TM1API.TM1ServerCubes(), TM1API.TM1ValIndex(this.pool.handle, i)); if (TM1API.IsError(user.handle, hCube)) { throw new Exception(); } Cube cube = new Cube(this.pool, this, hCube); cubes.Add(cube); } }
/// <summary> /// Connects the server to the database and sets the handle /// </summary> public int Connect() { this.handle = TM1API.TM1SystemServerConnect(pool.handle, vServerName, vClientName, vPassword); if (TM1API.IsError(this.user.handle, this.handle)) { throw new ServerConnectionException(); } /// if necessary cubes and dimensions can be stored /// SetDimensions(); SetCubes();// /// ---------------------------------------------- /// return(this.handle); }
/// <summary> /// Iterates over all dimensions in this cube /// and stores them in the dimensions List /// </summary> public void setDimensions() { int nOfDims = getNumberOfDimensions(); for (int i = 1; i <= nOfDims; i++) { int hDim = TM1API.TM1ObjectListHandleByIndexGet(this.pool.handle, this.handle, TM1API.TM1CubeDimensions(), TM1API.TM1ValIndex(this.pool.handle, i)); //if (TM1API.IsError(this.server.user.handle, hDim)) // throw new Exception(); //int nameProp = TM1API.TM1ObjectPropertyGet(pool.handle, hDim, TM1API.TM1ObjectName()); // WORKS!!!!!! //string dimName = TM1API.intPtrToString(server.user.handle, nameProp); dimensions.Add(new Dimension(pool, server, hDim)); } }
/// <summary> /// Searches the servers cubes list for the cube with the given name /// </summary> /// <param name="name">Cube name to search for</param> /// <returns>The first found cube with the given name</returns> public Cube GetCubeByName(string name) { Cube cube = this.cubes.Find(x => x.name.Equals(name)); if (cube == null) { int hCube = TM1API.TM1ObjectListHandleByNameGet(this.pool.handle, this.handle, TM1API.TM1ServerCubes(), TM1API.TM1ValString(this.pool.handle, name, 100)); if (TM1API.IsError(user.handle, hCube)) { throw new Cube.NoSuchCubeException(); } cube = new Cube(this.pool, this, hCube); } return(cube); }
/// <summary> /// best practice shut down: disco-->destroy-->close-->finalize /// </summary> public static void Kill() { if (instance != null) { TM1API.TM1SystemServerDisconnect(mainPool.handle, server.handle); TM1API.TM1ValPoolDestroy(mainPool.handle); TM1API.TM1SystemClose(hUser.handle); TM1API.TM1APIFinalize(); //adminHost = null; //hUser = null; //server = null; //docCube = null; //docServer = null; //mainPool = null; //isConnected = false; instance = null; } }
public void setElements() { int nOfElements = getNumberOfElements(); for (int i = 1; i <= nOfElements; i++) { int hElement = TM1API.TM1ObjectListHandleByIndexGet(this.pool.handle, this.handle, TM1API.TM1DimensionElements(), TM1API.TM1ValIndex(this.pool.handle, i)); if (TM1API.IsError(this.server.user.handle, hElement)) { throw new NoSuchElementException(); } int nameProp = TM1API.TM1ObjectPropertyGet(pool.handle, hElement, TM1API.TM1ObjectName()); // WORKS!!!!!! string elementName = TM1API.intPtrToString(server.user.handle, nameProp); Element element = new Element(this.pool, this.server, hElement); elements.Add(element); } }
/// <summary> /// initializes the TM1API and sets the Tools object if not present /// by default the Admin Host is localhost /// </summary> /// <remarks>sets the hUser handle</remarks> /// <returns>an instance of Tools</returns> public static Tools Init(string host) { if (instance == null || !adminHost.Equals(host)) { if (isConnected) { Kill(); } instance = new Tools(); adminHost = host; isConnected = false; TM1API.TM1APIInitialize(); hUser = new User(TM1API.TM1SystemOpen()); TM1API.TM1SystemAdminHostSet(hUser.handle, adminHost); mainPool = CreatePool(); } return(instance); }
/// <summary> /// Reads the given documentation cube on the server and creates a model for it /// </summary> /// <param name="docCube">The documentation cube, should be "}gmc2_server_documentation", change in the caller method/class if not</param> /// <param name="timestampPos">Position of the desired timestamp in the "}gmc2_server_documentation_timestamp" dimension, 0 = last timestamp</param> /// <param name="tm1server">Position of the desired tm1server in the "}tm1server" dimension, 0 = last tm1server</param> public DocumentationServer(Cube docCube, int timestampPos, int tm1server) { cubes = new List <DocCube>(); dimensions = new HashSet <DocDimension>(); look_ups = new Dictionary <string, List <string> >(); feeder = new Dictionary <string, List <string> >(); this.name = docCube.dimensions[1].elements[tm1server].ToString(); this.docCube = docCube; this.timestamp = timestampPos; this.tm1server = tm1server; // timestamp Dim... hDim_timestamp = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[0].ToString(), 100)); vDim_timestamp = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_timestamp, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[0].elements[timestamp].ToString(), 100)); // ... and server Dim are given hDim_tm1server = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[1].ToString(), 100)); vDim_tm1server = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_tm1server, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[1].elements[tm1server].ToString(), 100)); SetCubes(); SetLookFeed(); }
public Pool(User hUser) { this.hUser = hUser; this.handle = TM1API.TM1ValPoolCreate(hUser.handle); }
public static bool IsOK(Int32 handle) { return(!TM1API.IsError(hUser.handle, handle)); }
public int getNumberOfElements() { int hNOfElements = TM1API.TM1ObjectListCountGet(pool.handle, this.handle, TM1API.TM1DimensionElements()); return(TM1API.TM1ValIndexGet(server.user.handle, hNOfElements)); }
/// <summary> /// Sets the Admin Host Server for this hUser handle /// </summary> /// <param name="host">name of the Admin Host Server</param> public void SetAdminHost(string host) { TM1API.TM1SystemAdminHostSet(hUser.handle, host); }
public int getNumberOfAttributes() { int hNOfAttributes = TM1API.TM1ObjectListCountGet(pool.handle, this.handle, TM1API.TM1ElementComponents()); return(TM1API.TM1ValIndexGet(server.user.handle, hNOfAttributes)); }
private void SetCubes() { // Dimension object auf Cube gesetzt hDim_tm1object = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[2].ToString(), 100)); vDim_tm1object = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_tm1object, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[2].elements[TM1OBJECT_CUBE].ToString(), 100)); for (int i = 0; i < docCube.dimensions[3].elements.Count; i++) { hDim_item_name = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_name = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_name, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_name", 100)); hDim_item_nof_dims = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_nof_dims = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_dims, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_number_of_dimensions", 100)); hDim_item_nof_look = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_nof_look = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_look, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_number_of_lookup_cubes", 100)); hDim_item_list_of_look = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_list_of_look = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_look, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_list_of_lookup_cubes", 100)); hDim_item_nof_fed = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_nof_fed = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_fed, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_number_of_fed_cubes", 100)); hDim_item_list_of_feed = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_list_of_feed = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_look, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_list_of_fed_cubes", 100)); hDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].ToString(), 100)); vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[0].ToString(), 100)); hDim_list = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[3].ToString(), 100)); vDim_list = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_list, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[3].elements[i].ToString(), 100)); int[] elements_name = { vDim_timestamp, vDim_tm1server, vDim_tm1object, vDim_list, vDim_item_name, vDim_measure }; vArrayOfCells = TM1API.TM1ValArray(docCube.server.pool.handle, ref elements_name, 6); TM1API.TM1ValArraySet(vArrayOfCells, vDim_timestamp, 1); TM1API.TM1ValArraySet(vArrayOfCells, vDim_tm1server, 2); TM1API.TM1ValArraySet(vArrayOfCells, vDim_tm1object, 3); TM1API.TM1ValArraySet(vArrayOfCells, vDim_list, 4); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_name, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_name = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); cube_name = TM1API.intPtrToString(docCube.server.user.handle, value_name); // am Ende der Cubes angekommen if (cube_name.Equals("")) { break; } // ---------------------------------- List Dimensions ---------------------------------- // TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_nof_dims, 5); value_nof_dims = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); nof_dims = Int32.Parse(TM1API.intPtrToString(docCube.server.user.handle, value_nof_dims)); List <DocDimension> list_dims = new List <DocDimension>(); hDim_item_dim_name = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[4].ToString(), 100)); vDim_item_dim_name = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_item_nof_dims, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, "cube_list_of_dimensions", 100)); hDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, docCube.server.handle, TM1API.TM1ServerDimensions(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].ToString(), 100)); // get the dims for (int k = 1; k <= nof_dims; k++) { vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[k].ToString(), 100)); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_dim_name, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_dim_name = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); dim_name = TM1API.intPtrToString(docCube.server.user.handle, value_dim_name); DocDimension dim = new DocDimension(dim_name); dimensions.Add(dim); list_dims.Add(dimensions.First(x => x.name.Equals(dim_name))); } // ---------------------------------- List Look Up ---------------------------------- // vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[0].ToString(), 100)); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_nof_look, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_nof_look = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); // check if look_up cubes exist try { nof_look = Int32.Parse(TM1API.intPtrToString(docCube.server.user.handle, value_nof_look)); List <string> list_look_up_cubes = new List <string>(); for (int k = 1; k <= nof_look; k++) { int value_look_up_dim_name; string look_up_dim_name; vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[k].ToString(), 100)); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_list_of_look, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_look_up_dim_name = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); look_up_dim_name = TM1API.intPtrToString(docCube.server.user.handle, value_look_up_dim_name); list_look_up_cubes.Add(look_up_dim_name); } look_ups.Add(cube_name, list_look_up_cubes); } // if not set nof look_up cubes to -1 catch (System.FormatException) { nof_look = -1; } // ---------------------------------- List Feeder ---------------------------------- // vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[0].ToString(), 100)); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_nof_fed, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_nof_fed = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); // check if feeder cubes exist try { nof_fed = Int32.Parse(TM1API.intPtrToString(docCube.server.user.handle, value_nof_fed)); List <string> list_feeder_cubes = new List <string>(); for (int k = 1; k <= nof_fed; k++) { int value_feeder_dim_name; string feeder_dim_name; vDim_measure = TM1API.TM1ObjectListHandleByNameGet(docCube.server.pool.handle, hDim_measure, TM1API.TM1DimensionElements(), TM1API.TM1ValString(docCube.server.pool.handle, docCube.dimensions[5].elements[k].ToString(), 100)); TM1API.TM1ValArraySet(vArrayOfCells, vDim_item_list_of_feed, 5); TM1API.TM1ValArraySet(vArrayOfCells, vDim_measure, 6); value_feeder_dim_name = TM1API.TM1CubeCellValueGet(docCube.server.pool.handle, docCube.handle, vArrayOfCells); feeder_dim_name = TM1API.intPtrToString(docCube.server.user.handle, value_feeder_dim_name); list_feeder_cubes.Add(feeder_dim_name); } feeder.Add(cube_name, list_feeder_cubes); } // if not set nof look_up cubes to -1 catch (System.FormatException) { nof_fed = -1; } // -------------------------------------------------------------- // DocCube cube = new DocCube(i + 1, cube_name, nof_dims, list_dims); cube.nof_look = nof_look; cube.nof_fed = nof_fed; cubes.Add(cube); } }