Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        private async void ConnectAsync()
        {
            while (!cancellation.IsCancellationRequested)
            {
                try
                {
                    await Task.Delay(500);

                    if (suspended)
                    {
                        lbMessage.SetText("Aguardando configurações...");
                        continue;
                    }

                    lbMessage.SetText("Localizando o servidor de dados...");

                    var entity = await client.TransferAsync("Blueprint");

                    if (!entity.OK)
                    {
                        throw entity.Fault ?? new Exception(entity.FaultMessage);
                    }

                    if (cancellation.IsCancellationRequested)
                    {
                        break;
                    }
                    if (suspended)
                    {
                        continue;
                    }

                    this.BlueprintEntity = entity.Value;
                    this.Blueprint       = EntityParser.ParseEntity <Blueprint>(entity.Value);

                    if (cancellation.IsCancellationRequested)
                    {
                        break;
                    }
                    if (suspended)
                    {
                        continue;
                    }

                    await DownloadAssetsAsync();

                    this.DialogResult = DialogResult.OK;
                    break;
                }
                catch (Exception ex)
                {
                    ex.Trace();

                    var causes = ex.GetCauseMessages().Select(x => $"• {x}");
                    var detail = string.Join(Environment.NewLine, causes);

                    lbDetail.SetText(detail);
                    lbDetail.SetForeColor(Color.Firebrick);
                }

                if (cancellation.IsCancellationRequested)
                {
                    break;
                }
                if (suspended)
                {
                    continue;
                }

                lbMessage.SetText("Não conectado. Uma nova tentativa será feita em segundos...");
                await Task.Delay(1500);
            }

            if (cancellation.IsCancellationRequested)
            {
                DialogResult = DialogResult.Cancel;
            }
            this.Close();
        }