/// <inheritdoc/>
        public IDisposable BindCommandToObject(ICommand command, object target, IObservable <object> commandParameter)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            commandParameter = commandParameter ?? Observable.Return(target);

            object latestParam = null;
            var    ctlDelegate = new ControlDelegate(
                x =>
            {
                if (command.CanExecute(latestParam))
                {
                    command.Execute(latestParam);
                }
            })
            {
                IsEnabled = command.CanExecute(latestParam)
            };

            var sel = new Selector("theAction:");

            // TODO how does this work? Is there an Action property?
            Reflection.GetValueSetterOrThrow(target.GetType().GetRuntimeProperty("Action"))(target, sel, null);

            var targetSetter = Reflection.GetValueSetterOrThrow(target.GetType().GetRuntimeProperty("Target"));

            targetSetter(target, ctlDelegate, null);
            var actionDisp = Disposable.Create(() => targetSetter(target, null, null));

            var enabledSetter = Reflection.GetValueSetterForProperty(target.GetType().GetRuntimeProperty("Enabled"));

            if (enabledSetter == null)
            {
                return(actionDisp);
            }

            // initial enabled state
            enabledSetter(target, command.CanExecute(latestParam), null);

            var compDisp = new CompositeDisposable(
                actionDisp,
                commandParameter.Subscribe(x => latestParam = x),
                Observable.FromEventPattern <EventHandler, EventArgs>(x => command.CanExecuteChanged += x, x => command.CanExecuteChanged -= x)
                .Select(_ => command.CanExecute(latestParam))
                .Subscribe(x =>
            {
                enabledSetter(target, x, null);
                ctlDelegate.IsEnabled = x;
            }));

            return(compDisp);
        }
Example #2
0
        static void Main(string[] args)
        {
            Joystic         joystic = new Joystic();
            ControlDelegate up      = joystic.InputUpMoveForward;

            up += joystic.InputUpEyeLitght;
            up += joystic.InputWorkArm;

            joystic.Controller("up");
            up();

            Console.WriteLine();
            Console.WriteLine();

            ControlDelegate down = joystic.InputDownMoveBack;

            down += joystic.InputDownRotHead;
            down += joystic.InputWorkArm;

            joystic.Controller("down");
            down();

            Console.WriteLine();
            Console.WriteLine();
        }
Example #3
0
        /// <summary>
        /// 视频预览
        /// </summary>
        /// <param name="strDeviceID"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public int RealPlay(object strDeviceID, int index)
        {
            if (videoboxs[index].InvokeRequired)
            {
                ControlDelegate d = RealPlay;
                videoboxs[index].Invoke(d, strDeviceID);
            }
            else
            {
                Guid DeviceID = (Guid)strDeviceID;
                Entities.CameraList device = Class1.cameraList.Find(
                    delegate(Entities.CameraList camera)
                {
                    return(camera.DeviceID.Equals(DeviceID));
                }
                    );
                if (device == null)
                {
                    return(-1);
                }
                Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find(
                    delegate(Entities.StreamMediaList sm)
                {
                    return(sm.DeviceID.Equals(device.StreamMedia_DeviceID));
                });
                if (streamMedia == null)
                {
                    return(-1);
                }
                Entities.StreamServerList server = Class1.streamServerList.Find(
                    delegate(Entities.StreamServerList ss)
                {
                    return(ss.DeviceID.Equals(streamMedia.StreamServerID));
                }
                    );
                if (server == null)
                {
                    return(-1);
                }

                //视频预览
                VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER config = new VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER();
                config.sSID           = device.Stream_MainID.ToString();
                config.sDeviceAddress = server.StreamServerIP;

                hwnd[index] = VMSdk.VM_CLIENT_RealPlay(videoboxs[index].pictureBox1.Handle.ToInt32(), ref config, (int)VMSdk.VM_CLIENT_DEV_TYPE.VM_CLIENT_DEV_RTSP_VMSTREAMINGSER);
                if (hwnd[index] == -1)
                {
                    MessageBox.Show("视频预览失败!");
                }
                else
                {
                    SID[index] = config.sSID;
                }
            }
            return(hwnd[index]);
        }
