public ModelContext LoadModel(ModelDeclaration declaration) { var modelFilePath = declaration.GetParameter(ModelPathParameter); var modelRoot = new ModelContext( declaration, new JsonModel(JObject.Parse(File.ReadAllText(modelFilePath)), ModelFormat.Json, declaration.ModelName, declaration.Tags)); return(modelRoot); }
public bool Validate(ModelDeclaration context) { if (_loaderRegistry.TryGet(context.LoaderName, out IModelLoader loader)) { return(loader.ValidateArguments(context)); } return(false); }
public ModelContext LoadModel(ModelDeclaration declaration) { var result = new EntityModelRoot(); var tableName = declaration.GetParameter("tableName"); var databaseInfo = new DatabaseInfo { Server = declaration.GetParameter("server"), Name = declaration.GetParameter("db"), User = declaration.GetParameter("user"), Password = declaration.GetParameter("password") }; var query = TableMetadataQuery; AppTrace.Verbose($"Loading metadata from database {databaseInfo.Name} on {databaseInfo.Server} instance."); if (!string.IsNullOrWhiteSpace(tableName)) { query = string.Concat(query, " and tbl.TABLE_NAME = @TableName"); } using (var connection = new SqlConnection(SqlHelper.GetConnectionString(databaseInfo))) { var lines = connection.Query <DbObjectLine>(TableMetadataQuery, new { TableName = tableName }); var grouped = lines.GroupBy(l => l.ObjectName); foreach (var g in grouped) { var m = new EntityModel { ObjectName = SafeName(g.Key) }; m.AddProperties(g.OrderBy(p => p.PropertyPosition).Select(p => new PropertyModel { DateTimePrecision = p.DateTimePrecision, PropertyDefaultValue = p.PropertyDefaultValue, PropertyLength = p.PropertyLength, PropertyName = p.PropertyName, PropertyPosition = p.PropertyPosition, PropertyPrecision = p.PropertyPrecision, PropertyPrecisionRadix = p.PropertyPrecisionRadix, PropertySqlDataType = p.PropertySqlDataType, Scale = p.Scale, SqlIsNullable = p.SqlIsNullable })); result.AddModels(new[] { m }); } } AppTrace.Verbose($"Loaded { result.Entities.Count() } models."); return(new ModelContext(declaration, new DbModel(result, ModelFormat.Clr, declaration.ModelName, declaration.Tags))); }
public ModelContext LoadModel(ModelDeclaration context) { var modelFilePath = context.GetParameter(ModelPathParameter); using (var file = File.OpenRead(modelFilePath)) { var document = XDocument.Load(file); return(new ModelContext(context, new XmlModel(document, ModelFormat.Xml, context.ModelName, context.Tags))); } }
public void Match_GivenModelTypeFromModelDeclaration_ReturnsTrue() { ModelDeclaration modelDeclaration = SpanHelper.BuildModelDeclaration(); var sut = new IgnoreSpanTranslator(); var result = sut.Match(modelDeclaration.ModelType); Assert.IsTrue(result); }
public bool ValidateArguments(ModelDeclaration context) { if (string.IsNullOrWhiteSpace(context.GetParameter(ModelPathParameter))) { // TODO: this should be a validation service AppTrace.Error($"The parameter {ModelPathParameter} is required."); return(false); } return(true); }
public ModelContext LoadModel(ModelDeclaration context) { var modelFilePath = context.GetParameter(ModelPathParameter); using (var reader = new StreamReader(modelFilePath)) { var yamlStream = new YamlStream(); yamlStream.Load(reader); var model = yamlStream.Documents.FirstOrDefault()?.RootNode; var modelContext = new ModelContext(context, new YamlModel(model, ModelFormat.Yaml, context.ModelName, context.Tags)); return(modelContext); } }
public ModelContext GetOrLoad(ModelDeclaration declaration) { ModelContext modelRoot = Get(declaration.ModelName); if (modelRoot != null) { return(modelRoot); } if (_loaderRegistry.TryGet(declaration.LoaderName, out IModelLoader loader)) { // load the domain model modelRoot = loader?.LoadModel(declaration) ?? throw new InvalidOperationException($"It was not possible to load a model provider for '{ declaration.LoaderName }'. Check the transformation configuration to see if there is one and just one provider for '{ declaration.LoaderName }'."); _models.Add(declaration.ModelName, modelRoot); } return(modelRoot); }
static void Main(string[] args) { if (args.Length > 0) { var filePath = args[0]; var code = File.ReadAllText(filePath); SyntaxTree tree = CSharpSyntaxTree.ParseText(code); var root = (CompilationUnitSyntax)tree.GetRoot(); var members = root.Members; var helloWorldDeclaration = (NamespaceDeclarationSyntax)members[0]; var classDeclaration = (ClassDeclarationSyntax)helloWorldDeclaration.Members[0]; SyntaxList <MemberDeclarationSyntax> classMembers = classDeclaration.Members; var propertyList = new List <MemberDeclaration>(); var meaningfulMembers = classMembers .OfType <PropertyDeclarationSyntax>() .Where(member => !HasMemberJsonIgnoreAttribute(member)) .ToList(); foreach (var propertySyntax in meaningfulMembers) { var member = new MemberDeclaration(); member.Name = propertySyntax.Identifier.Text.ToCamelCase(); if (propertySyntax.Type is GenericNameSyntax) { member.Type = BuildPropertyTypeFromGenericNameSyntax(propertySyntax.Type as GenericNameSyntax); } else if (propertySyntax.Type is NullableTypeSyntax) { member.Type = BuildPropertyTypeFromNullableTypeSyntax(propertySyntax.Type as NullableTypeSyntax); } else { member.Type = BuildPropertyTypeFromStandardSyntax(propertySyntax.Type); } propertyList.Add(member); } //foreach (var memeber in propertyList) //{ // Console.WriteLine($"{memeber.Name}, Type: {memeber?.Type?.Name}, {memeber?.Type?.IsArray}"); //} var modelDeclaration = new ModelDeclaration(Path.GetFileNameWithoutExtension(filePath), propertyList); Console.Write(JsonConvert.SerializeObject(modelDeclaration, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Formatting.Indented })); } }
public bool ValidateArguments(ModelDeclaration context) { return(true); }