Inheritance: ConfigurationSection
コード例 #1
0
		public void ElementInformation_validator () {
			/* pick a Configuration class that doesn't
			 * specify an ElementInformation override */
			DefaultSection sect = new DefaultSection();
			ElementInformation info = sect.ElementInformation;

			Assert.AreEqual (typeof (DefaultValidator), info.Validator.GetType(), "A1");
		}
コード例 #2
0
ファイル: Configuration.cs プロジェクト: zr8091/AntData.ORM
        internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance)
        {
            object data = _elementData[config];
            var    sec  = data as ConfigurationSection;

            if (sec != null || !createDefaultInstance)
            {
                return(sec);
            }

            var secObj = config.CreateInstance();

            sec = secObj as ConfigurationSection;
            if (sec == null)
            {
                var ds = new DefaultSection();
                ds.SectionHandler = secObj as IConfigurationSectionHandler;
                sec = ds;
            }
            sec.Configuration = this;

            ConfigurationSection parentSection = null;

            if (Parent != null)
            {
                parentSection = Parent.GetSectionInstance(config, true);
                sec.SectionInformation.SetParentSection(parentSection);
            }
            sec.SectionInformation.ConfigFilePath = FilePath;

            sec.ConfigContext = _system.Host.CreateDeprecatedConfigContext(_configPath);

            var xml = data as string;

            sec.RawXml = xml;
            sec.Reset(parentSection);

            if (xml != null)
            {
                using (var r = XmlReader.Create(new StringReader(xml)))
                {
                    sec.DeserializeSection(r);
                }

                if (!string.IsNullOrEmpty(sec.SectionInformation.ConfigSource) && !string.IsNullOrEmpty(FilePath))
                {
                    sec.DeserializeConfigSource(Path.GetDirectoryName(FilePath));
                }
            }

            _elementData[config] = sec;
            return(sec);
        }
コード例 #3
0
        internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance)
        {
            object data = elementData [config];
            ConfigurationSection sec = data as ConfigurationSection;

            if (sec != null || !createDefaultInstance)
            {
                return(sec);
            }

            object secObj = config.CreateInstance();

            sec = secObj as ConfigurationSection;
            if (sec == null)
            {
                DefaultSection ds = new DefaultSection();
                ds.SectionHandler = secObj as IConfigurationSectionHandler;
                sec = ds;
            }
            sec.Configuration = this;

            ConfigurationSection parentSection = null;

            if (parent != null)
            {
                parentSection = parent.GetSectionInstance(config, true);
                sec.SectionInformation.SetParentSection(parentSection);
            }
            sec.SectionInformation.ConfigFilePath = FilePath;

            sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath);

            string xml = data as string;

            sec.RawXml = xml;
            sec.Reset(parentSection);

            if (xml != null)
            {
                XmlTextReader r = new ConfigXmlTextReader(new StringReader(xml), FilePath);
                sec.DeserializeSection(r);
                r.Close();

                if (!String.IsNullOrEmpty(sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty(FilePath))
                {
                    sec.DeserializeConfigSource(Path.GetDirectoryName(FilePath));
                }
            }

            elementData [config] = sec;
            return(sec);
        }
コード例 #4
0
ファイル: Configuration.cs プロジェクト: rabink/mono
		internal ConfigurationSection GetSectionInstance (SectionInfo config, bool createDefaultInstance)
		{
			object data = elementData [config];
			ConfigurationSection sec = data as ConfigurationSection;
			if (sec != null || !createDefaultInstance) return sec;
			
			object secObj = config.CreateInstance ();
			sec = secObj as ConfigurationSection;
			if (sec == null) {
				DefaultSection ds = new DefaultSection ();
				ds.SectionHandler = secObj as IConfigurationSectionHandler;
				sec = ds;
			}
			sec.Configuration = this;

			ConfigurationSection parentSection = null;
			if (parent != null) {
				parentSection = parent.GetSectionInstance (config, true);
				sec.SectionInformation.SetParentSection (parentSection);
			}
			sec.SectionInformation.ConfigFilePath = FilePath;

			sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath);
			
			string xml = data as string;
			sec.RawXml = xml;
			sec.Reset (parentSection);

			if (xml != null) {
				XmlTextReader r = new ConfigXmlTextReader (new StringReader (xml), FilePath);
				sec.DeserializeSection (r);
				r.Close ();

				if (!String.IsNullOrEmpty (sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty (FilePath))
					sec.DeserializeConfigSource (Path.GetDirectoryName (FilePath));
			}
			
			elementData [config] = sec;
			return sec;
		}
