Example #1
0
        public Delegate[] GetEventRecipients(string eventName)
        {
            if (null == _thisType)
            {
                _thisType = this.GetType();
            }

            MulticastDelegate eventDelegate = (MulticastDelegate)_thisType.GetField(
                "_" + eventName + "Event",
                NetRuntimeSystem.Reflection.BindingFlags.Instance |
                NetRuntimeSystem.Reflection.BindingFlags.NonPublic).GetValue(this);

            if (null != eventDelegate)
            {
                Delegate[] delegates = eventDelegate.GetInvocationList();
                return(delegates);
            }
            else
            {
                return(new Delegate[0]);
            }
        }
        private EventRegistrationToken AddEventHandlerNoLock(T handler)
        {
            Contract.Requires(handler != null);

            // Get a registration token, making sure that we haven't already used the value.  This should be quite
            // rare, but in the case it does happen, just keep trying until we find one that's unused.
            EventRegistrationToken token = GetPreferredToken(handler);

            while (m_tokens.ContainsKey(token))
            {
                token = new EventRegistrationToken(token.Value + 1);
            }
            m_tokens[token] = handler;

            // Update the current invocation list to include the newly added delegate
            Delegate invokeList = (Delegate)(object)m_invokeList;

            invokeList   = MulticastDelegate.Combine(invokeList, (Delegate)(object)handler);
            m_invokeList = (T)(object)invokeList;

            return(token);
        }
Example #3
0
            public void Painting(ObjectInspector inspector)
            {
                MulticastDelegate multicast = Field.GetValue(inspector.target) as MulticastDelegate;

                Delegate[] delegates = multicast != null?multicast.GetInvocationList() : null;

                GUILayout.BeginHorizontal();
                GUILayout.Space(10);
                IsFoldout = EditorGUILayout.Foldout(IsFoldout, string.Format("{0} [{1}]", Name, delegates != null ? delegates.Length : 0));
                GUILayout.EndHorizontal();

                if (IsFoldout && delegates != null)
                {
                    for (int i = 0; i < delegates.Length; i++)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        GUILayout.Label(string.Format("{0}->{1}", delegates[i].Target, delegates[i].Method), "Textfield");
                        GUILayout.EndHorizontal();
                    }
                }
            }
