public string GenerateProtoFile(IEnumerable <Type> clrTypes, string protoFileDirectory = null) { try { FireEvent(ProtoGenerationStarted); TypeSchema typeSchema = TypeSchemaGenerator.CreateTypeSchema(clrTypes); protoFileDirectory = protoFileDirectory ?? OutputDirectory; DirectoryInfo outputDir = new DirectoryInfo(protoFileDirectory); string nameSpace = GetNamespace(clrTypes); string targetNamespace = string.IsNullOrEmpty(TargetNamespace) ? $"{nameSpace}.Protobuf" : TargetNamespace; string filePath = Path.Combine(outputDir.FullName, $"{nameSpace}.proto"); string moveExistingFileTo = new FileInfo(filePath).FullName.GetNextFileName(); if (File.Exists(filePath)) { File.Move(filePath, moveExistingFileTo); } StringBuilder protoMessages = new StringBuilder(); protoMessages.AppendLine("syntax = \"proto3\";"); protoMessages.AppendLine($"package {targetNamespace};"); foreach (Type type in typeSchema.Tables) { ProtocolBufferType protoType = new ProtocolBufferType(type, PropertyNumberer, PropertyFilter); StringBuilder properties = new StringBuilder(); foreach (ProtocolBufferProperty prop in protoType.Properties) { string propertyFormat = prop.IsRepeated ? ArrayPropertyFormat : PropertyFormat; properties.Append(propertyFormat.NamedFormat(prop)); } ProtocolBufferTypeModel model = new ProtocolBufferTypeModel { TypeName = protoType.TypeName, Properties = properties.ToString() }; protoMessages.Append(MessageFormat.NamedFormat(model)); } protoMessages.ToString().SafeWriteToFile(filePath); FireEvent(ProtoGenerationComplete); return(filePath); } catch (Exception ex) { Message = ex.Message; FireEvent(ProtoGenerationError); return(string.Empty); } }
public override void CommitLogEvent(LogEvent logEvent) { System.Diagnostics.Trace.WriteLine(MessageFormat.NamedFormat(logEvent)); }
public override void CommitLogEvent(LogEvent logEvent) { OutputDebugString(MessageFormat.NamedFormat(logEvent)); }