Exemplo n.º 1
1
    void AssignAllActions(System.Action<BaseEventData> pressedAction,
						  System.Action<BaseEventData> releasedAction,
						  ref EventTrigger trigger)
    {
        EventTrigger.Entry entry1 = new EventTrigger.Entry();

        entry1.eventID = EventTriggerType.PointerDown;
        entry1.callback.AddListener(eventData => pressedAction.Invoke(eventData));

        trigger.triggers.Add(entry1);

        EventTrigger.Entry entry2 = new EventTrigger.Entry();

        entry2.eventID = EventTriggerType.PointerUp;
        entry2.callback.AddListener(eventData => releasedAction.Invoke(eventData));

        trigger.triggers.Add(entry2);

        EventTrigger.Entry entry3 = new EventTrigger.Entry();

        entry3.eventID = EventTriggerType.PointerExit;
        entry3.callback.AddListener(eventData => releasedAction.Invoke(eventData));

        trigger.triggers.Add(entry3);
    }
Exemplo n.º 2
0
 public static void QueueUserWorkItem(System.Threading.WaitCallback callback)
 {
     if (Pool != null)
     {
         Pool.QueueWorkItem(state => { callback.Invoke(state); return null; });
     }
     else
     {
         System.Threading.ThreadPool.QueueUserWorkItem(state => callback.Invoke(state));
     }
 }
Exemplo n.º 3
0
        public static void DelayExecute(System.Action callback, int msDelay, bool onUIThread = true)
        {
            Thread t = new Thread(delegate() {
                Thread.Sleep(msDelay);

                if (onUIThread)
                    Caliburn.Micro.Execute.OnUIThread(() => callback.Invoke());
                else
                    callback.Invoke();
            });
            t.Start();
        }
Exemplo n.º 4
0
        public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
        {
            Delegate del = null;
            string key = obj.GetType().Name + "." + methodName;
            Type tp;
            lock (methodLookup)
            {
                if (methodLookup.Contains(key))
                    tp = (Type)methodLookup[key];
                else
                {
                    Type[] paramList = new Type[obj.GetType().GetMethod(methodName).GetParameters().Length];
                    int n = 0;
                    foreach (ParameterInfo pi in obj.GetType().GetMethod(methodName).GetParameters()) paramList[n++] = pi.ParameterType;
                    TypeBuilder typeB = builder.DefineType("Del_" + obj.GetType().Name + "_" + methodName, TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate), PackingSize.Unspecified);
                    ConstructorBuilder conB = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(object), typeof(IntPtr) });
                    conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                    MethodBuilder mb = typeB.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, obj.GetType().GetMethod(methodName).ReturnType, paramList);
                    mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                    tp = typeB.CreateType();
                    methodLookup.Add(key, tp);
                }
            }

            del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
            return obj.Invoke(del, paramValues);
        }
Exemplo n.º 5
0
 /// <summary>
 ///   Invokes the given action on the UI thread - if the current thread is the UI thread this will just invoke the action directly on
 ///   the current thread so it can be safely called without the calling method being aware of which thread it is on.
 /// </summary>
 public static void Invoke(System.Action action)
 {
     if (Dispatcher.CheckAccess())
         action.Invoke();
     else
         Dispatcher.BeginInvoke(action);
 }
Exemplo n.º 6
0
		public static void Invoke(System.Windows.Forms.Control con, InvokeDelegate callback) {
			if (con.InvokeRequired) {
				con.Invoke(callback);
			} else {
				callback();
			}
		}
Exemplo n.º 7
0
		public static void Invoke(System.Windows.Forms.Control Control, InvokeDelegate Delegate) {
			if (Control.InvokeRequired) {
				Control.Invoke(Delegate);
			} else {
				Delegate();
			}
		}
