Stores information about an Event type as defined in CSVs.
An EventSave is like a "type" for events. It contains information such as the event name, the arguments, and so on.
Esempio n. 1
0
        internal void RefreshEvents()
        {
            var allGlueEvents = FlatRedBall.Glue.Events.EventManager.AllEvents;
            var kvpList       = allGlueEvents.Where(item => mEventsAdded.Contains(item.Value)).ToList();

            foreach (var key in kvpList.Select(item => item.Key))
            {
                allGlueEvents.Remove(key);
            }

            // Now let's re-add
            foreach (var element in AppState.Self.AllLoadedElements)
            {
                foreach (var gumEvent in element.Events.Where(item => item.Enabled))
                {
                    if (!allGlueEvents.ContainsKey(gumEvent.GetExposedOrRootName()))
                    {
                        var glueEventSave = new FlatRedBall.Glue.Events.EventSave();

                        glueEventSave.Arguments    = "FlatRedBall.Gui.IWindow callingWindow";
                        glueEventSave.DelegateType = "FlatRedBall.Gui.WindowEvent";


                        allGlueEvents.Add(gumEvent.GetExposedOrRootName(), glueEventSave);
                    }
                }
            }
        }
        /// <summary>
        /// Gets associated EventSave that comes from BuiltInEvents.csv.  This may be null
        /// if the EventResponseSave is an event responding to a changed variable.
        /// </summary>
        public static EventSave GetEventSave(this EventResponseSave instance)
        {
            EventSave toReturn = null;

            string key = "";

            if (!string.IsNullOrEmpty(instance.SourceObject) && !string.IsNullOrEmpty(instance.SourceObjectEvent))
            {
                key = instance.SourceObjectEvent;

                IElement container = ObjectFinder.Self.GetElementContaining(instance);

                if (container != null)
                {
                    NamedObjectSave nos = container.GetNamedObjectRecursively(instance.SourceObject);
#if GLUE
                    string type;
                    string args;

                    FlatRedBall.Glue.Plugins.PluginManager.GetEventSignatureArgs(nos, instance, out type, out args);
                    if (type != null)
                    {
                        toReturn              = new EventSave();
                        toReturn.Arguments    = args;
                        toReturn.DelegateType = type;
                    }
#endif
                    if (toReturn == null && nos != null && nos.SourceType == SourceType.Entity)
                    {
                        // This may be a tunnel into a tunneled event
                        FlatRedBall.Glue.SaveClasses.IElement element = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                        if (element != null)
                        {
                            foreach (EventResponseSave ers in element.Events)
                            {
                                if (ers.EventName == instance.SourceObjectEvent)
                                {
                                    toReturn = ers.GetEventSave();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                key = instance.EventName;
            }

            if (toReturn == null && EventManager.AllEvents.ContainsKey(key))
            {
                toReturn = EventManager.AllEvents[key];
            }

            return(toReturn);
        }
        public static string GetEffectiveDelegateType(this EventResponseSave ers, IElement containingElement)
        {
            if (ers.GetIsTunneling())
            {
                IElement          tunneledElement;
                EventResponseSave tunneledTo = ers.GetEventThisTunnelsTo(containingElement, out tunneledElement);

                if (tunneledTo != null)
                {
                    return(tunneledTo.GetEffectiveDelegateType(tunneledElement));
                }
            }

            EventSave eventSave = ers.GetEventSave();

            string delegateType;

            if (eventSave != null && !string.IsNullOrEmpty(eventSave.DelegateType))
            {
                delegateType = eventSave.DelegateType;
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                delegateType = ers.DelegateType;
            }
            else
            {
                delegateType = "EventHandler";
            }

            if (delegateType == "Action")
            {
                delegateType = "System.Action";
            }

            return(delegateType);
        }
 public TreeNode GetTreeNodeFor(EventSave eventSave)
 {
     foreach (TreeNode treeNode in this.mVariablesTreeNode.Nodes)
     {
         if (treeNode.Tag == eventSave)
         {
             return treeNode;
         }
     }
     return null;
 }
        public static string GetArgsForMethod(this EventResponseSave ers, IElement containingElement)
        {
            EventSave eventSave = ers.GetEventSave();


            string args      = null;
            bool   foundArgs = false;

            if (eventSave != null)
            {
                args      = eventSave.Arguments;
                foundArgs = true;
            }
            else if (ers.GetIsTunneling())
            {
                IElement          tunneledContainingElement;
                EventResponseSave tunneled = ers.GetEventThisTunnelsTo(containingElement, out tunneledContainingElement);

                if (tunneled != null)
                {
                    return(tunneled.GetArgsForMethod(tunneledContainingElement));
                }
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                if (ers.DelegateType.StartsWith("System.Action<"))
                {
                    string delegateType = ers.DelegateType;

                    int startOfGeneric  = delegateType.IndexOf("<") + 1;
                    int endofGeneric    = delegateType.LastIndexOf(">");
                    int lengthOfGeneric = endofGeneric - startOfGeneric;

                    string genericType = delegateType.Substring(startOfGeneric, lengthOfGeneric);

                    args      = genericType + " value";
                    foundArgs = true;
                }
                else
                {
                    Type type = TypeManager.GetTypeFromString(ers.DelegateType);

                    if (type != null)
                    {
                        MethodInfo      methodInfo = type.GetMethod("Invoke");
                        ParameterInfo[] parameters = methodInfo.GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (i != 0)
                            {
                                args += ", ";
                            }

                            ParameterInfo param = parameters[i];

                            args += param.ParameterType.FullName + " " + param.Name;
                            Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
                        }

                        foundArgs = true;
                    }
                }
            }

            if (!foundArgs)
            {
                args = "object sender, EventArgs e";
            }

            return(args);
        }