Example #4
0
        /// <summary>
        /// Handles when SystemEvent is received from the Paradox manager.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ParadoxSystemEventArgs"/> instance containing the event data.</param>
        private void OnSystemEvent(object sender, ParadoxSystemEventArgs e)
        {
            // Get the event to raise from the event group
            var eventToRaise = this.GetType().GetEvents()
                               .Select(ev => new
            {
                Description = ev.GetCustomAttribute <ParadoxGroupEventAttribute>(),
                EventInfo   = ev
            })
                               .Where(ev => ev.Description != null && ev.Description.IsMatch((int)e.EventGroup) && ev.EventInfo != null)
                               .Select(ev => new
            {
                EventName     = ev.EventInfo.Name,
                EventArgsType = ev.EventInfo.EventHandlerType.GenericTypeArguments.FirstOrDefault()
            })
                               .SingleOrDefault();

            // If the event exist
            if (eventToRaise != null && eventToRaise.EventArgsType != null)
            {
                // Create the custom event args from the original event
                ParadoxSystemEventArgs eventArgs = (ParadoxSystemEventArgs)Activator.CreateInstance(eventToRaise.EventArgsType);
                eventArgs.CopyFrom(e);
                // Raise the event handler(s)
                MulticastDelegate eventDelegate = (MulticastDelegate)this.GetType().GetField(eventToRaise.EventName, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
                if (eventDelegate != null)
                {
                    foreach (var handler in eventDelegate.GetInvocationList())
                    {
                        handler.Method.Invoke(handler.Target, new object[] { this, eventArgs });
                    }
                }
                // Raise the generic NewEventOccurred event
                if (this.NewEventOccurred != null)
                {
                    this.NewEventOccurred(this, EventArgs.Empty);
                }
            }
        }
Example #5
0
 /// <summary>
 /// Custom handler for firing a WMI event to a list of delegates. We use
 /// the process thread pool to handle the firing.
 /// </summary>
 /// <param name="md">The MulticastDelegate representing the collection
 /// of targets for the event</param>
 /// <param name="args">The accompanying event arguments</param>
 internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
 {
     try
     {
         if (null != md)
         {
             foreach (Delegate d in md.GetInvocationList())
             {
                 try
                 {
                     d.DynamicInvoke(new object[] { this.sender, args });
                 }
                 catch
                 {
                 }
             }
         }
     }
     catch
     {
     }
 }
Example #6
0
        public static object Raise(this MulticastDelegate multicastDelegate, object sender, EventArgs e)
        {
            object retVal = null;

            MulticastDelegate threadSafeMulticastDelegate = multicastDelegate;

            if (threadSafeMulticastDelegate != null)
            {
                foreach (Delegate d in threadSafeMulticastDelegate.GetInvocationList())
                {
                    var synchronizeInvoke = d.Target as ISynchronizeInvoke;
                    if (synchronizeInvoke != null && synchronizeInvoke.InvokeRequired)
                    {
                        retVal = synchronizeInvoke.EndInvoke(synchronizeInvoke.BeginInvoke(d, new[] { sender, e }));
                    }
                    else
                    {
                        retVal = d.DynamicInvoke(new[] { sender, e });
                    }
                }
            }
            return(retVal);
        }
Example #7
0
        /************************************************************************************************************************/

        /// <summary>Draws the target and name of the specified <see cref="Delegate"/>.</summary>
        public static void DrawInvocationList(ref Rect area, MulticastDelegate del)
        {
            if (del == null)
            {
                EditorGUI.LabelField(area, "Delegate", "Null");
                AnimancerGUI.NextVerticalArea(ref area);
                return;
            }

            var delegates = GetInvocationListIfMulticast(del);

            if (delegates == null)
            {
                Draw(ref area, del);
            }
            else
            {
                for (int i = 0; i < delegates.Length; i++)
                {
                    Draw(ref area, delegates[i]);
                }
            }
        }
Example #8
0
 /// <summary> Raise the event </summary>
 internal static void RaiseEvent(MulticastDelegate evt, object sender, WuReadingEventArgs e)
 {
     try
     {
         if (null != evt)
         {
             object[] args = new object[] { sender, e };
             foreach (MulticastDelegate d in evt.GetInvocationList())
             {
                 //if (d.Target is System.Windows.Forms.Control)
                 //{
                 //    Control c = d.Target as System.Windows.Forms.Control;
                 //    c.Invoke(d, args);
                 //}
                 //else
                 //{
                 d.DynamicInvoke(args);
                 //}
             }
         }
     }
     catch { }
 }
Example #9
0
        /// <summary>
        /// Raise an instance event
        /// </summary>
        /// <param name="instance">target instance</param>
        /// <param name="type">target instance type</param>
        /// <param name="eventName">name of the event without 'Event' at the end</param>
        /// <param name="paramsArray">custom arguments for the event</param>
        /// <returns>count of called event recipients</returns>
        public static int RaiseCustomEvent(ICOMObject instance, Type type, string eventName, ref object[] paramsArray)
        {
            string    fieldName = MakeEventFieldName(eventName);
            FieldInfo field     = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);

            if (field == null)
            {
                throw new ArgumentOutOfRangeException(nameof(eventName), eventName, $"Event with name '{eventName}' does not exist.");
            }

            MulticastDelegate eventDelegate = field.GetValue(instance) as MulticastDelegate;

            if (null != eventDelegate)
            {
                Delegate[] delegates = eventDelegate.GetInvocationList();
                foreach (var item in delegates)
                {
                    try
                    {
                        item.Method.Invoke(item.Target, paramsArray);
                    }
                    catch (Exception exception)
                    {
                        instance.Console.WriteException(exception);
                    }
                }

                if (instance.Settings.EnableAutoDisposeEventArguments)
                {
                    Invoker.ReleaseParamsArray(paramsArray);
                }

                return(delegates.Length);
            }

            return(0);
        }
