Inheritance: INotifyPropertyChanged
Ejemplo n.º 1
0
        public static void SnoopApplication()
        {
            Dispatcher dispatcher;

            if (Application.Current == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }
            else
            {
                dispatcher = Application.Current.Dispatcher;
            }

            if (dispatcher.CheckAccess())
            {
                SnoopUI snoop = new SnoopUI();
                var     title = TryGetMainWindowTitle();
                if (!string.IsNullOrEmpty(title))
                {
                    snoop.Title = string.Format("{0} - Snoop", title);
                }

                snoop.Inspect();

                CheckForOtherDispatchers(dispatcher);
            }
            else
            {
                dispatcher.Invoke((Action)SnoopApplication);
                return;
            }
        }
Ejemplo n.º 2
0
        public static void SnoopApplication()
        {
            Trace.WriteLine("Snooping application.");
            var     handle  = new IntPtr(long.Parse(TransientSettingsData.Current.Handle));
            var     control = System.Windows.Forms.Control.FromHandle(handle);
            SnoopUI sui     = new SnoopUI(control);

            sui.Show();
        }
Ejemplo n.º 3
0
 public SearchEngine(SnoopUI snoopUi)
 {
     this.snoopUi         = snoopUi;
     matchingItems        = new ObservableCollection <VisualTreeItem>();
     filterTimer          = new DispatcherTimer();
     filterTimer.Interval = TimeSpan.FromSeconds(0.3);
     filterTimer.Tick    += (s, e) => {
         EnqueueAfterSettingFilter();
         filterTimer.Stop();
     };
     filterCall = new DelayedCall(ProcessNewFilter, DispatcherPriority.Background);
 }
Ejemplo n.º 4
0
        private static void LaunchSnoopApplicationOnDispatcher()
        {
            var snoop = new SnoopUI();
            var title = TryGetMainWindowTitle();

            if (!string.IsNullOrEmpty(title))
            {
                snoop.Title = $"{title} - SnoopX";
            }

            snoop.Inspect();
        }
Ejemplo n.º 5
0
        private static void DispatchOut(object o)
        {
            var visuals = (List <Visual>)o;

            foreach (var visual in visuals)
            {
                visual.Dispatcher.InvokeAsync(() =>
                {
                    var snoopOtherDispatcher = new SnoopUI();
                    snoopOtherDispatcher.Inspect(visual, visual as Window);
                });
            }
        }
Ejemplo n.º 6
0
        public static void SnoopApplication()
        {
            Dispatcher dispatcher;

            if (Application.Current == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }
            else
            {
                dispatcher = Dispatcher.CurrentDispatcher; // Application.Current.Dispatcher;

                //try
                //{
                //    var app = Application.Current;
                //    PropertyInfo propInfo = app.GetType().GetProperty( "MainCore", BindingFlags.Static | BindingFlags.NonPublic);

                //        var mainCore = propInfo.GetValue(app);
                //        dispatcher = mainCore.GetType().GetProperty("MainWindowDispatcherThread", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(mainCore) as Dispatcher;

                //    //MainWindowDispatcherThread

                //}
                //catch( Exception e )
                //{

                //    MessageBox.Show( e.ToString());
                //}
            }

            if (dispatcher.CheckAccess())
            {
                //MessageBox.Show( "Pass check access");
                SnoopUI snoop = new SnoopUI();
                var     title = TryGetMainWindowTitle();
                if (!string.IsNullOrEmpty(title))
                {
                    snoop.Title = string.Format("{0} - Snoop", title);
                }

                dispatcher.Invoke((Action)snoop.Inspect);

                CheckForOtherDispatchers(dispatcher);
            }
            else
            {
                dispatcher.Invoke((Action)SnoopApplication);
                return;
            }
        }
