Example #1
0
        public static void GoBabyGo(string settingsFile)
        {
            TransientSettingsData.LoadCurrent(settingsFile);

            Dispatcher dispatcher;

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

            if (dispatcher.CheckAccess())
            {
                var zoomer = new Zoomer();
                zoomer.Magnify();
            }
            else
            {
                dispatcher.Invoke((Action)(() => GoBabyGo(settingsFile)));
            }
        }
Example #2
0
        public static bool GoBabyGo(string settingsFile)
        {
            TransientSettingsData.LoadCurrent(settingsFile);

            try
            {
                SnoopApplication();
                return(true);
            }
            catch (Exception exception)
            {
                ErrorDialog.ShowDialog(exception, "Error Snooping", "There was an error snooping the application.", exceptionAlreadyHandled: true);
                return(false);
            }
        }
Example #3
0
        public static bool GoBabyGo(string settingsFile)
        {
            TransientSettingsData.LoadCurrent(settingsFile);

            return(new CrossAppDomainSnoop().CrossDomainGoBabyGo(settingsFile));
        }
Example #4
0
        private bool StartSnoopInstance(string settingsFile)
        {
            Trace.WriteLine("Starting snoop...");

            var settingsData = TransientSettingsData.LoadCurrent(settingsFile);

            IList <AppDomain> appDomains = null;

            if (settingsData.MultipleAppDomainMode != MultipleAppDomainMode.NeverUse)
            {
                appDomains = new AppDomainHelper().GetAppDomains();
            }

            var numberOfAppDomains = 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 = this.RunInCurrentAppDomain(settingsData);
            }
            else if (numberOfAppDomains == 1)
            {
                Trace.WriteLine("Only found one app domain. Running in single app domain mode.");

                succeeded = this.RunInCurrentAppDomain(settingsData);
            }
            else
            {
                Trace.WriteLine($"Found {numberOfAppDomains} app domains. Running in multiple app domain mode.");

                var shouldUseMultipleAppDomainMode = settingsData.MultipleAppDomainMode == MultipleAppDomainMode.Ask ||
                                                     settingsData.MultipleAppDomainMode == MultipleAppDomainMode.AlwaysUse;
                if (settingsData.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,
                            MessageBoxResult.No);

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

                if (shouldUseMultipleAppDomainMode == false ||
                    appDomains == null)
                {
                    succeeded = this.RunInCurrentAppDomain(settingsData);
                }
                else
                {
                    SnoopModes.MultipleAppDomainMode = true;

                    // Use environment variable to transport snoop settings file accross multiple app domains
                    Environment.SetEnvironmentVariable("Snoop.SettingsFile", settingsFile, EnvironmentVariableTarget.Process);

                    var assemblyFullName      = typeof(SnoopManager).Assembly.Location;
                    var fullInjectorClassName = typeof(SnoopCrossAppDomainInjector).FullName;

                    foreach (var appDomain in appDomains)
                    {
                        Trace.WriteLine($"Trying to create Snoop instance in app domain \"{appDomain.FriendlyName}\"...");

                        try
                        {
                            AttachAssemblyResolveHandler(appDomain);

                            // the injection code runs inside the constructor of SnoopCrossAppDomainManager
                            appDomain.CreateInstanceFrom(assemblyFullName, fullInjectorClassName);

                            // if there is no exception we consider the injection successful
                            var appDomainSucceeded = true;
                            succeeded = succeeded || appDomainSucceeded;

                            Trace.WriteLine($"Successfully created Snoop instance in app domain \"{appDomain.FriendlyName}\".");
                        }
                        catch (Exception exception)
                        {
                            Trace.WriteLine($"Failed to create Snoop instance in app domain \"{appDomain.FriendlyName}\".");
                            Trace.WriteLine(exception);
                        }
                    }
                }
            }

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

            return(succeeded);
        }
Example #5
0
        private void RunInCurrentAppDomain(string settingsFile)
        {
            var settingsData = TransientSettingsData.LoadCurrent(settingsFile);

            new SnoopManager().RunInCurrentAppDomain(settingsData);
        }