Пример #1
0
        public static BuilderModel GetBuilderInfo(this MemberInfo info)
        {
            BuilderModel model = new BuilderModel();

            model.SetName(info.Name);
            switch (info.MemberType)
            {
            case MemberTypes.Field:

                model.SetType(((FieldInfo)info).FieldType);
                break;


            case MemberTypes.Property:

                model.SetType(((PropertyInfo)info).PropertyType);
                break;


            default:
                break;
            }


            return(model);
        }
Пример #2
0
        /// <summary>
        /// 生成代码单击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateCode_Click(object sender, RoutedEventArgs e)
        {
            string modelpath = ConfigHelper.Instance._ModelPath;
            string dalpath   = ConfigHelper.Instance._DalPath;
            string bllpath   = ConfigHelper.Instance._BllPath;

            if (TablecomboBox.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个表");
                return;
            }
            string tableName             = TablecomboBox.SelectedItem.ToString();
            DataColumnCollection columns = Returncolumns(tableName);

            //生成实体类
            BuilderModel builderModel = new BuilderModel(GetTableColumnInfo(tableName), tableName, modelpath);

            txtModel.Text = builderModel.CreatModel();
            //生成数据访问代码
            BuilderDAL builderDal = new BuilderDAL(tableName, GetTableColumnInfo(tableName), "SqlHelper.Instance", dalpath);

            txtDAL.Text = builderDal.GetDALCode(true, true, true, true, true, true, true);
            //生成业务逻辑层代码
            BuilderBLL builderBll = new BuilderBLL(tableName, GetTableColumnInfo(tableName), bllpath);

            txtBLL.Text = builderBll.GetBLLCode(true, true, true, true, true, true, true);

            ConfigHelper.Instance.WriteNamespaceConfig("modelpath", txtModelPath.Text);
            ConfigHelper.Instance.WriteNamespaceConfig("dalpath", txtDalPath.Text);
            ConfigHelper.Instance.WriteNamespaceConfig("bllpath", txtBllPath.Text);
        }
Пример #3
0
        public TariffModel RunTariff(int consumption, BuilderModel data)
        {
            var tariffModel = new TariffModel();
            var basicCost   = data.BaseCost * data.frequency.GetValueOrDefault();      // To calculate the basic cost yearly.

            tariffModel.AnnualCost = basicCost + (consumption * data.ConsumptionCost); // Calculation logic for Basic engine.
            tariffModel.TariffName = "Basic electricity tariff";

            return(tariffModel);
        }
        public TariffModel RunTariff(int consumption, BuilderModel data)
        {
            var tariffModel = new TariffModel();

            tariffModel.TariffName = "Packaged electricity tariff";

            if (consumption <= 4000)
            {
                tariffModel.AnnualCost = 800; // Return 800 if the consumption is less than or equal to 4000
            }
            else
            {
                var differenceFromBaseCost = consumption - 4000;
                tariffModel.AnnualCost = data.BaseCost + (differenceFromBaseCost * data.ConsumptionCost); // Calculation logic for Packaged engine.
            }

            return(tariffModel);
        }
Пример #5
0
        public QueueFiles(IEnumerable <string> filepaths, List <CONSTS.Filter> filters, List <string> exceptions, bool rebuildModel, int minScore)
        {
            try
            {
                Files = new List <QFile>();
                if (rebuildModel || !File.Exists(ModelLocation))        //обучаем модель заново
                {
                    QueueEvent("Обучение нейросети...");
                    var datasetpath = BuilderModel.GetDataSetPath();
                    var sortedDirs  = filters.ConvertAll(x => x.directory);
                    BuilderModel.BuildModel(sortedDirs, filepaths, BuilderModel.MyTrainerStrategy.OVAAveragedPerceptronTrainer, true);
                    QueueEvent("Обучение окончено.");
                    QueueEvent(BuilderModel.Errors.Message);
                }
                if (!File.Exists(ModelLocation))
                {
                    throw new Exception("Ошибка при обучении сортировщика. Модель не создана");
                }
                NSorter = new Sorter(ModelLocation);
                var sortedFiles = NSorter.PredictAll(filepaths);
                var parentDir   = Path.GetDirectoryName(filepaths.First());
                foreach (var sortedfile in sortedFiles)
                {
                    if (sortedfile.Score * 100 >= (float)(minScore))
                    {
                        Files.Add(new QFile(Path.Combine(parentDir, sortedfile.FileName), sortedfile.Label, exceptions, sortedfile.Score));
                    }
                    else
                    {
                        Files.Add(new QFile(Path.Combine(parentDir, sortedfile.FileName), "", exceptions, sortedfile.Score));
                    }
                }
            }
            catch (Exception ex)
            {
                QueueEvent(ex.Message);
                QueueEvent(BuilderModel.Errors.Message);

                //MessageBox.Show("QueueFiles", ex.Message);
            }
        }
Пример #6
0
        public void NoConstructors_OneGetSetProperty()
        {
            // Arrange
            var property   = new BuilderProperty("string", "Name", "_name", "\"Name\"", "name");
            var properties = new[]
            {
                property
            };
            var builderModel = new BuilderModel("ExampleClass", "ExampleClassBuilder", properties);

            // Act
            var result = Execute(builderModel);

            // Assert
            var expected = @"    public class ExampleClassBuilder
    {
        private string _name;

        public ExampleClassBuilder()
        {
            _name = ""Name"";
        }

        public ExampleClassBuilder WithName(string name)
        {
            _name = name;
            return this;
        }

        public ExampleClass Build()
        {
            return new ExampleClass()
            {
                Name = _name
            };
        }
    }";

            Assert.Equal(expected, result);
        }
Пример #7
0
        public string Execute(BuilderModel builderModel)
        {
            var creator = new BuilderCodeGenerator();

            return(creator.Generate(builderModel));
        }
Пример #8
0
 public IActionResult OnPostGenerate([FromBody] BuilderModel createModel)
 {
     return(new JsonResult(_builderService.CreateCode(createModel)));
 }