private void Load() { if (Invalid) { IsInitialized = false; } if (!IsInitialized) { Collection = new System.Collections.Generic.List <OlapCube>(0); _accessCollection = new System.Collections.Generic.Dictionary <string, int>(); System.Collections.Specialized.StringCollection cubeNames = NativeOlapApi.Cubes(_server.Store.ClientSlot, _server.ServerHandle, _server.LastErrorInternal); if (cubeNames != null) { for (int i = 0; i < cubeNames.Count; i++) { string cubename = cubeNames[i]; Collection.Add(new OlapCube(_server, cubename, _server.ServerHandle)); _accessCollection.Add(cubename.ToUpper(), i); } } else { if (_server.LastErrorInternal.Value != 0) { throw new OlapException("Receiving the cubes collection failed!", _server.LastErrorInternal.Value); } } Invalid = false; IsInitialized = true; } }
/// <summary> /// Deletes the comment of a cell of the cube. /// </summary> /// <param name="firstElement">The first element name.</param> /// <param name="secondElement">The second element name.</param> /// <param name="elements">A variable list of additional dimension elements that reference the cell.</param> /// <returns>True, if the comment has been deleted or false, otherwise.</returns> public bool DeleteCellComment(string firstElement, string secondElement, params string[] elements) { if (Dimensions == null) { return(false); } System.Collections.Specialized.StringCollection elementNames = new System.Collections.Specialized.StringCollection(); elementNames.Add(firstElement); elementNames.Add(secondElement); if (elements != null) { for (int i = 0; i < elements.Length; i++) { elementNames.Add(elements[i]); } } if (_dimensions.Count != elementNames.Count) { throw new System.ArgumentException(CreateExceptionString(_elementMismatch)); } bool result = NativeOlapApi.CubeDeleteCellComment(_server.Store.ClientSlot, _serverHandle, _name, elementNames, _server.LastErrorInternal); elementNames = null; return(result); }
private void Load() { if (Invalid) { IsInitialized = false; } if (!IsInitialized) { Collection = new System.Collections.Generic.List <OlapAttributeTable>(0); System.Collections.ArrayList attributeTables = NativeOlapApi.AttributeTables(_dimension.Server.Store.ClientSlot, _dimension.Server.ServerHandle, _dimension.Name, _dimension.Server.LastErrorInternal); if (attributeTables != null) { for (int i = 0; i < attributeTables.Count; i++) { OlapAttributeTableDefintion tableDef = (OlapAttributeTableDefintion)attributeTables[i]; Collection.Add(new OlapAttributeTable(_dimension, tableDef.Name, tableDef.Id, tableDef.FieldCount, tableDef.RecordCount)); } } else { if (_dimension.Server.LastErrorInternal.Value != 0) { throw new OlapException("Receiving the attribute table collection failed!", _dimension.Server.LastErrorInternal.Value); } } Invalid = false; IsInitialized = true; } }
/// <summary> /// Deactivates the data area on the specified cube on the Olap server. /// </summary> public void Deactivate() { if (_isActivated) { NativeOlapApi.DataAreaDestroy(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _parameters, _cube.Server.DataAreaActive, _cube.Server.LastErrorInternal); _isActivated = false; } }
/// <summary> /// Establishes a connection to the server. /// </summary> /// <param name="userName">The user name used to connect.</param> /// <param name="password">The password used to connect.</param> public void Connect(string userName, string password) { _serverHandle = NativeOlapApi.ServerConnect(_store.ClientSlot, _name, userName, password, _lastError); if (_serverHandle == 0) { throw new OlapException("Server connect failed!", _lastError.Value); } }
/// <summary> /// Establishes a connection to the server using a COS ticket. /// </summary> /// <param name="ticket">The COS ticket to use.</param> public void ConnectTicket(string ticket) { _serverHandle = NativeOlapApi.ServerConnect(_store.ClientSlot, _name, ticket, _lastError); if (_serverHandle == 0) { throw new OlapException("Server connect failed!", _lastError.Value); } }
/// <summary> /// Disconnects from the server. /// </summary> /// <returns>True, if disconnected; false, otherwise.</returns> public bool Disconnect() { bool result = NativeOlapApi.ServerDisconnect(_store.ClientSlot, _serverHandle, _lastError); _serverHandle = 0; _cubes = null; _dimensions = null; _settings = null; return(result); }
/// <summary> /// Initializes a new instance of the OlapStore class. /// </summary> /// <param name="userName">A user name to establish the client connection.</param> public OlapStore(string userName) { IntPointer lastError = new IntPointer(); _clientSlot = NativeOlapApi.ClientConnect(userName, lastError); if (_clientSlot == 0) { throw new OlapException("Client connect failed!", lastError.Value); } }
/// <summary> /// Converts a double into a string using a unique formatting provided by the OLAP server. /// </summary> /// <param name="number">The number to convert.</param> /// <returns>A string containing the converted number. If an error occured the string is empty.</returns> public static string ConvertDoubleToString(double number) { string result = string.Empty; if (NativeOlapApi.ConvertDoubleToString(out result, number) == (int)ClientSupportErrorCodes.ECI_OK) { return(result); } return(string.Empty); }
/// <summary> /// Refreshes the cubes and dimensions of the server. /// </summary> /// <returns>True, if the data has been saved; false, otherwise.</returns> public bool Refresh() { if (NativeOlapApi.ServerRefresh(_store.ClientSlot, _serverHandle, _lastError)) { _cubes.Invalid = true; _dimensions.Invalid = true; return(true); } return(false); }
/// <summary> /// Deletes the comment of a cell of the cube. /// </summary> /// <param name="elements">A list of dimension elements that reference the cell.</param> /// <returns>True, if the comment has been deleted or false, otherwise.</returns> public bool DeleteCellComment(System.Collections.Specialized.StringCollection elements) { if (Dimensions == null) { return(false); } if (_dimensions.Count != elements.Count) { throw new System.ArgumentException(CreateExceptionString(_elementMismatch)); } return(NativeOlapApi.CubeDeleteCellComment(_server.Store.ClientSlot, _serverHandle, _name, elements, _server.LastErrorInternal)); }
private void Load() { if (Invalid) { IsInitialized = false; } if (!IsInitialized) { Collection = new System.Collections.Generic.List <OlapAttributeTableField>(0); System.Collections.ArrayList fields = NativeOlapApi.AttributeTableFields(_attributeTable.Dimension.Server.Store.ClientSlot, _attributeTable.Dimension.Server.ServerHandle, this._attributeTable.Dimension.Name, _attributeTable.Id, _attributeTable.Dimension.Server.LastErrorInternal); if (fields != null) { for (int i = 0; i < fields.Count; i++) { OlapAttributeTableFieldDefinition fieldDef = (OlapAttributeTableFieldDefinition)fields[i]; OlapAttributeTableFieldType type; switch (fieldDef.Type) { case 'C': type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeCharacter; break; case 'N': type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeNumeric; break; case 'D': type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeDate; break; case 'L': type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeLogical; break; default: throw new OlapException("Found unknown attribute field type: " + fieldDef.Type); } Collection.Add(new OlapAttributeTableField(_attributeTable, fieldDef.FieldName, fieldDef.Id, fieldDef.FieldWidth, fieldDef.Decimals, type)); } } else { if (_attributeTable.Dimension.Server.LastErrorInternal.Value != 0) { throw new OlapException("Receiving the attribute table field collection failed!", _attributeTable.Dimension.Server.LastErrorInternal.Value); } } Invalid = false; IsInitialized = true; } }
/// <summary> /// Frees all resources immediately. /// </summary> public void FreeResources() { if (!_disposed) { _disposed = true; if (ClientSlot != 0) { IntPointer lastError = new IntPointer(); NativeOlapApi.ClientDisconnect(_clientSlot, lastError); _clientSlot = 0; } } }
/// <summary> /// Activates the data area on the specified cube on the Olap server. This method can be called only /// once and deactivate must be called when done. If activate is called two times without calling deactivate /// in between an exception is thrown. /// </summary> public void Activate() { if (!NativeOlapApi.DataAreaDefine(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _cube.Name, _elements, _parameters, _cube.Server.DataAreaActive, _cube.Server.LastErrorInternal)) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("The data area could not be activated!"); sb.Append(", Error: "); sb.Append(System.Convert.ToString(_cube.Server.LastErrorInternal.Value)); sb.Append(", "); sb.Append(ToString()); throw new OlapException(sb.ToString(), _cube.Server.LastErrorInternal.Value); } _data = NativeOlapApi.DataAreaFirst(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _cube.Name, _parameters, _cube.Server.LastErrorInternal); _currentDataSet = -1; _isActivated = true; }
/// <summary> /// Set values in the data area. /// </summary> /// <param name="value">Value which is to be set.</param> public void SetValues(string value) { MdsSetValueProlog(); if (!NativeOlapApi.DataAreaSetValues(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _parameters, value, _cube.Server.LastErrorInternal)) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("The data area values could not be set!"); sb.Append(", Error: "); sb.Append(System.Convert.ToString(_cube.Server.LastErrorInternal.Value)); sb.Append(", "); sb.Append(ToString()); throw new OlapException(sb.ToString(), _cube.Server.LastErrorInternal.Value); } MdsSetValueEpilog(); }
/// <summary> /// Loads the subset collection. /// </summary> private void Load() { if (Invalid) { IsInitialized = false; } if (!IsInitialized) { Collection = new System.Collections.Generic.List <OlapSubset>(0); System.Collections.ArrayList subsets = NativeOlapApi.DimensionSubsets(_dimension.Server.Store.ClientSlot, _dimension.Server.ServerHandle, _dimension.Name, _dimension.Server.LastErrorInternal); if (subsets != null) { for (int i = 0; i < subsets.Count; i++) { OlapSubsetTypes type; OlapSubsetDefinition subsetDef = (OlapSubsetDefinition)subsets[i]; if ((subsetDef.Type & 0x01) == 0x01) { type = OlapSubsetTypes.OlapSubsetTypesPublic; } else if ((subsetDef.Type & 0x02) == 0x02) { type = OlapSubsetTypes.OlapSubsetTypesPrivate; } else { throw new OlapException("Found unexpected subset type: " + subsetDef.Type); } Collection.Add(new OlapSubset(_dimension, subsetDef.RefName, subsetDef.LongName, subsetDef.CreatedByUser, type, subsetDef.SaveResultSet)); } } else { if (_dimension.Server.LastErrorInternal.Value != 0) { throw new OlapException("Receiving the subset collection failed!", _dimension.Server.LastErrorInternal.Value); } } Invalid = false; IsInitialized = true; } }
private void MdsSetValueProlog() { if (_isActivated) { Deactivate(); _isActivated = true; } if (!NativeOlapApi.DataAreaDefine(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _cube.Name, _elements, _parameters, _cube.Server.DataAreaActive, _cube.Server.LastErrorInternal)) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("The data area could not be defined!"); sb.Append(", Error: "); sb.Append(System.Convert.ToString(_cube.Server.LastErrorInternal.Value)); sb.Append(", "); sb.Append(ToString()); throw new OlapException(sb.ToString(), _cube.Server.LastErrorInternal.Value); } }
/// <summary> /// Creates a new OlapXmlResponse instance for a certain response document. /// Every response document will bec checked for a global error element /// immediately. /// </summary> /// <param name="response">Response document to be evaluated.</param> public OlapXmlResponse(string response) { _errors = new List <string>(); _document = XDocument.Parse(response); _namespaceManager = new XmlNamespaceManager(new NameTable()); _namespaceManager.AddNamespace("Alea", RequestBase.OlapNamespace.NamespaceName); XElement error = _document.XPathSelectElement("/Alea:Document/Alea:Request/Alea:Error", _namespaceManager); if (error != null) { string errorId = "unknown"; if (error.Attribute(ErrorIdAttribute) != null) { errorId = error.Attribute(ErrorIdAttribute).Value; _errors.Add(errorId); } NativeOlapApi.LogError(LogEvent.ErrorInXmlResponse, "Olap server returned the following error: " + errorId); } }
/// <summary> /// Gets the comment for a specified cell of the cube. /// </summary> /// <param name="elements">A list of dimension elements that reference the cell.</param> /// <returns>A string with the cell comment. If the cell comment did not exist the return value is null.</returns> public string GetCellComment(System.Collections.Specialized.StringCollection elements) { if (Dimensions == null) { return(null); } if (_dimensions.Count != elements.Count) { throw new System.ArgumentException(CreateExceptionString(_elementMismatch)); } string result = NativeOlapApi.CubeGetCellComment(_server.Store.ClientSlot, _serverHandle, _name, elements, _server.LastErrorInternal); if (result == null) { result = string.Empty; } return(result); }
/// <summary> /// Checks for errors that are specific to the RenameDimensionElement request. /// </summary> /// <param name="dimension">Dimension to rename element for.</param> /// <param name="element">The element to be renamed.</param> /// <param name="newName">The element's new name.</param> /// <returns>True, if the response document contains any errors. False, otherwise.</returns> public bool CheckForErrorsInRenameDimensionElement(string dimension, string element, string newName) { bool hasErrors = false; XElement errorElement = _document.XPathSelectElement("/Alea:Document/Alea:Request/Alea:Return/Alea:Dimension/Alea:Error", _namespaceManager); if (errorElement != null) { hasErrors = true; string errorID = "unknown"; XAttribute errorAttr = errorElement.Attribute("ErrorID"); if (errorAttr.Value != null) { errorID = errorAttr.Value; } // TODO 10.5: localize error messages string message = "The element " + element + " could not be renamed to '" + newName + "' in dimension " + dimension + ". The error code from the server was: " + errorID; NativeOlapApi.LogError(LogEvent.ErrorInXmlResponse, message); } return(hasErrors); }
/// <summary> /// Checks for errors that are specific to the CreateDimensionElement request. /// </summary> /// <param name="dimension">Dimension to create element for.</param> /// <param name="element">The element to be created.</param> /// <returns>True, if the response document contains any errors. False, otherwise.</returns> public bool CheckForErrorsInCreateDimensionElement(string dimension, string element) { bool hasErrors = false; XElement errorElement = _document.XPathSelectElement("/Alea:Document/Alea:Request/Alea:Return/Alea:Dimension/Alea:Elements", _namespaceManager); if (errorElement != null) { string[] returnValues = errorElement.Value.Split('\t'); string olapError = string.Empty; if (returnValues != null && returnValues.Length > 0) { olapError = returnValues[0]; _errors.Add(olapError); hasErrors = true; } // TODO 10.5: localize error messages string message = "The element " + element + " could not be created in dimension " + dimension + ". The error code from the server was: " + olapError; NativeOlapApi.LogError(LogEvent.ErrorInXmlResponse, message); } return(hasErrors); }
/// <summary> /// Gets a cell value of the cube. /// </summary> /// <param name="firstElement">The first element name.</param> /// <param name="secondElement">The second element name.</param> /// <param name="elements">A variable list of additional dimension elements that reference the cell.</param> /// <returns>An object representing the cell value. If the cell did not exist the return value is null.</returns> public object GetCell(string firstElement, string secondElement, params string[] elements) { if (Dimensions == null) { return(null); } int total = 2; if (elements != null) { total += elements.Length; } if (_dimensions.Count != total) { throw new System.ArgumentException(CreateExceptionString(_elementMismatch)); } return(NativeOlapApi.CubeGetCell(_server.Store.ClientSlot, _serverHandle, _name, firstElement, secondElement, elements, _server.LastErrorInternal)); }
/// <summary> /// Loads the server collection. /// </summary> private void Load() { if (Invalid) { IsInitialized = false; } if (!IsInitialized) { IntPointer lastError = new IntPointer(); Collection = new System.Collections.Generic.List <OlapServer>(0); System.Collections.Specialized.StringCollection serverNames = NativeOlapApi.Servers(_store.ClientSlot, lastError); if (serverNames != null) { for (int i = 0; i < serverNames.Count; i++) { Collection.Add(new OlapServer(_store, serverNames[i])); } } Invalid = false; IsInitialized = true; } }
/// <summary> /// Calculate the hash value for the data area. /// </summary> /// <param name="key">A key to calculate the hash. The default value is an empty string.</param> /// <param name="treatZeroAsNa">If true, the hash calculation will produce the same hash values for #NA and zero, or #NA and empty string for text cells.</param> /// <returns>A unique hash value for the data area.</returns> public string CalculateHash(string key, bool treatZeroAsNa) { MdsSetValueProlog(); string result = NativeOlapApi.DataAreaCalculateHash(_cube.Server.Store.ClientSlot, _cube.Server.ServerHandle, _parameters, key, _cube.Server.LastErrorInternal); if (_cube.Server.LastErrorInternal.Value != 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("The hash value could not be calculated!"); sb.Append(", Error: "); sb.Append(System.Convert.ToString(_cube.Server.LastErrorInternal.Value)); sb.Append(", "); sb.Append(ToString()); throw new OlapException(sb.ToString(), _cube.Server.LastErrorInternal.Value); } MdsSetValueEpilog(); _isActivated = false; _cube.Server.DataAreaActive.Value = false; return(result); }
/// <summary> /// Gets the native name for a unique name. /// </summary> /// <param name="uniqueName">The unique name to convert.</param> /// <returns>The native name. If the unique name was invalid the result will be an empty string.</returns> public string ConvertUniqueNameToNative(string uniqueName) { return(NativeOlapApi.ResolveUniqueName(_store.ClientSlot, _serverHandle, uniqueName)); }
/// <summary> /// Starts the OLAP load from source function. /// </summary> /// <returns>True, if successful; false, otherwise.</returns> public bool StartLoadFromSource() { return(NativeOlapApi.StartLoadFromSource(_store.ClientSlot, _serverHandle, "1")); }
/// <summary> /// Executes an XML request. Before a request can be executed a dataarea must be defined and activated. /// </summary> /// <param name="request">The XML request to be executed.</param> /// <returns>The result XML returned by the OLAP server.</returns> public string XMLRequest(string request) { return(NativeOlapApi.XMLRequest(_store.ClientSlot, _serverHandle, request)); }
/// <summary> /// Save all dimension and cubes to disk and removes them from memory. /// </summary> /// <returns>True, if cleared; false, otherwise.</returns> public bool Clear() { return(NativeOlapApi.ServerClear(_store.ClientSlot, _serverHandle, _lastError)); }
/// <summary> /// Sends an OLAP XML splash request to an OLAP server to write a value to a calculated cell. /// </summary> /// <param name="value">The value to splash.</param> /// <param name="mode">The splash mode.</param> /// <param name="rounding">True, if values should be rounded, false if not.</param> /// <param name="decimals">The number of decimals to round, if rounding is true.</param> /// <param name="notDeleteOnZero">If true, sending the value 0 will not delete the leaf cells, but it will write the value 0. Otherwise sending the value 0 will delete the leaf cells.</param> /// <param name="firstElement">The first element name.</param> /// <param name="secondElement">The second element name.</param> /// <param name="elements">A variable list of additional dimension elements that reference the cell.</param> /// <returns>True, if successful; false, otherwise.</returns> public bool SplashCell(double value, string mode, bool rounding, int decimals, bool notDeleteOnZero, string firstElement, string secondElement, string[] elements) { return(NativeOlapApi.SplashValue(_server.Store.ClientSlot, _serverHandle, "1", this, value, mode, rounding, decimals, notDeleteOnZero, firstElement, secondElement, elements)); }
/// <summary> /// Saves the cube to disc and removes it from memory. /// </summary> /// <returns>True, if the cube has been removed; false, otherwise.</returns> public bool Clear() { return(NativeOlapApi.CubeClear(_server.Store.ClientSlot, _serverHandle, _name, _server.LastErrorInternal)); }