Example #4
0
 /// <summary>
 /// Instantiates a control with a parent and size
 /// </summary>
 /// <param name="parent">Control this control is a child of</param>
 /// <param name="size">Width+Height of this control</param>
 public Control(Control parent, Vector2 size)
 {
     Parent = parent;
     if (parent != null)
     {
         parent.Children.Add(this);
     }
     Size           = size;
     MouseReleased += ReturnItem;
 }
        /// <summary>
        /// Creates a commands binding from event and a property
        /// </summary>
        /// <returns>The binding from event.</returns>
        /// <param name="command">Command.</param>
        /// <param name="target">Target.</param>
        /// <param name="commandParameter">Command parameter.</param>
        /// <param name="enablePropertyName">Enable property name.</param>
        protected static IDisposable ForTargetAction(ICommand command, object target, IObservable <object> commandParameter, string enablePropertyName)
        {
            commandParameter = commandParameter ?? Observable.Return(target);

            object latestParam = null;
            var    ctlDelegate = new ControlDelegate(x => {
                if (command.CanExecute(latestParam))
                {
                    command.Execute(latestParam);
                }
            });

            var sel = new Selector("theAction:");

#if UIKIT
            IDisposable actionDisp = null;

            var ctl = target as UIControl;
            if (ctl != null)
            {
                ctl.AddTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside);
                actionDisp = Disposable.Create(() => ctl.RemoveTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside));
            }
#else
            Reflection.GetValueSetterOrThrow(target.GetType(), "Action")(target, sel);

            var targetSetter = Reflection.GetValueSetterOrThrow(target.GetType(), "Target");
            targetSetter(target, ctlDelegate);
            var actionDisp = Disposable.Create(() => targetSetter(target, null));
#endif

            var enabledSetter = Reflection.GetValueSetterForProperty(target.GetType(), enablePropertyName);
            if (enabledSetter == null)
            {
                return(actionDisp);
            }

            // Initial enabled state
            enabledSetter(target, command.CanExecute(latestParam));

            var compDisp = new CompositeDisposable(
                actionDisp,
                commandParameter.Subscribe(x => latestParam = x),
                Observable.FromEventPattern <EventHandler, EventArgs>(x => command.CanExecuteChanged += x, x => command.CanExecuteChanged -= x)
                .Select(_ => command.CanExecute(latestParam))
                .Subscribe(x => enabledSetter(target, x)));

            return(compDisp);
        }
        protected CustomBioDescription(string name)
        {
            var index = BIO_get_new_index();

            _methodPointer = BIO_meth_new(index, name);
            _write         = new WriteDelegate(Write);
            _read          = new ReadDelegate(Read);
            _create        = new CreateDelegate(Create);
            _destroy       = new DestroyDelegate(Destroy);
            _control       = new ControlDelegate(Control);

            BIO_meth_set_write(_methodPointer, _write);
            BIO_meth_set_read(_methodPointer, _read);
            BIO_meth_set_ctrl(_methodPointer, _control);
            BIO_meth_set_create(_methodPointer, _create);
            BIO_meth_set_destroy(_methodPointer, _destroy);
        }
        public void VisitControls(ControlCollection list, DelegateTest isTarget, ControlDelegate visit)
        {
            foreach (Control member in list)
            {
                if (member.HasControls())
                {
                    VisitControls(member.Controls,
                                  isTarget,
                                  visit
                                  );
                }

                if (isTarget(member))
                {
                    visit(member);
                }
            }
        }
        public IDisposable BindCommandToObject(ICommand command, object target, IObservable <object> commandParameter)
        {
            commandParameter = commandParameter ?? Observable.Return(target);

            object latestParam = null;
            var    ctlDelegate = new ControlDelegate(x => {
                if (command.CanExecute(latestParam))
                {
                    command.Execute(latestParam);
                }
            });

            var sel = new Selector("theAction:");

            Reflection.GetValueSetterOrThrow(target.GetType(), "Action")(target, sel);

            var targetSetter = Reflection.GetValueSetterOrThrow(target.GetType(), "Target");

            targetSetter(target, ctlDelegate);
            var actionDisp = Disposable.Create(() => targetSetter(target, null));

            var enabledSetter = Reflection.GetValueSetterForProperty(target.GetType(), "Enabled");

            if (enabledSetter == null)
            {
                return(actionDisp);
            }

            // initial enabled state
            enabledSetter(target, command.CanExecute(latestParam));

            var compDisp = new CompositeDisposable(
                actionDisp,
                commandParameter.Subscribe(x => latestParam = x),
                Observable.FromEventPattern <EventHandler, EventArgs>(x => command.CanExecuteChanged += x, x => command.CanExecuteChanged -= x)
                .Select(_ => command.CanExecute(latestParam))
                .Subscribe(x => {
                enabledSetter(target, x);
            }));

            return(compDisp);
        }