Ejemplo n.º 7
0
        public bool ApplyReduceDepthFilterIfNeeded(ProperTreeViewItem curNode)
        {
            if (_pendingRoot != null)
            {
                OnRootLoaded();
            }

            if (_maxDepth == 0)
            {
                return false;
            }

            VisualTreeItem rootItem = (VisualTreeItem)_rootItem.Target;
            if (rootItem == null)
            {
                return false;
            }

            if (_snoopUI == null)
            {
                _snoopUI = VisualTreeHelper2.GetAncestor<SnoopUI>(this);
                if (_snoopUI == null)
                {
                    return false;
                }
            }

            VisualTreeItem item = (VisualTreeItem)curNode.DataContext;
            VisualTreeItem selectedItem = _snoopUI.CurrentSelection;
            if (selectedItem != null && item.Depth < selectedItem.Depth)
            {
                item = selectedItem;
            }

            if ((item.Depth - rootItem.Depth) <= _maxDepth)
            {
                return false;
            }

            for (int i = 0; i < _maxDepth; ++i)
            {
                item = item.Parent;
            }

            _snoopUI.ApplyReduceDepthFilter(item);
            return true;
        }
Ejemplo n.º 8
0
        static void DispatchOut(object o)
        {
            var visuals = (List <Visual>)o;

            foreach (var v in visuals)
            {
                // launch a snoop ui on each dispatcher
                v.Dispatcher.Invoke
                (
                    (Action)
                    (
                        () => {
                    var snoopOtherDispatcher = new SnoopUI();
                    snoopOtherDispatcher.Inspect(v, v as Window);
                }
                    )
                );
            }
        }
Ejemplo n.º 9
0
        public static void SnoopApplication()
        {
            Trace.WriteLine("Snooping application.");

            Dispatcher dispatcher;

            if (Application.Current == null)
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }
            else
            {
                dispatcher = Application.Current.Dispatcher;
            }

            if (dispatcher.CheckAccess())
            {
                Trace.WriteLine("Starting snoop UI.");

                var snoop = new SnoopUI();
                var title = TryGetMainWindowTitle();

                if (!string.IsNullOrEmpty(title))
                {
                    snoop.Title = $"{title} - Snoop";
                }

                snoop.Inspect();

                CheckForOtherDispatchers(dispatcher);
            }
            else
            {
                Trace.WriteLine("Current dispatcher runs on a different thread.");

                dispatcher.Invoke((Action)(SnoopApplication));
            }
        }
Ejemplo n.º 10
0
 private static void DispatchOut(object o)
 {
     List<Visual> visuals = (List<Visual>)o;
     foreach (var v in visuals)
     {
         // launch a snoop ui on each dispatcher
         v.Dispatcher.Invoke
         (
             (Action)
             (
                 () =>
                 {
                     SnoopUI snoopOtherDispatcher = new SnoopUI();
                     snoopOtherDispatcher.Inspect(v, v as Window);
                 }
             )
         );
     }
 }
