Example #1
0
        public static bool CanBeInList(this NamedObjectSave instance, NamedObjectSave listNos)
        {
            if (listNos.SourceClassGenericType == instance.SourceClassType ||
                listNos.SourceClassGenericType == instance.InstanceType ||
                listNos.SourceClassGenericType == instance.GetAssetTypeInfo()?.QualifiedRuntimeTypeName.QualifiedType)
            {
                return(true);
            }

            if (instance.SourceType == SourceType.Entity)
            {
                EntitySave instanceElement = instance.GetReferencedElement() as EntitySave;

                IElement listElementType = ObjectFinder.Self.GetIElement(listNos.SourceClassGenericType);

                if (instanceElement == null || listElementType == null)
                {
                    return(false);
                }

                if (instanceElement.InheritsFrom(listNos.SourceClassGenericType))
                {
                    return(true);
                }
            }


            return(false);
        }
        public static void WriteSetStateOnNamedObject(NamedObjectSave namedObject, ICodeBlock codeBlock)
        {
            if (!string.IsNullOrEmpty(namedObject.CurrentState))
            {
                IElement referencedElement = namedObject.GetReferencedElement();
                if (referencedElement != null && referencedElement.GetUncategorizedStatesRecursively().Count != 0)
                {
                    string qualifiedName = NamedObjectSaveCodeGenerator.GetQualifiedTypeName(namedObject);

                    string lineToAdd = namedObject.FieldName + ".CurrentState = " + qualifiedName + ".VariableState." + namedObject.CurrentState + ";";
                    codeBlock.Line(lineToAdd);
                }

            }


        }
        private bool DetermineIfShouldShowStates(NamedObjectSave instance)
        {
            IElement referencedEntitySave = instance.GetReferencedElement();

            bool shouldRemove = referencedEntitySave == null;

            if (referencedEntitySave != null)
            {
                shouldRemove = true;

                IElement element = referencedEntitySave;

                while (element != null)
                {
                    if (element.States.Count != 0)
                    {
                        shouldRemove = false;
                        break;
                    }
                    else
                    {
                        element = ObjectFinder.Self.GetIElement(element.BaseElement);
                    }
                }
            }

            return !shouldRemove;

        }
Example #4
0
        public static void FillPossibleStatesFor(List<string> listToFill, string selectedItemName, NamedObjectSave currentNamedObject)
        {


            IElement element = currentNamedObject.GetReferencedElement();

            while (element != null)
            {
                IEnumerable<StateSave> stateList = element.States;

                // Let's see if this element has a variable by this name
                CustomVariable foundVariable = element.GetCustomVariableRecursively(selectedItemName);

                if (foundVariable != null)
                {
                    FillPossibleStatesFor(listToFill, element, foundVariable);
                    break;
                }
                else
                {
                    listToFill.Add("<NONE>");
                    bool useDefaultStateList = selectedItemName == "CurrentVariableState" ||
                        (foundVariable == null && selectedItemName == "CurrentState");

                    if (useDefaultStateList)
                    {
                        foreach (StateSave state in element.States)
                        {
                            listToFill.Add(state.Name);
                        }
                        foreach (StateSaveCategory ssc in element.StateCategoryList)
                        {
                            if (ssc.SharesVariablesWithOtherCategories)
                            {
                                foreach (StateSave state in ssc.States)
                                {
                                    listToFill.Add(state.Name);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!useDefaultStateList)
                        {
                            string stateCategory = "";
                            if (foundVariable != null)
                            {
                                stateCategory = foundVariable.Type;
                            }
                            else
                            {
                                stateCategory = StateSaveExtensionMethods.GetStateTypeFromCurrentVariableName(selectedItemName);
                            }



                            StateSaveCategory category = element.GetStateCategory(stateCategory);
                            if (category != null)
                            {
                                stateList = category.States;
                            }
                        }

                        foreach (StateSave state in stateList)
                        {
                            listToFill.Add(state.Name);
                        }
                    }
                    element = ObjectFinder.Self.GetIElement(element.BaseElement);
                }
            }
        }