示例#1
0
        internal static void DoEvents()
        {
            var frame = new System.Windows.Threading.DispatcherFrame();

            System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(ExitFrames), frame);
            System.Windows.Threading.Dispatcher.PushFrame(frame);
        }
示例#2
0
        /// <summary>
        /// Shows the window.
        /// </summary>
        /// <param name="initializer">Action that will initialize <see cref="InteractiveWindow"/> before showing it.</param>
        public static void ShowWindow(Action <InteractiveWindow> initializer = null)
        {
            System.Threading.AutoResetEvent windowShown = new System.Threading.AutoResetEvent(false);

            ExecuteInSTA(() =>
            {
                InteractiveWindow window = null;

                try
                {
                    window = new InteractiveWindow();
                    initializer?.Invoke(window);
                    window.Show();
                    windowShown.Set();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed       += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    windowShown.Set();
                }

                window?.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            }, waitForExecution: false);
            windowShown.WaitOne();
        }
示例#3
0
        void SponsorReasonConfirmation(object sender, ReasonConfirmationArgs e)
        {
            DisableRemarkAlertReasonPopup.Show();

            //nugget: idea from here: http://www.deanchalk.me.uk/post/WPF-Modal-Controls-Via-Dispatcher (Army firewall blocks this site)
            //nugget: this is really cool because it maintains the synchronous nature of this call stack, returning the result to the model layer after the psuedo modal popup, even though the popup is actually acting on it's own asynch event handler!!
            _disableRemarkAlertReasonPopupDispatcherFrame = new System.Windows.Threading.DispatcherFrame(); //nugget:
            System.Windows.Threading.Dispatcher.PushFrame(_disableRemarkAlertReasonPopupDispatcherFrame);   //nugget: blocks gui message pump & createst nested pump, making this a blocking call

            e.Accept = DisableRemarkAlertReasonPopup.IsOK;
            e.Reason = DisableRemarkAlertReasonPopup.ReasonText;
        }
示例#4
0
        public void PushAgentDispatcherFrame(DispatcherFrame frame, jvmtiEnvHandle environment)
        {
            Contract.Requires <ArgumentNullException>(frame != null, "frame");
            Contract.Requires <ArgumentNullException>(environment != null, "environment");

            lock (_dispatchers)
            {
                _dispatchers.Add(Tuple.Create(Dispatcher.CurrentDispatcher, frame, environment, default(IAsyncResult)));
            }

            Dispatcher.PushFrame(frame);
        }
示例#5
0
    void SponsorReasonConfirmation(object sender, ReasonConfirmationArgs e)
    {
      DisableRemarkAlertReasonPopup.Show();

      //nugget: idea from here: http://www.deanchalk.me.uk/post/WPF-Modal-Controls-Via-Dispatcher (Army firewall blocks this site)
      //nugget: this is really cool because it maintains the synchronous nature of this call stack, returning the result to the model layer after the psuedo modal popup, even though the popup is actually acting on it's own asynch event handler!!
      _disableRemarkAlertReasonPopupDispatcherFrame = new System.Windows.Threading.DispatcherFrame(); //nugget:
      System.Windows.Threading.Dispatcher.PushFrame(_disableRemarkAlertReasonPopupDispatcherFrame); //nugget: blocks gui message pump & createst nested pump, making this a blocking call 

      e.Accept = DisableRemarkAlertReasonPopup.IsOK;
      e.Reason = DisableRemarkAlertReasonPopup.ReasonText;
    }
        public override void HandleVMDeath(JvmEnvironment environment)
        {
            if (!_subscribedEvents.Contains(JvmEventType.VMDeath))
            {
                return;
            }

            try
            {
                DispatcherFrame frame  = new DispatcherFrame(true);
                IAsyncResult    result = _subscriber.BeginHandleVMDeath(environment.VirtualMachine, environment.VirtualMachine.HandleAsyncOperationComplete, null);
                environment.VirtualMachine.PushDispatcherFrame(frame, environment, result);
                _subscriber.EndHandleVMDeath(result);
            }
            catch (CommunicationException)
            {
            }
        }
        public override void HandleClassPrepare(JvmEnvironment environment, JvmThreadReference thread, JvmClassReference @class)
        {
            if (!_subscribedEvents.Contains(JvmEventType.ThreadEnd))
            {
                return;
            }

            try
            {
                DispatcherFrame frame  = new DispatcherFrame(true);
                IAsyncResult    result = _subscriber.BeginHandleClassPrepare(environment.VirtualMachine, thread, @class, environment.VirtualMachine.HandleAsyncOperationComplete, null);
                environment.VirtualMachine.PushDispatcherFrame(frame, environment, result);
                _subscriber.EndHandleClassPrepare(result);
            }
            catch (CommunicationException)
            {
            }
        }
示例#8
0
        public void HandleAsyncOperationComplete(IAsyncResult result)
        {
            Dispatcher      dispatcher = null;
            DispatcherFrame frame      = null;

            lock (_dispatchers)
            {
                // find and remove the appropriate dispatcher
                int index = _dispatchers.FindIndex(i => i.Item4 == result);
                if (index < 0)
                {
                    throw new ArgumentException();
                }

                dispatcher = _dispatchers[index].Item1;
                frame      = _dispatchers[index].Item2;
                _dispatchers.RemoveAt(index);
            }

            // queue a low priority operation to end processing
            dispatcher.BeginInvoke((Action)(() => frame.Continue = false), DispatcherPriority.Background);
        }
