// "Unsafe" so we can very easily pass environmentPzz (a string with embedded nulls)
        // to Win32 as an IntPtr
        unsafe static public void SpawnWindowsStoreAppProcess(string packgeFullName, string appUserModelId, string appArgs, string[] environment, out uint pid)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            // NOTE: If you'd like to step through the native profiler DLL's startup, use a
            // string like this instead of the WindowsStoreAppThreadResumer string below
            //string debuggerCommandLine = "C:\\debuggers\\windbg.exe";

            string debuggerCommandLine = Path.Combine(
                Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                "CLRProfilerWindowsStoreAppThreadResumer.exe");

            if (!File.Exists(debuggerCommandLine))
            {
                pid = unchecked ((uint)-1);
                MessageBox.Show(
                    string.Format(
                        "Cannot launch Windows Store app, because the following file is missing: '{0}'",
                        debuggerCommandLine));
                return;
            }

            ushort[] environmentPzz = StringArrayToPzz(environment);

            fixed(ushort *fixedEnvironmentPzz = environmentPzz)
            {
                pkgDebugSettings.EnableDebugging(packgeFullName, debuggerCommandLine, (IntPtr)fixedEnvironmentPzz);
            }

            appActivationMgr.ActivateApplication(appUserModelId, appArgs, ACTIVATEOPTIONS.AO_NONE, out pid);
        }
        // Tells the OS to take a package out of "debugging" mode.  This resets the intent
        // to pass environment variables to the package and allows the package to be suspended
        // by the OS in the future, as usual.
        static public void DisableDebuggingForPackage(string packgeFullName)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            pkgDebugSettings.DisableDebugging(packgeFullName);
        }
        // Tells the OS to put the package in "debugging" mode, which ensures it does not
        // get suspended.  This is mainly used for attach, where environment variables are
        // not to be passed to the profilee.  For launch-profiling, SpawnWindowsStoreAppProcess()
        // also puts the package in debugging mode, but passes environment variables as well.
        static public void EnableDebuggingForPackage(string packageFullName)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            pkgDebugSettings.EnableDebugging(packageFullName, null /* debugger cmd line */, IntPtr.Zero /* environment */);
            pkgDebugSettings.Resume(packageFullName);
        }
Beispiel #4
0
        public void Run(bool debug, TimeSpan timeout)
        {
            object returnedComObj = null;

            NativeMethods.CoCreateInstance(Guids.ApplicationActivationManager, null, NativeMethods.CLSCTX_LOCAL_SERVER, Guids.IApplicationActivationManager, out returnedComObj);
            var activationManager = (IApplicationActivationManager)returnedComObj;

            if (debug)
            {
                var packageDebugSettings = new PackageDebugSettings() as IPackageDebugSettings;
                packageDebugSettings.EnableDebugging(packageFullName, null, null);
            }
            IntPtr pid;

            Console.WriteLine("Activating: " + appUserModelId);
            var hri   = activationManager.ActivateApplication(appUserModelId, this.argsToPass, ACTIVATEOPTIONS.AO_NOERRORUI | ACTIVATEOPTIONS.AO_NOSPLASHSCREEN, out pid);
            var timer = Stopwatch.StartNew();

            Console.WriteLine("UWP Install HRESULT: " + hri);
            var p = Process.GetProcessById(pid.ToInt32());

            Console.WriteLine("Running {0} in process {1} at {2}", p.ProcessName, pid, DateTimeOffset.Now);
            while (timer.ElapsedMilliseconds < timeout.TotalMilliseconds && !p.HasExited)
            {
                Thread.Sleep(1000);
            }
            var cleanExit = p.HasExited;

            if (!p.HasExited)
            {
                Console.WriteLine("Killing {0}", pid);
                p.Kill();
            }
            Console.WriteLine("Finished waiting for {0} at {1}, clean exit: {2}", pid, DateTimeOffset.Now, cleanExit);

            var resultPath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "testResults.xml");

            Console.WriteLine("Attempting to read {0}", resultPath);
            var destinationPath = Path.Combine(InstallLocation, Path.GetFileName(resultPath));

            Console.WriteLine("Attempting to copy {0} to {1}", resultPath, destinationPath);
            File.Copy(resultPath, destinationPath, true);
            Console.WriteLine("File copied to {0}", destinationPath);
            File.Delete(resultPath);
        }
        // "Unsafe" so we can very easily pass environmentPzz (a string with embedded nulls)
        // to Win32 as an IntPtr
        unsafe static public void SpawnWindowsStoreAppProcess(string packgeFullName, string appUserModelId, string appArgs, string[] environment, out uint pid)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();

            // NOTE: If you'd like to step through the native profiler DLL's startup, use a
            // string like this instead of the WindowsStoreAppThreadResumer string below
            //string debuggerCommandLine = "C:\\debuggers\\windbg.exe";
            
            string debuggerCommandLine = Path.Combine(
                Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                "CLRProfilerWindowsStoreAppThreadResumer.exe");
            
            if (!File.Exists(debuggerCommandLine))
            {
                pid = unchecked((uint)-1);
                MessageBox.Show(
                    string.Format(
                        "Cannot launch Windows Store app, because the following file is missing: '{0}'", 
                        debuggerCommandLine));
                return;
            }

            ushort[] environmentPzz = StringArrayToPzz(environment);

            fixed (ushort* fixedEnvironmentPzz = environmentPzz)
            {
                pkgDebugSettings.EnableDebugging(packgeFullName, debuggerCommandLine, (IntPtr)fixedEnvironmentPzz);
            }

	        appActivationMgr.ActivateApplication(appUserModelId, appArgs, ACTIVATEOPTIONS.AO_NONE, out pid);
        }
 // Tells the OS to take a package out of "debugging" mode.  This resets the intent
 // to pass environment variables to the package and allows the package to be suspended
 // by the OS in the future, as usual.
 static public void DisableDebuggingForPackage(string packgeFullName)
 {
     IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
     IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();
     pkgDebugSettings.DisableDebugging(packgeFullName);
 }
 // Tells the OS to put the package in "debugging" mode, which ensures it does not
 // get suspended.  This is mainly used for attach, where environment variables are
 // not to be passed to the profilee.  For launch-profiling, SpawnWindowsStoreAppProcess()
 // also puts the package in debugging mode, but passes environment variables as well.
 static public void EnableDebuggingForPackage(string packageFullName)
 {
     IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
     IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();
     pkgDebugSettings.EnableDebugging(packageFullName, null /* debugger cmd line */, IntPtr.Zero /* environment */);
     pkgDebugSettings.Resume(packageFullName);
 }