Exemplo n.º 8
0
        public override object GetInstance(System.Reflection.ConstructorInfo constructor, object[] parameters = null)
        {
            if (cache.ContainsKey(constructor.DeclaringType))
            {
                return cache[constructor.DeclaringType];
            }

            var dependencies = constructor.GetParameters();
            if (dependencies.Count() == 0)
            {
                var instance = Activator.CreateInstance(constructor.DeclaringType);
                cache.Add(constructor.DeclaringType, instance);

                return instance;
            }
            else
            {
                if (parameters == null || parameters.Count() != dependencies.Count())
                {
                    throw new Exception("Incorrect number of parameters to invoke instance.");
                }

                var instance = constructor.Invoke(parameters);
                cache.Add(constructor.DeclaringType, instance);

                return instance;
            }
        }
Exemplo n.º 9
0
 public void Authenticate(System.Action<bool> callback, bool silent)
 {
   LogUsage();
   if (callback != null)
     {
       callback.Invoke(false);
     }
 }
Exemplo n.º 10
0
 public static void UpdatePbar(System.Windows.Forms.ProgressBar name, int step)
 {
     if (name.InvokeRequired)
     {
         object[] params_list = new object[] { name, step };
         name.Invoke(new UpdateProgressBar(UpdatePbar), params_list);
     }
     else { name.Increment(step); }
 }
Exemplo n.º 11
0
 public static void SetText(System.Windows.Forms.TextBox ctrl, string text)
 {
     if (ctrl.InvokeRequired)
     {
         object[] params_list = new object[] { ctrl, text };
         ctrl.Invoke(new SetTextDelegate(SetText), params_list);
     }
     else { ctrl.AppendText(text); }
 }
Exemplo n.º 12
0
 internal void RunTestCase(System.Reflection.MethodInfo met)
 {
     var testInstance = Activator.CreateInstance(this.testCaseType);
     if (this.setupMethod != null)
     {
         this.setupMethod.Invoke(testInstance, null);
     }
     met.Invoke(testInstance, null);
 }
Exemplo n.º 13
0
        public void RunTest (Test test, System.Reflection.MethodInfo method)
        {
            var startTime = DateTime.Now;

            test.Setup ();
            var attributes = (TestAttribute[])method.GetCustomAttributes (typeof(TestAttribute), false);

            if (attributes[0].Async) {
                try {
                    method.Invoke (test, new object[] { (AsyncCallback)(result =>
                    {
                        var t = (Test)((object[])result.AsyncState)[0];
                        var m = (System.Reflection.MethodInfo)((object[])result.AsyncState)[1];
                        var s = (DateTime)((object[])result.AsyncState)[2];

                        t.TearDown ();

                        if (OnTestFinished != null)
                        {
                            OnTestFinished (t, m, DateTime.Now - s, null);
                        }
                    }), new object[] { test, method, startTime } });
                } catch (Exception ex)
                {
                    if (OnTestFinished != null)
                    {
                        OnTestFinished(test, method, DateTime.Now - startTime, ex);
                    }
                }
            } else {
                Exception ex = null;
                try {
                    method.Invoke (test, null);
                } catch (Exception e)
                {
                    ex = e;
                }
                test.TearDown ();

                if (OnTestFinished != null) {
                    OnTestFinished (test, method, DateTime.Now - startTime, ex);
                }
            }
        }
        public virtual object Invoke(object proxy, System.Reflection.MethodInfo method, params object[] arguments)
        {
            PreInvoke(proxy, method, arguments);

            object returnValue = method.Invoke( Target, arguments );

            PostInvoke(proxy, method, ref returnValue, arguments);

            return returnValue;
        }
Exemplo n.º 15
0
            public object Invoke(object target, System.Reflection.MethodInfo method, params object[] parameters)
            {
                Console.WriteLine("before call:"+method.Name);

                object result = method.Invoke(target , parameters);

                Console.WriteLine("after call:" + method.Name);

                return result;
            }
Exemplo n.º 16
0
        /// <summary>
        /// Thread safely updates given control
        /// </summary>
        /// <param name="pControl"></param>
        /// <param name="pAction"></param>
        public static void safelyUpdateControl(System.Windows.Forms.Control pControl, updateControlAction pAction)
        {
            if (pControl.InvokeRequired)
            {
                pControl.Invoke(pAction);
                return;
            }

            pAction();
        }
        public void SendConnectionRequest(string name, string remoteEndpointId, byte[] payload, System.Action<ConnectionResponse> responseCallback, IMessageListener listener)
        {
            Debug.LogError("SendConnectionRequest called from dummy implementation");

            if (responseCallback != null)
            {
                ConnectionResponse obj = ConnectionResponse.Rejected(0, string.Empty);
                responseCallback.Invoke(obj);
            }
        }