Ejemplo n.º 11
0
        public static void SnoopApplication()
        {
            Dispatcher dispatcher;
            if (Application.Current == null)
                dispatcher = Dispatcher.CurrentDispatcher;
            else
                dispatcher = Application.Current.Dispatcher;

            if (dispatcher.CheckAccess())
            {
                SnoopUI snoop = new SnoopUI();
                var title = TryGetMainWindowTitle();
                if (!string.IsNullOrEmpty(title))
                {
                    snoop.Title = string.Format("{0} - Snoop", title);
                }

                snoop.Inspect();

                CheckForOtherDispatchers(dispatcher);
            }
            else
            {
                dispatcher.Invoke((Action)SnoopApplication);
                return;
            }
        }
        public bool CrossDomainGoBabyGo(string settingsFile)
        {
            TransientSettingsData.LoadCurrentIfRequired(settingsFile);

            if (TransientSettingsData.Current.MultipleAppDomainMode == MultipleAppDomainMode.AlwaysUse ||
                TransientSettingsData.Current.MultipleAppDomainMode == MultipleAppDomainMode.Ask)
            {
                var staThread = new Thread(this.EnumAppDomains);
                staThread.SetApartmentState(ApartmentState.STA); //STA is required when enumerating app domains
                this.autoResetEvent = new AutoResetEvent(false);
                staThread.Start();

                this.autoResetEvent.WaitOne();
            }

            var numberOfAppDomains = this.appDomains?.Count ?? 1;
            var succeeded          = false;

            if (numberOfAppDomains <= 1)
            {
                Trace.WriteLine("Snoop wasn't able to enumerate app domains or MultipleAppDomainMode was disabled. Trying to run in single app domain mode.");

                succeeded = SnoopUI.GoBabyGoForCurrentAppDomain(settingsFile);
            }
            else if (numberOfAppDomains == 1)
            {
                Trace.WriteLine("Only found one app domain. Running in single app domain mode.");

                succeeded = SnoopUI.GoBabyGoForCurrentAppDomain(settingsFile);
            }
            else
            {
                Trace.WriteLine($"Found {numberOfAppDomains} app domains. Running in multiple app domain mode.");

                var shouldUseMultipleAppDomainMode = true;
                if (TransientSettingsData.Current.MultipleAppDomainMode == MultipleAppDomainMode.Ask)
                {
                    var result =
                        MessageBox.Show
                        (
                            "Snoop has noticed multiple app domains.\n\n" +
                            "Would you like to enter multiple app domain mode, and have a separate Snoop window for each app domain?\n\n" +
                            "Without having a separate Snoop window for each app domain, you will not be able to Snoop the windows in the app domains outside of the main app domain. ",
                            "Enter Multiple AppDomain Mode",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question
                        );

                    if (result == MessageBoxResult.Yes)
                    {
                        shouldUseMultipleAppDomainMode = true;
                    }
                    else
                    {
                        shouldUseMultipleAppDomainMode = false;
                    }
                }

                if (shouldUseMultipleAppDomainMode == false)
                {
                    succeeded = SnoopUI.GoBabyGoForCurrentAppDomain(settingsFile);
                }
                else
                {
                    SnoopModes.MultipleAppDomainMode = true;

                    var assemblyFullName = typeof(CrossAppDomainSnoop).Assembly.Location;
                    var fullName         = typeof(CrossAppDomainSnoop).FullName;

                    foreach (var appDomain in this.appDomains)
                    {
                        var crossAppDomainSnoop = (CrossAppDomainSnoop)appDomain.CreateInstanceFromAndUnwrap(assemblyFullName, fullName);
                        //runs in a separate AppDomain
                        var appDomainSucceeded = crossAppDomainSnoop.GoBabyGoForCurrentAppDomain(settingsFile);
                        succeeded = succeeded || appDomainSucceeded;
                    }
                }
            }

            if (!succeeded)
            {
                MessageBox.Show
                (
                    "Can't find a current application or a PresentationSource root visual!",
                    "Can't Snoop",
                    MessageBoxButton.OK,
                    MessageBoxImage.Exclamation
                );
            }

            return(succeeded);
        }
 // We have to wrap the call to SnoopUI.GoBabyGoForCurrentAppDomain in an instance member.
 // Otherwise we are not called in the desired appdomain.
 // ReSharper disable once MemberCanBeMadeStatic.Local
 private bool GoBabyGoForCurrentAppDomain(string settingsFile)
 {
     return(SnoopUI.GoBabyGoForCurrentAppDomain(settingsFile));
 }
Ejemplo n.º 14
0
        public static void SnoopApplication()
        {
            Dispatcher dispatcher;
            if( Application.Current == null )
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }
            else
            {
                dispatcher = Dispatcher.CurrentDispatcher; // Application.Current.Dispatcher;

                //try
                //{
                //    var app = Application.Current;
                //    PropertyInfo propInfo = app.GetType().GetProperty( "MainCore", BindingFlags.Static | BindingFlags.NonPublic);

                //        var mainCore = propInfo.GetValue(app);
                //        dispatcher = mainCore.GetType().GetProperty("MainWindowDispatcherThread", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(mainCore) as Dispatcher;

                //    //MainWindowDispatcherThread

                //}
                //catch( Exception e )
                //{

                //    MessageBox.Show( e.ToString());
                //}
            }

            if( dispatcher.CheckAccess() )
            {
                //MessageBox.Show( "Pass check access");
                SnoopUI snoop = new SnoopUI();
                var title = TryGetMainWindowTitle();
                if( !string.IsNullOrEmpty( title ) )
                {
                    snoop.Title = string.Format( "{0} - Snoop", title );
                }

                dispatcher.Invoke( (Action) snoop.Inspect );

                CheckForOtherDispatchers( dispatcher );
            }
            else
            {
                dispatcher.Invoke( (Action) SnoopApplication );
                return;
            }
        }