示例#1
0
        private static void AddTableColumns(CodeGenConfig config, Table table)
        {
            if (CodeGenConfig.FindConfigList(config, "Column") != null)
            {
                return;
            }

            var eci     = string.IsNullOrEmpty(config.GetAttributeValue <string>("IncludeColumns")) ? new List <string>() : config.GetAttributeValue <string>("IncludeColumns").Split(',').Select(x => x.Trim()).ToList();
            var ecx     = string.IsNullOrEmpty(config.GetAttributeValue <string>("ExcludeColumns")) ? new List <string>() : config.GetAttributeValue <string>("ExcludeColumns").Split(',').Select(x => x.Trim()).ToList();
            var colList = new List <CodeGenConfig>();

            foreach (var col in table.Columns)
            {
                if (string.IsNullOrEmpty(col.Name))
                {
                    continue;
                }

                if (eci.Count > 0 && !eci.Contains(col.Name))
                {
                    continue;
                }

                if (ecx.Contains(col.Name))
                {
                    continue;
                }

                var c = new CodeGenConfig("Column", config);
                c.AttributeAdd("Name", col.Name);
                c.AttributeAdd("Type", col.Type);
                c.AttributeAdd("IsNullable", XmlConvert.ToString(col.IsNullable));
                c.AttributeAdd("IsIdentity", XmlConvert.ToString(col.IsIdentity));
                c.AttributeAdd("IsPrimaryKey", XmlConvert.ToString(col.IsPrimaryKey));
                c.AttributeAdd("IsComputed", XmlConvert.ToString(col.IsComputed));
                if (col.Length.HasValue)
                {
                    c.AttributeAdd("Length", XmlConvert.ToString(col.Length.Value));
                }

                if (col.Precision.HasValue)
                {
                    c.AttributeAdd("Precision", XmlConvert.ToString(col.Precision.Value));
                }

                if (col.Scale.HasValue)
                {
                    c.AttributeAdd("Scale", XmlConvert.ToString(col.Scale.Value));
                }

                c.AttributeAdd("DotNetType", col.DotNetType);

                colList.Add(c);
            }

            if (colList.Count > 0)
            {
                config.Children.Add("Column", colList);
            }
        }
示例#2
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public void LoadBeforeChildren(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (_tables == null)
            {
                LoadDatabase(config.Root.GetAttributeValue <string>("ConnectionString") ?? throw new CodeGenException("Config.ConnectionString has not been specified."), config.Root.GetAttributeValue <string>("RefDatabaseSchema"));
            }

            var name = config.GetAttributeValue <string>("Name") ?? throw new CodeGenException("Table has no Name attribute specified.");

            config.AttributeAdd("Schema", "dbo");
            var schema = config.GetAttributeValue <string>("Schema");
            var table  = _tables.Where(x => x.Name == name && x.Schema == schema).SingleOrDefault();

            if (table == null)
            {
                throw new CodeGenException($"Specified Schema.Table '{schema}.{name}' not found in database.");
            }

            config.AttributeAdd("Alias", table.Alias);
            config.AttributeAdd("IsAView", XmlConvert.ToString(table.IsAView));
        }
示例#3
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public Task LoadBeforeChildrenAsync(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (!config.Attributes.ContainsKey("Name"))
            {
                throw new CodeGenException("Property element must have a Name property.");
            }

            config.AttributeAdd("Type", "string");

            if (config.GetAttributeValue <string>("Type").StartsWith("RefDataNamespace.", StringComparison.InvariantCulture))
            {
                config.AttributeAdd("RefDataType", "string");
            }

            if (config.GetAttributeValue <string>("RefDataType") != null)
            {
                config.AttributeAdd("Text", string.Format(System.Globalization.CultureInfo.InvariantCulture, "{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"])));
            }
            else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"] !))
            {
                config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"]));
            }