コード例 #5
0
        // .Net Framework handles IConfigurationSectionHandler sections only for default configurations (app/web.config), not for custom loaded.
        // This is because IConfigurationSectionHandler is deprecated, but still a lot of 3rd party libraries use it. (log4net, nlog etc.)
        // These sections returned as DefaultSection from Configuration.GetSection so we need to handle such sections by our self.
        private object HandleIConfigurationSectionHandlerSection(DefaultSection section)
        {
            string sectionTypeName = section.SectionInformation.Type;
            var sectionType = Type.GetType(sectionTypeName);

            if (typeof (IConfigurationSectionHandler).IsAssignableFrom(sectionType))
            {
                var ctor = sectionType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
                if (ctor == null)
                    throw new InvalidOperationException("Can't instantiate section handler without default ctor.");

                // Create IConfigurationSectionHandler for this section.
                var handler = Activator.CreateInstance(sectionType, true) as IConfigurationSectionHandler;
                if (handler == null)
                    return null;

                var rawXml = section.SectionInformation.GetRawXml();
                if (string.IsNullOrEmpty(rawXml))
                    return null;

                var doc = new XmlDocument();
                doc.LoadXml(rawXml);

                // Invoke IConfigurationSectionHandler.Create method with read rawXlm as parameter.
                // We pass DocumentElement because some 3rd party libs expects XmlElement passed, not XmlNode as declared in Create signature.
                return handler.Create(null, null, doc.DocumentElement);
            }

            return null;
        }
