public static void ClassCleanup()
 {
     if (solution != null)
     {
         solution.Close(); solution = null;
     }
     if (dte != null)
     {
         dte.Quit();
     }
     WebLinterVsix.WebLinterPackage.Settings = null;
     WebLinterVsix.WebLinterPackage.Dte      = null;
     MessageFilter.Revoke();
 }
        public void ClearFiles(ClearFilesArgs clearFilesArgs)
        {
            try
            {
                TryHelper.Run(() => CleanUp());

                //If it throws exeption you may want to retry couple more times
                EnvDTE.Solution soln = GetSolution(clearFilesArgs);

                if (!String.IsNullOrWhiteSpace(clearFilesArgs.ProyectFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Limpiando '{0}'", Path.GetFileName(clearFilesArgs.ProyectFile)));
                    }
                }
                else if (!String.IsNullOrWhiteSpace(clearFilesArgs.SoluctionFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Limpiando '{0}'", Path.GetFileName(clearFilesArgs.SoluctionFile)));
                    }
                }

                if (String.IsNullOrWhiteSpace(clearFilesArgs.FilesFile))
                {
                    TryHelper.Run(() => soln.DTE.Commands.Raise(Settings.Default.GuidCodeMaidCommandCleanupAllCodeString, Settings.Default.CmdIDCodeMaidCleanupAllCode, null, null));
                }
                else
                {
                    ProjectItemIterator iterator = new ProjectItemIterator(soln);
                    String[]            files    = File.ReadAllLines(clearFilesArgs.FilesFile).Select(f => Path.GetFileName(f)).ToArray();

                    foreach (var addedItem in iterator)
                    {
                        string itemName = TryHelper.Run(() => addedItem.Name);

                        string kind = TryHelper.Run(() => addedItem.Kind);

                        if (kind == ProjectKinds.vsProjectKindSolutionFolder || kind == folderKindGUID)
                        {
                            continue;
                        }

                        if (files.Select(f => String.Compare(itemName, f, true) == 0).Count() == 0)
                        {
                            continue;
                        }

                        if (!clearFilesArgs.MinimumOutput)
                        {
                            Console.WriteLine(String.Format("\tLimpiando {0}...", itemName));
                        }

                        TryHelper.Run(() =>
                        {
                            // Console.WriteLine(nameFile);
                            addedItem.Open(Constants.vsViewKindCode);
                            addedItem.Document.Activate();

                            addedItem.Document.DTE.Commands.Raise(Settings.Default.GuidCodeMaidCommandCleanupActiveCodeString, Settings.Default.CmdIDCodeMaidCleanupActiveCode, null, null);

                            addedItem.Save();
                        });

                        if (clearFilesArgs.MinimumOutput)
                        {
                            Console.WriteLine(itemName);
                        }
                    }
                }

                TryHelper.Run(() => soln.Close());

                if (!String.IsNullOrWhiteSpace(clearFilesArgs.ProyectFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Finalizado limpieza '{0}'", Path.GetFileName(clearFilesArgs.ProyectFile)));
                    }
                }
                else if (!String.IsNullOrWhiteSpace(clearFilesArgs.SoluctionFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Finalizado limpieza '{0}'", Path.GetFileName(clearFilesArgs.SoluctionFile)));
                    }
                }
            }
            finally
            {
                TryHelper.Run(() => CleanUp());
            }
        }