コード例 #1
0
ファイル: Loader.cs プロジェクト: jean/phosphorusfive
        /// <summary>
        ///     Creates a new ApplicationContext for you
        /// </summary>
        /// <returns>The newly created context</returns>
        public ApplicationContext CreateApplicationContext(
            ApplicationContext.ContextTicket ticket = null)
        {
            var context = new ApplicationContext(_instanceActiveEvents, _staticActiveEvents, ticket);

            return(context);
        }
コード例 #2
0
ファイル: ActiveEvents.cs プロジェクト: jean/phosphorusfive
        /// <summary>
        ///     Raise the specified Active Event with the given name
        /// </summary>
        /// <param name="name">Name of Active Event to raise</param>
        /// <param name="args">Arguments to pass into Event Handlers</param>
        /// <param name="context">Application Context</param>
        public Node Raise(
            string name,
            Node args,
            ApplicationContext context,
            ApplicationContext.ContextTicket ticket)
        {
            try
            {
                // Constructing EventArgs
                ActiveEventArgs e = new ActiveEventArgs(name, args ?? new Node());

                // Checking if we have any Active Event handlers for given name
                if (_events.ContainsKey(name))
                {
                    // Looping through all Active Events handlers for the given Active Event name
                    foreach (var idxMethod in _events[name].Methods.ToList())
                    {
                        // Invoking Event Handler
                        idxMethod.Method.Invoke(idxMethod.Instance, new object[] { context, e });
                    }
                }

                // Then looping through all "null Active Event handlers" afterwards
                if (_events.ContainsKey(""))
                {
                    // Active Event was not protected, and we have a "null event handler"
                    foreach (var idxMethod in _events[""].Methods)
                    {
                        idxMethod.Method.Invoke(idxMethod.Instance, new object[] { context, e });
                    }
                }

                // Returning args to caller
                return(e.Args);
            }
            catch (TargetInvocationException err)
            {
                // Making sure we transform reflection exceptions into actual exceptions thrown
                ExceptionDispatchInfo.Capture(err.InnerException).Throw();
                throw; // Never reached, needed for compiler to not choke ...!!
            }
        }