Beispiel #1
0
        public static void LaunchClientAppForDebugging(Agent agent)
        {
#if DEBUG
            if (!Debugger.IsAttached)
            {
                return;
            }

            var clientAssemblyLocation = Assembly.GetExecutingAssembly().Location;

            var agentType = agent.ClientSessionUri.AgentType;

            InteractiveInstallation.InitializeDefault(null);

            var clientPath = InteractiveInstallation
                             .Default
                             .LocateClientApplication(agent.ClientSessionUri.SessionKind);

            if (string.IsNullOrEmpty(clientPath))
            {
                return;
            }

            var connectUri = new ClientSessionUri(
                agent.Identity.AgentType,
                agent.ClientSessionUri.SessionKind,
                agent.Identity.Host,
                agent.Identity.Port);

            if (HostEnvironment.OS == HostOS.macOS)
            {
                var executableName = Directory.GetFiles(
                    Path.Combine(clientPath, "Contents", "MacOS")) [0];
                clientPath = Path.Combine(clientPath, "Contents", "MacOS", executableName);
            }

            Exec.Log += (sender, e) => {
                if (e.ExitCode == null)
                {
                    Log.Debug(TAG, $"Exec[{e.ExecId}] ({e.Flags}): {e.Arguments}");
                }
                else
                {
                    Log.Debug(TAG, $"Exec[{e.ExecId}] exited: {e.ExitCode}");
                }
            };

            Exec.RunAsync(
                segment => Debug.WriteLine($"!! {segment.Data.TrimEnd ()}"),
                clientPath,
                connectUri).ContinueWith(task => {
                if (task.Exception != null)
                {
                    Log.Error(TAG, task.Exception);
                }
            });
#endif
        }
Beispiel #2
0
        public static void LaunchClientAppForDebugging(Agent agent)
        {
#if DEBUG
            if (!Debugger.IsAttached)
            {
                return;
            }

            var clientAssemblyLocation = Assembly.GetExecutingAssembly().Location;

            var buildDepth = 5;
            var agentType  = agent.ClientSessionUri.AgentType;

            // The Mac executable is more deeply nested, so we need to go up a little further
            // to get the base build path.
            if (agentType == AgentType.MacMobile || agentType == AgentType.MacNet45)
            {
                buildDepth = 7;
            }

            var buildDir = clientAssemblyLocation;
            for (var i = 0; i < buildDepth; i++)
            {
                buildDir = Path.GetDirectoryName(buildDir);
            }

            InteractiveInstallation.InitializeDefault(
                isMac: Environment.OSVersion.Platform == PlatformID.Unix,
                buildPath: buildDir);

            var clientPath = InteractiveInstallation
                             .Default
                             .LocateClientApplication(agent.ClientSessionUri.SessionKind);

            if (string.IsNullOrEmpty(clientPath))
            {
                return;
            }

            var connectUri = new ClientSessionUri(
                agent.Identity.AgentType,
                agent.ClientSessionUri.SessionKind,
                agent.Identity.Host,
                agent.Identity.Port);

            if (InteractiveInstallation.Default.IsMac)
            {
                var executableName = Directory.GetFiles(
                    Path.Combine(clientPath, "Contents", "MacOS")) [0];
                clientPath = Path.Combine(clientPath, "Contents", "MacOS", executableName);
            }

            Exec.Log += (sender, e) => {
                if (e.ExitCode == null)
                {
                    Log.Debug(TAG, $"Exec[{e.ExecId}] ({e.Flags}): {e.Arguments}");
                }
                else
                {
                    Log.Debug(TAG, $"Exec[{e.ExecId}] exited: {e.ExitCode}");
                }
            };

            Exec.RunAsync(
                segment => Debug.WriteLine($"!! {segment.Data.TrimEnd ()}"),
                clientPath,
                connectUri).ContinueWith(task => {
                if (task.Exception != null)
                {
                    Log.Error(TAG, task.Exception);
                }
            });
#endif
        }