Ejemplo n.º 1
0
        public static bool Serialize(string filePath, SystemSetting setting)
        {
            if (setting == null)
            {
                return false;
            }

            return SerializerProviderFactory.Create(SerializerType.Xml).
                Serialize(filePath, setting);
        }
        public void Save(Window window)
        {
            if (string.IsNullOrWhiteSpace(this.SelectedTemplate))
            {
                MessageBox.Show("请选择有效的模板!", "系统设置...");

                return;
            }

            if (string.IsNullOrWhiteSpace(this.NameSpace))
            {
                MessageBox.Show("请输入命名空间!", "系统设置...");

                return;
            }

            if (!Directory.Exists(this.OutputDirectory))
            {
                MessageBox.Show("请选择有效的文件输出路径!", "系统设置...");

                return;
            }

            var setting = new SystemSetting();
            setting.AddAttribute = this.HasAttribute;
            setting.DefaultNameSpace = this.NameSpace.Trim();
            setting.OutputDir = this.OutputDirectory;
            setting.SelectedTemplate = this.SelectedTemplate;

            SystemSetting.Serialize(SystemConfig.SettingFilePath, setting);

            if (window != null)
            {
                window.Close();
            }
        }
Ejemplo n.º 3
0
        private void GenerateFile(IList<string> names, OperationType operationType, SystemSetting setting, string templateFilePath)
        {
            if(names==null||names.Count==0)
            {
                return;
            }

            foreach(var name in names)
            {
                GenerateFile(name, operationType, setting, templateFilePath, true);
            }
        }
Ejemplo n.º 4
0
        private bool CheckSystemSetting(out SystemSetting setting , out string templateFilePath ,out string error)
        {
            setting = SystemSetting.Deserialize(SystemConfig.SettingFilePath);
            templateFilePath = null;
            error = string.Empty;

            if(setting==null)
            {
                error += "不存在相关系统设置,请设置系统配置!";
                return false;
            }

            templateFilePath = SystemConfig.TemplateFilePath + setting.SelectedTemplate;

            if (!File.Exists(templateFilePath))
            {
                error += "不存在有效的模板文件,请设置系统配置模板文件!";
                return false;
               
            }

            return true;
        }
Ejemplo n.º 5
0
        private void GenerateFile(string name, OperationType operationType, SystemSetting setting,
            string templateFilePath, bool generateFile,bool openFile= false)
        {
            string content = this._provider.Build(name.Trim(), operationType,
                                                  setting.DefaultNameSpace,setting.AddAttribute,templateFilePath);
            this.rtxtCode.Text = content;

            if(generateFile)
            {
                string outputDir = setting.OutputDir;

                if(!Directory.Exists(setting.OutputDir))
                {
                    Directory.CreateDirectory(SystemConfig.OutputFilePath);
                    outputDir = SystemConfig.OutputFilePath;
                    SystemSetting.Serialize(SystemConfig.SettingFilePath, setting);
                }

                string outputFileName = outputDir + "\\" + name.Trim() + ".cs";
                File.WriteAllText(outputFileName, content.Replace("\n","\r\n"),Encoding.GetEncoding("gb2312"));
                Process.Start(outputFileName);
            }
        }
Ejemplo n.º 6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.cmbTemplates.Text))
            {
                MessageBox.Show("请选择有效的模板!", "系统设置...", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if(string.IsNullOrWhiteSpace(this.textBox1.Text))
            {
                MessageBox.Show("请输入命名空间!", "系统设置...", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (!Directory.Exists(this.txtOutputDir.Text))
            {
                MessageBox.Show("请选择有效的文件输出路径!", "系统设置...", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            var setting =new SystemSetting();
            setting.AddAttribute = this.ckbAddAttribute.Checked;
            setting.DefaultNameSpace = this.textBox1.Text.Trim();
            setting.OutputDir = this.txtOutputDir.Text;
            setting.SelectedTemplate = this.cmbTemplates.Text;

            SystemSetting.Serialize(SystemConfig.SettingFilePath, setting);

            this.Close();
        }