コード例 #6
0
        /// <summary>
        /// The actually processing happens in this method
        /// </summary>
        private void UpdateSolution()
        {
            AddToStatus("Adding AndroMDA support to solution...");

            Project commonProject = null;
            Project coreProject = null;
            Project schemaExportProject = null;
            Project testProject = null;
            Project webProject = null;
            Project webCommonProject = null;

            m_srcPath = m_settings.SolutionWizardResourcesLocation + "\\";
            m_dstPath = m_configuration["solution.path"] + "\\";

            string versionControlType = m_configuration["application.versioncontrol"];
            bool versionControl =  versionControlType != "None";
            string ignoreFile = string.Empty;
            switch (versionControlType)
            {
                case "CVS":
                    ignoreFile = ".cvsignore";
                    break;
            }

            nvelocityContext = new VelocityContext();
            foreach (string key in m_configuration.Keys)
            {
                object value = m_configuration[key];
                if (m_configuration[key] == "true" || m_configuration[key] == "false")
                {
                    value = GetConfigSettingBool(key);
                }

                nvelocityContext.Put("wizard." + key, value);
                nvelocityContext.Put("wizard_" + key.Replace('.', '_'), value);
            }

            AddToStatus("Creating AndroMDA configuration files...");

            // Create mda directory
            CreateDirectory("mda");
            // Create mda/conf directory
            CreateDirectory("mda/conf");

            // Render /cvsignore
            if (versionControl)
            {
                WriteFile("cvsignore", ignoreFile);
            }

            if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x")
            {

                // Render /pom.xml
                WriteFile("pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Render /mda/pom.xml
                WriteFile("mda/pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Render /mda/conf/andromda.xml
                WriteFile("mda/conf/andromda.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Create mda/conf/mappings directory
                CreateDirectory("mda/conf/mappings");

                // Render /mda/conf/mappings/MergeMappings.xml
                WriteFile("mda/conf/mappings/MergeMappings.xml");

                // Render /mda/conf/mappings/NHibernateTypeMappings.xml (Required for NHibernate 1.2)
                WriteFile("mda/conf/mappings/NHibernateTypeMappings.xml");

                // Create mda/resources
                CreateDirectory("mda/resources");

                // Create mda/resources
                CreateDirectory("mda/resources/templates");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/cs");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/nspring");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/nhibernate");

            }

            // Write mda/cvsignore
            if (versionControl)
            {
                WriteFile("mda/cvsignore", "mda/" + ignoreFile);
            }

            AddToStatus("Creating empty model file...");
            // Create mda/src directory
            CreateDirectory("mda/src");
            // Create mda/src/uml directory
            CreateDirectory("mda/src/uml");

            {
                string modelPackageXML = "<UML:Model xmi.id='_9_5_1_874026a_1149883877463_480535_0' name='" + m_configuration["solution.name"] + "'><UML:Namespace.ownedElement>";
                string xmiIdBase = "_9_5_1_874026a_" + DateTime.Now.Ticks.ToString();
                modelPackageXML += GetXMI(m_configuration["solution.name"].Split('.'), xmiIdBase);
                modelPackageXML += "</UML:Namespace.ownedElement></UML:Model>";

                string emptyModelFileData = ReadFile("mda/src/uml/empty-model.xmi");

                emptyModelFileData = emptyModelFileData.Replace("${wizard.model.packagestructure.xml}", modelPackageXML);

                WriteFileProperties modelProperties = WriteFileProperties.SourceFileIsContent | WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables;
                if (GetConfigSettingBool("application.model.zipped"))
                {
                    modelProperties |= WriteFileProperties.Compressed;
                }
                WriteFile(emptyModelFileData, "mda/src/uml/" + m_configuration["application.model.filename"], modelProperties);
            }

            // Create the AndroMDA solution folder
            AddToStatus("Adding solution folder...");
            Solution2 sol = m_applicationObject.Solution as Solution2;
            Project solutionFolder = null;
            try
            {
                solutionFolder = sol.AddSolutionFolder("AndroMDA");
                if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x")
                {

                    solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\pom.xml");
                }
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\andromda.xml");
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\MergeMappings.xml");
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\NHibernateTypeMappings.xml");
                //solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\src\\uml\\" + m_configuration["application.model.filename"]);
            }
            catch { }

            //////////////////////////////////
            // Create/find the common project
            if (GetConfigSettingBool("projects.common.create"))
            {
                AddToStatus("Creating common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.common.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.common.name"], m_applicationObject.Solution);
            }

            try { commonProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch { }
            try { commonProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { }

            // Write common/cvsignore
            if (versionControl)
            {
                WriteFile("Common/cvsignore", m_configuration["projects.common.dir"] + "/" + ignoreFile);
            }

            //////////////////////////////////
            // Create/find the core project
            if (GetConfigSettingBool("projects.core.create"))
            {
                AddToStatus("Creating core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.core.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.core.name"], m_applicationObject.Solution);
            }
            try { coreProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch {}
            try { coreProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { }

            // Write core/cvsignore
            if (versionControl)
            {
                WriteFile("Core/cvsignore", m_configuration["projects.core.dir"] + "/" + ignoreFile);
            }

            //////////////////////////////////
            // Create the schema export project
            if (GetConfigSettingBool("projects.schemaexport.create"))
            {
                AddToStatus("Creating schema export project " + m_configuration["projects.schemaexport.name"] + "...");
                schemaExportProject = VSSolutionUtils.AddConsoleAppProjectToSolution(m_configuration["projects.schemaexport.name"], (Solution2)m_applicationObject.Solution);

                WriteFile("SchemaExport/App.config", m_configuration["projects.schemaexport.dir"] + "/App.config");
                WriteFile("SchemaExport/nhibernate.config", m_configuration["projects.schemaexport.dir"] + "/nhibernate.config");
                WriteFile("SchemaExport/SchemaExport.cs", m_configuration["projects.schemaexport.dir"] + "/SchemaExport.cs");
                WriteFile("SchemaExport/TestDataManager.cs", m_configuration["projects.schemaexport.dir"] + "/TestDataManager.cs");

                ProjectItem appConfig = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\App.config");
                ProjectItem nhibernateConfig = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\nhibernate.config");

                // Set the config files 'Copy to Output Directory' property to 'Copy if Newer'
                appConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                appConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent;
                nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                nhibernateConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent;

                schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\SchemaExport.cs");
                schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\TestDataManager.cs");

                // Write SchemaExport/cvsignore
                if (versionControl)
                {
                    WriteFile("SchemaExport/cvsignore", m_configuration["projects.schemaexport.dir"] + "/" + ignoreFile);
                }
            }

            //////////////////////////////////
            // Configure the web project
            if (GetConfigSettingBool("projects.web.configure"))
            {

                //////////////////////////////////
                // Create/find the web project
                if (GetConfigSettingBool("projects.web.create"))
                {
                    AddToStatus("Creating web project " + m_configuration["projects.web.name"] + "...");
                    webProject = VSSolutionUtils.AddWebProjectToSolution(m_configuration["projects.web.name"], (Solution2)m_applicationObject.Solution);
                }
                else
                {
                    AddToStatus("Using existing web project " + m_configuration["projects.web.name"] + "...");
                    webProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.dir"], m_applicationObject.Solution);
                }

                // Write the nhibernate.config if required
                if (GetConfigSettingBool("projects.web.usenhibernateconfig"))
                {
                    WriteFile("Web/nhibernate.config", webProject.Name + "nhibernate.config", WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables);
                }

                string webConfigDstFile = webProject.Name + "Web.config";

                if (!System.IO.File.Exists(webConfigDstFile))
                {
                    // Write out the web.config file
                    WriteFile("Web/web.config", webConfigDstFile, WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables);
                    webProject.ProjectItems.AddFromFile(webConfigDstFile);
                }

                // Open the web.config file
                System.Configuration.Configuration webconfig = OpenWebConfig(webConfigDstFile);

                // If the nhibernate settings are stored in nhibernate.config
                if (GetConfigSettingBool("projects.web.usenhibernateconfig"))
                {
                    // Add that to the app settings
                    if (webconfig.AppSettings.Settings["nhibernate.config"] == null)
                    {
                        webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config");
                    }
                    else
                    {
                        webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config");
                    }
                    // Remove the nhibernate section if it exists
                    if (webconfig.Sections.Get("nhibernate") != null)
                    {
                        webconfig.Sections.Remove("nhibernate");
                    }
                }
                else
                {
                    // Remove the nhibernate.config app setting if it exists
                    if (webconfig.AppSettings.Settings["nhibernate.config"] != null)
                    {
                        webconfig.AppSettings.Settings.Remove("nhibernate.config");
                    }

                    // Add the nhibernate config to the web.config
                    DefaultSection nhibernateSection = new DefaultSection();
                    nhibernateSection.SectionInformation.Type = "System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089";

                    nhibernateSection.SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.nhibernate")));

                    webconfig.Sections.Add("nhibernate", nhibernateSection);

                }

                // Write Web/cvsignore and Web\Bin\cvsignore
                if (versionControl)
                {
                    WriteFile("web/cvsignore", webProject.Name + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete);
                    CreateDirectory(webProject.Name + "Bin", false);
                    WriteFile("web/bin/cvsignore", webProject.Name + "Bin\\" + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete);
                }

                if (GetConfigSettingBool("projects.web.common.configure"))
                {
                    // Create/find the core project
                    if (GetConfigSettingBool("projects.web.common.create"))
                    {
                        AddToStatus("Creating web common project " + m_configuration["projects.web.common.name"] + "...");
                        webCommonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.web.common.name"], (Solution2)m_applicationObject.Solution);
                    }
                    else
                    {
                        AddToStatus("Using existing web common project " + m_configuration["projects.web.common.name"] + "...");
                        webCommonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.common.name"], m_applicationObject.Solution);
                    }

                }

                // Get the web site object
                VsWebSite.VSWebSite webSite = webProject.Object as VsWebSite.VSWebSite;

                // Refresh folder view
                webSite.Refresh();

                // Add Membership support
                if (GetConfigSettingBool("projects.web.addmembership"))
                {
                    AddToStatus("Adding membership support...");

                    string file;
                    ProjectItem membershipFolder = VSSolutionUtils.FindProjectFolder(webCommonProject, "Membership");
                    if (membershipFolder == null)
                    {
                        membershipFolder = webCommonProject.ProjectItems.AddFolder("Membership", Constants.vsProjectItemKindPhysicalFolder);
                    }

                    // Render DomainMembershipProvider.cs
                    WriteFile("Membership/DomainMembershipProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipProvider.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipProvider.cs");

                    // Render DomainRoleProvider.cs
                    WriteFile("Membership/DomainRoleProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainRoleProvider.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainRoleProvider.cs");

                    // Render DomainMembershipUser.cs
                    WriteFile("Membership/DomainMembershipUser.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipUser.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipUser.cs");

                    // Create core/src/* folder tree from namespace
                    string solutionName = m_configuration["solution.name"];
                    string[] namespaces = solutionName.Split('.');
                    file = m_configuration["projects.core.dir"] + "\\src\\";
                    foreach (string folder in namespaces)
                    {
                        file = file + folder;
                        CreateDirectory(file);
                        file = file + "\\";
                    }
                    CreateDirectory(file + "Domain");
                    CreateDirectory(file + "Service");

                    // Render UserDao.cs
                    WriteFile("Membership/UserDao.cs", file + "Domain/UserDao.cs");
                    coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Domain\\UserDao.cs");

                    // Render MembershipService.cs
                    WriteFile("Membership/MembershipService.cs", file + "Service/MembershipService.cs");
                    coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Service\\MembershipService.cs");

                    ConfigurationSectionGroup systemweb = webconfig.SectionGroups["system.web"];

                    systemweb.Sections["membership"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.membershipsection")));
                    systemweb.Sections["roleManager"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.rolesection")));

                    systemweb.Sections["membership"].SectionInformation.ForceSave = true;
                    systemweb.Sections["roleManager"].SectionInformation.ForceSave = true;

                    // Turn on authentication
                    systemweb.Sections["authentication"].SectionInformation.SetRawXml("<authentication mode=\"Forms\"> <forms name=\"FormsAuth\" timeout=\"30\" loginUrl=\"~/Public/Login.aspx\" defaultUrl=\"~/Default.aspx\" path=\"/\" protection=\"All\"/></authentication>");

                }

                // Save the changes to the web.config
                webconfig.Save();

            }

            // Create the lib directory
            CreateDirectory("Lib");

            // Write the libraries out
            WriteBinaryFile("Lib/AndroMDA.NHibernateSupport.dll");
            WriteBinaryFile("Lib/Bamboo.Prevalence.dll");
            WriteBinaryFile("Lib/Castle.DynamicProxy.dll");
            //WriteBinaryFile("Lib/HashCodeProvider.dll");
            WriteBinaryFile("Lib/Iesi.Collections.dll");
            WriteBinaryFile("Lib/log4net.dll");
            WriteBinaryFile("Lib/NHibernate.Caches.Prevalence.dll");
            WriteBinaryFile("Lib/NHibernate.Caches.SysCache.dll");
            WriteBinaryFile("Lib/NHibernate.dll");
            //WriteBinaryFile("Lib/NHibernate.Nullables2.dll");
            WriteBinaryFile("Lib/Nullables.dll");
            WriteBinaryFile("Lib/Nullables.NHibernate.dll");

            //////////////////////////////////
            // Configure the tests project
            if (GetConfigSettingBool("projects.tests.configure"))
            {
                // Create/find the core project
                if (GetConfigSettingBool("projects.tests.create"))
                {
                    AddToStatus("Creating testing project " + m_configuration["projects.tests.name"] + "...");
                    testProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.tests.name"], (Solution2)m_applicationObject.Solution);
                }
                else
                {
                    AddToStatus("Using existing testing project " + m_configuration["projects.tests.name"] + "...");
                    testProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.tests.name"], m_applicationObject.Solution);
                }
                WriteFile("Tests/App.config", m_configuration["projects.tests.dir"] + "/App.config", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);
                WriteFile("Tests/nhibernate.config", m_configuration["projects.tests.dir"] + "/nhibernate.config");

                ProjectItem appConfig = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\App.config");
                ProjectItem nhibernateConfig = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\nhibernate.config");

                // Set the config files 'Copy to Output Directory' property to 'Copy if Newer'
                appConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                appConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent;
                nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                nhibernateConfig.Properties.Item("BuildAction").Value = VSLangProj.prjBuildAction.prjBuildActionContent;

                AddToStatus("Writing NUnit assemblies...");

                WriteBinaryFile("Lib/nunit.core.dll");
                WriteBinaryFile("Lib/nunit.framework.dll");

                AddToStatus("Adding NUnit references...");

                VSProject vsTestProj = (VSProject)testProject.Object;
                vsTestProj.References.Add(m_dstPath + "Lib\\nunit.core.dll");
                vsTestProj.References.Add(m_dstPath + "Lib\\nunit.framework.dll");

                if (GetConfigSettingBool("projects.tests.scenariounit"))
                {
                    AddToStatus("Writing ScenarioUnit assemblies...");
                    WriteBinaryFile("Lib/NXUnit.Framework.dll");
                    WriteBinaryFile("Lib/AndroMDA.ScenarioUnit.dll");
                    AddToStatus("Adding ScenarioUnit references...");
                    vsTestProj.References.Add(m_dstPath + "Lib\\NXUnit.Framework.dll");
                    vsTestProj.References.Add(m_dstPath + "Lib\\AndroMDA.ScenarioUnit.dll");
                    ProjectItem testDataFolder = testProject.ProjectItems.AddFolder("TestData", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("actual_output", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("expected_output", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("rules", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("input", Constants.vsProjectItemKindPhysicalFolder);
                }
            }

            // Add the references to all the DLLs we just put in /Lib
            AddToStatus("Adding project references to common project...");
            AddBinaryReferences(commonProject);
            AddToStatus("Adding project references to core project...");
            AddBinaryReferences(coreProject);

            // Add a reference from the core project to the common project
            AddProjectReference(coreProject, commonProject);

            // If we created the schema export project
            if (schemaExportProject != null)
            {
                VSProject proj = schemaExportProject.Object as VSProject;
                AddToStatus("Adding references to schema export project...");
                // Add the references to the DLLs
                AddBinaryReferences(schemaExportProject);

                // Add references to the core and common projects
                AddProjectReference(schemaExportProject, commonProject);
                AddProjectReference(schemaExportProject, coreProject);

                AddToStatus("Adding System.Configuration reference to schema export project...");
                try { proj.References.Add("System.Configuration"); } catch { }
            }

            // If we created the schema export project
            if (testProject != null)
            {
                AddToStatus("Adding references to testing project...");
                // Add the references to the DLLs
                AddBinaryReferences(testProject);

                // Add references to the core and common projects
                AddProjectReference(testProject, commonProject);
                AddProjectReference(testProject, coreProject);
            }

            if (webProject != null)
            {
                AddToStatus("Adding project references to web project...");

                VsWebSite.VSWebSite proj = webProject.Object as VsWebSite.VSWebSite;

                proj.References.AddFromFile(m_dstPath + "Lib\\AndroMDA.NHibernateSupport.dll");

                try { proj.References.AddFromProject(commonProject); } catch {}
                try { proj.References.AddFromProject(coreProject); } catch {}
                if (webCommonProject != null)
                {
                    try { proj.References.AddFromProject(webCommonProject); } catch { }
                }
                //m_applicationObject.Solution.Properties.Item("StartupProject").Value = webProject.Name;
            }

            if (webCommonProject != null)
            {
                VSProject proj = webCommonProject.Object as VSProject;
                AddToStatus("Adding common project reference to web common project...");
                try { proj.References.AddProject(commonProject); } catch { }
                AddToStatus("Adding core project reference to web common project...");
                try { proj.References.AddProject(coreProject); } catch { }
                AddToStatus("Adding System.Configuration reference to web common project...");
                try { proj.References.Add("System.Configuration"); } catch { }
                AddToStatus("Adding System.Web reference to web common project...");
                try { proj.References.Add("System.Web"); } catch { }
            }

            AddToStatus("Processing complete, cleaning up...");
        }
コード例 #7
0
 public DatabaseElement(DefaultSection section)
 {
     doc = new XmlDocument();
     doc.LoadXml(section.SectionInformation.GetRawXml());
 }