示例#4
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public void LoadBeforeChildren(CodeGenConfig config)
        {
            CodeGenConfig entity = CodeGenConfig.FindConfig(config, "Entity");

            if (config.GetAttributeValue <bool>("UniqueKey"))
            {
                List <CodeGenConfig> paramList = new List <CodeGenConfig>();
                var layerPassing = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "ToManagerSet" : "All";
                var isMandatory = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "false" : "true";

                var propConfigs = CodeGenConfig.FindConfigList(config, "Property") ?? new List <CodeGenConfig>();
                foreach (CodeGenConfig propConfig in propConfigs)
                {
                    if (!propConfig.GetAttributeValue <bool>("UniqueKey"))
                    {
                        continue;
                    }

                    CodeGenConfig p = new CodeGenConfig("Parameter", config);
                    p.AttributeAdd("Name", propConfig.GetAttributeValue <string>("Name"));
                    p.AttributeAdd("LayerPassing", layerPassing);
                    p.AttributeAdd("IsMandatory", isMandatory);
                    ParameterConfigLoader.UpdateConfigFromProperty(p, propConfig.GetAttributeValue <string>("Name"));
                    paramList.Add(p);
                }

                if (paramList.Count > 0)
                {
                    config.Children.Add("Parameter", paramList);
                }
            }

            config.AttributeAdd("OperationType", "Get");
            config.AttributeAdd("ReturnType", "void");

            if (config.Attributes.ContainsKey("ReturnType"))
            {
                config.AttributeAdd("ReturnText", string.Format("A resultant {{{{{0}}}}}.", config.Attributes["ReturnType"]));
            }
            else
            {
                config.AttributeAdd("ReturnText", string.Format("A resultant {{{{{0}}}}}.", entity.Attributes["Name"]));
            }

            config.AttributeUpdate("ReturnText", config.Attributes["ReturnText"]);

            if (config.Attributes.ContainsKey("OperationType") && config.Attributes["OperationType"] == "Custom")
            {
                config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"]));
            }

            if (config.Attributes.ContainsKey("Text"))
            {
                config.AttributeUpdate("Text", config.Attributes["Text"]);
            }

            config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"]));
            config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"]));
            config.AttributeAdd("QualifiedName", entity.Attributes["Name"] + config.Attributes["Name"]);
        }
示例#5
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public void LoadBeforeChildren(CodeGenConfig config)
        {
            if (config.Attributes.ContainsKey("Property"))
            {
                UpdateConfigFromProperty(config, config.Attributes["Property"]);
            }

            config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"]));
            config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"]));
            config.AttributeAdd("Type", "string");
            config.AttributeAdd("LayerPassing", "All");

            if (config.GetAttributeValue <string>("RefDataType") != null)
            {
                config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"])));
            }
            else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"]))
            {
                config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"]));
            }
            else
            {
                config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"])));
            }

            config.AttributeUpdate("Text", config.Attributes["Text"]);
        }
示例#6
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public async Task LoadBeforeChildrenAsync(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (_tables == null)
            {
                await LoadDatabaseAsync(config.Root.GetAttributeValue <string>("ConnectionString") ?? throw new CodeGenException("Config.ConnectionString has not been specified."), config.Root.GetAttributeValue <string>("RefDatabaseSchema")).ConfigureAwait(false);
            }

            if (!config.Attributes.ContainsKey("Name"))
            {
                throw new CodeGenException("Table element must have a Name property.");
            }

            var name = config.GetAttributeValue <string>("Name") !;

            config.AttributeAdd("Schema", "dbo");
            var schema = config.GetAttributeValue <string>("Schema");
            var table  = _tables.Where(x => x.Name == name && x.Schema == schema).SingleOrDefault();

            if (table == null)
            {
                throw new CodeGenException($"Specified Schema.Table '{schema}.{name}' not found in database.");
            }

            config.AttributeAdd("Alias", table.Alias);
            config.AttributeAdd("IsAView", XmlConvert.ToString(table.IsAView));
        }
