コード例 #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (_isModified == true)
     {
         FileOprateHelp.SaveFile(rcBoxContect.Text, _cunrrentModel.Value);
         MsgBoxHelp.ShowInfo("保存成功!");
         btnSave.Enabled = false;
         _isModified     = false;
     }
 }
コード例 #2
0
 private void btnwriteProject_Click(object sender, EventArgs e)
 {
     if (_isModified == true)
     {
         FileOprateHelp.SaveFile(rcBoxContect.Text, _cunrrentModel.Value);
         btnSave.Enabled = false;
         _isModified     = false;
     }
     ModelManageLogic.WriteModel(_cunrrentModel.Text);
     //this.Close();
 }
コード例 #3
0
        private void lbl_Click(object sender, EventArgs e)
        {
            Label lbl = (Label)sender;
            ModelManageArgment obj = lbl.Tag as ModelManageArgment;

            if (_isModified)
            {
                DialogResult dialog = MessageBox.Show("当前模型已经修改,是否保存?", "Entity2Code", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk);
                if (dialog == DialogResult.Cancel)
                {
                    return;
                }
                else if (dialog == DialogResult.Yes)
                {
                    FileOprateHelp.SaveFile(rcBoxContect.Text, _cunrrentModel.Value);
                    //保存
                }
                else
                {
                    //继续
                }
            }
            SetUnSelect();
            lbl.BackColor  = Color.FromArgb(19, 130, 206);
            lbl.ForeColor  = Color.White;
            obj.isSelected = true;
            lbl.Tag        = obj;

            _cunrrentModel = obj;

            _isLocked         = false;
            _oldText          = manger.GetModelContent(obj.Value);
            rcBoxContect.Text = _oldText;
            SetRichColor();
            string[] strs   = new string[] { "Application", "IApplication", "Service", "IService", "Map" };
            bool     enable = strs.Contains(System.IO.Path.GetFileNameWithoutExtension(_cunrrentModel.Text));

            rcBoxContect.ReadOnly   = !enable;
            btnSave.Enabled         = enable;
            btnwriteProject.Enabled = enable;
            _isLocked = true;
        }
コード例 #4
0
ファイル: ServiceLogic.cs プロジェクト: comicwang/Entity2Code
        public static void CreateFrame(bool overWrite)
        {
            if (ProjectContainer.Service == null)
            {
                ProjectContainer.Service = SolutionCommon.Dte.AddWebService(SolutionCommon.Service, true);
            }

            if (ProjectContainer.Service.ProjectItems.Find("web.config") != null)
            {
                ProjectContainer.Service.ProjectItems.Find("web.config").Delete();
            }
            if (SolutionCommon.infrastryctType == InfrastructType.DbFirst)
            {
                using (StreamReader reader = new StreamReader(Path.Combine(ProjectContainer.Infrastructure.ToDirectory(), "app.config")))
                {
                    while (reader.Peek() != -1)
                    {
                        string temp = reader.ReadLine();
                        if (temp.IndexOf(ModelContainer.Resolve("$ContextName$")) != -1)
                        {
                            ModelContainer.Regist("$ConnectionString$", temp, "数据库连接字符串");
                            break;
                        }
                    }
                }
            }
            else
            {
                string str = string.Empty;
                if (CodeFirstTools.DataType == "MicrosoftSqlServer")
                {
                    str = "<add name=\"" + CodeFirstTools.DbContextName + "\" providerName=\"" + CodeFirstTools.ProviderName + "\" connectionString=\"" + CodeFirstTools.ConnectionString + ";MultipleActiveResultSets=True;Pooling=True;\"/>";
                }
                else
                {
                    str = "<add name=\"" + CodeFirstTools.DbContextName + "\" providerName=\"Oracle.DataAccess.Client\" connectionString=\"" + CodeFirstTools.ConnectionString + "\"/>";
                }
                ModelContainer.Regist("$ConnectionString$", str, "数据库连接字符串");
            }

            if (SolutionCommon.infrastryctType == InfrastructType.CodeFirst)
            {
                ModelContainer.Regist("$DBSchemaApp$", string.Format("<add key=\"DBSchema\" value=\"{0}\"/>", CodeFirstTools.SchemaName), "数据库命名空间");
            }
            else
            {
                ModelContainer.Regist("$DBSchemaApp$", "", "数据库命名空间");
            }
            CodeStaticManager staticManager = new CodeStaticManager(ConstructType.WebConfig);

            staticManager.BuildTaget = new StringCodeArgment()
            {
                Encode = Encoding.UTF8, Name = "web.config", Target = ProjectContainer.Service
            };
            staticManager.CreateCode();

            //ServiceBehinde
            string behindCode = string.Format("<%@ ServiceHost Language=\"C#\" Debug=\"true\" Service=\"{1}.{0}Service\" CodeBehind=\"{0}Service.svc.cs\" %>", SolutionCommon.ProjectName, SolutionCommon.Service);

            ProjectContainer.Service.AddFromFileString(behindCode, SolutionCommon.ProjectName + "Service.svc", Encoding.Default);


            //AttachDataSignBehavior
            staticManager            = new CodeStaticManager(ConstructType.AttachDataSignBehavior);
            staticManager.BuildTaget = new StringCodeArgment()
            {
                Folder = "InstanceProviders", Name = "AttachDataSignBehavior.cs", Target = ProjectContainer.Service
            };
            staticManager.CreateCode();

            //UnityInstanceProvider
            staticManager            = new CodeStaticManager(ConstructType.UnityInstanceProvider);
            staticManager.BuildTaget = new StringCodeArgment()
            {
                Folder = "InstanceProviders", Name = "UnityInstanceProvider.cs", Target = ProjectContainer.Service
            };
            staticManager.CreateCode();

            //UnityInstanceProviderServiceBehavior
            staticManager            = new CodeStaticManager(ConstructType.UnityInstanceProviderServiceBehavior);
            staticManager.BuildTaget = new StringCodeArgment()
            {
                Folder = "InstanceProviders", Name = "UnityInstanceProviderServiceBehavior.cs", Target = ProjectContainer.Service
            };
            staticManager.CreateCode();

            //AssemblyInfo
            string        assemblyInfoPath = Path.Combine(ProjectContainer.Service.ToDirectory(), "Properties", "AssemblyInfo.cs");
            StringBuilder build            = FileOprateHelp.ReadFile(assemblyInfoPath);

            build.AppendLine("[assembly: log4net.Config.XmlConfigurator(Watch = true)]");//日志监视
            FileOprateHelp.SaveFile(build.ToString(), assemblyInfoPath);

            SolutionCommon.Dte.SetStartup(ProjectContainer.Service);
        }