Example #10
0
        private void WriteDelegate(XElement element, object obj, ObjectHeader header)
        {
            bool multi = obj is MulticastDelegate;

            // Write the delegates type
            if (multi)
            {
                element.SetAttributeValue("multi", XmlConvert.ToString(multi));
            }

            if (!multi)
            {
                XElement methodElement = new XElement("method");
                XElement targetElement = new XElement("target");
                element.Add(methodElement);
                element.Add(targetElement);

                Delegate objAsDelegate = obj as Delegate;
                this.WriteObjectData(methodElement, objAsDelegate.GetMethodInfo());
                this.WriteObjectData(targetElement, objAsDelegate.Target);
            }
            else
            {
                XElement methodElement         = new XElement("method");
                XElement targetElement         = new XElement("target");
                XElement invocationListElement = new XElement("invocationList");
                element.Add(methodElement);
                element.Add(targetElement);
                element.Add(invocationListElement);

                MulticastDelegate objAsDelegate = obj as MulticastDelegate;
                Delegate[]        invokeList    = objAsDelegate.GetInvocationList();
                this.WriteObjectData(methodElement, objAsDelegate.GetMethodInfo());
                this.WriteObjectData(targetElement, objAsDelegate.Target);
                this.WriteObjectData(invocationListElement, invokeList);
            }
        }
