public static async Task <String> Create(JsonSchema4 schema, Dictionary <String, JsonSchema4> others, String ns)
        {
            bool hasBase = false;

            var baseModelWriter = new BaseModelWriter("Input", CreatePropertyAttributes());
            var baseClass       = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseModelWriter, ns, ns + ".InputModels", allowPropertyCallback: p =>
            {
                if (p.CreateInputModel())
                {
                    hasBase = hasBase | p.IsAbstractOnInputModel();
                    return(p.IsAbstractOnInputModel());
                }
                return(false);
            });

            var modelWriter = new MainModelWriter(hasBase ? baseClass : null, "Input", CreatePropertyAttributes(), CreateClassAttributes(), false, false,
                                                  a =>
            {
                var interfaces = new String[] { a.BaseClassName, }
                .Concat(a.Writer.GetAdditionalInterfaces());

                a.Builder.AppendLine(
                    $@"    public partial class {a.Name}{a.ModelSuffix}{InterfaceListBuilder.Build(interfaces)}
    {{"
                    );
            })
            {
                AdditionalUsings = $@"using Threax.AspNetCore.Halcyon.Ext.ValueProviders;"
                                   + schema.GetExtraNamespaces(StrConstants.FileNewline)
            };

            return(ModelTypeGenerator.Create(schema, schema.GetPluralName(), modelWriter, ns, ns + ".InputModels",
                                             allowPropertyCallback: AllowProperty,
                                             additionalProperties: await AdditionalProperties(schema, others)));
        }
        public static String Get(JsonSchema4 schema, String ns, bool generated)
        {
            bool hasBase = false;

            var baseWriter = new QueryBaseModelWriter("Query", QueryPropertiesWriter.CreateAttributeBuilder())
            {
                InheritFrom = new String[] { "PagedCollectionQuery" }
            };
            var baseClass = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseWriter, ns, ns + ".Database", allowPropertyCallback: p =>
            {
                if (p.IsQueryable())
                {
                    hasBase = hasBase | p.IsAbstractOnQuery();
                    return(p.IsAbstractOnQuery());
                }
                return(false);
            });

            var baseClassName = "PagedCollectionQuery";

            if (hasBase)
            {
                baseClassName = $"{BaseModelWriter.CreateBaseClassName(schema.Title, "Query")}";
                baseClass     = $@"
{baseClass}
";
            }
            else
            {
                baseClass = "";
            }

            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            String queryProps = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new QueryPropertiesWriter(), schema, ns, ns, allowPropertyCallback: p =>
            {
                return(p.IsQueryable() && !p.IsAbstractOnQuery());
            });
            String queryCreate = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new QueryCreateWriter(), schema, ns, ns, allowPropertyCallback: p =>
            {
                return(p.IsQueryable());
            });

            return(Create(ns, Model, model, Models, models, queryProps, queryCreate, schema.GetKeyType().GetTypeAsNullable(), baseClass, baseClassName, NameGenerator.CreatePascal(schema.GetKeyName()), schema.GetExtraNamespaces(StrConstants.FileNewline), generated));
        }
