Пример #1
0
        public static void SignalConnectObject <TDelegate>(IntPtr widget, string name, TDelegate callback, IntPtr obj) where TDelegate : Delegate
        {
            var delegat = callback as Delegate;

            Delegates.Add(delegat);
            SignalConnect(widget, name, Marshal.GetFunctionPointerForDelegate(callback), obj, 0);
        }
Пример #2
0
 private void AddDelegate(ITypeDefinition dlgte, StringBuilder key)
 {
     if (dlgte.Namespace == "")
     {
         lock (Delegates)
         {
             foreach (var typeArg in dlgte.TypeParameters)
             {
                 foreach (var constraint in typeArg.DirectBaseTypes)
                 {
                     key.Append(constraint.Name);
                 }
             }
             if (Delegates.ContainsKey(key.ToString()))
             {
                 return;
             }
             Delegates.Add(key.ToString(), new DelegateProperties(dlgte));
         }
     }
     else
     {
         AddNamespace(key, dlgte);
     }
 }
Пример #3
0
        public static void AddActions(IntPtr app, IEnumerable <GtkAction> actions)
        {
            var gtkActions = actions.OfType <GtkAction>();

            foreach (var action in gtkActions)
            {
                if (action.Action != null)
                {
                    Delegates.Add(action.Action);
                    var simpleAction = NewAction(action.Name, null);
                    Gtk.SignalConnect <Action>(simpleAction, "activate", action.Action);
                    AddAction(app, simpleAction);
                }
                else
                {
                    Delegates.Add(action.StateChanged);
                    var state = action.StateParameterType == "s"
                        ? NewString(action.State as string)
                        : NewBool((bool)action.State == true ? -1 : 0);
                    var simpleAction = NewStatefulAction(action.Name, action.StateParameterType, state);
                    Gtk.SignalConnect <GtkAction.StateChangedDelegate>(simpleAction, "change-state", action.StateChanged);
                    AddAction(app, simpleAction);
                }
            }

            var accelEntries =
                actions
                .Where(n => n.Accelerator != null)
                .Select(n => new { Name = "app." + n.Name, n.Accelerator });

            foreach (var accelEntry in accelEntries)
            {
                Application.SetAccelsForAction(app, accelEntry.Name, new [] { accelEntry.Accelerator, null });
            }
        }
        /// <summary>
        /// Add a delegate for the build process
        /// </summary>
        /// <param name="action">the delegate to use in the building process</param>
        /// <param name="ordinal">the sort order of the delegate</param>
        protected void AddDelegate(Func <T, object[], bool> action, int ordinal = int.MaxValue)
        {
            DelegateInfo <T> info = new DelegateInfo <T>()
            {
                Delegate = action,
                Ordinal  = ordinal
            };

            Delegates.Add(info);
        }
Пример #5
0
 private void AddDelegate(IType dlgte, StringBuilder key)
 {
     lock (Delegates)
     {
         foreach (var typeArg in dlgte.TypeParameters)
         {
             foreach (var constraint in typeArg.Constraints)
             {
                 key.Append(constraint.Name);
             }
         }
         if (Delegates.ContainsKey(key.ToString()))
         {
             return;
         }
         Delegates.Add(key.ToString(), new DelegateProperties(dlgte));
     }
 }