示例#9
0
        /// <summary>
        /// Shows the window.
        /// </summary>
        public static void ShowWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.Show();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed       += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
            }, waitForExecution: false);
        }
        /// <summary>
        /// Shows the window.
        /// </summary>
        public static void ShowWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.Show();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            }, waitForExecution: false);
        }
示例#11
0
        public static unsafe int OnLoad(IntPtr vmPtr, IntPtr optionsPtr, IntPtr reserved)
        {
            _loaded = true;

            JavaVM vm = JavaVM.GetOrCreateInstance(new JavaVMHandle(vmPtr));

            string optionsString = null;
            if (optionsPtr != IntPtr.Zero)
                optionsString = ModifiedUTF8Encoding.GetString((byte*)optionsPtr);

            string[] options = new string[0];
            if (optionsString != null)
            {
                options = optionsString.Split(',', ';');
            }

#if false
            // quick test
            GetEnvironmentVersion(vm);

            Action<JavaVM> action = GetEnvironmentVersion;
            IAsyncResult result = action.BeginInvoke(vm, null, null);
            result.AsyncWaitHandle.WaitOne();
#endif

            AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;

            if (options.Contains("ShowAgentExceptions", StringComparer.OrdinalIgnoreCase))
            {
                AppDomain.CurrentDomain.FirstChanceException += HandleFirstChanceException;
                AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
                //AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
            }

            if (options.Contains("DisableStatementStepping", StringComparer.OrdinalIgnoreCase))
            {
                JavaVM.DisableStatementStepping = true;
            }

            List<WaitHandle> waitHandles = new List<WaitHandle>();
            Binding binding;

            /*
             * start the wcf services and wait for the client to connect
             */

#if false
            /* IJvmEventsService
             */
            _jvmEventsPublisherHost = new ServiceHost(typeof(JvmEventsPublisher));
            Binding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmEventsPublisherHost.AddServiceEndpoint(typeof(IJvmEventsService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmEventsService/");
            IAsyncResult jvmEventsPublisherStartResult = _jvmEventsPublisherHost.BeginOpen(null, null);
            waitHandles.Add(jvmEventsPublisherStartResult.AsyncWaitHandle);

            /* IJvmToolsInterfaceService
             */
            _jvmToolsInterfaceHost = new ServiceHost(typeof(JvmToolsInterfaceService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmToolsInterfaceHost.AddServiceEndpoint(typeof(IJvmToolsInterfaceService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmToolsInterfaceService/");
            IAsyncResult toolsInterfaceStartResult = _jvmToolsInterfaceHost.BeginOpen(null, null);
            waitHandles.Add(toolsInterfaceStartResult.AsyncWaitHandle);

            /* IJvmDebugSessionService
             */
            _jvmDebugSessionHost = new ServiceHost(typeof(JvmDebugSessionService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _jvmDebugSessionHost.AddServiceEndpoint(typeof(IJvmDebugSessionService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmDebugSessionService/");
            IAsyncResult debugSessionStartResult = _jvmDebugSessionHost.BeginOpen(null, null);
            waitHandles.Add(debugSessionStartResult.AsyncWaitHandle);
#endif

            /* IDebugProtocolService
             */
            var debugProtocolService = new DebugProtocolService(vm);
            _debugProtocolHost = new ServiceHost(debugProtocolService);
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                MaxReceivedMessageSize = 10 * 1024 * 1024,
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout = TimeSpan.MaxValue
            };

            _debugProtocolHost.AddServiceEndpoint(typeof(IDebugProtocolService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/DebugProtocolService/");
            IAsyncResult debugProtocolStartResult = _debugProtocolHost.BeginOpen(null, null);
            waitHandles.Add(debugProtocolStartResult.AsyncWaitHandle);

            /* Wait for the services to finish opening
             */
            WaitHandle.WaitAll(waitHandles.ToArray());

            EventWaitHandle eventWaitHandle = null;
            try
            {
                eventWaitHandle = EventWaitHandle.OpenExisting(string.Format("JavaDebuggerInitHandle{0}", Process.GetCurrentProcess().Id));
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                // must have been launched without the debugger
            }

            if (eventWaitHandle != null)
            {
                eventWaitHandle.Set();
                Action waitAction = _debuggerAttachComplete.Wait;
                IAsyncResult waitResult = waitAction.BeginInvoke(vm.HandleAsyncOperationComplete, null);
                DispatcherFrame frame = new DispatcherFrame(true);
                JvmtiEnvironment environment = debugProtocolService.Environment;
                vm.PushDispatcherFrame(frame, environment, waitResult);
            }

            return 0;
        }
示例#12
0
        public static unsafe int OnLoad(IntPtr vmPtr, IntPtr optionsPtr, IntPtr reserved)
        {
            _loaded = true;

            JavaVM vm = JavaVM.GetOrCreateInstance(new JavaVMHandle(vmPtr));

            string optionsString = null;

            if (optionsPtr != IntPtr.Zero)
            {
                optionsString = ModifiedUTF8Encoding.GetString((byte *)optionsPtr);
            }

            string[] options = new string[0];
            if (optionsString != null)
            {
                options = optionsString.Split(',', ';');
            }

#if false
            // quick test
            GetEnvironmentVersion(vm);

            Action <JavaVM> action = GetEnvironmentVersion;
            IAsyncResult    result = action.BeginInvoke(vm, null, null);
            result.AsyncWaitHandle.WaitOne();
#endif

            AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;

            if (options.Contains("ShowAgentExceptions", StringComparer.OrdinalIgnoreCase))
            {
                AppDomain.CurrentDomain.FirstChanceException += HandleFirstChanceException;
                AppDomain.CurrentDomain.UnhandledException   += HandleUnhandledException;
                //AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
            }

            if (options.Contains("DisableStatementStepping", StringComparer.OrdinalIgnoreCase))
            {
                JavaVM.DisableStatementStepping = true;
            }

            List <WaitHandle> waitHandles = new List <WaitHandle>();
            Binding           binding;

            /*
             * start the wcf services and wait for the client to connect
             */

#if false
            /* IJvmEventsService
             */
            _jvmEventsPublisherHost = new ServiceHost(typeof(JvmEventsPublisher));
            Binding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout    = TimeSpan.MaxValue
            };

            _jvmEventsPublisherHost.AddServiceEndpoint(typeof(IJvmEventsService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmEventsService/");
            IAsyncResult jvmEventsPublisherStartResult = _jvmEventsPublisherHost.BeginOpen(null, null);
            waitHandles.Add(jvmEventsPublisherStartResult.AsyncWaitHandle);

            /* IJvmToolsInterfaceService
             */
            _jvmToolsInterfaceHost = new ServiceHost(typeof(JvmToolsInterfaceService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout    = TimeSpan.MaxValue
            };

            _jvmToolsInterfaceHost.AddServiceEndpoint(typeof(IJvmToolsInterfaceService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmToolsInterfaceService/");
            IAsyncResult toolsInterfaceStartResult = _jvmToolsInterfaceHost.BeginOpen(null, null);
            waitHandles.Add(toolsInterfaceStartResult.AsyncWaitHandle);

            /* IJvmDebugSessionService
             */
            _jvmDebugSessionHost = new ServiceHost(typeof(JvmDebugSessionService));
            binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                ReceiveTimeout = TimeSpan.MaxValue,
                SendTimeout    = TimeSpan.MaxValue
            };

            _jvmDebugSessionHost.AddServiceEndpoint(typeof(IJvmDebugSessionService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/JvmDebugSessionService/");
            IAsyncResult debugSessionStartResult = _jvmDebugSessionHost.BeginOpen(null, null);
            waitHandles.Add(debugSessionStartResult.AsyncWaitHandle);
#endif

            /* IDebugProtocolService
             */
            var debugProtocolService = new DebugProtocolService(vm);
            _debugProtocolHost = new ServiceHost(debugProtocolService);
            binding            = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                MaxReceivedMessageSize = 10 * 1024 * 1024,
                ReceiveTimeout         = TimeSpan.MaxValue,
                SendTimeout            = TimeSpan.MaxValue
            };

            _debugProtocolHost.AddServiceEndpoint(typeof(IDebugProtocolService), binding, "net.pipe://localhost/Tvl.Java.DebugHost/DebugProtocolService/");
            IAsyncResult debugProtocolStartResult = _debugProtocolHost.BeginOpen(null, null);
            waitHandles.Add(debugProtocolStartResult.AsyncWaitHandle);

            /* Wait for the services to finish opening
             */
            WaitHandle.WaitAll(waitHandles.ToArray());

            EventWaitHandle eventWaitHandle = null;
            try
            {
                eventWaitHandle = EventWaitHandle.OpenExisting(string.Format("JavaDebuggerInitHandle{0}", Process.GetCurrentProcess().Id));
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                // must have been launched without the debugger
            }

            if (eventWaitHandle != null)
            {
                eventWaitHandle.Set();
                Action           waitAction  = _debuggerAttachComplete.Wait;
                IAsyncResult     waitResult  = waitAction.BeginInvoke(vm.HandleAsyncOperationComplete, null);
                DispatcherFrame  frame       = new DispatcherFrame(true);
                JvmtiEnvironment environment = debugProtocolService.Environment;
                vm.PushDispatcherFrame(frame, environment, waitResult);
            }

            return(0);
        }
示例#13
0
 public static void DoEvents()
 {
     System.Windows.Threading.DispatcherFrame frame = new System.Windows.Threading.DispatcherFrame();
     System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(ExitFrame), frame);
     System.Windows.Threading.Dispatcher.PushFrame(frame);
 }
示例#14
0
 /// <summary/>
 public static void PushFrame(System.Windows.Threading.DispatcherFrame frame)
 {
     new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted).Assert();
     System.Windows.Threading.Dispatcher.PushFrame(frame);
 }