GetState() public méthode

public GetState ( string stateName ) : StateSave
stateName string
Résultat StateSave
        public void ReactToStateSaveCategoryChangedValue(StateSaveCategory stateSaveCategory, string changedMember, object oldValue, IElement element, ref bool updateTreeView)
        {
            if(changedMember == "SharesVariablesWithOtherCategories")
            {

                string oldType;
                string newType;
                if ((bool)oldValue == true)
                {
                    oldType = "VariableState";
                    newType = stateSaveCategory.Name;
                }
                else
                {
                    oldType = stateSaveCategory.Name;
                    newType = "VariableState";
                }

                string whyIsntAllowed = GetWhySharesVariableChangeIsntAllowed(stateSaveCategory, element);

                if (!string.IsNullOrEmpty(whyIsntAllowed))
                {
                    MessageBox.Show(whyIsntAllowed);
                    stateSaveCategory.SharesVariablesWithOtherCategories = false;
                }
                else
                {

                    // See if any variables are using this.  If so, let's change them
                    // We need to see if any variables are already tunneling in to this
                    // new type.  If so, then notify the user that the variable will be removed.
                    // Otherwise, notify the user that the variable type is changing.
                    foreach (CustomVariable customVariable in element.CustomVariables)
                    {
                        if (customVariable.Type == oldType && !string.IsNullOrEmpty(customVariable.DefaultValue as string) &&
                            stateSaveCategory.GetState(customVariable.DefaultValue as string) != null)
                        {
                            // We need to do something here...
                            bool shouldChange = false;

                            #if !UNIT_TESTS
                            var dialogResult = System.Windows.Forms.MessageBox.Show("Change variable " + customVariable.Name + " to be of type " + newType + " ?  Selecting 'No' will introduce compile errors.",
                                "Change variable type?", System.Windows.Forms.MessageBoxButtons.YesNo);
                            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                            {
                                shouldChange = true;
                            }
                            #else
                            shouldChange = true;
                            #endif
                            if (shouldChange)
                            {
                                customVariable.Type = newType;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static void GetAdditionsNeededForChangingType(string oldType, string newType, List <PropertyValuePair> valuesToBeSet,
                                                             List <CustomVariable> neededVariables, List <StateSave> neededStates, List <StateSaveCategory> neededCategories)
        {
            IElement oldElement = ObjectFinder.Self.GetIElement(oldType);
            IElement newElement = ObjectFinder.Self.GetIElement(newType);

            if (oldElement != null && newElement != null)
            {
                #region Compare CustomVariables
                foreach (CustomVariable customVariable in oldElement.CustomVariables)
                {
                    string name = customVariable.Name;
                    string type = customVariable.Type;

                    // Is there a custom variable in the type to change to?
                    // We used to only call GetCustomVariable, but this needs
                    // to be recursive, because the object will get variables from
                    // the immediate type as well as all base types.
                    //CustomVariable customVariableInNewType = newElement.GetCustomVariable(name);
                    CustomVariable customVariableInNewType = newElement.GetCustomVariableRecursively(name);

                    if (customVariableInNewType == null || customVariableInNewType.Type != type)
                    {
                        neededVariables.Add(customVariable);
                    }
                }
                #endregion

                #region Compare interfaces like IClickable

                if (oldElement is EntitySave && newElement is EntitySave)
                {
                    EntitySave oldEntity = oldElement as EntitySave;
                    EntitySave newEntity = newElement as EntitySave;

                    if (oldEntity.GetImplementsIClickableRecursively() && !newEntity.GetImplementsIClickableRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIClickable", true));
                    }
                    if (oldEntity.GetImplementsIVisibleRecursively() && !newEntity.GetImplementsIVisibleRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIVisible", true));
                    }
                    if (oldEntity.GetImplementsIWindowRecursively() && !newEntity.GetImplementsIWindowRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIWindow", true));
                    }
                }

                #endregion

                #region Compare States

                // Don't use AllStates because we want
                // states that belong to categories to be
                // identified as being in categories.
                foreach (StateSave state in oldElement.States)
                {
                    if (newElement.GetUncategorizedStateRecursively(state.Name) == null)
                    {
                        neededStates.Add(state);
                    }
                }

                #endregion

                #region Compare Categories

                foreach (StateSaveCategory category in oldElement.StateCategoryList)
                {
                    StateSaveCategory cloneOfCategory = null;
                    StateSaveCategory categoryInNew   = newElement.GetStateCategoryRecursively(category.Name);
                    if (categoryInNew == null)
                    {
                        cloneOfCategory = new StateSaveCategory {
                            Name = category.Name
                        };
                        neededCategories.Add(cloneOfCategory);
                    }

                    List <StateSave> statesMissingInNewCategory = new List <StateSave>();

                    foreach (StateSave state in category.States)
                    {
                        if (categoryInNew == null || categoryInNew.GetState(state.Name) == null)
                        {
                            if (cloneOfCategory == null)
                            {
                                cloneOfCategory = new StateSaveCategory {
                                    Name = category.Name
                                };
                            }
                            cloneOfCategory.States.Add(state);
                        }
                    }

                    if (cloneOfCategory != null)
                    {
                        neededCategories.Add(cloneOfCategory);
                    }
                }


                #endregion
            }
        }