/// <summary> /// Get operatorIDs from a partial operator name (according to search mode options). /// </summary> /// <param name="operatorNamePart">The partial name of the operator to find</param> /// <param name="searchMode">Search method</param> /// <param name="limitOfResults">Maximum capacity accepted for the result set</param> /// <returns>ResultSet: The existent operatorIDs associated with the operator name OR the new created operator if there was no operator and if the permissions are right</returns> public List<OperatorID> GetOperatorsByName(string operatorNamePart, int searchMode, int limitOfResults = 10) { // Start logging System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; // Prepare result set List<OperatorID> ResultedOperators = new List<OperatorID>(); try { string commandString; switch (searchMode) { case (int)SearchMode.ExactMatch: // strict commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` WHERE `En` LIKE '" + operatorNamePart + "' "; break; case (int)SearchMode.StartWith: // commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` WHERE `En` LIKE '" + operatorNamePart + "%' "; break; case (int)SearchMode.Containing: // commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` WHERE `En` LIKE '%" + operatorNamePart + "%' "; break; case (int)SearchMode.EndingWith: // commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` WHERE `En` LIKE '%" + operatorNamePart + "' "; break; default: commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` WHERE `En` LIKE '" + operatorNamePart + "' "; break; } if (limitOfResults != 0) { commandString += " Limit " + limitOfResults + " "; } MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); TryToOpenConnection(); MySqlDataReader myReader = mySqlCommand.ExecuteReader(); while (myReader.Read()) { if (!string.IsNullOrEmpty(myReader.GetString(0))) { OperatorLocation relationID = new OperatorLocation(); int.TryParse(myReader.GetString(0), out relationID.IR); int.TryParse(myReader.GetString(1), out relationID.Var); int.TryParse(myReader.GetString(2), out relationID.IR2); int.TryParse(myReader.GetString(3), out relationID.Var2); if (relationID.IR != 0 || relationID.Var != 0) { ResultedOperators.Add(new OperatorID(relationID)); } } } myReader.Close(); } catch (MySqlException retrieveSymbolIndexException) { Console.WriteLine("Error: {0}", retrieveSymbolIndexException.ToString()); } if (MyResultsTrace) { string ResultLog = ""; foreach (OperatorID itemOperatorID in ResultedOperators) { ResultLog += " [" + itemOperatorID.Location.IR + ":" + "0" + "]"; } SQLView.LogResult(new string[] { ResultLog }); } if (ResultedOperators.Count < 1 && searchMode == 0 && AcceptOperators) { // TODO FLORIN: Create expected Operator // ResultedOperators = CreateSymbolByName(OperatorNamePart, true); // set AcceptDuplicates to avoid other check for existence } #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { thisMethod.Parameters.Add(new string[] { "string operatorNamePart", operatorNamePart.ToString() }); thisMethod.Parameters.Add(new string[] { "int mode", searchMode.ToString() }); thisMethod.Parameters.Add(new string[] { "int limitOfResults", limitOfResults.ToString() }); } if (logLevel >= 1) // results { string result = string.Empty; foreach (OperatorID itemOperatorID in ResultedOperators) { result += "{" + itemOperatorID.Location.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return ResultedOperators; }
/// <summary> /// Get all operators known /// </summary> /// <returns>ResultSet: List of all operators stored in the database</returns> public List<OperatorID> GetAllOperators() { // Start logging System.Diagnostics.StackTrace stackTrace0 = new System.Diagnostics.StackTrace(); LoggingSystem.BranchName = stackTrace0.GetFrame(0).GetMethod().Name; // Prepare result set List<OperatorID> allRelations = new List<OperatorID>(); try { string commandString = "SELECT `IR`, `Var`, `IR2`, `Var2` FROM `" + DB + "`.`srel` "; MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(commandString, mySQLConnection); MySqlDataReader myReader = mySqlCommand.ExecuteReader(); if (MySqlTrace) SQLView.Log(mySqlCommand.CommandText); //List<string[]> list = (from IDataRecord r in myReader // select (string)r["IR"] // ).ToList(); while (myReader.Read()) { if (!string.IsNullOrEmpty(myReader.GetString(0))) { OperatorLocation operatorID = new OperatorLocation(); int.TryParse(myReader.GetString(0), out operatorID.IR); int.TryParse(myReader.GetString(1), out operatorID.Var); int.TryParse(myReader.GetString(2), out operatorID.IR2); int.TryParse(myReader.GetString(3), out operatorID.Var2); if (operatorID.IR != 0 || operatorID.Var != 0) { allRelations.Add(new OperatorID(operatorID)); } } } myReader.Close(); } catch (MySqlException retrieveSymbolIndexException) { Console.WriteLine("Error: {0}", retrieveSymbolIndexException.ToString()); } if (MyResultsTrace) { string ResultLog = ""; foreach (OperatorID operatorID in allRelations) { ResultLog += operatorID.ToString(); } SQLView.LogResult(new string[] { ResultLog }); } #region LOG //=== CUSTOM LOGGER=================================================================================== ElementMethod thisMethod = new ElementMethod(); int logLevel = -1; if (logingOptions != null) logLevel = logingOptions.levelNumbers; if (logLevel >= 3) // code { System.Diagnostics.StackTrace stackTrace; System.Diagnostics.StackFrame fr; stackTrace = new System.Diagnostics.StackTrace(); fr = stackTrace.GetFrame(0); thisMethod.ElementNamespaceName = this.GetType().Namespace; thisMethod.ElementClassName = this.GetType().Name; string methodName = fr.GetMethod().ToString(); thisMethod.ElementName = fr.GetMethod().Name; thisMethod.ReturnType = methodName.Substring(0, methodName.IndexOf(" ")); } if (logLevel >= 2) // parameters { } if (logLevel >= 1) // results { string result = string.Empty; foreach (OperatorID operatorID in allRelations) { result += "{" + operatorID.ToString() + "}"; } thisMethod.Result = result; } LoggingSystem.LogMethod = thisMethod; //==================================================================================================== #endregion LOG return allRelations; }
public OperatorID(OperatorLocation location) { Location = location; Multiplicity = new OperatorMultiplicity(); }
public OperatorID() { Location = new OperatorLocation(); Multiplicity = new OperatorMultiplicity(); }
public OperatorItem(OperatorLocation ID, string Name) { // TODO: Complete member initialization this.ID = ID; this.Name = Name; }