Exemplo n.º 1
0
        public static List <EntitySave> GetAllBaseEntities(this EntitySave instance)
        {
            List <EntitySave> listToReturn = new List <EntitySave>();

            instance.GetAllBaseEntities(listToReturn);

            return(listToReturn);
        }
Exemplo n.º 2
0
        public static void GetAllBaseEntities(this EntitySave instance, List <EntitySave> entityListToFill)
        {
            if (!string.IsNullOrEmpty(instance.BaseEntity))
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(instance.BaseEntity);

                if (baseEntity != null)
                {
                    entityListToFill.Add(baseEntity);

                    baseEntity.GetAllBaseEntities(entityListToFill);
                }
            }
        }
Exemplo n.º 3
0
        public void SetResetVariablesForEntitySave(EntitySave entitySave)
        {
            // set reset variables
            bool hasNamedObjectEntities = false;

            List<NamedObjectSave> skippedNoses = new List<NamedObjectSave>();

            #region Loop through the NamedObjects to identify which variables should be added
            foreach (NamedObjectSave nos in entitySave.NamedObjects)
            {
                hasNamedObjectEntities |= AddResetVariablesFor(skippedNoses, nos);
            }

            // let's make sure to get all the NOS's that are defined in base types too:
            foreach (var element in entitySave.GetAllBaseEntities())
            {
                foreach (NamedObjectSave nos in element.NamedObjects)
                {
                    if (!nos.DefinedByBase && !nos.SetByDerived)
                    {
                        hasNamedObjectEntities |= AddResetVariablesFor(skippedNoses, nos);
                    }
                }
            }

            if (skippedNoses.Count != 0)
            {
                string message = "Couldn't add reset variables for the following objects.  This may cause pooling to behave improperly for these objects:";

                foreach (NamedObjectSave skipped in skippedNoses)
                {
                    message += "\n " + skipped.InstanceName;
                }

                MessageBox.Show(message);
            }
            #endregion

            #region See if there are any variables to add

            bool areAnyVariablesBeingAdded = false;

            foreach (KeyValuePair<NamedObjectSave, List<string>> kvp in mResetVariablesToAdd)
            {
                NamedObjectSave nos = kvp.Key;
                List<string> variables = kvp.Value;

                // reverse loop here because we're removing from the list
                for (int i = variables.Count - 1; i > -1; i--)
                {
                    string variable = variables[i];

                    if (nos.VariablesToReset.Contains(variable))
                    {
                        variables.Remove(variable);
                    }
                    else
                    {
                        areAnyVariablesBeingAdded = true;
                    }
                }
            }
            #endregion

            #region If there are any variables, ask the user if resetting should be added

            if (areAnyVariablesBeingAdded)
            {
                DialogResult result = MessageBox.Show("Glue will add some best-guess variables to be reset " +
                    "to the objects in your Entity.  Existing variables will be preserved.  You may " +
                    "need to manually add additional variables depending on the logic contained in your Entity." +
                    "\n\nAdd variables?", "Add Variables for " + entitySave.Name + "?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (KeyValuePair<NamedObjectSave, List<string>> kvp in mResetVariablesToAdd)
                    {
                        NamedObjectSave nos = kvp.Key;
                        List<string> variables = kvp.Value;

                        foreach (string s in variables)
                        {
                            Plugins.PluginManager.ReceiveOutput("Added reset variable " + s + " in object " + nos);
                        }


                        nos.VariablesToReset.AddRange(variables);
                    }
                }

                GluxCommands.Self.SaveGlux();

                ElementViewWindow.GenerateSelectedElementCode();
            }
            else
            {
                Plugins.PluginManager.ReceiveOutput("No reset variables added to " + entitySave);
            }

            #endregion

            #region As the user if Glue should reset variables for all NamedObjects which are Entities

            if (hasNamedObjectEntities)
            {
                DialogResult result = MessageBox.Show(
                    "Would you like to set reset variables for all contained objects which reference Entities inside " + entitySave.Name + "?  This " +
                    "action is recommended.", "Reset objects referencing Entities?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (NamedObjectSave nos in entitySave.NamedObjects)
                    {
                        if (nos.SourceType == SourceType.Entity)
                        {
                            EntitySave containedEntitySave = nos.GetReferencedElement() as EntitySave;

                            if (containedEntitySave != null)
                            {
                                SetResetVariablesForEntitySave(containedEntitySave);

                            }
                        }
                    }
                }
            }
            #endregion

            #region Check for inheritance and ask if all derived Entities should have their variables reset too

            List<EntitySave> inheritingEntities = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(entitySave);

            if (inheritingEntities.Count != 0)
            {
                string message =
                    "Would you like to set reset variables for Entities which inherit from " + entitySave.Name + "?  " +
                    "The following Entities will be modified:\n\n";

                foreach (EntitySave inheritingEntity in inheritingEntities)
                {
                    message += inheritingEntity.Name + "\n";
                }

                message += "\nThis " +
                    "action is recommended.";

                DialogResult result = MessageBox.Show(message,
                    "Reset Entites inheriting from this?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (EntitySave inheritingEntity in inheritingEntities)
                    {
                        SetResetVariablesForEntitySave(inheritingEntity);
                    }
                }
            }

            #endregion

            foreach (NamedObjectSave nos in entitySave.NamedObjects)
            {
                StringFunctions.RemoveDuplicates(nos.VariablesToReset);
            }

            CodeWriter.GenerateCode(entitySave);

            foreach(var element in entitySave.GetAllBaseEntities())
            {
                CodeWriter.GenerateCode(element);
            }
            // Not sure we don't save the project here...
            GluxCommands.Self.SaveGlux();
        }