Beispiel #1
0
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if ((commandName == "TestCocoonVs2005AddIn.Connect.GenerateConfiguration") ||
                    (commandName == "TestCocoonVs2008AddIn.Connect.GenerateConfiguration"))
                {
                    TestCocoon.AdjustPath();
                    // get the list of projects
                    ArrayList projects = new ArrayList();
                    try
                    {
                        TestCocoon.FindProjects(ref projects);
                        if (projects.Count == 0)
                        {
                            ShowMessageBox("No Visual C++ projects open.", "Error");
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Debug(e);
                        ShowMessageBox("No Visual C++ projects open.", "Error");
                        return;
                    }
                    // get the active project
                    string activeProject = TestCocoon.FindActiveProject();
                    handled = true;
                    BuildModeGenerationGUI f = new BuildModeGenerationGUI();
                    // load the given configurations into the combo box
                    foreach (String project in projects)
                    {
                        String[] configs = TestCocoon.FindConfigs(project, "WIN32");
                        f.AddConfigs(project, configs);
                    }
                    f.setAdditionalIncludes(TestCocoon.FindListOfIncludeDirectories());
                    // load project names
                    f.FillProjects(ref projects, activeProject);
                    f.ShowDialog();
                    // determine linker type
                    List <string> additionalParams     = f.Parameters();
                    string        coveragescanner_args = "";
                    try
                    {
                        coveragescanner_args = System.Environment.GetEnvironmentVariable("COVERAGESCANNER_ARGS");
                    }
                    catch
                    {
                        coveragescanner_args = "";
                    }
                    string coveragescanner_args_new = coveragescanner_args;

                    try
                    {
                        switch (f.Action)
                        {
                        case BuildModeGenerationGUI.action_t.DISABLE_COVERAGE_CONFIG:
                        {
                            TestCocoon.AdjustPath();
                            if (f.AllProjects())
                            {
                                foreach (string project in projects)
                                {
                                    try
                                    {
                                        TestCocoon.DisableTestCocoonConfig(
                                            f._config.SelectedItem.ToString(),
                                            project);
                                    }
                                    catch (Exception e)
                                    {
                                        Debug(e);
                                        ShowMessageBox("Error creating the configuration", "Error");
                                    }
                                }
                            }
                            else
                            {
                                TestCocoon.DisableTestCocoonConfig(
                                    f._config.SelectedItem.ToString(),
                                    f._projects.SelectedItem.ToString());
                            }

                            ShowMessageBox("Code coverage disabled.", "TestCocoon");
                        }
                        break;

                        case BuildModeGenerationGUI.action_t.ENABLE_COVERAGE_CONFIG:
                        {
                            TestCocoon.AdjustPath();
                            if (f.AllProjects())
                            {
                                foreach (string project in projects)
                                {
                                    try
                                    {
                                        TestCocoon.CreateTestCocoonConfig(
                                            f._config.SelectedItem.ToString(),
                                            project,
                                            additionalParams,
                                            f.getAdditionalIncludes(),
                                            f.GenerateQtConfiguration);
                                    }
                                    catch (Exception e)
                                    {
                                        Debug(e);
                                        ShowMessageBox("Error creating the configuration", "Error");
                                    }
                                }
                            }
                            else
                            {
                                TestCocoon.CreateTestCocoonConfig(
                                    f._config.SelectedItem.ToString(),
                                    f._projects.SelectedItem.ToString(),
                                    additionalParams,
                                    f.getAdditionalIncludes(),
                                    f.GenerateQtConfiguration);
                            }

                            ShowMessageBox("Code coverage enabled.", "TestCocoon");
                        }
                        break;

                        case BuildModeGenerationGUI.action_t.ENABLE_COVERAGE_ENV:
                        {
                            coveragescanner_args_new = "";
                            bool first = true;
                            foreach (string s in additionalParams)
                            {
                                if (!first)
                                {
                                    coveragescanner_args_new += " ";
                                }
                                coveragescanner_args_new += s;
                                first = false;
                            }
                        }
                        break;

                        case BuildModeGenerationGUI.action_t.DISABLE_COVERAGE_ENV:
                            coveragescanner_args_new = "";
                            break;
                        }

                        if (coveragescanner_args != coveragescanner_args_new)
                        {
                            try
                            {
                                System.Environment.SetEnvironmentVariable("COVERAGESCANNER_ARGS", coveragescanner_args_new);
                                if (coveragescanner_args_new == "")
                                {
                                    Log("COVERAGESCANNER_ARGS system variable is unset");
                                }
                                else
                                {
                                    Log("COVERAGESCANNER_ARGS system variable is set to '" + coveragescanner_args_new + "'");
                                }
                                ShowMessageBox(
                                    "The code coverage settings are modified for this session\n" +
                                    "Do not forget to rebuild the entire application",
                                    "Code Coverage Setting");
                            }
                            catch
                            {
                                ShowMessageBox(
                                    "Setting environment varible COVERAGESCANNER_ARGS failed",
                                    "Code Coverage Setting");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug(e);
                        ShowMessageBox("Error creating the configuration", "Error");
                    }
                    handled = true;
                    return;
                }
            }
        }
Beispiel #2
0
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
             if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
             {
            if ((commandName == "TestCocoonVs2005AddIn.Connect.GenerateConfiguration")
                  || (commandName == "TestCocoonVs2008AddIn.Connect.GenerateConfiguration"))
            {
                TestCocoon.AdjustPath();
               // get the list of projects
               ArrayList projects = new ArrayList();
               try
               {
                  TestCocoon.FindProjects(ref projects);
                  if (projects.Count == 0)
                  {
                     ShowMessageBox("No Visual C++ projects open.", "Error");
                     return;
                  }
               }
               catch (Exception e)
               {
                  Debug(e);
                  ShowMessageBox("No Visual C++ projects open.", "Error");
                  return;
               }
               // get the active project
               string activeProject = TestCocoon.FindActiveProject();
               handled = true;
               BuildModeGenerationGUI f = new BuildModeGenerationGUI();
               // load the given configurations into the combo box
               foreach (String project in projects)
               {
                  String[] configs = TestCocoon.FindConfigs(project, "WIN32");
                  f.AddConfigs(project, configs);
               }
               f.setAdditionalIncludes(TestCocoon.FindListOfIncludeDirectories());
               // load project names
               f.FillProjects(ref projects, activeProject);
               f.ShowDialog();
               // determine linker type
               List<string> additionalParams = f.Parameters();
               string coveragescanner_args = "";
               try
               {
                 coveragescanner_args = System.Environment.GetEnvironmentVariable("COVERAGESCANNER_ARGS");
               }
               catch
               {
                 coveragescanner_args = "";
               }
               string coveragescanner_args_new = coveragescanner_args;

               try
               {
                 switch (f.Action)
                 {
                   case BuildModeGenerationGUI.action_t.DISABLE_COVERAGE_CONFIG:
                     {
                       TestCocoon.AdjustPath();
                       if (f.AllProjects())
                       {
                         foreach (string project in projects)
                         {
                           try
                           {
                             TestCocoon.DisableTestCocoonConfig(
                                   f._config.SelectedItem.ToString(),
                                   project);
                           }
                           catch (Exception e)
                           {
                             Debug(e);
                             ShowMessageBox("Error creating the configuration", "Error");
                           }
                         }
                       }
                       else
                       {
                         TestCocoon.DisableTestCocoonConfig(
                               f._config.SelectedItem.ToString(),
                               f._projects.SelectedItem.ToString());
                       }

                       ShowMessageBox("Code coverage disabled.", "TestCocoon");
                     }
                     break;
                   case BuildModeGenerationGUI.action_t.ENABLE_COVERAGE_CONFIG:
                     {
                       TestCocoon.AdjustPath();
                       if (f.AllProjects())
                       {
                         foreach (string project in projects)
                         {
                           try
                           {
                             TestCocoon.CreateTestCocoonConfig(
                                   f._config.SelectedItem.ToString(),
                                   project,
                                   additionalParams,
                                   f.getAdditionalIncludes(),
                                   f.GenerateQtConfiguration);
                           }
                           catch (Exception e)
                           {
                             Debug(e);
                             ShowMessageBox("Error creating the configuration", "Error");
                           }
                         }
                       }
                       else
                       {
                         TestCocoon.CreateTestCocoonConfig(
                               f._config.SelectedItem.ToString(),
                               f._projects.SelectedItem.ToString(),
                               additionalParams,
                               f.getAdditionalIncludes(),
                               f.GenerateQtConfiguration);
                       }

                       ShowMessageBox("Code coverage enabled.", "TestCocoon");
                     }
                     break;
                   case BuildModeGenerationGUI.action_t.ENABLE_COVERAGE_ENV:
                     {
                       coveragescanner_args_new = "";
                       bool first = true;
                       foreach (string s in additionalParams)
                       {
                         if (!first)
                           coveragescanner_args_new += " ";
                         coveragescanner_args_new += s;
                         first = false;
                       }
                     }
                     break;
                   case BuildModeGenerationGUI.action_t.DISABLE_COVERAGE_ENV:
                     coveragescanner_args_new = "";
                     break;
                 }

                 if (coveragescanner_args != coveragescanner_args_new)
                 {
                   try
                   {
                     System.Environment.SetEnvironmentVariable("COVERAGESCANNER_ARGS", coveragescanner_args_new);
                     if (coveragescanner_args_new == "")
                       Log("COVERAGESCANNER_ARGS system variable is unset");
                     else
                       Log("COVERAGESCANNER_ARGS system variable is set to '" + coveragescanner_args_new + "'");
                     ShowMessageBox(
                       "The code coverage settings are modified for this session\n" +
                       "Do not forget to rebuild the entire application",
                      "Code Coverage Setting");
                   }
                   catch
                   {
                     ShowMessageBox(
                       "Setting environment varible COVERAGESCANNER_ARGS failed",
                      "Code Coverage Setting");
                   }
                 }
               }
               catch (Exception e)
               {
                  Debug(e);
                  ShowMessageBox("Error creating the configuration", "Error");
               }
               handled = true;
               return;
            }
             }
        }