Exemplo n.º 18
0
        private void DisplayToLabel(string message, System.Windows.Forms.Label label)
        {
            if (label.InvokeRequired)
            {
                label.Invoke(new Action<string, System.Windows.Forms.Label>(DisplayToLabel), message, label);
                return;
            }

            label.Text = message;
        }
		public void Unload(System.Action callback = null) {

			if (this.component != null) {

				this.UnregisterSubComponent(this.component, () => {

					this.component.Recycle();
					this.component = null;

					if (callback != null) callback.Invoke();

				});

			} else {
				
				if (callback != null) callback.Invoke();

			}

		}
Exemplo n.º 20
0
 public static void SetControlPropertyThreadSafe(System.Windows.Forms.Control control, string propertyName, object propertyValue)
 {
     if (control.InvokeRequired)
     {
     control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
     }
     else
     {
     control.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, control, new object[] { propertyValue });
     }
 }
Exemplo n.º 21
0
 //経験値グラフの表示
 public static void DrawExperienceGraph(System.Windows.Forms.DataVisualization.Charting.Chart chart, GraphInfo info)
 {
     if (chart.InvokeRequired)
     {
         CallBacks.SetChartCallBack d = new CallBacks.SetChartCallBack(DrawExperienceGraph);
         chart.Invoke(d, new object[] { chart, info });
     }
     else
     {
         //初期化が必要な場合
         if (HistoricalData.GraphInfoExperience != info) ExperienceGraphInit(chart, info, true);
         //そうでない場合
         else
         {
             //古い値の消去
             if (HistoricalData.GraphInfoExperience.Term != GraphInfoTerm.All)
             {
                 DateTime mindate = HistoricalData.GraphInfoExperience.Term.GetMinDate();
                 //消去する必要がある場合
                 bool isdelete = DateTime.FromOADate(chart.Series[0].Points[0].XValue) < mindate;
                 if (isdelete)
                 {
                     //消去
                     for (int i = 0; i < Math.Min(5, chart.Series[0].Points.Count); i++)
                     {
                         DateTime date = DateTime.FromOADate(chart.Series[0].Points[i].XValue);
                         if (date >= mindate) break;//消す必要がなくなったら離脱
                         foreach (var x in chart.Series) x.Points.RemoveAt(i);
                     }
                 }
             }
             //最新の値の追加
             if (info.Mode == 1)
             {
                 ExpRecord latest = HistoricalData.LogExperience[HistoricalData.LogExperience.Count - 1];
                 chart.Series[0].Points.AddXY(latest.Date, latest.Value);
             }
             else if (info.Mode == 2)
             {
                 SenkaRecord latest = HistoricalData.LogSenka[HistoricalData.LogSenka.Count - 1];
                 int[] display_rank = SenkaRecord.DisplayRank;
                 //ボーダー
                 for (int i = 0; i < display_rank.Length; i++)
                 {
                     int senkaval = latest.TopSenka[display_rank[i] - 1];
                     if (senkaval >= 0) chart.Series[i].Points.AddXY(latest.StartTime, senkaval);
                 }
                 //自分の戦果
                 int mysenka = latest.StartSenka;
                 if (mysenka >= 0) chart.Series[display_rank.Length].Points.AddXY(latest.StartTime, mysenka);
             }
         }
     }
 }
Exemplo n.º 22
0
 private AbstractTree.Method GetMethodTree(System.Reflection.MethodInfo methodInfo, object instance)
 {
     Method = new AbstractTree.Method(methodInfo.Name);
     Log(ConsoleColor.Yellow, $"Начало парсинга метода {Method.Name}");
     methodInfo.Invoke(instance, null);            
     foreach(var command in Method.Commands)
     {
         Log(ConsoleColor.Cyan, $"   {command}");
     }
     Log(ConsoleColor.Yellow, $"Парсинг метода {Method.Name} завершен.");
     return Method;
 }