Example #11
0
        public static void RegisterProcessExitHandlerAndMakeItFirstInLineToExecute(EventHandler eventHandler)
        {
            // Here we subscribe to AppDomain.CurrentDomain.ProcessExit event in order to trace a message when process is exiting
            // The problem is that NLOG subscribed to that event before us and therefore is going to shutdown logging subsystem
            // before our handler is called and tries to trace its message.

            // Getting to private field AppDomain.CurrentDomain._processExit
            FieldInfo field = typeof(AppDomain).GetField("_processExit",
                                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

            if (field == null || !field.FieldType.IsSubclassOf(typeof(MulticastDelegate)))
            {
                // If the field is not simple MulticastDelegate, then just add our handler to the end of the list
                AppDomain.CurrentDomain.ProcessExit += eventHandler;
                return;
            }

            // Get the list of existing AppDomain.CurrentDomain.ProcessExit event subscribers
            MulticastDelegate multicastDelegate = field.GetValue(AppDomain.CurrentDomain) as MulticastDelegate;

            Debug.Assert(multicastDelegate != null, "multicastDelegate != null");
            Delegate[] subscribers = multicastDelegate.GetInvocationList();

            // Remove all subscriptions
            foreach (var subscriber in subscribers)
            {
                AppDomain.CurrentDomain.ProcessExit -= (EventHandler)subscriber;
            }

            Delegate[] newSubscriptions = new Delegate[subscribers.Length + 1];  // Create new subscriptions list
            newSubscriptions[0] = eventHandler;                                  // Put our delegate first to the new subscriptions list
            Array.Copy(subscribers, 0, newSubscriptions, 1, subscribers.Length); // Move the rest of the old subscriptions list after ours
            Delegate combinedDelegate = Delegate.Combine(newSubscriptions);      // Combine subscriptions list to Delegate

            field.SetValue(AppDomain.CurrentDomain, combinedDelegate);           // Inject new delegate into event
        }
Example #12
0
        public static T ConvertDelegate <T>(Delegate d)
        {
            if (!(typeof(T).IsSubclassOf(typeof(Delegate))))
            {
                throw new ArgumentException("T is no Delegate");
            }
            if (d == null)
            {
                throw new ArgumentNullException();
            }
            MulticastDelegate md = d as MulticastDelegate;

            Delegate[] invList  = null;
            int        invCount = 1;

            if (md != null)
            {
                invList = md.GetInvocationList();
            }
            if (invList != null)
            {
                invCount = invList.Length;
            }
            if (invCount == 1)
            {
                return((T)(object)Delegate.CreateDelegate(typeof(T), d.Target, d.Method));
            }
            else
            {
                for (int i = 0; i < invList.Length; i++)
                {
                    invList[i] = (Delegate)(object)ConvertDelegate <T>(invList[i]);
                }
                return((T)(object)MulticastDelegate.Combine(invList));
            }
        }
Example #13
0
        public static Delegate RemoveAll(Delegate source, Delegate value)
        {
            if (source == null)
            {
                return(null);
            }
            if (value == null)
            {
                return(source);
            }

            var next = (MulticastDelegate)source;
            MulticastDelegate prev = null;

            while (next != null)
            {
                var nextItem = next._next;
                if (next._methodPtr == value._methodPtr && next._target == value._target)
                {
                    if (next == source)
                    {
                        source     = next._next;
                        next._next = null;
                    }
                    else if (prev != null)
                    {
                        prev._next = next._next;
                        next._next = null;
                    }
                }
                prev = next;
                next = nextItem;
            }

            return(source);
        }
Example #14
0
        public void RaisePostBackEvent(String eventName)
        {
            LoadPostData();

            Type type = Widget.GetType();

            foreach (EventDescriptor @event in TypeDescriptor.GetEvents(type).OfType <EventDescriptor>())
            {
                WidgetEventAttribute attribute = @event.Attributes.OfType <WidgetEventAttribute>().SingleOrDefault();

                if (attribute == null || attribute.Name != eventName)
                {
                    continue;
                }

                FieldInfo         delegateField = type.GetField(@event.Name, BindingFlags.Instance | BindingFlags.NonPublic);
                MulticastDelegate @delegate     = delegateField.GetValue(Widget) as MulticastDelegate;

                if (@delegate != null && @delegate.GetInvocationList().Length > 0)
                {
                    @delegate.DynamicInvoke(new object[] { Widget, EventArgs.Empty });
                }
            }
        }
Example #15
0
        internal static void ThrowIfUnitialised
        (
            this MulticastDelegate checkedDelegate,
            string delegateName,
            string callerName,
            string predecessorName
        )
        {
            bool isDelegateUninitalised = checkedDelegate.GetInvocationList().Any
                                          (
                checkedInvocation => (checkedInvocation == null)
                                          );

            if (isDelegateUninitalised)
            {
                throw new InvalidOperationException
                      (
                          string.Format("'{0}' is null. '{1}' may be called without previous '{2}' call.",
                                        delegateName,
                                        callerName,
                                        predecessorName)
                      );
            }
        }
Example #16
0
        private void InvokeHandler(MulticastDelegate handlerList, EventArgs e)
        {
            if (handlerList == null)
            {
                return;
            }

            object[] args = new object[] { e };
            foreach (Delegate handler in handlerList.GetInvocationList())
            {
                object target = handler.Target;
                System.Windows.Forms.Control control
                    = target as System.Windows.Forms.Control;

                if (control != null && control.InvokeRequired)
                {
                    control.Invoke(handler, args);
                }
                else
                {
                    handler.Method.Invoke(target, args);
                }
            }
        }
Example #17
0
        /// <summary>
        /// Writes the specified <see cref="System.Delegate"/>, including references objects.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        /// <param name="objSerializeType">The <see cref="Duality.Serialization.SerializeType"/> describing the object.</param>
        /// <param name="id">The objects id.</param>
        protected void WriteDelegate(object obj, SerializeType objSerializeType, uint id = 0)
        {
            bool multi = obj is MulticastDelegate;

            // Write the delegates type
            this.writer.Write(objSerializeType.TypeString);
            this.writer.Write(id);
            this.writer.Write(multi);

            if (!multi)
            {
                Delegate objAsDelegate = obj as Delegate;
                this.WriteObjectData(objAsDelegate.Method);
                this.WriteObjectData(objAsDelegate.Target);
            }
            else
            {
                MulticastDelegate objAsDelegate = obj as MulticastDelegate;
                Delegate[]        invokeList    = objAsDelegate.GetInvocationList();
                this.WriteObjectData(objAsDelegate.Method);
                this.WriteObjectData(objAsDelegate.Target);
                this.WriteObjectData(invokeList);
            }
        }
Example #18
0
        /// <summary>Raises the event (on the UI thread if available).</summary>
        /// <param name="multicastDelegate">The event to raise.</param>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An EventArgs that contains the event data.</param>
        /// <returns>The return value of the event invocation or null if none.</returns>
        /// <summary>
        /// Safely raises any EventHandler event asynchronously.
        /// </summary>
        /// <param name="sender">The object raising the event (usually this).</param>
        /// <param name="e">The EventArgs for this event.</param>
        public static void Raise(this MulticastDelegate thisEvent, object sender,
                                 EventArgs e)
        {
            EventHandler       uiMethod;
            ISynchronizeInvoke target;
            AsyncCallback      callback = new AsyncCallback(EndAsynchronousEvent);

            foreach (Delegate d in thisEvent.GetInvocationList())
            {
                uiMethod = d as EventHandler;
                if (uiMethod != null)
                {
                    target = d.Target as ISynchronizeInvoke;
                    if (target != null)
                    {
                        target.BeginInvoke(uiMethod, new[] { sender, e });
                    }
                    else
                    {
                        uiMethod.BeginInvoke(sender, e, callback, uiMethod);
                    }
                }
            }
        }
Example #19
0
        protected override Delegate CombineImpl(Delegate follow)
        {
            MulticastDelegate ret = (MulticastDelegate)object.Clone(this);
            MulticastDelegate cur = ret;

            // Clone and add all the current delegate(s)
            for (MulticastDelegate del = (MulticastDelegate)this.pNext; del != null; del = (MulticastDelegate)del.pNext)
            {
                cur.pNext = (MulticastDelegate)object.Clone(del);
                cur       = (MulticastDelegate)cur.pNext;
            }

            // Add all the following delegate(s)
            cur.pNext = (MulticastDelegate)object.Clone(follow);
            cur       = (MulticastDelegate)cur.pNext;
            for (MulticastDelegate del = (MulticastDelegate)((MulticastDelegate)follow).pNext; del != null; del = (MulticastDelegate)del.pNext)
            {
                cur.pNext = (MulticastDelegate)object.Clone(del);
                cur       = (MulticastDelegate)cur.pNext;
            }
            cur.pNext = null;

            return(ret);
        }
Example #20
0
        public static String ToStringFromEnum <T>(this T value)
            where T : Enum
        {
            if (UseEmit == false)
            {
                return(value.ToString());
            }

            var tp = typeof(T);

            if (tp.IsEnum == false)
            {
                throw new ArgumentException("value must be a enum type");
            }

            MulticastDelegate md = null;

            if (_ToStringFromEnumMethods.TryGetValue(tp, out md) == false)
            {
                var aa = tp.GetCustomAttributes(typeof(FlagsAttribute), false);
                if (aa.Length == 0)
                {
                    md = CreateToStringFromEnumFunc <T>();
                }
                _ToStringFromEnumMethods[tp] = md;
            }
            // Flags
            if (md == null)
            {
                return(value.ToString().Replace(" ", ""));
            }

            var f = (Func <T, String>)md;

            return(f(value));
        }
 protected EventHolder(MulticastDelegate multiDel)
 {
     mDelegate = multiDel;
 }
Example #22
0
 private EventCallback <TValue> CreateCore <TValue>(object receiver, MulticastDelegate callback)
 {
     return(new EventCallback <TValue>(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback));
 }
Example #23
0
File: Dask.cs Project: Raxtion/CT74
 public static extern short GPTC_EventCallBack(ushort CardNumber, ushort Enabled, ushort EventType, MulticastDelegate callbackAddr);
Example #24
0
 private extern IntPtr Thread_internal(MulticastDelegate start);
Example #25
0
        internal static bool RegisterCustomPacketHandler(PacketRegistrationType registrationType, Type packetType, MethodInfo handler, Type baseNetManagerType)
        {
            try
            {
                if (m_registerPacketHandlerMethod == null)
                {
                    return(false);
                }
                if (m_registerPacketHandlerMethod2 == null)
                {
                    return(false);
                }
                if (m_registerPacketHandlerMethod3 == null)
                {
                    return(false);
                }
                if (packetType == null)
                {
                    return(false);
                }
                if (handler == null)
                {
                    return(false);
                }

                //Find the old packet handler
                Type             masterNetManagerType        = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(NetworkManager.InternalNetManagerNamespace, NetworkManager.InternalNetManagerClass);
                FieldInfo        packetRegisteryHashSetField = masterNetManagerType.GetField("9858E5CD512FFA5633683B9551FA4C30", BindingFlags.NonPublic | BindingFlags.Static);
                Object           packetRegisteryHashSetRaw   = packetRegisteryHashSetField.GetValue(null);
                HashSet <Object> packetRegisteryHashSet      = UtilityFunctions.ConvertHashSet(packetRegisteryHashSetRaw);
                if (packetRegisteryHashSet.Count == 0)
                {
                    return(false);
                }
                Object        matchedHandler     = null;
                List <Object> matchedHandlerList = new List <object>();
                List <Type>   messageTypes       = new List <Type>();
                foreach (var entry in packetRegisteryHashSet)
                {
                    FieldInfo delegateField   = entry.GetType().GetField("C2AEC105AF9AB1EF82105555583139FC");
                    Type      fieldType       = delegateField.FieldType;
                    Type[]    genericArgs     = fieldType.GetGenericArguments();
                    Type[]    messageTypeArgs = genericArgs[1].GetGenericArguments();
                    Type      messageType     = messageTypeArgs[0];
                    if (messageType == packetType)
                    {
                        matchedHandler = entry;
                        matchedHandlerList.Add(entry);
                    }

                    messageTypes.Add(messageType);
                }

                if (matchedHandlerList.Count > 1)
                {
                    LogManager.APILog.WriteLine("Found more than 1 packet handler match for type '" + packetType.Name + "'");
                    return(false);
                }

                if (matchedHandler == null)
                {
                    return(false);
                }

                FieldInfo         field = matchedHandler.GetType().GetField("C2AEC105AF9AB1EF82105555583139FC", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value = field.GetValue(matchedHandler);
                FieldInfo         secondaryFlagsField = matchedHandler.GetType().GetField("655022D3B2BE47EBCBA675CCE8B784AD", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            secondaryFlags      = secondaryFlagsField.GetValue(matchedHandler);
                MulticastDelegate action  = (MulticastDelegate)value;
                object            target  = action.Target;
                FieldInfo         field2  = target.GetType().GetField("F774FA5087F549F79181BD64E7B7FF30", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value2  = field2.GetValue(target);
                MulticastDelegate action2 = (MulticastDelegate)value2;
                object            target2 = action2.Target;

                string field3Name          = "";
                string flagsFieldName      = "";
                string serializerFieldName = "";
                switch (registrationType)
                {
                case PacketRegistrationType.Static:
                    field3Name          = "2919BD18904683E267BFC1B48709D971";
                    flagsFieldName      = "0723D9EDBE6B0BE979D08F70F06DA741";
                    serializerFieldName = "9F70C9F89F36D5FC6C1EB816AFF491A9";
                    break;

                case PacketRegistrationType.Instance:
                    field3Name          = "F6EE81B03BFA4E50FF9E5E08DA897D98";
                    flagsFieldName      = "A766151383CE73157E57B8ACCB430B04";
                    serializerFieldName = "501AE44AC35E909FEB7EAEE4264D3398";
                    break;

                case PacketRegistrationType.Timespan:
                    field3Name          = "B76A60C8C0680C4AD569366502B8CF47";
                    flagsFieldName      = "90FCC62CB555FB7216BD38667979B221";
                    serializerFieldName = "DB0C5A72269DAB99179543BE08EEADAB";
                    break;

                default:
                    return(false);
                }
                FieldInfo         field3  = target2.GetType().GetField(field3Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object            value3  = field3.GetValue(target2);
                MulticastDelegate action3 = (MulticastDelegate)value3;

                FieldInfo flagsField      = target2.GetType().GetField(flagsFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object    flagsValue      = flagsField.GetValue(target2);
                FieldInfo serializerField = target2.GetType().GetField(serializerFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                Object    serializerValue = serializerField.GetValue(target2);

                FieldInfo methodBaseField   = action3.GetType().GetField("_methodBase", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                FieldInfo methodPtrField    = action3.GetType().GetField("_methodPtr", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                FieldInfo methodPtrAuxField = action3.GetType().GetField("_methodPtrAux", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                Delegate handlerAction = CreatePacketHandlerDelegate(registrationType, packetType, handler);

                //Remove the old handler from the registry
                MethodInfo removeMethod = packetRegisteryHashSetRaw.GetType().GetMethod("Remove");
                removeMethod.Invoke(packetRegisteryHashSetRaw, new object[] { matchedHandler });

                //Update the handler delegate with our new method info
                methodBaseField.SetValue(action3, handlerAction.Method);
                methodPtrField.SetValue(action3, methodPtrField.GetValue(handlerAction));
                methodPtrAuxField.SetValue(action3, methodPtrAuxField.GetValue(handlerAction));

                if (baseNetManagerType == null)
                {
                    baseNetManagerType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType("", "48D79F8E3C8922F14D85F6D98237314C");
                }

                //Register the new packet handler
                MethodInfo registerMethod = null;
                switch (registrationType)
                {
                case PacketRegistrationType.Static:
                    registerMethod = m_registerPacketHandlerMethod.MakeGenericMethod(packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                case PacketRegistrationType.Instance:
                    registerMethod = m_registerPacketHandlerMethod2.MakeGenericMethod(baseNetManagerType, packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                case PacketRegistrationType.Timespan:
                    registerMethod = m_registerPacketHandlerMethod3.MakeGenericMethod(packetType);
                    registerMethod.Invoke(null, new object[] { action3, flagsValue, secondaryFlags, serializerValue });
                    break;

                default:
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
                return(false);
            }
        }
Example #26
0
 public static extern short DIO_T2_EventMessage(ushort CardNumber, short T2En, long windowHandle, uint message, MulticastDelegate callbackAddr);
Example #27
0
		void SetStart (MulticastDelegate start, int maxStackSize)
		{
			m_Delegate = start;
			Internal.stack_size = maxStackSize;
		}
Example #28
0
        private MulticastDelegate NewMulticastDelegate(MulticastDelegate[] invocationList, int invocationCount)
        {
            MulticastDelegate result = (MulticastDelegate)this.MemberwiseClone();
            result._invocationList = invocationList;
            result._invocationCount = invocationCount;

            return result;
        }
Example #29
0
 private static extern void mg_set_log_callback(IntPtr ctx, MulticastDelegate func);
		public static Delegate FindBUilder (MulticastDelegate mcd)
		{
			throw new NotImplementedException ();
		}
Example #31
0
		public Thread (ThreadStart start, int maxStackSize)
		{
			if (start == null)
				throw new ArgumentNullException ("start");
			if (maxStackSize < 131072)
				throw new ArgumentException ("< 128 kb", "maxStackSize");

			threadstart = start;
			stack_size = maxStackSize;
			Thread_init ();
		}
Example #32
0
 public static extern short DO_EventCallBack(ushort CardNumber, short mode, short EventType, MulticastDelegate callbackAddr);
Example #33
0
 public static extern short DIO_T2_EventMessage(ushort CardNumber, short T2En, long windowHandle, uint message, MulticastDelegate callbackAddr);
Example #34
0
 public static extern short DIO_INT2_EventMessage(ushort CardNumber, short Int2Mode, long windowHandle, long message, MulticastDelegate callbackAddr);
Example #35
0
 private bool EqualInvocationLists(MulticastDelegate[] a, MulticastDelegate[] b, int start, int count)
 {
     for (int i = 0; i < count; i++)
     {
         if (!(a[start + i].Equals(b[i])))
             return false;
     }
     return true;
 }
Example #36
0
	[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void	mg_set_log_callback(IntPtr ctx, MulticastDelegate func);
Example #37
0
        protected override Delegate CombineImpl(Delegate follow)
        {
            if (follow == null)
                return this;

            // Verify that the types are the same...
            if (this.GetType() != follow.GetType())
                throw new ArgumentException("DlgtTypeMis");

            MulticastDelegate dFollow = (MulticastDelegate)follow;
            MulticastDelegate[] resultList;
            int followCount = 1;
            MulticastDelegate[] followList = dFollow._invocationList;
            if (followList != null)
                followCount = (int)dFollow._invocationCount;

            int resultCount;
            MulticastDelegate[] invocationList = _invocationList;
            if (invocationList == null)
            {
                resultCount = 1 + followCount;
                resultList = new MulticastDelegate[resultCount];
                resultList[0] = this;
                if (followList == null)
                {
                    resultList[1] = dFollow;
                }
                else
                {
                    for (int i = 0; i < followCount; i++)
                        resultList[1 + i] = followList[i];
                }
                return NewMulticastDelegate(resultList, resultCount);
            }
            else
            {
                int invocationCount = _invocationCount;
                resultCount = invocationCount + followCount;
                resultList = null;
                if (resultCount <= invocationList.Length)
                {
                    resultList = invocationList;
                    if (followList == null)
                    {
                        if (!TrySetSlot(resultList, invocationCount, dFollow))
                            resultList = null;
                    }
                    else
                    {
                        for (int i = 0; i < followCount; i++)
                        {
                            if (!TrySetSlot(resultList, invocationCount + i, followList[i]))
                            {
                                resultList = null;
                                break;
                            }
                        }
                    }
                }

                if (resultList == null)
                {
                    int allocCount = invocationList.Length;
                    while (allocCount < resultCount)
                        allocCount *= 2;

                    resultList = new MulticastDelegate[allocCount];

                    for (int i = 0; i < invocationCount; i++)
                        resultList[i] = invocationList[i];

                    if (followList == null)
                    {
                        resultList[invocationCount] = dFollow;
                    }
                    else
                    {
                        for (int i = 0; i < followCount; i++)
                            resultList[invocationCount + i] = followList[i];
                    }
                }
                return NewMulticastDelegate(resultList, resultCount);
            }
        }
Example #38
0
        public IRendererTreeBuilder AddAttribute(string name, MulticastDelegate value)
        {
            renderTreeBuilder.AddAttribute(++sequence, name, value);

            return(this);
        }
Example #39
0
	[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void	mg_set_uri_callback(IntPtr ctx, string uri_regex, MulticastDelegate func, IntPtr data);
Example #40
0
		public Thread (ParameterizedThreadStart start, int maxStackSize)
		{
			if (start == null)
				throw new ArgumentNullException ("start");
			if (maxStackSize < 0)
				throw new ArgumentOutOfRangeException ("less than zero", "maxStackSize");
			if (maxStackSize < 131072) //make sure stack is at least 128k big
				maxStackSize = 131072;

			threadstart = start;
			Internal.stack_size = maxStackSize;
		}
        public override object Execute(MulticastDelegate dele, ParameterCollection parameters)
        {
            object result = dele.DynamicInvoke(parameters.AllParameterValues);

            return(this.ExecuteAfter(result, parameters));
        }
Example #42
0
		private extern IntPtr Thread_internal (MulticastDelegate start);
	public static bool op_Inequality(MulticastDelegate d1, MulticastDelegate d2) {}
Example #44
0
		public Thread (ParameterizedThreadStart start)
		{
			if (start == null)
				throw new ArgumentNullException ("start");

			threadstart = start;
		}
Example #45
0
 void SetStart(MulticastDelegate start, int maxStackSize)
 {
     m_Delegate          = start;
     Internal.stack_size = maxStackSize;
 }
// ReSharper disable UnusedMember.Local
    void Start()
// ReSharper restore UnusedMember.Local
    {
        // keys
        ObjectClicked = new MulticastDelegate(Dispatcher, OBJECT_CLICKED);
    }
Example #47
0
		public Thread(ThreadStart start) {
			if(start==null) {
				throw new ArgumentNullException("Null ThreadStart");
			}
			threadstart=start;
		}
 // ReSharper restore UnusedMember.Local
 // ReSharper disable UnusedMember.Local
 void Start()
 {
     // keys
     ObjectClicked = new MulticastDelegate(this, OBJECT_CLICKED);
 }
Example #49
0
		public Thread (ParameterizedThreadStart start, int maxStackSize)
		{
			if (start == null)
				throw new ArgumentNullException ("start");
			if (maxStackSize < 131072)
				throw new ArgumentException ("< 128 kb", "maxStackSize");

			threadstart = start;
			Internal.stack_size = maxStackSize;
		}
Example #50
0
        private bool TrySetSlot(MulticastDelegate[] a, int index, MulticastDelegate o)
        {
            if (a[index] == null && System.Threading.Interlocked.CompareExchange(ref a[index], o, null) == null)
                return true;

            if (a[index] != null)
            {
                MulticastDelegate d = o;
                MulticastDelegate dd = a[index];
                if (dd._methodPtr == d._methodPtr &&
                    dd._target == d._target)
                {
                    return true;
                }
            }

            return false;
        }
 public ConnectionStatusEventHolder(MulticastDelegate multiDel, ConnectionStatusType status, bool willReconnect)
     : base(multiDel)
 {
     mStatus        = status;
     mWillReconnect = willReconnect;
 }
Example #52
0
        private MulticastDelegate[] DeleteFromInvocationList(MulticastDelegate[] invocationList, int invocationCount, int deleteIndex, int deleteCount)
        {
            MulticastDelegate[] thisInvocationList = _invocationList;
            int allocCount = thisInvocationList.Length;
            while (allocCount / 2 >= invocationCount - deleteCount)
                allocCount /= 2;

            MulticastDelegate[] newInvocationList = new MulticastDelegate[allocCount];

            for (int i = 0; i < deleteIndex; i++)
                newInvocationList[i] = invocationList[i];

            for (int i = deleteIndex + deleteCount; i < invocationCount; i++)
                newInvocationList[i - deleteCount] = invocationList[i];

            return newInvocationList;
        }
		private IntPtr Thread_internal (MulticastDelegate start)
		{
			throw new System.NotImplementedException();
		}
Example #54
0
 private static extern void mg_set_uri_callback(IntPtr ctx, string uri_regex, MulticastDelegate func, IntPtr data);
Example #55
0
 public static T AsDelegate <T>(this MulticastDelegate del)
 {
     return(Marshal.GetDelegateForFunctionPointer <T>(
                Marshal.GetFunctionPointerForDelegate(del)));
 }
Example #56
0
		public Thread (ParameterizedThreadStart start, int maxStackSize)
		{
			if (start == null)
				throw new ArgumentNullException ("start");

			threadstart = start;
			Internal.stack_size = CheckStackSize (maxStackSize);
		}