private CachedSchema NewCachedSchema(string name, SchemaSource source) { XElement config = InstanceConfigGetter.GetConfig(name); CachedSchema cachedSchema; if (source == SchemaSource.DbSchemaProvider) { cachedSchema = new CachedSchema() { DbSchema = GetDbSchemaProvider(name, config).GetDbSchema() }; } else { cachedSchema = new CachedSchema(Cache[name]); } if (source <= SchemaSource.DbSchemaReviser) { cachedSchema.RevisedDbSchema = GetDbSchemaReviser(config).Revise(cachedSchema.DbSchema); } if (source <= SchemaSource.Mapper) { cachedSchema.MappedSchema = GetMapper(config).Map(cachedSchema.RevisedDbSchema); } if (source <= SchemaSource.SchemaReviser) { XElement revisedSchema = GetSchemaReviser(config).Revise(cachedSchema.MappedSchema); DateTime utcNow = DateTime.UtcNow; cachedSchema.RevisedSchema = revisedSchema; } return(cachedSchema); }
private void AddMutableItem(string absoluteKey, SchemaSource schemaSource, bool isValid, object value) { var itemGo = Instantiate(MutableItemPrefab, ItemsRoot); itemGo.transform.localScale = Vector3.one; var item = itemGo.GetComponent <MutableBoxMutableItemBehaviour>(); item.SchemaSource = schemaSource; item.AbsoluteKey = absoluteKey; if (value != null) { item.Type = value.GetType(); } else { item.Type = null; } item.IsValidType = isValid; item.Selected += HandleMutableItemSelected; MutableDropDownItems.Add(item); }
public Task <string> LoadSchema(SchemaSource source) { var path = new Uri(typeof(Program).GetTypeInfo().Assembly.CodeBase).LocalPath; var exe = path; var query = string.Join(" ", (source.QueryType ?? Enumerable.Empty <string>()).Select(x => $"--query \"{x}\"")); var mutations = string.Join(" ", (source.MutationType ?? Enumerable.Empty <string>()).Select(x => $"--mutation \"{x}\"")); var args = $"introspect \"{source.Location}\" {query} {mutations}"; if (path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { args = $"\"{exe}\" {args}"; exe = "dotnet"; } try { var process = Process.Start(new ProcessStartInfo { RedirectStandardOutput = true, Arguments = args, FileName = exe, UseShellExecute = false }); process.WaitForExit(); var schema = process.StandardOutput.ReadToEnd(); return(Task.FromResult(schema)); } catch (Exception ex) { throw ex; } }
public void Update(string name, SchemaSource source) { CachedSchema cachedSchema = NewCachedSchema(name, source); lock (LockObj) { Cache[name] = cachedSchema; } }
public ColumnInfo GetColumn(string tableName, string columnName) { string columnKey = SchemaSource.GetColumnKey(tableName, columnName); ColumnInfo column = null; SchemaSource.Columns.TryGetValue(columnKey, out column); return(column); }
public IEnumerable <uint> GetDicomTag(string tableName, string columnName) { string columnKey = SchemaSource.GetColumnKey(tableName, columnName); ColumnInfo column = null; if (SchemaSource.Columns.TryGetValue(columnKey, out column)) { return(column.Tags); } return(null); }
public Task <string> LoadSchema(SchemaSource source) { if (!parseCache.TryGetValue(source.Location, out var schema)) { lock (parseCache) { if (!parseCache.TryGetValue(source.Location, out schema)) { schema = ConvertJsonToSchema(File.ReadAllText(source.Location)); parseCache.Add(source.Location, schema); } } } return(Task.FromResult(schema)); }
void StartEFCoreFlow2() { var loadCtx = AssemblyLoadContext.GetLoadContext(typeof(Program).GetTypeInfo().Assembly); var comp = new Compiler(new LibraryLoader(loadCtx)); var schemaSrc = SchemaSource.Get(GetSqliteConnectionString(), "DbSchema"); comp.References = GetRuntimeRefs(); var schemaBuild = comp.Build("DbSchema", schemaSrc); var t = schemaBuild.Item1.ExportedTypes.Where(x => x.Name == "DbContext"); var queryBuild = comp.Build("DbQuery", _worldsqliteQuery, schemaBuild.Item2); var queryInstance = queryBuild.Item1.ExportedTypes.Single(x => x.Name == "Program"); var inst = Activator.CreateInstance(queryInstance) as IEFQuery; var result = inst.Run(); Console.WriteLine("Generated returned {0}", result); }
int StartEFCoreFlow3(IEnumerable <MetadataReference> reference) { var loadCtx = AssemblyLoadContext.GetLoadContext(typeof(Program).GetTypeInfo().Assembly); var comp = new Compiler(new LibraryLoader(loadCtx)); var schemaSrc = SchemaSource.Get(GetSqliteConnectionString(), "DbSchema"); Console.WriteLine(schemaSrc); comp.References = reference; var schemaBuild = comp.Build("DbSchema", schemaSrc); var t = schemaBuild.Item1.ExportedTypes.Where(x => x.Name == "DbContext"); var queryBuild = comp.Build("DbQuery", _worldsqliteQuery, schemaBuild.Item2); var queryInstance = queryBuild.Item1.ExportedTypes.Single(x => x.Name == "Program"); var inst = Activator.CreateInstance(queryInstance) as IEFQuery; var result = inst.Run(); Console.WriteLine(result == 83 ? "SUCCESS" : "FAILURE"); return(result); }
public async Task <string> LoadSchema(SchemaSource source) { var client = new HttpClient() { BaseAddress = new Uri(source.Location), }; foreach (var h in source.Headers) { client.DefaultRequestHeaders.Add(h.Key, h.Value); } var response = await client.PostAsync(source.Location, new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { query = IntrospectionQuery }), Encoding.UTF8, "application/json")); var json = await response.Content.ReadAsStringAsync(); return(JsonIntrospection.ConvertJsonToSchema(json)); }
public XElement GetSchema(string name, SchemaSource source) { if (!Cache.ContainsKey(name)) { Update(name, SchemaSource.DbSchemaProvider); } switch (source) { case SchemaSource.DbSchemaProvider: return(new XElement(Cache[name].DbSchema)); case SchemaSource.DbSchemaReviser: return(new XElement(Cache[name].RevisedDbSchema)); case SchemaSource.Mapper: return(new XElement(Cache[name].MappedSchema)); case SchemaSource.SchemaReviser: return(new XElement(Cache[name].RevisedSchema)); } throw new NotSupportedException(); // never }
private void EvaluateMutableValueForAdding(string absoluteKey, SchemaSource source, object value) { if (value == null) { Debug.Log("Indicating error because the type of the mutable object is null."); IndicateError = true; return; } var isValidType = false; var collisionList = value as TypeCollisionList; if (collisionList == null) { isValidType = Type.IsInstanceOfType(value); } else { isValidType = collisionList.ContainsType(Type); } AddMutableItem(absoluteKey, source, isValidType, value); }
public Task <string> LoadSchema(SchemaSource source) { return(Task.FromResult(File.ReadAllText(source.Location))); }
public Task <string> LoadSchema(SchemaSource source) { var schema = ConvertJsonToSchema(File.ReadAllText(source.Location)); return(Task.FromResult(schema)); }
private void GenerateMutableDropDownItems(MutableObject schemaSegment, SchemaSource source, Stack <string> ancestorTokens) { if (schemaSegment == null) { return; } foreach (var pair in schemaSegment) { var ancestorKeys = ancestorTokens.Any() ? ancestorTokens.Reverse().Aggregate((accumulator, current) => accumulator + "." + current) + "." : string.Empty; if (pair.Value is MutableObject) { EvaluateMutableValueForAdding(ancestorKeys + pair.Key, source, pair.Value); ancestorTokens.Push(pair.Key); GenerateMutableDropDownItems(pair.Value as MutableObject, source, ancestorTokens); ancestorTokens.Pop(); } else if (pair.Value is ICollection <MutableObject> ) { EvaluateMutableValueForAdding(ancestorKeys + pair.Key + ArraySuffix, source, pair.Value); var enumerable = (pair.Value as ICollection <MutableObject>).ToList(); if (enumerable.Any()) { ancestorTokens.Push(pair.Key + ArraySuffix); GenerateMutableDropDownItems(enumerable.First(), source, ancestorTokens); ancestorTokens.Pop(); } } else if (pair.Value is TypeCollisionList) { EvaluateMutableValueForAdding(ancestorKeys + pair.Key, source, pair.Value); var colList = pair.Value as TypeCollisionList; foreach (var obj in colList.Objects) { if (obj is MutableObject) { ancestorTokens.Push(pair.Key); GenerateMutableDropDownItems(obj as MutableObject, source, ancestorTokens); ancestorTokens.Pop(); continue; } if (obj is ICollection <MutableObject> ) { var enumerable = obj as ICollection <MutableObject>; if (!enumerable.Any()) { continue; } ancestorTokens.Push(pair.Key + ArraySuffix); GenerateMutableDropDownItems(enumerable.First(), source, ancestorTokens); ancestorTokens.Pop(); } } } else { EvaluateMutableValueForAdding(ancestorKeys + pair.Key, source, pair.Value); } } }
public Task <string> LoadSchema(SchemaSource source) { // this is a recursive call back into this same exe calling the introsepction output, marked as output to standard out. return(Task.FromResult(schema)); }