Ejemplo n.º 1
0
        bool CheckForUnusedAcronyms(double progressSoFar = 0.0, double progressToAchieve = 0.0, BackgroundWorker backgroundWorker = null)
        {
            if (_acronymsToDisplay == null)
            {
                _acronymsToDisplay = new List <VarConfig.AcronymRow>();
            }
            else
            {
                _acronymsToDisplay.Clear();
            }

            int acronymsCount = _varConfigFacade.GetAcronymsCount(); //for displaying progress, see below
            int i             = 0;

            //get all variables to check whether they use an acronym ...
            List <string> variablesNames = _varConfigFacade.GetVariables_Names();

            foreach (VarConfig.AcronymTypeRow typeRow in _varConfigFacade.GetAllAcronyms())
            {
                if (backgroundWorker != null && backgroundWorker.CancellationPending)
                {
                    return(false);
                }
                foreach (VarConfig.AcronymLevelRow levelRow in typeRow.GetAcronymLevelRows())
                {
                    if (backgroundWorker != null && backgroundWorker.CancellationPending)
                    {
                        return(false);
                    }
                    foreach (VarConfig.AcronymRow acroRow in levelRow.GetAcronymRows())
                    {
                        if (backgroundWorker != null && backgroundWorker.CancellationPending)
                        {
                            return(false);
                        }
                        bool used = false;
                        foreach (string variableName in variablesNames)
                        {
                            if (backgroundWorker != null && backgroundWorker.CancellationPending)
                            {
                                return(false);
                            }
                            if (_variablesToDelete.Contains(variableName.ToLower()))
                            {
                                continue; //... but exempt variables which are to be deleted from the check
                            }
                            if (AcronymManager.IsAcronymOfVariable(variableName, acroRow.Name, typeRow.ShortName))
                            {
                                used = true;
                                break;
                            }
                        }

                        if (!used)                           //store unused acronyms to be displayed outside (via DisplayAcronyms), as this function is (amongst others) used by the background worker,
                        {
                            _acronymsToDisplay.Add(acroRow); //thus displaying here isn't possible, as the acronym-tree-list belongs to another thread
                        }
                        if (backgroundWorker != null)
                        {
                            double progressPart = (i++ + 1.0) / acronymsCount * progressToAchieve;
                            backgroundWorker.ReportProgress(Convert.ToInt32((progressSoFar + progressPart) * 100.0));
                        }
                    }
                }
            }

            return(true);
        }