EnumType GetEnum(MetaDataTypeDefinition d, SymbolTable bindings, string path) { EnumType t = new EnumType(new InputElement(d.Name), bindings); bindings.Add(t.Name, t); MetaDataField v = null; foreach (MetaDataField x in d.Fields) { if (x.Name == "value__") { v = x; break; } } t.baseType = GetType(v.Signature.FieldType, path); foreach (MetaDataField x in d.Fields) { if (x != v) { EnumMember e = t.AddEnumMember(new InputElement(x.Name), msg); e.Type = t; e.value = x.DefaultValue; } } t.Modifiers = GetTypeModifiers(d); return(t); }
// parse utility function to ensure that the class of a field matches the // class name specified in a TokenDefinition public bool MatchFieldType(FieldDefinition rule, MetaDataField field) { if (rule.matchClassType != null) { MetaDataObject classobj = field.Signature.FieldType.ClassObject; string classtype = ""; // Since we can pass in different objects as field, we need to be // careful here about how we get the class type if (classobj is MetaDataTypeDefinition) { classtype = ((MetaDataTypeDefinition)classobj).FullName; } else if (classobj is MetaDataTypeReference) { classtype = ((MetaDataTypeReference)classobj).FullName; } else if (classobj == null) { classtype = field.Signature.FieldType.ElementType.ToString(); } if (classtype != rule.matchClassType) { Error("{0} can't be applied to {1}", LastName(rule.attribute), field.FullName); Error("{0}does not match {1}", classtype, rule.matchClassType); return(false); } } return(true); }
/// <summary> /// Get meta data from a SQL statement /// </summary> /// <param name="connectionString">Connection string to use</param> /// <param name="entityName">Name of the entity class</param> /// /// <param name="cmd">Current command to get meta data for</param> /// <param name="nameOfPrimaryKeyField">Name of the primary key field. Default: null</param> public override void GetMetaData(string connectionString, string entityName, DbCommand cmd, string nameOfPrimaryKeyField = null) { if (string.IsNullOrEmpty(nameOfPrimaryKeyField)) { nameOfPrimaryKeyField = "CustomerId"; } var table = new MetaDataTable { Name = entityName, Sql = "SELECT * FROM Customer" }; var f = new MetaDataField { Name = nameOfPrimaryKeyField, DatabaseType = typeof(int) }; f.SourceDataType = f.DatabaseType.ToString(); table.Fields.Add(f); f = new MetaDataField { Name = "Customer", DatabaseType = typeof(string) }; f.SourceDataType = f.DatabaseType.ToString(); table.Fields.Add(f); Table = table; }
private static StringBuilder GetFieldParameter(MetaDataField field) { var erg = new StringBuilder(); erg.AppendLine($"// Parameter @{field.Name}"); erg.AppendLine($"p = new SqlParameter(\"@{field.Name}\", {GetFieldTypeFromType(field.DatabaseType)}) {{ Value = item.{field.Name} }};"); erg.AppendLine("cmd.Parameters.Add(p); "); erg.AppendLine(""); return(erg); }
private static StringBuilder GetFieldParameter(MetaDataField field) { var erg = new StringBuilder(); erg.AppendLine($"// Parameter @{field.Name}"); erg.AppendLine($"p = new NpgsqlParameter(\"@{field.Name}\", \"{field.SourceDataType}\") {{ Value = item.{field.Name} }};"); erg.AppendLine($"cmd.Parameters.Add(p); "); erg.AppendLine(""); return(erg); }
/// <summary> /// Get meta data from a SQL statement /// </summary> /// <param name="connectionString">Connection string to use</param> /// <param name="entityName">Name of the entity class</param> /// /// <param name="cmd">Current command to get meta data for</param> /// <param name="nameOfPrimaryKeyField">Name of the primary key field. Default: null</param> public override void GetMetaData(string connectionString, string entityName, DbCommand cmd, string nameOfPrimaryKeyField = null) { var table = new MetaDataTable { Name = entityName }; IConnManager db = new PostgresConnManager(connectionString); table.Sql = cmd.CommandText; // Act var reader = (NpgsqlDataReader)db.GetDataReader(cmd); // var schema = reader.GetColumnSchema(); for (var i = 0; i < schema.Count; i++) { var col = schema[i]; var colItem = new MetaDataField { Name = col.ColumnName, DatabaseType = col.DataType, SourceDataType = reader.GetProviderSpecificFieldType(i).ToString(), IsPrimaryKey = col.ColumnName == nameOfPrimaryKeyField }; //Debug.Print(colItem.SourceDataType); if (col.ColumnSize != null) { colItem.MaxLength = (int)col.ColumnSize; } table.Fields.Add(colItem); } //var p = new NpgsqlParameter() Table = table; }
/// <summary> /// Get a C# property for a database field /// </summary> /// <param name="field"></param> /// <returns></returns> private static string GetFieldProperty(MetaDataField field) { var type = field.DatabaseType; var attr = type == typeof(string) ? $"\t[MaxLength({field.MaxLength}, ErrorMessage = \"Maximum number of characters that can be entered for {field.Name} is {field.MaxLength}!\")]\r\n" : ""; var comment = type == typeof(string) ? $" Maximum length: {field.MaxLength} chars" : ""; comment = $"\t/// <summary>\r\n\t/// {field.Name} {comment}\r\n\t/// </summary>\r\n"; var fieldName = field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1); var result = $"{comment}{attr}\tpublic {type.Name} {fieldName} {{ get; set; }}"; return(result); }
stringList GetFieldModifiers(MetaDataField f) { stringList mods = new stringList(); switch (f.Flags & (int)(FieldAttributes.FieldAccessMask)) { case (int)FieldAttributes.Private: mods.Add("private"); break; case (int)FieldAttributes.FamORAssem: mods.Add("protected"); mods.Add("internal"); break; case (int)FieldAttributes.Assembly: mods.Add("internal"); break; case (int)FieldAttributes.Family: mods.Add("protected"); break; case (int)FieldAttributes.Public: mods.Add("public"); break; } if ((f.Flags & (int)FieldAttributes.Static) != 0) { mods.Add("static"); } return(mods); }
/// <summary> /// A search request. All parameters are optional, although it's good practice to at least provide a query. /// </summary> /// <param name="q">The query as inputted by the user</param> /// <param name="s">The system name that performs the search. Supported values are: "Klara", "SuntLiv", "Klaratest", "SuntLivTest"</param> /// <param name="collections">The Collections in which to search for hits. You can use . (AND) or | (OR) to search in several collections.</param> /// <param name="client">A string that indicates a valid front end</param> /// <param name="resultsPerPage">The maximum number of hits to return. Default is 10. Maximum is 100.</param> /// <param name="requiredFields">The required metadata fields that the hits must contain in order to be returned. Should be separated by |. /// The values specified will be required to exist as a metadata tag on page for it to be included in the result.</param> /// <param name="partialfields">Metadata fields that are partially required, /// that means the metadatafield and value must contain the specified word or phrases. For example specifying "dep" for a partialfield would /// return hits that contains the metadatafield "department" and "depending". Should be separated by |</param> /// <returns>The searchresult</returns> public ISearchResult Get(string q, string s, string collections = "", string client = "", int resultsPerPage = 10, string requiredFields = "", string partialfields = "") { var server = new SearchServer(); var query = new Query(); query.SearchTerm = q; query.Collections = collections; query.Client = client; query.MaxSearchHits = 10; if (!string.IsNullOrEmpty(requiredFields)) { if (requiredFields.Contains("|")) { //The more complex scenario. The user has serveral required fields that needs to be handled //TODO update this to handle not only AND but OR and NEGATE too var tags = requiredFields.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var tag in tags) { if (!string.IsNullOrEmpty(tag)) { var field = new MetaDataField(); field.Key = tag; field.MetaDataSearchSpecification = MetaDataSearchSpecification.And; query.RequiredFields.Add(field); } } } else { var field = new MetaDataField(); field.Key = requiredFields; field.MetaDataSearchSpecification = MetaDataSearchSpecification.Ignore; query.RequiredFields.Add(field); } } if (!string.IsNullOrEmpty(partialfields)) { if (partialfields.Contains("|")) { //The more complex scenario. The user has serveral partial fields that needs to be handled //TODO update this to handle not only AND but OR and NEGATE too var tags = partialfields.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var tag in tags) { if (!string.IsNullOrEmpty(tag)) { var field = new MetaDataField(); field.Key = tag; field.MetaDataSearchSpecification = MetaDataSearchSpecification.And; query.PartialFields.Add(field); } } } else { var field = new MetaDataField(); field.Key = partialfields; field.MetaDataSearchSpecification = MetaDataSearchSpecification.Ignore; query.PartialFields.Add(field); } } query.GsaHostAddress = string.Format(this.GetHostFromSystemName(s), "/search"); var result = server.Search(query); return result; }
private static string GetFieldMappingFromDb(MetaDataField field, int index) { var fieldName = field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1); var result = ""; switch (field.DatabaseType.Name.ToLowerInvariant()) { case "byte": result = $"dto.{fieldName}=reader.GetByte({index});"; break; case "int16": result = $"dto.{fieldName}=reader.GetInt16({index});"; break; case "int32": result = $"dto.{fieldName}=reader.GetInt32({index});"; break; case "int64": result = $"dto.{fieldName}=reader.GetInt64([{index});"; break; case "uint16": result = $"dto.{fieldName}=reader.GetUInt16({index});"; break; case "uint32": result = $"dto.{fieldName}=reader.GetUInt32({index});"; break; case "uint64": result = $"dto.{fieldName}=reader.GetUInt64({index});"; break; case "single": result = $"dto.{fieldName}=reader.GetSingle({index});"; break; case "double": result = $"dto.{fieldName}=reader.GetDouble({index});"; break; case "currency": result = $"dto.{fieldName}=reader.GetDecimal({index});"; break; case "decimal": result = $"dto.{fieldName}=reader.GetDecimal({index});"; break; case "boolean": result = $"dto.{fieldName}=reader.GetBoolean({index});"; break; case "datetime": result = $"dto.{fieldName}=reader.GetDate({index});"; break; case "string": result = $"dto.{fieldName}=reader[{index}].ToString();"; break; default: break; } return(result); }
private static string GetFieldValues(MetaDataField field) { var result = $"{field.Name}="; switch (field.DatabaseType.Name.ToUpperInvariant()) { case "BYTE": case "SBYTE": case "INT16": case "INT32": case "INT64": case "UINT16": case "UINT32": case "UINT64": result += "1"; break; //case "SINGLE": // result += "(Single)1.0"; // break; case "DOUBLE": result += "1.0f"; break; case "FLOAT": result += "1.0f"; break; case "DECIMAL": result += "(decimal)1.0"; break; case "BOOLEAN": result += "true"; break; case "DATETIME": result += "DateTime.Now"; break; case "CHAR": result += "'a'"; break; case "STRING": if (field.MaxLength > 20) { result += "\"Test mit ü und ö\""; } else { result += "\"T\""; } break; default: break; } return(result + ",\r\n"); }