Example #9
0
        public frmMDI()
        {
            try
            {
                InitializeComponent();
                wtObj = new TryGameWorkThread(this, 0, 3, "", "");
                wtObj.StartShowResult();
                cdObj = SetRecord;
            }
            catch (Exception ex)
            {
                if (wtObj != null)
                {
                    wtObj.EndShowResult();
                }

                MessageBox.Show("系统发生异常,请联系管理员!", "错误");
                LogHelper.WriteLog("窗体异常", ex);
            }
        }
Example #10
0
        public IDisposable BindCommandToObject(ICommand command, object target, IObservable <object> commandParameter)
        {
            commandParameter = commandParameter ?? Observable.Return(target);

            object latestParam = null;
            var    ctlDelegate = new ControlDelegate(x => {
                if (command.CanExecute(latestParam))
                {
                    command.Execute(latestParam);
                }
            });

            var sel = new Selector("theAction:");

#if UIKIT
            var ctl = (UIControl)target;
            ctl.AddTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside);
            var actionDisp = Disposable.Create(() => ctl.RemoveTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside));
#else
            Reflection.GetValueSetterOrThrow(target.GetType(), "Action")(target, sel);
            var targetSetter = Reflection.GetValueSetterOrThrow(target.GetType(), "Target");
            targetSetter(target, ctlDelegate);
            var actionDisp = Disposable.Create(() => targetSetter(target, null));
#endif

            var enabledSetter = Reflection.GetValueSetterForProperty(target.GetType(), "Enabled");
            var disp          = new CompositeDisposable(
                actionDisp,
                commandParameter.Subscribe(x => latestParam = x),
                Observable.FromEventPattern <EventHandler, EventArgs>(x => command.CanExecuteChanged += x, x => command.CanExecuteChanged -= x)
                .Select(_ => command.CanExecute(latestParam))
                .Subscribe(x => {
                if (enabledSetter == null)
                {
                    return;
                }
                enabledSetter(target, x);
            }));

            return(disp);
        }
Example #11
0
 ///////////////////////////////////////////////////////////////////////////////
 /**
  * タブを開く
  */
 private static void OpenControl(
     ControlDelegate controlDelegate,
     ControlDelegate returnDelegate = null)
 {
     Type thisType = typeof(XnetMenuItems);
     EditorWindow.GetWindow(thisType, false, tabTitle, true);
     currentControlDelegate = controlDelegate;
     //currentReturnDelegate = returnDelegate;
 }