示例#7
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public Task LoadBeforeChildrenAsync(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (!config.Attributes.ContainsKey("Name"))
            {
                throw new CodeGenException("Parameter element must have a Name property.");
            }

            if (config.Attributes.ContainsKey("Property"))
            {
                UpdateConfigFromProperty(config, config.Attributes["Property"] !);
            }

            config.AttributeAdd("PrivateName", StringConversion.ToPrivateCase(config.Attributes["Name"]));
            config.AttributeAdd("ArgumentName", StringConversion.ToCamelCase(config.Attributes["Name"]));
            config.AttributeAdd("Type", "string");
            config.AttributeAdd("LayerPassing", "All");

            if (config.GetAttributeValue <string>("RefDataType") != null)
            {
                config.AttributeAdd("Text", string.Format(System.Globalization.CultureInfo.InvariantCulture, "{1} (see {{{{{0}}}}})", config.Attributes["Type"], StringConversion.ToSentenceCase(config.Attributes["Name"])));
            }
            else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"] !))
            {
                config.AttributeAdd("Text", StringConversion.ToSentenceCase(config.Attributes["Name"]));
            }
示例#8
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public void LoadBeforeChildren(CodeGenConfig config)
        {
            config.AttributeAdd("Type", "string");

            if (config.GetAttributeValue <string>("RefDataType") != null)
            {
                config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"])));
            }
            else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"]))
            {
                config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"]));
            }
            else
            {
                config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"])));
            }

            config.AttributeUpdate("Text", config.Attributes["Text"]);

            config.AttributeAdd("StringTrim", "End");
            config.AttributeAdd("StringTransform", "EmptyToNull");
            config.AttributeAdd("DateTimeTransform", "DateTimeLocal");
            config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"]));
            config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"]));
            config.AttributeAdd("DisplayName", GenerateDisplayName(config));
        }
示例#9
0
        private void ExcludeUdtColumns(CodeGenConfig config)
        {
            var ecx = string.IsNullOrEmpty(config.GetAttributeValue <string>("UdtExcludeColumns")) ? new List <string>() : config.GetAttributeValue <string>("UdtExcludeColumns").Split(',').Select(x => x.Trim()).ToList();

            if (ecx.Count == 0)
            {
                return;
            }

            var csConfig = CodeGenConfig.FindConfigList(config, "Column");

            if (csConfig != null)
            {
                foreach (CodeGenConfig cConfig in csConfig)
                {
                    if (ecx.Contains(cConfig.GetAttributeValue <string>("Name")))
                    {
                        cConfig.AttributeUpdate("UdtExclude", "true");
                    }
                }
            }
        }
示例#10
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> after the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public void LoadAfterChildren(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var schema = config.GetAttributeValue <string>("Schema");
            var name   = config.GetAttributeValue <string>("Name");
            var table  = _tables.Where(x => x.Name == name && x.Schema == schema).SingleOrDefault();

            AddTableColumns(config, table);
            ExcludeUdtColumns(config);

            var autoGet    = config.GetAttributeValue <bool>("Get");
            var autoGetAll = config.GetAttributeValue <bool>("GetAll");
            var autoCreate = config.GetAttributeValue <bool>("Create");
            var autoUpdate = config.GetAttributeValue <bool>("Update");
            var autoUpsert = config.GetAttributeValue <bool>("Upsert");
            var autoDelete = config.GetAttributeValue <bool>("Delete");
            var autoMerge  = config.GetAttributeValue <bool>("Merge");

            // Check quick Get/Create/Update/Delete configurations.
            var spsConfig = CodeGenConfig.FindConfigList(config, "StoredProcedure");

            if (spsConfig != null)
            {
                foreach (CodeGenConfig spConfig in spsConfig)
                {
                    switch (spConfig.GetAttributeValue <string>("Name"))
                    {
                    case "Get": autoGet = false; break;

                    case "GetAll": autoGetAll = false; break;

                    case "Create": autoCreate = false; break;

                    case "Update": autoUpdate = false; break;

                    case "Upsert": autoUpsert = false; break;

                    case "Delete": autoDelete = false; break;

                    case "Merge": autoMerge = false; break;
                    }
                }
            }

            // Stop if no quick configs.
            if (!autoGet && !autoGetAll && !autoCreate && !autoUpdate && !autoUpsert && !autoDelete && !autoMerge)
            {
                return;
            }

            // Where no stored procedures already defined, need to add in the placeholder.
            if (spsConfig == null)
            {
                spsConfig = new List <CodeGenConfig>();
                config.Children.Add("StoredProcedure", spsConfig);
            }

            // Add each stored proecedure.
            if (autoMerge)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Merge");
                sp.AttributeAdd("Type", "Merge");
                spsConfig.Insert(0, sp);
            }

            if (autoDelete)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Delete");
                sp.AttributeAdd("Type", "Delete");
                spsConfig.Insert(0, sp);
            }

            if (autoUpsert)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Upsert");
                sp.AttributeAdd("Type", "Upsert");
                spsConfig.Insert(0, sp);
            }

            if (autoUpdate)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Update");
                sp.AttributeAdd("Type", "Update");
                spsConfig.Insert(0, sp);
            }

            if (autoCreate)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Create");
                sp.AttributeAdd("Type", "Create");
                spsConfig.Insert(0, sp);
            }

            if (autoGetAll)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "GetAll");
                sp.AttributeAdd("Type", "GetAll");

                if (config.Root.Attributes.ContainsKey("RefDatabaseSchema") && table.Schema == config.Root.GetAttributeValue <string>("RefDatabaseSchema"))
                {
                    var           obList = new List <CodeGenConfig>();
                    CodeGenConfig ob     = new CodeGenConfig("OrderBy", config);
                    ob.AttributeAdd("Name", "SortOrder");
                    ob.AttributeAdd("Order", "ASC");
                    obList.Add(ob);

                    ob = new CodeGenConfig("OrderBy", config);
                    ob.AttributeAdd("Name", "Code");
                    ob.AttributeAdd("Order", "ASC");
                    obList.Add(ob);

                    sp.Children.Add("OrderBy", obList);
                }

                spsConfig.Insert(0, sp);
            }

            if (autoGet)
            {
                CodeGenConfig sp = new CodeGenConfig("StoredProcedure", config);
                sp.AttributeAdd("Name", "Get");
                sp.AttributeAdd("Type", "Get");
                spsConfig.Insert(0, sp);
            }
        }
