private static void Main(string[] args) { Spring.Context.Support.AbstractApplicationContext appContext = null; var retryOnStartupPolicy = Policy //.HandleInner<StackExchange.Redis.RedisConnectionException>() .Handle <Exception>() .WaitAndRetry(9, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)) ); //2^9=512 segundos (8,53333 minutos) retryOnStartupPolicy.Execute(() => { appContext = ContextBuilder.BuildContext(); }); Task.Run(() => { while (true) { appContext.GetObject <Services.DataService>().RebuildCache(); System.Threading.Thread.Sleep(TimeSpan.FromMinutes(2)); } }); AppDomain.CurrentDomain.ProcessExit += (sender, e) => { Console.WriteLine("Fim!"); }; var statemachine = appContext.GetObject <DevWeek.Architecture.Workflow.QueuedWorkFlow.QueuedStateMachine>("IngestionPipeline"); statemachine.Start(); //new CancellationTokenSource() while (true) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); } Console.WriteLine("Hello World!"); }
public void Execute(GeneratorExecutionContext context) { var @namespace = "RapidCMS.ModelMaker"; // TODO: config? var propertyParser = new PropertyParser(); var entityParser = new EntityParser(propertyParser); var propertyBuilder = new PropertyBuilder(); var entityBuilder = new EntityBuilder(propertyBuilder); var configObjectBuilder = new ConfigObjectBuilder(); var entityValidatorBuilder = new EntityValidationBuilder(configObjectBuilder); var fieldBuilder = new FieldBuilder(configObjectBuilder); var collectionBuilder = new CollectionBuilder(fieldBuilder); var contextBuilder = new ContextBuilder(); var entityTypeConfigurationBuilder = new EntityTypeConfigurationBuilder(); var repositoryBuilder = new RepositoryBuilder(); var entities = new List <EntityInformation>(); foreach (var file in context.AdditionalFiles) { if (file.GetText() is SourceText text) { var jObject = JObject.Parse(text.ToString()); var entity = entityParser.ParseEntity(jObject); if (entity.IsValid()) // TODO: unit test { entities.Add(entity); } // context.ReportDiagnostic(Diagnostic.Create("RC0001", "", json.Value<string>("$type"), DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 1)); } } var modelMakerContext = new ModelMakerContext(@namespace, entities); foreach (var entity in entities) { entityParser.NormalizeEntity(entity, modelMakerContext); } foreach (var entity in entities) { entityParser.ExtendEntity(entity, modelMakerContext); } foreach (var entity in entities) { var entitySourceText = entityBuilder.BuildEntity(entity, modelMakerContext); if (entitySourceText != null) { context.AddSource($"ModelMaker_Entity_{entity.Name?.Replace(" ", "_")}.cs", entitySourceText); } var validatorSourceText = entityValidatorBuilder.BuildValidation(entity, modelMakerContext); if (validatorSourceText != null) { context.AddSource($"ModelMaker_EntityValidator_{entity.Name?.Replace(" ", "_")}.cs", validatorSourceText); } var collectionSourceText = collectionBuilder.BuildCollection(entity, modelMakerContext); if (collectionSourceText != null) { context.AddSource($"ModelMaker_Collection_{entity.Name?.Replace(" ", "_")}.cs", collectionSourceText); } } var contextSourceText = contextBuilder.BuildContext(modelMakerContext); if (contextSourceText != null) { context.AddSource("ModelMaker_DbContext.cs", contextSourceText); } foreach (var entity in entities) { var entityTypeConfigurationSourceText = entityTypeConfigurationBuilder.BuildEntityTypeConfiguration(entity, modelMakerContext); if (entityTypeConfigurationSourceText != null) { context.AddSource($"ModelMaker_EntityTypeConfiguration_{entity.Name?.Replace(" ", "_")}.cs", entityTypeConfigurationSourceText); } var repositorySourceText = repositoryBuilder.BuildRepository(entity, modelMakerContext); if (repositorySourceText != null) { context.AddSource($"ModelMaker_Repository_{entity.Name?.Replace(" ", "_")}.cs", repositorySourceText); } } }
static void Main(string[] args) { ConsoleColor forecolor = Console.ForegroundColor; ConsoleColor backgroundColor = Console.BackgroundColor; try { if (!File.Exists("dataflip.json")) { HelpWithDataflipJsonFile(); return; } Console.Title = "Dataflip is working on some awesome stuff right now..."; Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Working on it!"); Console.WriteLine(); GlobalProgress.Notify += GlobalProgress_Notify; string json = null; Console.WriteLine("Getting data from 'dataflip.json'."); using (var stream = File.Open("dataflip.json", FileMode.Open)) using (StreamReader reader = new StreamReader(stream)) json = reader.ReadToEnd(); Console.WriteLine("File found, parsing configuration..."); var config = GlobalConfiguration.FromJson(json); Console.WriteLine("Configuration looks OK. Resolving contexts..."); foreach (var contextConfig in config.Contexts) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Working on {contextConfig.Name}, {contextConfig.Sprocs.Count} sproc(s)..."); Console.ForegroundColor = ConsoleColor.White; ContextBuilder resolver = new ContextBuilder(contextConfig); var context = resolver.BuildContext(); Console.WriteLine(); Console.WriteLine("Generating code..."); CSharpContextGenerator generator = new CSharpContextGenerator(context); string code = generator.GenerateCode(); TypeScriptTypingsGenerator typeScript = new TypeScriptTypingsGenerator(context); string typeScriptCode = typeScript.GenerateCode(); HtmlBindingsGenerator htmlBindings = new HtmlBindingsGenerator(context); string htmlBindingsCode = htmlBindings.GenerateCode(); Console.WriteLine($"Writing code to {contextConfig.Output}..."); using (FileStream stream = File.Create(contextConfig.Output)) using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(code); Console.WriteLine(); Console.WriteLine("Awesome! C# Context class written successfully."); } if (contextConfig.TypeScriptTypings != null) { Console.WriteLine($"Working on typescript typings! Creating file {contextConfig.TypeScriptTypings}..."); using (FileStream stream = File.Create(contextConfig.TypeScriptTypings)) using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(typeScriptCode); Console.WriteLine(); Console.WriteLine("Great! TypeScript typings file written successfully."); } } if (contextConfig.AngularHtmlBindings != null) { Console.WriteLine($"Working on angular html bindings! Creating file {contextConfig.AngularHtmlBindings}..."); using (FileStream stream = File.Create(contextConfig.AngularHtmlBindings)) using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(htmlBindingsCode); Console.WriteLine(); Console.WriteLine("Excellent! TypeScript typings file written successfully."); } } } } catch (Exception ex) { Console.Title = "Darn... I guess not."; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Ouch!"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(); Console.WriteLine("Write any line to continue..."); Console.Read(); } Console.BackgroundColor = backgroundColor; Console.ForegroundColor = forecolor; }