Ejemplo n.º 3
0
        public static String Get(JsonSchema4 schema, String ns, bool generated)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);

            String inputToEntityEqualAssertFunc = "";
            String entityToViewEqualAssertFunc  = "";
            String createInputFunc  = "";
            String createEntityFunc = "";
            String createViewFunc   = "";

            if (!generated)
            {
                ModelTestWrapperGenerated.GetTestHelpers(schema, ns, out inputToEntityEqualAssertFunc, out entityToViewEqualAssertFunc, out createInputFunc, out createEntityFunc, out createViewFunc);
            }

            var repoMockup = "";

            if (schema.CreateRepository())
            {
                repoMockup = $"mockup.Add<I{Model}Repository>(m => new {Model}Repository(m.Get<AppDbContext>(), m.Get<AppMapper>()));";
            }

            return(Create(ns, Model, model, Models, models, schema.GetExtraNamespaces(StrConstants.FileNewline), repoMockup, inputToEntityEqualAssertFunc, entityToViewEqualAssertFunc, createInputFunc, createEntityFunc, createViewFunc));
        }
        public static async Task <String> Create(JsonSchema4 schema, Dictionary <String, JsonSchema4> others, String ns, bool generated)
        {
            bool hasBase = false;

            var baseWriter = new BaseModelWriter("", CreateAttributeBuilder());
            var baseClass  = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseWriter, ns, ns + ".ViewModels", allowPropertyCallback: p =>
            {
                if (p.CreateViewModel())
                {
                    hasBase = hasBase | p.IsAbstractOnViewModel();
                    return(p.IsAbstractOnViewModel());
                }
                return(false);
            });

            var mainWriter = new MainModelWriter(hasBase ? baseClass : null, "", CreateAttributeBuilder(), new NoAttributeBuilder(), schema.AllowCreated(), schema.AllowModified(),
                                                 a =>
            {
                var interfaces = new String[] { a.BaseClassName, }
                .Concat(a.Writer.GetAdditionalInterfaces());

                if (!generated)
                {
                    a.Builder.AppendLine(GetLinks(schema.GetPluralName()));
                }

                a.Builder.AppendLine(
                    $@"    public partial class {a.Name}{InterfaceListBuilder.Build(interfaces)}
    {{");

                a.Writer.CreateProperty(a.Builder, NameGenerator.CreatePascal(schema.GetKeyName()), new TypeWriterPropertyInfo(schema.GetKeyType()));
            }
                                                 )
            {
                AdditionalUsings =
                    $@"using {ns}.Controllers.Api;
using Threax.AspNetCore.Halcyon.Ext.ValueProviders;"
                    + schema.GetExtraNamespaces(StrConstants.FileNewline)
            };

            return(ModelTypeGenerator.Create(schema, schema.GetPluralName(), mainWriter, ns, ns + ".ViewModels",
                                             allowPropertyCallback: AllowProperty,
                                             additionalProperties: await AdditionalProperties(schema, others)));
        }
Ejemplo n.º 5
0
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            return(Create(ns, Model, model, Models, models));
        }
Ejemplo n.º 6
0
        public static String GetUserPartial(JsonSchema4 schema, String ns, String generatedSuffix = ".Generated")
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            return(CreatePartial(ns, Model, model, Models, models, generatedSuffix, schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            return(Create(ns, Model, model, Models, models, NameGenerator.CreatePascal(schema.GetKeyName()), schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }
        public static String GetComplete(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);

            return(Create(ns, Model, model, Models, models, schema.GetKeyType().GetTypeAsNullable(), schema.GetExtraNamespaces(StrConstants.FileNewline), true, true, true, null));
        }
        public static String Create(JsonSchema4 schema, Dictionary <String, JsonSchema4> others, String ns)
        {
            bool hasBase = false;

            var baseWriter = new BaseModelWriter("Entity", CreateAttributeBuilder());
            var baseClass  = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseWriter, ns, ns + ".Database", allowPropertyCallback: p =>
            {
                if (p.CreateEntity())
                {
                    hasBase = hasBase | p.IsAbstractOnEntity();
                    return(p.IsAbstractOnEntity());
                }
                return(false);
            });

            var mainWriter = new MainModelWriter(hasBase ? baseClass : null, "Entity", CreateAttributeBuilder(), new NoAttributeBuilder(), schema.AllowCreated(), schema.AllowModified(),
                                                 a =>
            {
                var interfaces = new String[] { a.BaseClassName, }
                .Concat(a.Writer.GetAdditionalInterfaces());

                a.Builder.AppendLine(
                    $@"    public partial class {a.Name}Entity{InterfaceListBuilder.Build(interfaces)}
    {{
        [Key]"
                    );

                a.Writer.CreateProperty(a.Builder, NameGenerator.CreatePascal(schema.GetKeyName()), new TypeWriterPropertyInfo(schema.GetKeyType()));
            }
                                                 )
            {
                AdditionalUsings = schema.GetExtraNamespaces(StrConstants.FileNewline)
            };

            return(ModelTypeGenerator.Create(schema, schema.GetPluralName(), mainWriter, ns, ns + ".Database",
                                             allowPropertyCallback: AllowProperty,
                                             additionalProperties: AdditionalProperties(schema, others)));
        }
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            string inputToEntityEqualAssertFunc, entityToViewEqualAssertFunc, createInputFunc, createEntityFunc, createViewFunc;

            GetTestHelpers(schema, ns, out inputToEntityEqualAssertFunc, out entityToViewEqualAssertFunc, out createInputFunc, out createEntityFunc, out createViewFunc);

            return(Create(ns, Model, model, Models, models, inputToEntityEqualAssertFunc, entityToViewEqualAssertFunc, createInputFunc, createEntityFunc, createViewFunc, schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }
Ejemplo n.º 11
0
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            String ModelId, modelId;

            NameGenerator.CreatePascalAndCamel(schema.GetKeyName(), out ModelId, out modelId);

            String queryProps = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new QueryPropWriter(), schema, ns, ns, allowPropertyCallback: p =>
            {
                return(p.IsQueryable());
            });
            String customizer = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new QueryCustomizerWriter(), schema, ns, ns, allowPropertyCallback: p =>
            {
                return(p.IsQueryable());
            });

            return(Create(ns, Model, model, Models, models, queryProps, customizer, schema.GetKeyType().GetTypeAsNullable(), ModelId, modelId, schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }
        /// <summary>
        /// Create a cshtml view. OutDir must match the folder where the view will be located, use / between folders.
        /// This is important because it will be set as the runner and must match the typescript file.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <param name="propertyNames">The property names.</param>
        /// <returns></returns>
        public static String Get(JsonSchema4 schema, IEnumerable <String> propertyNames = null)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);

            if (propertyNames == null)
            {
                propertyNames = new String[] { "Thing" };
            }

            return(Create(Model, model, Models, models, propertyNames, schema.Properties.Values.Any(i => i.IsQueryableShowOnUi())));
        }
Ejemplo n.º 13
0
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);

            var    authAttribute = "";
            String authName      = schema.GetAuthorizationRoleString();

            if (authName != null)
            {
                authAttribute = $@"[Authorize(Roles = {authName})]
        ";
            }
            return(Create(ns, NameGenerator.CreatePascal(schema.GetUiControllerName()), Model, model, Models, models, authAttribute));
        }
        public static string GetTestHelpers(JsonSchema4 schema, string ns, out string inputToEntityEqualAssertFunc, out string entityToViewEqualAssertFunc, out string createInputFunc, out string createEntityFunc, out string createViewFunc)
        {
            String createArgs = "";

            inputToEntityEqualAssertFunc = "";
            if (schema.CreateInputModel() && schema.CreateEntity())
            {
                inputToEntityEqualAssertFunc = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new ModelEqualityAssert(i => i.OnInputModel && i.OnEntity, "Input", "Entity"), schema, ns, ns);
            }

            entityToViewEqualAssertFunc = "";
            if (schema.CreateEntity() && schema.CreateViewModel())
            {
                entityToViewEqualAssertFunc = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new ModelEqualityAssert(i => i.OnEntity && i.OnViewModel, "Entity", ""), schema, ns, ns);
            }

            createInputFunc = "";
            if (schema.CreateInputModel())
            {
                createArgs      = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new ModelCreateArgs(), schema, ns, ns, p => p.CreateInputModel());
                createInputFunc = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new CreateInputModel(createArgs), schema, ns, ns, p => p.CreateInputModel());
            }

            createEntityFunc = "";
            if (schema.CreateEntity())
            {
                createArgs       = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new ModelCreateArgs(), schema, ns, ns, p => p.CreateEntity());
                createEntityFunc = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new CreateEntity(schema, createArgs), schema, ns, ns, p => p.CreateEntity());
            }

            createViewFunc = "";
            if (schema.CreateViewModel())
            {
                createArgs     = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new ModelCreateArgs(), schema, ns, ns, p => p.CreateViewModel());
                createViewFunc = ModelTypeGenerator.Create(schema, schema.GetPluralName(), new CreateViewModel(schema, createArgs), schema, ns, ns, p => p.CreateViewModel());
            }

            return(createArgs);
        }
        public static String Get(JsonSchema4 schema, String ns)
        {
            String Model, model;

            NameGenerator.CreatePascalAndCamel(schema.Title, out Model, out model);
            String Models, models;

            NameGenerator.CreatePascalAndCamel(schema.GetPluralName(), out Models, out models);
            String ModelId, modelId;

            NameGenerator.CreatePascalAndCamel(schema.GetKeyName(), out ModelId, out modelId);

            var    additionalAuthorize = "";
            String authName            = schema.GetAuthorizationRoleString();

            if (authName != null)
            {
                additionalAuthorize = $", Roles = {authName}";
            }
            return(Create(ns, Model, model, Models, models, additionalAuthorize, schema.GetKeyType().Name, ModelId, modelId, schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }
        private static IEnumerable <KeyValuePair <String, JsonProperty> > WriteManySide(JsonSchema4 schema, JsonSchema4 other, RelationshipSettings relationship)
        {
            var name = other.GetPluralName();

            if (!schema.Properties.ContainsKey(name)) //Don't write if schema defined property.
            {
                yield return(new KeyValuePair <string, JsonProperty>
                             (
                                 key: name,
                                 value: new JsonProperty()
                {
                    Type = JsonObjectType.Array,
                    Item = new JsonSchema4()
                    {
                        Type = JsonObjectType.Object,
                        Format = other.Title + "Entity",
                    },
                    Parent = schema,
                    ExtensionData = relationship.CopyExtensions(),
                }
                             ));
            }
        }
 public static String GetFileName(JsonSchema4 schema)
 {
     return($"Controllers/Api/{schema.GetPluralName()}Controller.cs");
 }
 public static String GetFileName(JsonSchema4 schema)
 {
     return($"Views/{schema.GetUiControllerName()}/{schema.GetPluralName()}.ts");
 }