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); }
public static T GetObjectModel <T>() { return(ModelContainer.Resolve <T>()); }