Пример #6
0
        private void _Invoke(ref object RetObject, params object[] args)
        {
            if (args.Length < ArgumentTypes.Length) //check if a argument is using "params x[] args"
            {
                throw new Exception("missing arguments");
            }

            List <int>    usedDelegates = new List <int>();
            PayloadWriter pw            = new PayloadWriter();

            pw.WriteInteger(sharedClass.SharedId);
            pw.WriteInteger(MethodId);
            pw.WriteByte(isDelegate ? (byte)1 : (byte)0);

            if (isDelegate)
            {
                pw.WriteInteger(this.DelegateId);
                pw.WriteInteger(this.sharedClass.SharedId);
            }

            SmartSerializer serializer = new SmartSerializer();

            for (int i = 0; i < args.Length; i++)
            {
                object obj = ArgumentTypes[i].IsByRef ? null : args[i];

                if (DelegateIndex.ContainsKey(i))
                {
                    obj = null;
                }

                byte[] SerializedObj = serializer.Serialize(obj);
                pw.WriteInteger(SerializedObj.Length);
                pw.WriteBytes(SerializedObj);
            }

            for (int i = 0; i < DelegateIndex.Count; i++)
            {
                Delegate del = args[DelegateIndex.Keys[i]] as Delegate;

                if (del != null)
                {
                    if (del.Method == null)
                    {
                        throw new Exception("Target delegate is NULL");
                    }

                    int id = rnd.Next();
                    while (Delegates.ContainsKey(id))
                    {
                        id = rnd.Next();
                    }

                    pw.WriteByte(1);
                    SharedDelegate sharedDel = new SharedDelegate(del.Method, sharedClass, del.GetType(), id, del, this.MethodId);
                    sharedDel.sharedMethod.Unchecked      = DelegateIndex.Values[i].isUnchecked;
                    sharedDel.sharedMethod.usePacketQueue = DelegateIndex.Values[i].UsePacketQueue;
                    sharedDel.sharedMethod.useUdp         = DelegateIndex.Values[i].UseUDP;
                    sharedDel.sharedMethod.NoWaitingTime  = DelegateIndex.Values[i].NoWaitingTime;
                    pw.WriteObject(sharedDel);

                    if (!isDelegate)
                    {
                        Delegates.Add(id, sharedDel);
                    }
                    continue;
                }
                pw.WriteByte(0);
            }

            if (Unchecked || useUdp)
            {
                //just execute the method and don't wait for response
                sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(0, pw.ToByteArray(), false));
            }
            else
            {
                SyncObject syncObject = null;
                Random     rnd        = new Random();
                int        RequestId  = rnd.Next();
                lock (sharedClass.connection.MethodRequests)
                {
                    while (sharedClass.connection.MethodRequests.ContainsKey(RequestId))
                    {
                        RequestId = rnd.Next();
                    }
                    syncObject = new SyncObject(sharedClass.connection.Connection.Connection);
                    sharedClass.connection.MethodRequests.Add(RequestId, syncObject);
                    sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(RequestId, pw.ToByteArray(), true));
                }
                RetObject = syncObject.Wait <ReturnResult>(null, 0);
            }

            /*if (callback != null)
             * {
             *  sharedClass.connection.BeginSendRequest(pw, callback, true, this.usePacketQueue);
             * }
             * else
             * {
             *  if (Unchecked || useUdp)
             *  {
             *      //just don't wait till we received something back since it's a VOID anyway
             *      sharedClass.connection.BeginSendRequest(pw, (object obj) => { }, false, this.usePacketQueue);
             *  }
             *  else
             *  {
             *      RetObject = sharedClass.connection.SendRequest(pw, this.usePacketQueue);
             *  }
             * }*/
            serializer = null;
        }
Пример #7
0
 private void registerDelegate(Delegate del, object att, List <OpuxlArgumentAttribute> argAtt)
 {
     Delegates.Add(del);
     Attributes.Add(att);
     Arguments.Add((argAtt.Cast <object>().ToList()));
 }