Example #12
0
        /// <summary>
        /// 视频预览
        /// </summary>
        /// <param name="strDeviceID"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static int Open(string strDeviceID, int index, ref string IP, ref int nChannel, ref int m_lUserID, ref int m_lRealHandle)
        {
            if (Form1.videoboxs[index].InvokeRequired)
            {
                ControlDelegate d = Open;
                Form1.videoboxs[index].Invoke(d, strDeviceID, index, IP, nChannel, m_lUserID, m_lRealHandle);
            }
            else
            {
                Guid DeviceID = new Guid(strDeviceID);
                Entities.CameraList device = Class1.cameraList.Find(
                    delegate(Entities.CameraList camera)
                {
                    return(camera.DeviceID.Equals(DeviceID));
                }
                    );
                if (device == null)
                {
                    return(-1);
                }
                Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find(
                    delegate(Entities.StreamMediaList sm)
                {
                    return(sm.DeviceID.Equals(device.StreamMedia_DeviceID));
                });
                if (streamMedia == null)
                {
                    return(-1);
                }
                IP       = streamMedia.VideoIP;
                nChannel = device.VideoChannel;
                string mediaMedia = System.Configuration.ConfigurationManager.AppSettings["MediaStream"];
                if (mediaMedia == "1")
                {
                    #region 流媒体预览
                    Entities.StreamServerList server = Class1.streamServerList.Find(
                        delegate(Entities.StreamServerList ss)
                    {
                        return(ss.DeviceID.Equals(streamMedia.StreamServerID));
                    }
                        );
                    if (server == null)
                    {
                        return(-1);
                    }
                    //视频预览
                    VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER config = new VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER();
                    config.sSID           = device.Stream_MainID.ToString();
                    config.sDeviceAddress = server.StreamServerIP;
                    if (SearchRealPlayVideo(config.sSID, index))
                    {
                        //流媒体预览视频
                        //Form1.hwnd[index] = VMSdk.VM_CLIENT_RealPlay(Form1.videoboxs[index].pictureBox1.Handle.ToInt32(), ref config, (int)VMSdk.VM_CLIENT_DEV_TYPE.VM_CLIENT_DEV_RTSP_VMSTREAMINGSER);

                        Form1.hwnd[index] = CMSSdk.VM_CMS_RealPlay(0, Form1.videoboxs[index].pictureBox1.Handle, config.sSID);
                        //存储视频信息
                        Form1.SID[index] = config.sSID;
                    }
                    #endregion
                }
                else
                {
                    if (SearchRealPlayVideo2(strDeviceID, index))
                    {
                        CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                        lpPreviewInfo.hPlayWnd        = Form1.videoboxs[index].pictureBox1.Handle;              //预览窗口
                        lpPreviewInfo.lChannel        = device.VideoChannel;                                    //预te览的设备通道
                        lpPreviewInfo.dwStreamType    = 0;                                                      //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                        lpPreviewInfo.dwLinkMode      = 0;                                                      //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                        lpPreviewInfo.bBlocked        = true;                                                   //0- 非阻塞取流,1- 阻塞取流
                        lpPreviewInfo.dwDisplayBufNum = 15;                                                     //播放库播放缓冲区最大缓冲帧数
                        CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数
                        IntPtr pUser = new IntPtr();                                                            //用户数据
                        if (streamMedia.VideoIP == null)
                        {
                            return(-1);
                        }
                        if (!RecDll.ManualRec.userIDList.ContainsKey(streamMedia.VideoIP))
                        {
                            return(-1);
                        }
                        int UserID = RecDll.ManualRec.userIDList[streamMedia.VideoIP];
                        m_lUserID         = UserID;
                        Form1.hwnd[index] = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);
                        m_lRealHandle     = Form1.hwnd[index];
                        if (Form1.hwnd[index] == -1)
                        {
                            uint temp = CHCNetSDK.NET_DVR_GetLastError();
                            MessageBox.Show("视频预览失败!");
                        }
                        else
                        {
                            //Form1.SID[index] = config.sSID;
                            Form1.DeviceIDs[index] = strDeviceID;
                            Form1.videoboxs[index].SetVideoInfo(IP, nChannel, m_lUserID, m_lRealHandle, strDeviceID, device.VideoName);
                        }
                    }
                }
            }
            return(Form1.hwnd[index]);
        }
Example #13
0
 private static extern int Internal_BIO_meth_set_ctrl(BIO_METHOD biom, ControlDelegate controlMethod);
Example #14
0
        internal static void BIO_meth_set_ctrl(BIO_METHOD biom, ControlDelegate controlMethod)
        {
            var result = Internal_BIO_meth_set_ctrl(biom, controlMethod);

            ThrowOnErrorReturnCode(result);
        }
Example #15
0
 public void DettachControl()
 {
     control = null;
 }
Example #16
0
 // Use this for initialization
 void Start()
 {
     if(m_controlType == ControlType.mouse) {
         controlDelegate = mouseControl;
     } else {
         controlDelegate = touchControl;
     }
 }
Example #17
0
 public void AttachControl(ControlDelegate newControl)
 {
     control = newControl;
 }
Example #18
0
 public FMain()
 {
     InitializeComponent();
     f1 = new ControlDelegate(ControlWriteText);
     f2 = new TBDelegate(TBGetDouble);
 }
