Beispiel #1
0
        private static CustomVariable FillPossibleStatesFor(List <string> listToFill, IElement currentElement, CustomVariable customVariable)
        {
            IElement sourceElement = null;

            customVariable = customVariable.GetDefiningCustomVariable();

            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                NamedObjectSave namedObjectSave = currentElement.GetNamedObjectRecursively(customVariable.SourceObject);

                sourceElement = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType);
                if (sourceElement == null)
                {
                    sourceElement = ObjectFinder.Self.GetScreenSave(namedObjectSave.SourceClassType);
                }
            }
            else
            {
                var name = customVariable.GetEntityNameDefiningThisTypeCategory();

                if (!string.IsNullOrEmpty(name) && name != currentElement?.Name)
                {
                    sourceElement = ObjectFinder.Self.GetIElement(name);
                }
                else
                {
                    sourceElement = currentElement;
                }
            }


            IEnumerable <StateSave> whatToLoopThrough = null;

            if (customVariable != null)
            {
                string categoryName = customVariable.Type;

                // If the type name has a '.', then it's a fully qualified type. We already know the entity
                // so let's unqualify it:
                if (categoryName.Contains('.'))
                {
                    categoryName = categoryName.Substring(categoryName.LastIndexOf('.') + 1);
                }

                StateSaveCategory category = sourceElement.GetStateCategoryRecursively(categoryName);

                if (category != null)
                {
                    whatToLoopThrough = category.States;
                }
            }

            listToFill.Add("<NONE>");

            if (whatToLoopThrough == null)
            {
                foreach (StateSave state in sourceElement.GetUncategorizedStatesRecursively())
                {
                    listToFill.Add(state.Name);
                }
                foreach (StateSaveCategory ssc in sourceElement.StateCategoryList)
                {
                    if (ssc.SharesVariablesWithOtherCategories == true)
                    {
                        foreach (StateSave stateInCategory in ssc.States)
                        {
                            listToFill.Add(stateInCategory.Name);
                        }
                    }
                }
            }
            else
            {
                // We are looping through a category
                foreach (StateSave stateSave in whatToLoopThrough)
                {
                    listToFill.Add(stateSave.Name);
                }
            }
            return(customVariable);
        }