コード例 #1
0
        public static void Execute(ProjectItem projectItem)
        {
            if (projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration") && !projectItem.ContainingProject.IsTestProject())
            {
                var    dte        = (DTE)Package.GetGlobalService(typeof(SDTE));
                string configFile = projectItem.ReadAllText();

                var moduleConfig = configFile.Deserialize <XmlModuleConfig>();
                if (moduleConfig != null)
                {
                    var project           = dte.Solution.FindProject(p => p.Name == moduleConfig.AssemblyName);
                    var moduleProjectItem = project.FindProjectItem(p => p.Name == moduleConfig.CsFileName);

                    string csFile = moduleProjectItem.ReadAllText();

                    string newConfig = DetermineNewConfig(configFile, csFile);

                    if (!(configFile.EqualsExcludingWhitespace(newConfig)))
                    {
                        projectItem.Document?.Activate();
                        projectItem.ClearAllText();
                        projectItem.SetText(newConfig);
                    }
                }
            }
        }
コード例 #2
0
		public static void Execute(ProjectItem projectItem)
		{
			if (projectItem.Name.EndsWith(".config", StringComparison.CurrentCulture) && projectItem.Contains("<moduleConfiguration") && !projectItem.ContainingProject.IsTestProject())
			{
				var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
				string configFile = projectItem.ReadAllText();

				var moduleConfig = configFile.Deserialize<XmlModuleConfig>();
				if (moduleConfig != null)
				{
					var project = dte.Solution.FindProject(p => p.Name == moduleConfig.AssemblyName);
					var moduleProjectItem = project.FindProjectItem(p => p.Name == moduleConfig.CsFileName);

					string csFile = moduleProjectItem.ReadAllText();

					string newConfig = DetermineNewConfig(configFile, csFile);

					if (!(configFile.EqualsExcludingWhitespace(newConfig)))
					{
						projectItem.Document?.Activate();
						projectItem.ClearAllText();
						projectItem.SetText(newConfig);
					}
				}
			}
		}
コード例 #3
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var         dte    = (DTE)Package.GetGlobalService(typeof(SDTE));
            ProjectItem module = null;
            ProjectItem config = null;

            if (this.isModuleClass)
            {
                module = dte.ActiveDocument.ProjectItem;
                config = SearchService.FindConfigFromModule(module);
            }
            else
            {
                config = dte.ActiveDocument.ProjectItem;
                module = SearchService.FindModuleFromConfig(config);
            }

            dte.UndoContext.Open("ctx");
            try
            {
                if (dte.ActiveDocument.ProjectItem.IsDirty)
                {
                    dte.ActiveDocument.Save();
                }

                string existingConfigText  = config.ReadAllText();
                string generatedConfigText = ModuleClassService.GenerateConfig(module, config);

                if (!ModuleClassService.CompareTwoConfigFiles(generatedConfigText, existingConfigText))
                {
                    config.OpenInEditor();
                    config.ClearAllText();
                    config.SetText(generatedConfigText);
                    dte.FormatDocument();
                }
                else if (!config.IsOpen)
                {
                    config.OpenInEditor();
                }
            }
            finally
            {
                dte.UndoContext.Close();
            }
        }