示例#11
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> after the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public async Task LoadAfterChildrenAsync(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var autoGet    = config.GetAttributeValue <bool>("Get");
            var autoGetAll = config.GetAttributeValue <bool>("GetAll");
            var autoCreate = config.GetAttributeValue <bool>("Create");
            var autoUpdate = config.GetAttributeValue <bool>("Update");
            var autoPatch  = config.GetAttributeValue <bool>("Patch");
            var autoDelete = config.GetAttributeValue <bool>("Delete");

            // Check quick Get/Create/Update/Delete configurations.
            var opsConfig = CodeGenConfig.FindConfigList(config, "Operation");

            if (opsConfig != null)
            {
                foreach (CodeGenConfig opConfig in opsConfig)
                {
                    switch (opConfig.GetAttributeValue <string>("Name"))
                    {
                    case "Get": autoGet = false; break;

                    case "GetAll": autoGetAll = false; break;

                    case "Create": autoCreate = false; break;

                    case "Update": autoUpdate = false; break;

                    case "Patch": autoPatch = false; break;

                    case "Delete": autoDelete = false; break;
                    }
                }
            }

            // Stop if no quick configs.
            if (!autoGet && !autoGetAll && !autoCreate && !autoUpdate && !autoDelete)
            {
                return;
            }

            // Where no operations already defined, need to add in the placeholder.
            if (opsConfig == null)
            {
                opsConfig = new List <CodeGenConfig>();
                config.Children.Add("Operation", opsConfig);
            }

            // Where ReferenceData is being generated; add an 'Id' property to enable the code gen to function.
            var refDataType = config.GetAttributeValue <string>("RefDataType");

            if (refDataType != null)
            {
                var propsConfig = CodeGenConfig.FindConfigList(config, "Property");
                if (propsConfig == null)
                {
                    propsConfig = new List <CodeGenConfig>();
                    config.Children.Add("Property", propsConfig);
                }

                ApplyRefDataProperties(config, propsConfig, refDataType);
            }

            // Determine the WebApiRout based on the unique key.
            var webApiRoute = string.Join("/", CodeGenConfig.FindConfigList(config, "Property").Where(x => x.GetAttributeValue <bool>("UniqueKey")).Select(x => "{" + x.GetAttributeValue <string>("ArgumentName") + "}"));

            if (string.IsNullOrEmpty(webApiRoute))
            {
                return;
            }

            // Add each operation.
            if (autoDelete)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "Delete");
                o.AttributeAdd("OperationType", "Delete");
                o.AttributeAdd("UniqueKey", "true");
                o.AttributeAdd("WebApiRoute", webApiRoute);
                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }

            if (autoPatch)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "Patch");
                o.AttributeAdd("OperationType", "Patch");
                o.AttributeAdd("UniqueKey", "true");
                o.AttributeAdd("WebApiRoute", webApiRoute);
                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }

            if (autoUpdate)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "Update");
                o.AttributeAdd("OperationType", "Update");
                o.AttributeAdd("UniqueKey", "true");
                o.AttributeAdd("WebApiRoute", webApiRoute);

                if (refDataType != null)
                {
                    o.AttributeAdd("ValidatorFluent", $"Entity(new ReferenceDataValidator<{config.GetAttributeValue<string>("Name")}>())");
                }

                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }

            if (autoCreate)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "Create");
                o.AttributeAdd("OperationType", "Create");
                o.AttributeAdd("UniqueKey", "false");
                o.AttributeAdd("WebApiRoute", "");

                if (refDataType != null)
                {
                    o.AttributeAdd("ValidatorFluent", $"Entity(new ReferenceDataValidator<{config.GetAttributeValue<string>("Name")}>())");
                }

                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }

            if (autoGet)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "Get");
                o.AttributeAdd("OperationType", "Get");
                o.AttributeAdd("UniqueKey", "true");
                o.AttributeAdd("WebApiRoute", webApiRoute);
                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }

            if (autoGetAll)
            {
                CodeGenConfig o = new CodeGenConfig("Operation", config);
                o.AttributeAdd("Name", "GetAll");
                o.AttributeAdd("OperationType", "GetColl");
                o.AttributeAdd("WebApiRoute", "");
                opsConfig.Insert(0, await ApplyOperationLoaderAsync(o).ConfigureAwait(false));
            }
        }