Exemplo n.º 23
0
		public void TestAction(System.Action<DetachedCriteria> action)
		{
			using (ISession session = OpenSession())
			{
				DetachedCriteria criteria = DetachedCriteria.For<DomainClass>("alias");
				
				action.Invoke(criteria);
				
				IList  l = criteria.GetExecutableCriteria(session).List();
				Assert.AreNotEqual(l, null);
			}
		}
Exemplo n.º 24
0
 void UpdateTexture(System.Func<int, int, float> generator)
 {
     for (var y = 0; y < size; y++)
     {
         for (var x = 0; x < size; x++)
         {
             var n = (generator.Invoke(x, y) + 1) / 2;
             texture.SetPixel(x, y, new Color(n, n, n));
         }
     }
     texture.Apply();
 }
Exemplo n.º 25
0
 static void SolveIteration(int iteration, GH_Component component, List<object[]> input, List<object[]> output, System.Reflection.MethodInfo method)
 {
     var da = new GhPyDataAccess(component, input[iteration]);
       method.Invoke(component, new object[] { da });
       object[] solve_results = da.Output;
       if (solve_results != null)
       {
     for (int j = 0; j < solve_results.Length; j++)
     {
       output[j][iteration] = solve_results[j];
     }
       }
 }
Exemplo n.º 26
0
 public static void SetText2(System.Windows.Forms.Control ctrl, string text)
 {
     if (ctrl.InvokeRequired)
     {
         object[] params_list = new object[] { ctrl, text };
         ctrl.Invoke(new SetTextDelegate(SetText2), params_list);
     }
     else
     {
         ctrl.Text = text;
     }
     Application.DoEvents();
 }
 private StringBuilder Invoke(MyCommandArgs x, System.Reflection.MethodInfo method)
 {
     m_cache.Clear();
     var args = x as MyCommandMethodArgs;
     if (args.Args != null)
     {
         m_cache.Append("Success. ");
         var retVal = method.Invoke(null, args.Args);
         if (retVal != null)
             m_cache.Append(retVal.ToString());
     }
     else
         m_cache.Append(string.Format("Invoking {0} failed", method.Name));
     return m_cache;
 }
Exemplo n.º 28
0
 public static System.Windows.Forms.DialogResult SafeShowMessageBox(System.Windows.Forms.UserControl form, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon)
 {
     if (form.InvokeRequired)
     {
         //important to show the notification on the main thread of BIDS
         return (System.Windows.Forms.DialogResult)form.Invoke(
             new DialogResultDelegate2(SafeShowMessageBox), new object[] { form, text, caption, buttons, icon }
         );
     }
     else
     {
         System.Windows.Forms.IWin32Window owner = (System.Windows.Forms.IWin32Window)form;
         return System.Windows.Forms.MessageBox.Show(owner, text, caption, buttons, icon);
     }
 }
Exemplo n.º 29
0
 public Object Invoke(Object proxy, System.Reflection.MethodInfo method, Object[] parameters)
 {
     Object retVal = null;
     string userRole = "role";
     if (SecurityManager.IsMethodInRole(userRole, method.Name))
     {
         retVal = method.Invoke(obj, parameters);
         Console.WriteLine("fx");
     }
     else
     {
         throw new Exception("Invalid permission to invoke " + method.Name);
     }
     return retVal;
 }
Exemplo n.º 30
0
    void UpdateTexture(System.Func<float, float, float, float> generator)
    {
        var scale = 1.0f / size;
        var time = Time.time;

        for (var y = 0; y < size; y++)
        {
            for (var x = 0; x < size; x++)
            {
                var n = generator.Invoke(x * scale, y * scale, time);
                texture.SetPixel(x, y, Color.white * (n / 1.4f + 0.5f));
            }
        }

        texture.Apply();
    }
        private void ProcessSystemMessage(string msg, string[] values)
        {
            var systemMessage = new SystemMessage(values[0], msg);

            System?.Invoke(systemMessage);
        }
        private void ProcessSystemMessage(string msg)
        {
            var systemMessage = SystemMessage.Parse(msg);

            System?.Invoke(systemMessage);
        }