Пример #1
0
        /// <summary>
        /// Registers the specified handler. Returns handle to registration which can be used in Unregister method.
        /// </summary>
        /// <param name="handler">The handler function. This can be null if only suppression is required.</param>
        /// <param name="priority">The priority where higher priority gets called last.</param>
        /// <param name="count">The count. Set zero or negative for infinite, otherwise the handler is called this many times before automatically removed.</param>
        /// <param name="flags">The flags of registration.</param>
        /// <returns></returns>
        public long Register(EventHandler handler, int priority = 0, int count = 0, EventRegistrationFlags flags = EventRegistrationFlags.None)
        {
            string pluginKey = null;
            int    pluginVer = 0;
            var    assembly  = System.Reflection.Assembly.GetCallingAssembly();

            if (assembly != null)
            {
                if (assembly == Main.FrameworkAssembly)
                {
                    pluginKey = string.Empty;
                    pluginVer = Main.FrameworkVersion;
                }
                else
                {
                    var plugin = PluginManager.GetPlugin(assembly);
                    if (plugin != null)
                    {
                        pluginKey = plugin.InternalKey;
                        pluginVer = plugin.InternalVersion;
                    }
                }
            }
            lock (this.Locker)
            {
                return(this._Register(handler, priority, count, flags, pluginKey, pluginVer));
            }
        }
Пример #2
0
        /// <summary>
        /// Register a new event handler.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="totalCount">The total count.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="fromPluginKey">The plugin.</param>
        /// <param name="fromPluginVersion">The plugin version.</param>
        /// <returns></returns>
        internal protected long _Register(Delegate handler, int priority, int totalCount, EventRegistrationFlags flags, string fromPluginKey, int fromPluginVersion)
        {
            var registration = new EventRegistration();

            registration.Guid         = Main.GenerateGuid();
            registration.Handler      = handler;
            registration.Priority     = priority;
            registration.TotalCount   = totalCount;
            registration.CurrentCount = totalCount;
            registration.Flags        = flags;
            if (fromPluginKey != null)
            {
                registration.PluginKey = fromPluginKey;
                registration.PluginVer = fromPluginVersion;
            }
            else
            {
                registration.PluginKey = null;
                registration.PluginVer = 0;
            }
            this._Register(registration);
            this._Recalculate();
            return(registration.Guid);
        }