Example #19
0
        /// <summary>
        /// Does magic cross thread stuff, I mostly use it for GUI updates from background threads.
        /// </summary>
        /// <param name="_Control">Control that might be on a different Thread</param>
        /// <param name="_Value">Method or Property to set or execute</param>
        /// <param name="_OptionalProperty">Takes NULL or sub-component of _Control that _Value is excecuted on</param>
        /// <param name="_OptionalArg">Takes NULL or object used in setting or executing _Value</param>
        public static void ControlAction(Control _Control, string _Value, object _OptionalMember, object[] _OptionalParameters)
        {
            if (_Control.InvokeRequired)
            {
                ControlDelegate d = new ControlDelegate(ControlAction);
                _Control.Invoke(d, new object[] { _Control, _Value, _OptionalMember, _OptionalParameters });
            }
            else
            {
                try {
                    if (_OptionalMember != null)  //Does stuff with _OptionalProperty instead of _Control
                    {
                        if (_Value.Contains('=')) //Handles setting Properties
                        //Get Property Name
                        {
                            PropertyInfo Property = _OptionalMember.GetType().GetProperty(_Value.Split(new char[] { '=' })[0]);

                            //Organize Value
                            object Value;
                            if (_OptionalParameters != null && _OptionalParameters.Length == 1)
                            {
                                Value = _OptionalParameters[0];
                            }
                            else
                            {
                                Value = _Value.Split(new char[] { '=' })[1];
                            }

                            //Set Parameter
                            Property.SetValue(_OptionalMember, System.Convert.ChangeType(Value, Property.PropertyType), null);
                        }
                        else  //Handles calling methods
                              //Get Method Name
                        {
                            string Method = _Value.Split("( )".ToCharArray())[0];

                            //Organize Parameters
                            object[] parameters;
                            if (_OptionalParameters == null)
                            {
                                parameters = _Value.Split("( )".ToCharArray())[1].Split(", ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                            }
                            else
                            {
                                parameters = _OptionalParameters;
                            }

                            //Used to specify which method if who have the same name
                            List <Type> Types = new List <Type>();
                            foreach (object O in parameters)
                            {
                                Types.Add(O.GetType());
                            }

                            //Execute Method
                            _OptionalMember.GetType().GetMethod(Method, Types.ToArray()).Invoke(_OptionalMember, parameters);
                        }
                    }
                    else if (_Value.Contains('='))  //Handles setting Properties
                    //Get Property
                    {
                        PropertyInfo Property = _Control.GetType().GetProperty(_Value.Split(new char[] { '=' })[0]);

                        //Organize Value
                        object Value;
                        if (_OptionalParameters != null && _OptionalParameters.Length == 1)
                        {
                            Value = _OptionalParameters[0];
                        }
                        else
                        {
                            Value = _Value.Split(new char[] { '=' })[1];
                        }

                        //Set Property
                        Property.SetValue(_Control, System.Convert.ChangeType(Value, Property.PropertyType), null);
                    }
                    else  //Handles calling methods
                          //Get method name
                    {
                        string Method = _Value.Split("( )".ToCharArray())[0];

                        //Organize parameters
                        object[] parameters;
                        if (_OptionalParameters == null)
                        {
                            parameters = _Value.Split("( )".ToCharArray())[1].Split(", ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                        }
                        else
                        {
                            parameters = _OptionalParameters;
                        }

                        //Used to specify which method if two have the same name.
                        List <Type> Types = new List <Type>();
                        foreach (object O in parameters)
                        {
                            Types.Add(O.GetType());
                        }

                        //execute method
                        _Control.GetType().GetMethod(Method, Types.ToArray()).Invoke(_Control, parameters);
                    }
                }
                catch (System.Exception x) {
                    if (_OptionalMember == null)
                    {
                        MessageBox.Show(string.Format("Error:{0} ({1}.{2} {3})", x.Message, _Control, _Value, _OptionalParameters[0]), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Error:{0} ({1}.{2} {3})", x.Message, _OptionalMember, _Value, _OptionalParameters[0]), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #20
0
 public MenuBox( ControlDelegate onControlUpdate, RenderDelegate onDraw )
 {
     OnControlUpdate = onControlUpdate;
     OnDraw = onDraw;
 }
Example #21
0
        public MenuBox( Texture2D _img, int final_x, int final_y, int start_x, int start_y, ControlDelegate onControlUpdate, RenderDelegate onDraw )
        {
            image = _img;
            OnControlUpdate = onControlUpdate;
            OnDraw = onDraw;
            x = final_x;
            y = final_y;
            bounds = new Rectangle( x, y, image.Width, image.Height );
            color_bounds = new Rectangle( x, y, image.Width, image.Height );
            color_bounds.Inflate( -2, -2 );

            McgLayer l = _.sg.renderstack.GetLayer( "menu" );
            rendernode = l.AddNode(
                new McgNode( onDraw, l, start_x, start_y, final_x, final_y, MainMenu.delay )
            );
        }