private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperation) { SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ADD COLUMN "); ColumnModel column = migrationOperation.Column; ddlBuilder.AppendIdentifier(column.Name); TypeUsage storeType = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity); //DEFAULT VALUE if (column.DefaultValue != null) { if (column.DefaultValue is DateTime defaultValue) { var format = "yyyy-MM-dd HH:mm:ss.ffffff"; if (defaultValue.Kind == DateTimeKind.Utc) { format += 'Z'; } ddlBuilder.AppendSql($" DEFAULT '{defaultValue.ToString(format)}'"); } } ddlBuilder.AppendNewLine(); return(ddlBuilder.GetCommandText()); }
private string BuildPropertyType(PropertyModel propertyModel) { DebugCheck.NotNull(propertyModel); var originalStoreTypeName = propertyModel.StoreType; var typeUsage = ProviderManifest.GetStoreType(propertyModel.TypeUsage); if (string.IsNullOrWhiteSpace(originalStoreTypeName)) { originalStoreTypeName = typeUsage.EdmType.Name; } else { var storeTypeUsage = BuildStoreTypeUsage(originalStoreTypeName, propertyModel); typeUsage = storeTypeUsage ?? typeUsage; } var storeTypeName = originalStoreTypeName; const string MaxSuffix = "(max)"; if (storeTypeName.EndsWith(MaxSuffix, StringComparison.Ordinal)) { storeTypeName = Quote(storeTypeName.Substring(0, storeTypeName.Length - MaxSuffix.Length)) + MaxSuffix; } else { storeTypeName = Quote(storeTypeName); } switch (originalStoreTypeName) { case "decimal": case "numeric": storeTypeName += "(" + (propertyModel.Precision ?? (byte)typeUsage.Facets[DbProviderManifest.PrecisionFacetName].Value) + ", " + (propertyModel.Scale ?? (byte)typeUsage.Facets[DbProviderManifest.ScaleFacetName].Value) + ")"; break; case "datetime2": case "datetimeoffset": case "time": storeTypeName += "(" + (propertyModel.Precision ?? (byte)typeUsage.Facets[DbProviderManifest.PrecisionFacetName].Value) + ")"; break; case "binary": case "varbinary": case "nvarchar": case "varchar": case "char": case "nchar": storeTypeName += "(" + (propertyModel.MaxLength ?? (int)typeUsage.Facets[DbProviderManifest.MaxLengthFacetName].Value) + ")"; break; } return(storeTypeName); }
private void OnManifestReceived(ProviderManifest providerManifest) { // Update schemas for this provider this.schemaCache.UpdateSchemaFromManifest(providerManifest.Guid, providerManifest.Manifest); // Update manifest cache so any new worker instance may pick up the updates version on start up by calling "this.manifestCache.Read()". // Notice that we are refreshing the manifest with the latest version received so any older version will be overwritten. this.manifestCache.Write(); }
private string GenerateSqlStatementConcrete(CreateTableOperation migrationOperation) { SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder(); ddlBuilder.AppendSql("CREATE TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" ("); ddlBuilder.AppendNewLine(); bool first = true; string autoincrementColumnName = null; foreach (ColumnModel column in migrationOperation.Columns) { if (first) { first = false; } else { ddlBuilder.AppendSql(","); } ddlBuilder.AppendSql(" "); ddlBuilder.AppendIdentifier(column.Name); ddlBuilder.AppendSql(" "); if (column.IsIdentity) { autoincrementColumnName = column.Name; ddlBuilder.AppendSql(" integer constraint "); ddlBuilder.AppendIdentifier(ddlBuilder.CreateConstraintName("PK", migrationOperation.Name)); ddlBuilder.AppendSql(" primary key autoincrement"); ddlBuilder.AppendNewLine(); } else { TypeUsage storeTypeUsage = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeTypeUsage, column.IsNullable ?? true, column.IsIdentity); if (!String.IsNullOrEmpty(column.DefaultValueSql)) { ddlBuilder.AppendSql(" DEFAULT "); ddlBuilder.AppendSql(column.DefaultValueSql); } ddlBuilder.AppendNewLine(); } } if (migrationOperation.PrimaryKey != null && autoincrementColumnName == null) { ddlBuilder.AppendSql(","); ddlBuilder.AppendSql(GenerateSqlStatementConcrete(migrationOperation.PrimaryKey)); } ddlBuilder.AppendSql(")"); return(ddlBuilder.GetCommandText()); }
string BuildPropertyType(PropertyModel propertyModel) { var storeTypeName = propertyModel.StoreType; var typeUsage = ProviderManifest.GetStoreType(propertyModel.TypeUsage); if (!string.IsNullOrWhiteSpace(storeTypeName)) { typeUsage = BuildStoreTypeUsage(storeTypeName, propertyModel) ?? typeUsage; } return(SqlGenerator.GetSqlPrimitiveType(typeUsage)); }
private void AddProvider(ProviderManifest provider) { // If someone as asked for callbacks on every event, then include these too. if (allCallbackCalled && state.providers.ContainsKey(provider.Guid)) { provider.AddProviderEvents(source, allCallback); } // Remember this serialized information. state.providers[provider.Guid] = provider; }
public DynamicTraceEventParser(TraceEventSource source) : base(source) { if (source == null) // Happens during deserialization. { return; } // Try to retieve persisted state state = (DynamicTraceEventParserState)StateObject; if (state == null) { StateObject = state = new DynamicTraceEventParserState(); dynamicManifests = new Dictionary <Guid, DynamicManifestInfo>(); this.source.RegisterUnhandledEvent(delegate(TraceEvent data) { if (data.Opcode != (TraceEventOpcode)0xFE) { return; } if (data.ID != 0 && (byte)data.ID != 0xFE) // Zero is for classic ETW. { return; } // Look up our information. DynamicManifestInfo dynamicManifest; if (!dynamicManifests.TryGetValue(data.ProviderGuid, out dynamicManifest)) { dynamicManifest = new DynamicManifestInfo(); dynamicManifests.Add(data.ProviderGuid, dynamicManifest); } ProviderManifest provider = dynamicManifest.AddChunk(data); // We have a completed manifest, add it to our list. if (provider != null) { AddProvider(provider); } }); } else if (allCallbackCalled) { foreach (ProviderManifest provider in state.providers.Values) { provider.AddProviderEvents(source, allCallback); } } }
private void OnManifestReceived(ProviderManifest providerManifest) { if (providerManifest.Error != null) { this.logger.TraceEventServiceManifestGenerationFault(providerManifest.Guid, providerManifest.Error.ToString()); return; } // Update schemas for this provider this.schemaCache.UpdateSchemaFromManifest(providerManifest.Guid, providerManifest.Manifest); // Update manifest cache so any new worker instance may pick up the updates version on start up by calling "this.manifestCache.Read()". // Notice that we are refreshing the manifest with the latest version received so any older version will be overwritten. this.manifestCache.Write(); }
internal static void CacheSchema(ProviderManifest manifest) { var manifestXml = XElement.Parse(manifest.Manifest); var manifestNamespace = manifestXml.DescendantsAndSelf().First(x => x.Name.LocalName != "Event").Name.Namespace; var unused = manifestXml .Descendants(manifestNamespace + "template") .ToDictionary(x => x.Attribute("tid")?.Value, x => new ReadOnlyCollection <string>(x.Elements(manifestNamespace + "data") .Select(y => y.Attribute("name")?.Value) .ToArray())); var manifestEvents = manifestXml .Descendants(manifestNamespace + "event") .ToDictionary( x => int.Parse(x.Attribute("value")?.Value ?? throw new InvalidOperationException()), x => x.Attribute("keywords")?.Value ?? ""); Cache[manifest.Guid] = new ReadOnlyDictionary <int, string>(manifestEvents); }
private string GenerateSqlStatementConcrete(AlterColumnOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ALTER COLUMN "); ColumnModel column = migrationOperation.Column; ddlBuilder.AppendIdentifier(column.Name); ddlBuilder.AppendSql(" "); TypeUsage storeType = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity); ddlBuilder.AppendNewLine(); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(CreateTableOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("CREATE TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" ("); ddlBuilder.AppendNewLine(); bool first = true; foreach (ColumnModel column in migrationOperation.Columns) { if (first) { first = false; } else { ddlBuilder.AppendSql(","); } ddlBuilder.AppendSql(" "); ddlBuilder.AppendIdentifier(column.Name); ddlBuilder.AppendSql(" "); TypeUsage storeTypeUsage = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeTypeUsage, column.IsNullable ?? true, column.IsIdentity); ddlBuilder.AppendNewLine(); } ddlBuilder.AppendSql(")"); if (migrationOperation.PrimaryKey != null) { ddlBuilder.AppendSql(BATCHTERMINATOR); ddlBuilder.AppendSql(GenerateSqlStatementConcrete(migrationOperation.PrimaryKey)); } return(ddlBuilder.GetCommandText()); }
internal static void CacheSchema(ProviderManifest manifest) { var xElem = XElement.Parse(manifest.Manifest); var ns = xElem.DescendantsAndSelf().First(x => x.Name.LocalName != "Event").Name.Namespace; // { tid : {[payloadNames]}} var tidRef = xElem.Descendants(ns + "template") .ToDictionary(x => x.Attribute("tid").Value, x => new ReadOnlyCollection <string>( x.Elements(ns + "data") .Select(y => y.Attribute("name").Value) .ToArray())); var dict = xElem.Descendants(ns + "event") .ToDictionary( x => int.Parse(x.Attribute("value").Value), x => x.Attribute("keywords")?.Value ?? ""); var readOnlyDict = new ReadOnlyDictionary <int, string>(dict); cache[manifest.Guid] = readOnlyDict; }
private void ProcessEvent(TraceEvent evt) { try { if (evt.ID == TraceEventUtil.ManifestEventID) { XElement element = XElement.Parse(evt.ToString()); byte[] eventData = Encoding.UTF8.GetBytes(element.FirstNode.ToString()); ProviderManifest manifest = new ProviderManifest(new MemoryStream(eventData), eventData.Length); this.OnManifestReceived(manifest); } else { this.sink.OnNext(this.CreateEventEntry(evt)); } } catch (Exception exception) { this.logger.TraceEventServiceSinkUnhandledFault(this.sessionName, exception.ToString()); } }
internal unsafe ProviderManifest AddChunk(TraceEvent data) { if (provider != null) { return(null); } if (data.EventDataLength <= sizeof(ManifestEnvelope) || data.GetByteAt(3) != 0x5B) // magic number { return(null); } ushort totalChunks = (ushort)data.GetInt16At(4); ushort chunkNum = (ushort)data.GetInt16At(6); if (chunkNum >= totalChunks || totalChunks == 0) { return(null); } if (Chunks == null) { format = (ManifestEnvelope.ManifestFormats)data.GetByteAt(0); majorVersion = (byte)data.GetByteAt(1); minorVersion = (byte)data.GetByteAt(2); ChunksLeft = totalChunks; Chunks = new byte[ChunksLeft][]; } else { // Chunks have to agree with the format and version information. if (format != (ManifestEnvelope.ManifestFormats)data.GetByteAt(0) || majorVersion != data.GetByteAt(1) || minorVersion == data.GetByteAt(2)) { return(null); } } if (Chunks[chunkNum] != null) { return(null); } byte[] chunk = new byte[data.EventDataLength - 8]; Chunks[chunkNum] = data.EventData(chunk, 0, 8, chunk.Length); --ChunksLeft; if (ChunksLeft > 0) { return(null); } // OK we have a complete set of chunks byte[] serializedData = Chunks[0]; if (Chunks.Length > 1) { int totalLength = 0; for (int i = 0; i < Chunks.Length; i++) { totalLength += Chunks[i].Length; } // Concatinate all the arrays. serializedData = new byte[totalLength]; int pos = 0; for (int i = 0; i < Chunks.Length; i++) { Array.Copy(Chunks[i], 0, serializedData, pos, Chunks[i].Length); pos += Chunks[i].Length; } } Chunks = null; // string str = Encoding.UTF8.GetString(serializedData); provider = new ProviderManifest(serializedData, format, majorVersion, minorVersion); return(provider); }
internal unsafe ProviderManifest AddChunk(TraceEvent data) { if (provider != null) return null; // TODO if (data.EventDataLength <= sizeof(ManifestEnvelope) || data.GetByteAt(3) != 0x5B) // magic number return null; ushort totalChunks = (ushort)data.GetInt16At(4); ushort chunkNum = (ushort)data.GetInt16At(6); if (chunkNum >= totalChunks || totalChunks == 0) return null; if (Chunks == null) { format = (ManifestEnvelope.ManifestFormats)data.GetByteAt(0); majorVersion = (byte)data.GetByteAt(1); minorVersion = (byte)data.GetByteAt(2); ChunksLeft = totalChunks; Chunks = new byte[ChunksLeft][]; } else { // Chunks have to agree with the format and version information. if (format != (ManifestEnvelope.ManifestFormats)data.GetByteAt(0) || majorVersion != data.GetByteAt(1) || minorVersion == data.GetByteAt(2)) return null; } if (Chunks[chunkNum] != null) return null; byte[] chunk = new byte[data.EventDataLength - 8]; Chunks[chunkNum] = data.EventData(chunk, 0, 8, chunk.Length); --ChunksLeft; if (ChunksLeft > 0) return null; // OK we have a complete set of chunks byte[] serializedData = Chunks[0]; if (Chunks.Length > 1) { int totalLength = 0; for (int i = 0; i < Chunks.Length; i++) totalLength += Chunks[i].Length; // Concatinate all the arrays. serializedData = new byte[totalLength]; int pos = 0; for (int i = 0; i < Chunks.Length; i++) { Array.Copy(Chunks[i], 0, serializedData, pos, Chunks[i].Length); pos += Chunks[i].Length; } } Chunks = null; // string str = Encoding.UTF8.GetString(serializedData); provider = new ProviderManifest(serializedData, format, majorVersion, minorVersion); return provider; }
private void AddProvider(ProviderManifest provider) { // If someone as asked for callbacks on every event, then include these too. if (allCallbackCalled && state.providers.ContainsKey(provider.Guid)) provider.AddProviderEvents(source, allCallback); // Remember this serialized information. state.providers[provider.Guid] = provider; }