Пример #8
0
        private void _Invoke(ref object RetObject, params object[] args)
        {
            if (args.Length < ArgumentTypes.Length) //check if a argument is using "params x[] args"
            {
                throw new Exception("missing arguments");
            }

            List <int>    usedDelegates = new List <int>();
            PayloadWriter pw            = new PayloadWriter();

            SmartSerializer serializer = new SmartSerializer();

            for (int i = 0; i < args.Length; i++)
            {
                object obj = ArgumentTypes[i].IsByRef ? null : args[i];

                if (DelegateIndex.ContainsKey(i))
                {
                    obj = null;
                }

                byte[] SerializedObj = serializer.Serialize(obj);
                pw.WriteInteger(SerializedObj.Length);
                pw.WriteBytes(SerializedObj);
            }

            for (int i = 0; i < DelegateIndex.Count; i++)
            {
                Delegate del = args[DelegateIndex.Keys[i]] as Delegate;

                if (del != null)
                {
                    if (del.Method == null)
                    {
                        throw new Exception("Target delegate is NULL");
                    }

                    int id = rnd.Next();
                    while (Delegates.ContainsKey(id))
                    {
                        id = rnd.Next();
                    }

                    pw.WriteBool(true);
                    SharedDelegate sharedDel = new SharedDelegate(del.Method, sharedClass, del.GetType(), id, del, this.MethodId);
                    sharedDel.sharedMethod.Unchecked      = this.Unchecked;      //DelegateIndex.Values[i].isUnchecked;
                    sharedDel.sharedMethod.usePacketQueue = this.usePacketQueue; //DelegateIndex.Values[i].UsePacketQueue;
                    sharedDel.sharedMethod.useUdp         = this.useUdp;         //DelegateIndex.Values[i].UseUDP;
                    pw.WriteObject(sharedDel);

                    if (!isDelegate)
                    {
                        Delegates.Add(id, sharedDel);
                    }
                    continue;
                }
                pw.WriteBool(false);
            }

            try
            {
                if (Unchecked || useUdp)
                {
                    //just execute the method and don't wait for response
                    sharedClass.Client.Send(new MsgExecuteMethod(0, pw.ToByteArray(), false, sharedClass.SharedId, MethodId, this.DelegateId, this.sharedClass.SharedId));
                }
                else
                {
                    SyncObject syncObject = null;
                    Random     rnd        = new Random();
                    int        RequestId  = rnd.Next();
                    lock (sharedClass.Client.Requests)
                    {
                        while (sharedClass.Client.Requests.ContainsKey(RequestId))
                        {
                            RequestId = rnd.Next();
                        }
                        syncObject = new SyncObject(sharedClass.Client);
                        sharedClass.Client.Requests.Add(RequestId, syncObject);
                        sharedClass.Client.Send(new MsgExecuteMethod(RequestId, pw.ToByteArray(), true, sharedClass.SharedId, MethodId, this.DelegateId, this.sharedClass.SharedId));
                    }
                    RetObject = syncObject.Wait <ReturnResult>(null, TimeOutLength);

                    if (syncObject.TimedOut)
                    {
                        //copying the object in memory, maybe a strange way todo it but it works
                        RetObject = new ReturnResult(serializer.Deserialize(serializer.Serialize(this.TimeOutValue)), false);
                    }
                }
            }
            catch
            {
                //client most likely disconnected and was unable to send the message
                RetObject = null;
            }

            /*if (callback != null)
             * {
             *  sharedClass.connection.BeginSendRequest(pw, callback, true, this.usePacketQueue);
             * }
             * else
             * {
             *  if (Unchecked || useUdp)
             *  {
             *      //just don't wait till we received something back since it's a VOID anyway
             *      sharedClass.connection.BeginSendRequest(pw, (object obj) => { }, false, this.usePacketQueue);
             *  }
             *  else
             *  {
             *      RetObject = sharedClass.connection.SendRequest(pw, this.usePacketQueue);
             *  }
             * }*/
            serializer = null;
        }
Пример #9
0
 public void Add(FScriptDelegate value)
 {
     Delegates.Add(value);
 }
Пример #10
0
 protected void btnSave_Click(Object Sender, EventArgs e)
 {
     oDelegate.Add(intUser, Int32.Parse(Request.Form[hdnDelegate.UniqueID]), Int32.Parse(ddlRights.SelectedItem.Value));
     Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "saved", "<script type=\"text/javascript\">window.parent.navigate('" + oPage.GetFullLink(intParent) + "?action=addbuddy');window.close();<" + "/" + "script>");
 }