private string GeneratePackageImplement(string name) { var pattern = @"// {PackageClassName}.cs // // Generated by Kuicker.Tools.EntityGenerator. // {Today} using System; using System.Collections.Generic; using System.ComponentModel; using Kuicker; using Kuicker.Data; namespace {Namespace} { /// <summary> /// {Comments} /// </summary> [Description(""{Comments}"")] [Package] public partial class {PackageClassName} : IPackage { } }"; var now = DateTime.Now.yyyy_MM_dd_HH_mm_ss_fff(); var nameSpace = txtNamespace.Text; var packageName = name; var packageClassName = packageName .TrimStart(txtPackageTrimPrefix.Text); packageClassName = NamingFilter(packageClassName) .AppendSuffix(txtPackageAppendSuffix.Text); if (packageClassName.IsNullOrEmpty()) { packageClassName = packageName; } var packageSchema = PackageSchemas.FirstOrDefault(x => x.PackageName == packageName ); var sb = new StringBuilder(); sb.Append(pattern); sb .Replace("{Comments}", packageSchema.PackageName) .Replace("{Today}", now) .Replace("{Namespace}", nameSpace) .Replace("{PackageClassName}", packageClassName); return(sb.ToString()); }
private string GeneratePackageSchema(string name) { var pattern = @"// {PackageClassName}.cs // // Generated by Kuicker.Tools.EntityGenerator. // {Today} using System; using System.Collections.Generic; using System.ComponentModel; using Kuicker; using Kuicker.Data; namespace {Namespace} { public partial class {PackageClassName} : IPackage { public static string __PackageName { get { return ""{PackageName}""; } } {Procedures} } }"; var now = DateTime.Now.yyyy_MM_dd_HH_mm_ss_fff(); var nameSpace = txtNamespace.Text; var packageName = name; var packageClassName = packageName .TrimStart(txtPackageTrimPrefix.Text); packageClassName = NamingFilter(packageClassName) .AppendSuffix(txtPackageAppendSuffix.Text); if (packageClassName.IsNullOrEmpty()) { packageClassName = packageName; } var packageSchema = PackageSchemas.FirstOrDefault(x => x.PackageName == packageName ); var ef = EnumCache.Get <DataFormat>(); var sbProcedures = new StringBuilder(); foreach (var procedure in packageSchema.Procedures) { var propertyName = procedure.ProcedureName .TrimStart(txtProcedureTrimPrefix.Text); propertyName = NamingFilter(propertyName); if (propertyName.IsNullOrEmpty()) { propertyName = procedure.ProcedureName; } if (sbProcedures.Length > 0) { sbProcedures.AppendLine(); } sbProcedures.AppendFormat(@" #region {2} /// <summary> /// {0} /// </summary> public static {1} {2}({3}) {{ return {2}( new EntityApi(__PackageName){4} ); }} public static {1} {2}( EntityApi api{5}) {{ return api.{6}( ""{7}""{8} ){9}; }} #endregion" , // 0 procedure.DbFullName, // 1 procedure.ToOutType(Formater), // 2 propertyName, // 3 (!procedure.Ins.IsNullOrEmpty()).If( procedure .Ins .Select(x => x.ToMethodArgument(Formater)) .Join( "," + Environment.NewLine, " ", string.Empty ) .AppendPrefix(Environment.NewLine) ), // 4 (!procedure.Ins.IsNullOrEmpty()).If( procedure .Ins .Select(x => x.ArgumentName) .Join( "," + Environment.NewLine, " ", string.Empty ) .AppendPrefix("," + Environment.NewLine) ), // 5 (!procedure.Ins.IsNullOrEmpty()).If( procedure .Ins .Select(x => x.ToMethodArgument(Formater)) .Join( "," + Environment.NewLine, " ", string.Empty ) .AppendPrefix("," + Environment.NewLine) ), // 6 procedure.ToApiMethod(), // 7 procedure.ProcedureName, // 8 (!procedure.Ins.IsNullOrEmpty()).If( procedure .Ins .Select(x => string.Format( @"new Any(""{0}"", {0})", x.ArgumentName )) .Join( "," + Environment.NewLine, " ", string.Empty ) .AppendPrefix("," + Environment.NewLine) ), // 9 procedure.ToOutFormatMethod(Formater) ); } var sb = new StringBuilder(); sb.Append(pattern); sb .Replace("{Comments}", packageSchema.PackageName) .Replace("{Today}", now) .Replace("{Namespace}", nameSpace) .Replace("{PackageClassName}", packageClassName) .Replace("{PackageName}", packageName) .Replace("{Procedures}", sbProcedures.ToString()); return(sb.ToString()); }
private void lbxPackages_SelectedIndexChanged(object sender, EventArgs e) { ListBox lbx = sender as ListBox; if (null == lbx) { return; } clbProcedures.Items.Clear(); txtCode.Text = string.Empty; string name = lbx.SelectedItem.ToString(); if (name.IsNullOrEmpty()) { return; } var obj = PackageSchemas.FirstOrDefault(x => x.PackageName == name); if (null == obj) { return; } string procedurePrefix = string.Empty; bool procedurePrefixDone = false; foreach (var procedure in obj.Procedures) { clbProcedures.Items.Add(procedure.ProcedureName, true); if (!procedurePrefixDone) { if (procedurePrefix.IsNullOrEmpty()) { string[] parts = procedure.ProcedureName.Split('_'); if (parts.Length > 1) { procedurePrefix = procedure.ProcedureName.Split('_')[0]; } else { procedurePrefixDone = true; } } else { if (procedurePrefix != procedure.ProcedureName.Split('_')[0]) { procedurePrefix = string.Empty; } else { procedurePrefix += "_"; } procedurePrefixDone = true; } } } RefreshPackage(name); }