示例#12
0
        /// <summary>
        /// Applies standard and configured reference data properties.
        /// </summary>
        private static void ApplyRefDataProperties(CodeGenConfig config, List <CodeGenConfig> propsConfig, string refDataType)
        {
            var i = 0;

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "Id"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "Id");
                p.AttributeAdd("ArgumentName", "id");
                p.AttributeAdd("PrivateName", "_id");
                p.AttributeAdd("Text", "{{" + config.GetAttributeValue <string>("Name") + "}} identifier");
                p.AttributeAdd("Type", refDataType);
                p.AttributeAdd("UniqueKey", "true");
                p.AttributeAdd("DataAutoGenerated", "true");
                p.AttributeAdd("DataName", config.GetAttributeValue <string>("Name") + "Id");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "Code"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "Code");
                p.AttributeAdd("ArgumentName", "code");
                p.AttributeAdd("PrivateName", "_code");
                p.AttributeAdd("Type", "string");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "Text"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "Text");
                p.AttributeAdd("ArgumentName", "text");
                p.AttributeAdd("PrivateName", "_text");
                p.AttributeAdd("Type", "string");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "IsActive"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "IsActive");
                p.AttributeAdd("ArgumentName", "isActive");
                p.AttributeAdd("PrivateName", "_isActive");
                p.AttributeAdd("Type", "bool");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "SortOrder"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "SortOrder");
                p.AttributeAdd("ArgumentName", "sortOrder");
                p.AttributeAdd("PrivateName", "_sortOrder");
                p.AttributeAdd("Type", "int");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "ETag"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "ETag");
                p.AttributeAdd("ArgumentName", "etag");
                p.AttributeAdd("PrivateName", "_etag");
                p.AttributeAdd("Type", "string");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            if (!propsConfig.Any(x => x.GetAttributeValue <string>("Name") == "ChangeLog"))
            {
                CodeGenConfig p = new CodeGenConfig("Property", config);
                p.AttributeAdd("Name", "ChangeLog");
                p.AttributeAdd("ArgumentName", "changeLog");
                p.AttributeAdd("PrivateName", "_changeLog");
                p.AttributeAdd("Type", "ChangeLog");
                p.AttributeAdd("Inherited", "true");
                propsConfig.Insert(i++, p);
            }

            var pns = config.GetAttributeValue <string>("RefDataProperties");

            if (!string.IsNullOrEmpty(pns))
            {
                foreach (var pn in pns.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    CodeGenConfig p = new CodeGenConfig(pn, config);
                    p.AttributeAdd("Name", pn);
                    p.AttributeAdd("Type", "ChangeLog");
                    p.AttributeAdd("Inherited", "true");
                    propsConfig.Insert(i++, p);
                }
            }
        }
