//public ExportConfig(bool enableTypeCheckAndConversion = true) public ExportConfig() { this.enableTypeCheckAndConversion = true; this.metadata = MetadataSchema.CreateFromMetaDataJSON(); this.configs = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); }
public ParseDemocracy() { var dbCon = "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password="******"wss://kusama-rpc.polkadot.io/"; _app = PolkaApi.GetAppication(); _sch = new MetadataSchema(); string nodeUrl = substrateCon; _app.Connect(nodeUrl); // Connect to db and check metadata version _postgres = new Postgres(dbCon); _indexer = new Indexer(_app, _postgres); // Create or update current schema var metadata = _app.GetMetadata(null); _sch.ParseMetadata(metadata); var si = _app.GetSystemInfo(); _sch.DatabaseSchema.Title = "Test_ParseBalances"; _sch.CommitToDb(_postgres, si); // Check current schema _indexer.CheckSystemInfo(); }
public object GenerateSchema(ISchema schema) { var properties = schema.ToObjectSchema().Properties; string[] compactSchema = MetadataSchema.GenerateCompactSchema(properties, GetJsonPropertyName, _metadataJsonSerializationOptions.Separator, _metadataJsonSerializationOptions.TypeMapper); return(compactSchema); }
public PSMetadataSchema(MetadataSchema schema) { if (schema != null) { this.Name = schema.Name; this.Version = schema.Version; } }
public void Dispose() { if (metadata != null) { metadata.Clear(); metadata = null; } if (configs != null) { this.Clear(); configs = null; } }
/// <summary> /// Populate the metadata header. /// </summary> void InitMap() { _map = new MetadataSchema(); _typeList = new List <Dictionary <string, object> >(); _typeNames = new HashSet <string>(); _resourceMap = new Dictionary <string, string>(); _map.ForeignKeyMap = new Dictionary <string, string>(); _enumList = new List <Dictionary <string, object> >(); _map.Add("localQueryComparisonOptions", "caseInsensitiveSQL"); _map.Add("structuralTypes", _typeList); _map.Add("resourceEntityTypeMap", _resourceMap); _map.Add("enumTypes", _enumList); _syntheticProperties = new Dictionary <Type, List <NHSyntheticProperty> >(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins(ConfigurationManager.AppSettings["ClientUIHost"]) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); MetadataSchema sch = new MetadataSchema(); var MetadataBlockHash = ConfigurationManager.AppSettings["MetadataBlockHash"]; using (IApplication app = PolkaApi.GetAppication()) { app.Connect("wss://kusama-rpc.polkadot.io/", MetadataBlockHash); sch.ParseMetadata(app.GetMetadata(null)); app.Disconnect(); } var rt = File.ReadAllText("runtime.txt"); var dataReader = new Postgres(ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString); services.AddSingleton(sch); services.AddSingleton(dataReader); services.AddSingleton <IRuntime>(new Runtime(rt)); services.AddSingleton <IWebApiDataAdapter>(new IndexedWebApi(dataReader, sch)); services.AddMvc() .AddJsonOptions(x => { x.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }; }); }
public void Commit(MetadataSchema schema, SystemInfo systemInfo) { var con = new Npgsql.NpgsqlConnection(_connectionString); using (DbConnection db = con) { db.Open(); var dbName = schema.DatabaseSchema.Title; var com = db.CreateCommand(); com.CommandText = $"CREATE DATABASE {dbName}"; try { var result = com.ExecuteNonQuery(); var dbText = DatabaseSqlString(schema.DatabaseSchema); com = db.CreateCommand(); com.CommandText = dbText; var reader = com.ExecuteReader(); } catch (Exception e) { // 42P04 - database already exist if (!e.Data["SqlState"].Equals("42P04")) { throw e; } } WriteSystemInfo(systemInfo); //var tables = string.Join(",", schema.DatabaseSchema.TableList.Select(i => i.Title)); db.Close(); } }
public object GenerateSchema(IPropertyContainer container) { string[] compactSchema = MetadataSchema.GenerateCompactSchema(container, GetJsonPropertyName, _metadataJsonSerializationOptions.Separator, _metadataJsonSerializationOptions.TypeMapper); return(compactSchema); }
public IndexedWebApi(IDatabaseDataReader reader, MetadataSchema md) { _reader = reader; _md = md; }
public InherentController(IWebApiDataAdapter dataAdapter, MetadataSchema metadataSchema) { _dataAdapter = dataAdapter; _metadataSchema = metadataSchema; }
protected virtual void OnMetadataBuilt(MetadataSchema metadata) { }
public ExtrinsicController(IWebApiDataAdapter dataAdapter, MetadataSchema metadataSchema) { _dataAdapter = dataAdapter; _metadataSchema = metadataSchema; }
public RuntimeCallController(IRuntime runtime, MetadataSchema sch) { _sch = sch; }
public BreezeMetadataBuiltEvent(MetadataSchema metadata, ISessionFactory sessionFactory) { Metadata = metadata; SessionFactory = sessionFactory; }
/// <inheritdoc /> public override void Write(Utf8JsonWriter writer, TPropertyContainer container, JsonSerializerOptions options) { writer.WriteStartObject(); if (container != null && container.Properties.Count > 0) { string GetJsonPropertyName(string name) => options.PropertyNamingPolicy?.ConvertName(name) ?? name; if (Options.WriteSchemaCompact) { Type containerType = container.GetType(); bool writeSchemaCompact = true; if (Options.WriteSchemaOnceForKnownTypes && container is IKnownPropertySet) { JsonWriterContext?jsonWriterContext = writer.AsMetadataProvider().GetMetadata <JsonWriterContext>(); if (jsonWriterContext != null) { writeSchemaCompact = !jsonWriterContext.IsWritten(containerType); } } if (writeSchemaCompact) { writer.WritePropertyName("$metadata.schema.compact"); string[] compactSchema = MetadataSchema.GenerateCompactSchema(container, GetJsonPropertyName, Options.Separator, Options.TypeMapper); JsonSerializer.Serialize(writer, compactSchema, options); if (Options.WriteSchemaOnceForKnownTypes && container is IKnownPropertySet) { writer.AsMetadataProvider().ConfigureMetadata <JsonWriterContext>(context => context.SetIsWritten(containerType)); } } } foreach (IPropertyValue propertyValue in container.Properties) { string jsonPropertyName = GetJsonPropertyName(propertyValue.PropertyUntyped.Name); Type propertyType = propertyValue.PropertyUntyped.Type; // PropertyName writer.WritePropertyName(jsonPropertyName); if (Options.WriteArraysInOneRow && propertyType.IsArray && writer.Options.Indented) { // Creates NotIndented writer Utf8JsonWriter writerCopy = writer.CloneNotIndented(); // PropertyValue JsonSerializer.Serialize(writerCopy, propertyValue.ValueUntyped, propertyType, options); // Needs to copy internal state back to writer writerCopy.CopyStateTo(writer); } else { // PropertyValue JsonSerializer.Serialize(writer, propertyValue.ValueUntyped, propertyType, options); } } } writer.WriteEndObject(); }
/// <inheritdoc /> public override TPropertyContainer Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions options) { IPropertySet?schema = null; var propertyContainer = new MutablePropertyContainer(); IPropertySet?knownPropertySet = typeToConvert.GetSchemaByKnownPropertySet(); if (knownPropertySet != null) { schema = knownPropertySet; } while (utf8JsonReader.Read()) { if (utf8JsonReader.TokenType == JsonTokenType.PropertyName) { TryReadProperty(ref utf8JsonReader); } else { break; } } void TryReadProperty(ref Utf8JsonReader reader) { try { ReadProperty(ref reader); } catch (Exception e) { if (!Options.DoNotFail) { throw; } } } void ReadProperty(ref Utf8JsonReader reader) { string propertyName = reader.GetString(); Type? propertyType = null; bool autoDetected = false; IProperty?property = null; // Advance reader to property value. reader.Read(); // Compact schema presentation. Use for embedding to json. // NOTE: Some json implementations can change property order so $metadata.schema.compact can be not first!!!... if (propertyName == "$metadata.schema.compact") { var compactSchemaItems = JsonSerializer.Deserialize <string[]>(ref reader, options); IPropertySet schemaFromJson = MetadataSchema.ParseCompactSchema(compactSchemaItems, Options.Separator, Options.TypeMapper); schema = knownPropertySet != null?knownPropertySet.AppendAbsentProperties(schemaFromJson) : schemaFromJson; return; } if (propertyType == null && schema != null) { property = schema.GetFromSchema(propertyName); propertyType = property?.Type; } if (propertyType == null) { propertyType = GetPropertyTypeFromToken(ref reader); autoDetected = true; } object?propertyValue = JsonSerializer.Deserialize(ref reader, propertyType, options); if (autoDetected && propertyValue is decimal numeric) { bool isInt = numeric % 1 == 0; if (isInt) { propertyType = typeof(int); propertyValue = (int)numeric; } else { propertyType = typeof(double); propertyValue = (double)numeric; } } if (property == null) { property = Property.Create(propertyType, propertyName); if (Options.AddSchemaInfo) { property.SetIsNotFromSchema(); } } propertyContainer.WithValueUntyped(property, propertyValue); } var resultContainer = propertyContainer.ToPropertyContainerOfType <TPropertyContainer>(); if (Options.AddSchemaInfo && schema != null) { resultContainer.SetSchema(schema.ToSchema()); } return(resultContainer); }
public BlockController(IWebApiDataAdapter dataAdapter, MetadataSchema metadataSchema) { _dataAdapter = dataAdapter; _metadataSchema = metadataSchema; }