/// <summary> /// Queries all structures contained in the Structures data table using a wildcard query. The '?' and '*' wildcard characters can be used to /// query the structures in the function. The '?' character will serve as a single character wildcard in the string, whereas the '*' character /// will serve as a wildcard for any number of characters proceeding the wildcard symbol. If the MatchCase parameter is set to true, then /// the wildcard query will be case-sensitive. /// </summary> /// <param name="strExpression"></param> /// <param name="blMatchCase"></param> /// <returns></returns> public CHeaderDataSet.tblStructuresRow[] QueryStructsByWildcard( string strExpression, bool blMatchCase = false, SortOrderEnum sortOrder = SortOrderEnum.Ascending, StructUnionEnum structOrUnion = StructUnionEnum.Both) { try { IEnumerable <CHeaderDataSet.tblStructuresRow> qryStructRows = null; CHeaderDataSet.tblStructuresRow[] aryStructRows = null; strExpression = "^" + strExpression.Replace('?', '.').Replace("*", "\\w*") + "\\z"; if (!blMatchCase) { strExpression = "(?i)" + strExpression; qryStructRows = StructuresTable.Where(s => Regex.IsMatch(s.StructName, strExpression)); } else { strExpression = "(?-i)" + strExpression; qryStructRows = StructuresTable.Where(s => Regex.IsMatch(s.StructName, strExpression)); }//end if if (structOrUnion != StructUnionEnum.Both) { if (structOrUnion == StructUnionEnum.Structure) { qryStructRows = qryStructRows.Where(s => s.StructUnion == 1); } else { qryStructRows = qryStructRows.Where(s => s.StructUnion == 2); } }//end if if (sortOrder == SortOrderEnum.Ascending) { qryStructRows = qryStructRows.OrderBy(s => s.StructName); } else { qryStructRows = qryStructRows.OrderByDescending(s => s.StructName); } aryStructRows = qryStructRows.ToArray(); return(aryStructRows); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryStructsByWildcard function of DataAccess class."); return(null); } }
/// <summary> /// Retrieves the row in the Structures data table in the Header Data Set object linked to the DataAccess class with the name specified /// in the function's StructName parameter. /// </summary> /// <param name="strStructName"></param> /// <returns></returns> public CHeaderDataSet.tblStructuresRow GetStruct(string strStructName) { try { CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.FindByStructName(strStructName); return(rowStruct); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in GetStruct function of DataAccess class."); return(null); } }
/// <summary> /// Queries all structures from the Structure data table contained in the linked HeaderData data set that are within a specified range of data sizes. /// The structure rows will be queried and sorted in ascending or descending order. This function can be used to query either sets of structures or unions. /// </summary> /// <param name="iMinSize"></param> /// <param name="iMaxSize"></param> /// <param name="sortOrder"></param> /// <param name="structOrUnion"></param> /// <returns></returns> public CHeaderDataSet.tblStructuresRow[] QueryStructsBySize(int iMinSize, int iMaxSize = -1, SortOrderEnum sortOrder = SortOrderEnum.Ascending, StructUnionEnum structOrUnion = StructUnionEnum.Structure) { try { if (iMaxSize == -1) { iMaxSize = Int32.MaxValue; } IEnumerable <CHeaderDataSet.tblStructuresRow> qryStructRows = null; CHeaderDataSet.tblStructuresRow[] aryStructRows = null; qryStructRows = StructuresTable.Where(s => s.DataSize >= iMinSize && s.DataSize <= iMaxSize); if (structOrUnion != StructUnionEnum.Both) { if (structOrUnion == StructUnionEnum.Structure) { qryStructRows = qryStructRows.Where(s => s.StructUnion == 1); } else { qryStructRows = qryStructRows.Where(s => s.StructUnion == 2); } }//end if if (sortOrder == SortOrderEnum.Ascending) { qryStructRows = qryStructRows.OrderBy(s => s.DataSize); } else { qryStructRows = qryStructRows.OrderByDescending(s => s.DataSize); } aryStructRows = qryStructRows.ToArray(); return(aryStructRows); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryStructsBySize function of DataAccess class."); return(null); } }
/// <summary> /// Queries all structures contained in the Structures data table using a regular expression query. The results will match exactly to criteria /// specified in the regular expression and will be case and space sensitive. /// </summary> /// <param name="strRegex"></param> /// <returns></returns> public CHeaderDataSet.tblStructuresRow[] QueryStructsByRegex(string strRegex, SortOrderEnum sortOrder = SortOrderEnum.Ascending, StructUnionEnum structOrUnion = StructUnionEnum.Both) { try { IEnumerable <CHeaderDataSet.tblStructuresRow> qryStructRows = null; CHeaderDataSet.tblStructuresRow[] aryStructRows = null; qryStructRows = StructuresTable.Where(s => Regex.IsMatch(s.StructName, strRegex)); if (structOrUnion != StructUnionEnum.Both) { if (structOrUnion == StructUnionEnum.Structure) { qryStructRows = qryStructRows.Where(s => s.StructUnion == 1); } else { qryStructRows = qryStructRows.Where(s => s.StructUnion == 2); } }//end if if (sortOrder == SortOrderEnum.Ascending) { qryStructRows = qryStructRows.OrderBy(s => s.StructName); } else { qryStructRows = qryStructRows.OrderByDescending(s => s.StructName); } aryStructRows = qryStructRows.ToArray(); return(aryStructRows); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryStructsByRegex function of DataAccess class."); return(null); } }
/// <summary> /// Queries the data type associated with the field with the specified key passed to the function. The linked data type record will be returned /// by the function. Depending on what type of data type is associated with the field, will determine whether a structure data row, typedef data row /// or primitive data object is returned by the function. Primtive data types will not be stored in the Header Data Set and will have its data returned /// from the Global Primitive data object. /// </summary> /// <param name="strFieldKey"></param> /// <returns></returns> public object QueryFieldTypeDataByKey(string strFieldKey) { try { CHeaderDataSet.tblFieldsRow rowField = FieldsTable.FindByFieldKey(strFieldKey); if (rowField == null) { return(null); } switch ((FieldTypeEnum)rowField.FieldType) { case FieldTypeEnum.Primitive: case FieldTypeEnum.Enum: case FieldTypeEnum.Pointer: object[] aryPrimTypeData = new object[] { rowField.FieldTypeName, DataAccess.PrimDataTypes[rowField.FieldTypeName] }; return(aryPrimTypeData); case FieldTypeEnum.TypeDef: CHeaderDataSet.tblTypeDefsRow rowTypeDef = TypeDefsTable.FindByTypeDefName(rowField.FieldTypeName); return(rowTypeDef); case FieldTypeEnum.Structure: CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.FindByStructName(rowField.FieldTypeName); return(rowStruct); } ; return(null); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryFieldTypeDataByKey function of DataAccess class."); return(null); } }
/// <summary> /// Adds a row to the Structures data table in the Header Data Set object linked to the DataAccess class using the data contained in the /// StructData object passed to the function. The StructData object will contain all the required information needed to create a structure record /// in the Structures table. /// </summary> /// <param name="sdStruct"></param> /// <returns></returns> public bool AddStructRow(StructData sdStruct) { try { CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.NewtblStructuresRow(); rowStruct.StructName = sdStruct.StructName; rowStruct.StructUnion = (byte)sdStruct.StructUnion; rowStruct.FieldCount = sdStruct.Fields.Count; rowStruct.Elements = sdStruct.Elements; rowStruct.DataSize = sdStruct.DataSize; StructuresTable.AddtblStructuresRow(rowStruct); return(true); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in AddStructRow function of DataAccess class."); return(false); } }
/* NOT USED: Structures and Unions can be queried specifically by the StructOrUnion parameter. * /// <summary> * /// Queries all unions from the Structure data table contained in the linked HeaderData data set that are within a specified range of data sizes. * /// The union rows will be queried and sorted in ascending or descending order. * /// </summary> * /// <param name="iMinSize"></param> * /// <param name="iMaxSize"></param> * /// <param name="sortOrder"></param> * /// <param name="structOrUnion"></param> * /// <returns></returns> * public CHeaderDataSet.tblStructuresRow[] QueryUnionsBySize(int iMinSize, int iMaxSize = -1, * SortOrderEnum sortOrder = SortOrderEnum.Ascending) * { * try * { * return QueryStructsBySize(iMinSize, iMaxSize, sortOrder, StructUnionEnum.Union); * } * catch (Exception err) * { * ErrorHandler.ShowErrorMessage(err, "Error in QueryUnionsBySize function of DataAccess class."); * * return null; * } * } */ /// <summary> /// Queries all structures contained in the Structures data table that match either a portion or the entire name of the structure query string passed /// to the function. The structure query can also be case-sensitive depending on the parameters that are set in the function. /// NOTE: This version of the function does not use wildcards, but will just match a portion or the entire name of each structure stored in the /// Structures data table. /// </summary> /// <param name="strStructQuery"></param> /// <returns></returns> public CHeaderDataSet.tblStructuresRow[] QueryStructsByName( string strStructQuery, bool blMatchAny = true, bool blMatchExact = false, bool blMatchCase = false, SortOrderEnum sortOrder = SortOrderEnum.Ascending, StructUnionEnum structOrUnion = StructUnionEnum.Both) { try { IEnumerable <CHeaderDataSet.tblStructuresRow> qryStructRows = null; CHeaderDataSet.tblStructuresRow[] aryStructRows = null; if (!blMatchExact) { if (!blMatchCase) { qryStructRows = StructuresTable.Where(s => blMatchAny ? s.StructName.ToUpper().Contains(strStructQuery.ToUpper()) : s.StructName.ToUpper().StartsWith(strStructQuery.ToUpper())); } else { qryStructRows = StructuresTable.Where(s => blMatchAny ? s.StructName.Contains(strStructQuery) : s.StructName.StartsWith(strStructQuery)); }//end if } else { if (!blMatchCase) { qryStructRows = StructuresTable.Where(s => s.StructName.ToUpper() == strStructQuery.ToUpper()); } else { qryStructRows = StructuresTable.Where(s => s.StructName == strStructQuery); } //end if } //end if if (structOrUnion != StructUnionEnum.Both) { if (structOrUnion == StructUnionEnum.Structure) { qryStructRows = qryStructRows.Where(s => s.StructUnion == 1); } else { qryStructRows = qryStructRows.Where(s => s.StructUnion == 2); } }//end if if (sortOrder == SortOrderEnum.Ascending) { qryStructRows = qryStructRows.OrderBy(s => s.StructName); } else { qryStructRows = qryStructRows.OrderByDescending(s => s.StructName); } aryStructRows = qryStructRows.ToArray(); return(aryStructRows); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryStructsByName function of DataAccess class."); return(null); } }