Beispiel #8
0
        public int Run(bool debug, TimeSpan timeout)
        {
            object returnedComObj = null;

            NativeMethods.CoCreateInstance(Guids.ApplicationActivationManager, null, NativeMethods.CLSCTX_LOCAL_SERVER, Guids.IApplicationActivationManager, out returnedComObj);
            var activationManager = (IApplicationActivationManager)returnedComObj;

            if (debug)
            {
                var packageDebugSettings = new PackageDebugSettings() as IPackageDebugSettings;
                packageDebugSettings.EnableDebugging(packageFullName, null, null);
            }
            IntPtr pid;

            Console.WriteLine("Activating: " + appUserModelId);
            var hr    = activationManager.ActivateApplication(appUserModelId, this.argsToPass, ACTIVATEOPTIONS.AO_NOERRORUI | ACTIVATEOPTIONS.AO_NOSPLASHSCREEN, out pid);
            var timer = Stopwatch.StartNew();

            Console.WriteLine("UWP Activation HRESULT: " + hr);
            if (hr == 0)
            {
                var p = Process.GetProcessById(pid.ToInt32());
                Console.WriteLine($"Running {p.ProcessName} in process {pid} at {DateTimeOffset.Now}");
                while (timer.ElapsedMilliseconds < timeout.TotalMilliseconds && !p.HasExited)
                {
                    Thread.Sleep(1000);
                }
                var cleanExit = p.HasExited;
                if (!cleanExit)
                {
                    Console.WriteLine($"Killing {pid}");
                    p.Kill();
                    ReturnCode = -1;
                }
                Console.WriteLine($"Finished waiting for {pid} at {DateTimeOffset.Now}, clean exit: {cleanExit}");
            }
            else
            {
                ReturnCode = -1;
            }

            var resultPath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "testResults.xml");
            var logsPath   = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "logs.txt");

            var destinationResultPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(resultPath));
            var destinationLogsPath   = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(logsPath));

            if (File.Exists(resultPath))
            {
                Console.WriteLine($"Copying {resultPath} to test directory");
                File.Copy(resultPath, destinationResultPath, true);
                PrintTestResults(destinationResultPath);
            }
            else
            {
                Console.WriteLine($"No results found at {resultPath}");
            }
            if (File.Exists(logsPath))
            {
                File.Copy(logsPath, destinationLogsPath, true);
                PrintLogResults(destinationLogsPath);
            }
            else
            {
                Console.WriteLine($"No logs found at {logsPath}");
            }

            Console.WriteLine("Cleaning up...");
            if (File.Exists(resultPath))
            {
                File.Delete(resultPath);
            }
            if (File.Exists(logsPath))
            {
                File.Delete(logsPath);
            }
            return(ReturnCode);
        }