示例#13
0
        /// <summary>
        /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>.
        /// </summary>
        /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param>
        public Task LoadBeforeChildrenAsync(CodeGenConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (!config.Attributes.ContainsKey("Name"))
            {
                throw new CodeGenException("Operation element must have a Name property.");
            }

            CodeGenConfig entity = CodeGenConfig.FindConfig(config, "Entity") ?? throw new CodeGenException("Operation element must have an Entity element parent.");

            if (config.GetAttributeValue <bool>("UniqueKey"))
            {
                List <CodeGenConfig> paramList = new List <CodeGenConfig>();
                var layerPassing = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "ToManagerSet" : "All";
                var isMandatory = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "false" : "true";

                var propConfigs = CodeGenConfig.FindConfigList(config, "Property") ?? new List <CodeGenConfig>();
                foreach (CodeGenConfig propConfig in propConfigs)
                {
                    if (!propConfig.GetAttributeValue <bool>("UniqueKey"))
                    {
                        continue;
                    }

                    CodeGenConfig p = new CodeGenConfig("Parameter", config);
                    p.AttributeAdd("Name", propConfig.GetAttributeValue <string>("Name"));
                    p.AttributeAdd("LayerPassing", layerPassing);
                    p.AttributeAdd("IsMandatory", isMandatory);
                    ParameterConfigLoader.UpdateConfigFromProperty(p, propConfig.GetAttributeValue <string>("Name"));
                    paramList.Add(p);
                }

                if (paramList.Count > 0)
                {
                    config.Children.Add("Parameter", paramList);
                }
            }

            config.AttributeAdd("OperationType", "Get");
            config.AttributeAdd("ReturnType", "void");

            if (config.Attributes.ContainsKey("ReturnType"))
            {
                config.AttributeAdd("ReturnText", string.Format(System.Globalization.CultureInfo.InvariantCulture, "A resultant {{{{{0}}}}}.", config.Attributes["ReturnType"]));
            }
            else
            {
                config.AttributeAdd("ReturnText", string.Format(System.Globalization.CultureInfo.InvariantCulture, "A resultant {{{{{0}}}}}.", entity.Attributes["Name"]));
            }

            config.AttributeUpdate("ReturnText", config.Attributes["ReturnText"]);

            if (config.Attributes.ContainsKey("OperationType") && config.Attributes["OperationType"] == "Custom")
            {
                config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"]));
            }

            if (config.Attributes.ContainsKey("Text"))
            {
                config.AttributeUpdate("Text", config.Attributes["Text"]);
            }

            config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"]));
            config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"]));
            config.AttributeAdd("QualifiedName", entity.Attributes["Name"] + config.Attributes["Name"]);

            return(Task.CompletedTask);
        }