Beispiel #9
0
        public void Run(bool debug, TimeSpan timeout)
        {
            object returnedComObj = null;
            NativeMethods.CoCreateInstance(Guids.ApplicationActivationManager, null, NativeMethods.CLSCTX_LOCAL_SERVER, Guids.IApplicationActivationManager, out returnedComObj);
            var activationManager = (IApplicationActivationManager)returnedComObj;
            if (debug)
            {
                var packageDebugSettings = new PackageDebugSettings() as IPackageDebugSettings;
                packageDebugSettings.EnableDebugging(packageFullName, null, null);
            }
            IntPtr pid;
            Console.WriteLine("Activating: " + appUserModelId);
            var hri = activationManager.ActivateApplication(appUserModelId, this.argsToPass, ACTIVATEOPTIONS.AO_NOERRORUI | ACTIVATEOPTIONS.AO_NOSPLASHSCREEN, out pid);
            var timer = Stopwatch.StartNew();
            Console.WriteLine("UWP Install HRESULT: " + hri);
            var p = Process.GetProcessById(pid.ToInt32());
            Console.WriteLine("Running {0} in process {1} at {2}", p.ProcessName, pid, DateTimeOffset.Now);
            while (timer.ElapsedMilliseconds < timeout.TotalMilliseconds && !p.HasExited)
            {
                Thread.Sleep(1000);
            }
            var cleanExit = p.HasExited;
            if (!p.HasExited)
            {
                Console.WriteLine("Killing {0}", pid);
                p.Kill();
            }
            Console.WriteLine("Finished waiting for {0} at {1}, clean exit: {2}", pid, DateTimeOffset.Now, cleanExit);

            var resultPath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "testResults.xml");
            Console.WriteLine("Attempting to read {0}", resultPath);
            var destinationPath = Path.Combine(InstallLocation, Path.GetFileName(resultPath));
            Console.WriteLine("Attempting to copy {0} to {1}", resultPath, destinationPath);
            File.Copy(resultPath, destinationPath, true);
            Console.WriteLine("File copied to {0}", destinationPath);
            File.Delete(resultPath);
        }
Beispiel #10
0
        public int Run(bool debug, TimeSpan timeout)
        {
            object returnedComObj = null;
            NativeMethods.CoCreateInstance(Guids.ApplicationActivationManager, null, NativeMethods.CLSCTX_LOCAL_SERVER, Guids.IApplicationActivationManager, out returnedComObj);
            var activationManager = (IApplicationActivationManager)returnedComObj;
            if (debug)
            {
                var packageDebugSettings = new PackageDebugSettings() as IPackageDebugSettings;
                packageDebugSettings.EnableDebugging(packageFullName, null, null);
            }
            IntPtr pid;
            Console.WriteLine("Activating: " + appUserModelId);
            var hr = activationManager.ActivateApplication(appUserModelId, this.argsToPass, ACTIVATEOPTIONS.AO_NOERRORUI | ACTIVATEOPTIONS.AO_NOSPLASHSCREEN, out pid);
            var timer = Stopwatch.StartNew();
            Console.WriteLine("UWP Activation HRESULT: " + hr);
            if (hr == 0)
            {
                var p = Process.GetProcessById(pid.ToInt32());
                Console.WriteLine($"Running {p.ProcessName} in process {pid} at {DateTimeOffset.Now}");
                while (timer.ElapsedMilliseconds < timeout.TotalMilliseconds && !p.HasExited)
                {
                    Thread.Sleep(1000);
                }
                var cleanExit = p.HasExited;
                if (!cleanExit)
                {
                    Console.WriteLine($"Killing {pid}");
                    p.Kill();
                    ReturnCode = -1;
                }
                Console.WriteLine($"Finished waiting for {pid} at {DateTimeOffset.Now}, clean exit: {cleanExit}");
            }
            else
            {
                ReturnCode = -1;
            }

            var resultPath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "testResults.xml");
            var logsPath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Packages", appUserModelId.Substring(0, appUserModelId.IndexOf('!')), "LocalState", "logs.txt");

            var destinationResultPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(resultPath));
            var destinationLogsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(logsPath));
            if (File.Exists(resultPath))
            {
                Console.WriteLine($"Copying {resultPath} to test directory");
                File.Copy(resultPath, destinationResultPath, true);
                PrintTestResults(destinationResultPath);
            }
            else
            {
                Console.WriteLine($"No results found at {resultPath}");
            }
            if (File.Exists(logsPath))
            {
                File.Copy(logsPath, destinationLogsPath, true);
                PrintLogResults(destinationLogsPath);
            }
            else
            {
                Console.WriteLine($"No logs found at {logsPath}");
            }

            Console.WriteLine("Cleaning up...");
            if (File.Exists(resultPath))
            {
                File.Delete(resultPath);
            }
            if (File.Exists(logsPath))
            {
                File.Delete(logsPath);
            }
            return ReturnCode;
        }