public ClientSessionUri(
            AgentType agentType,
            ClientSessionKind sessionKind,
            string host,
            ushort port,
            IEnumerable <string> assemblySearchPaths = null,
            string workbookPath     = null,
            string workingDirectory = null,
            IEnumerable <KeyValuePair <string, string> > parameters = null)
        {
            if (port != 0)
            {
                ValidPortRange.Assert(port);
            }

            AgentType   = agentType;
            SessionKind = sessionKind;
            Host        = host ?? localhost;
            Port        = port;

            if (assemblySearchPaths != null)
            {
                AssemblySearchPaths = assemblySearchPaths.ToArray();
            }

            WorkbookPath     = NormalizePath(workbookPath);
            WorkingDirectory = NormalizePath(workingDirectory);

            if (parameters != null)
            {
                Parameters = parameters.ToArray();
            }
        }
        internal static async Task <WorkspaceConfiguration> CreateAsync(
            IAgentConnection agent,
            ClientSessionKind sessionKind,
            CancellationToken cancellationToken = default)
        {
            // HACK: This is a temporary fix to get iOS agent/app assemblies
            // sent to the Windows client when using the remote simulator.
            var includePeImage = agent.IncludePeImage;

            var configuration = await agent.Api.InitializeEvaluationContextAsync(includePeImage)
                                .ConfigureAwait(false);

            if (configuration == null)
            {
                throw new Exception(
                          $"{nameof (agent.Api.InitializeEvaluationContextAsync)} " +
                          $"did not return a {nameof (TargetCompilationConfiguration)}");
            }

            var dependencyResolver = CreateDependencyResolver(
                agent.Type,
                agent.AssemblySearchPaths);

            var defaultRefs = await agent.Api.GetAppDomainAssembliesAsync(includePeImage)
                              .ConfigureAwait(false);

            // Only do this for Inspector sessions. Workbooks will do their own Forms init later.
            if (sessionKind == ClientSessionKind.LiveInspection)
            {
                var formsReference = defaultRefs.FirstOrDefault(ra => ra.Name.Name == "Xamarin.Forms.Core");
                if (formsReference != null)
                {
                    await LoadFormsAgentExtensions(
                        formsReference.Name.Version,
                        agent,
                        dependencyResolver,
                        configuration.EvaluationContextId,
                        includePeImage).ConfigureAwait(false);
                }
            }

            dependencyResolver.AddDefaultReferences(defaultRefs);

            return(new WorkspaceConfiguration(
                       configuration,
                       dependencyResolver,
                       includePeImage,
                       ResolveHostObjectType(
                           dependencyResolver,
                           configuration,
                           agent.Type)));
        }
Exemple #3
0
        internal static async Task <WorkspaceConfiguration> CreateAsync(
            IEvaluationContextManager evaluationContextManager,
            ClientSessionKind sessionKind,
            CancellationToken cancellationToken = default)
        {
            if (evaluationContextManager == null)
            {
                throw new ArgumentNullException(nameof(evaluationContextManager));
            }

            var configuration = await evaluationContextManager
                                .CreateEvaluationContextAsync(cancellationToken)
                                .ConfigureAwait(false);

            if (configuration == null)
            {
                throw new Exception(
                          $"{nameof (IEvaluationContextManager)}." +
                          $"{nameof (IEvaluationContextManager.CreateEvaluationContextAsync)} " +
                          $"returned null");
            }

            var dependencyResolver = CreateDependencyResolver(configuration);

            // Only do this for Inspector sessions. Workbooks will do their own Forms init later.
            if (sessionKind == ClientSessionKind.LiveInspection)
            {
                var formsReference = configuration
                                     .InitialReferences
                                     .FirstOrDefault(ra => ra.Name.Name == "Xamarin.Forms.Core");
                if (formsReference != null)
                {
                    await LoadFormsAgentExtensions(
                        formsReference.Name.Version,
                        configuration,
                        evaluationContextManager,
                        dependencyResolver).ConfigureAwait(false);
                }
            }

            dependencyResolver.AddDefaultReferences(configuration.InitialReferences);

            var globalStateType = ResolveHostObjectType(
                dependencyResolver,
                configuration);

            configuration = configuration.With(globalStateType: configuration
                                               .GlobalStateType
                                               .WithResolvedType(globalStateType));

            return(new WorkspaceConfiguration(configuration, dependencyResolver));
        }
        IReadOnlyList <string> LocateClientApplications(ClientSessionKind clientSessionKind)
        {
            if (clientAppPaths != null)
            {
                return(clientAppPaths);
            }

            var searchPaths = new List <string> ();

            var clientInstallPath = clientSessionKind == ClientSessionKind.LiveInspection
                ? inspectorClientInstallPath
                : workbooksClientInstallPath;

            string appFileName;

            if (IsMac)
            {
                appFileName = clientSessionKind == ClientSessionKind.LiveInspection
                    ? "Xamarin Inspector.app"
                    : "Xamarin Workbooks.app";
                searchPaths.Add(Path.Combine(
                                    BuildPath, "Clients", "Xamarin.Interactive.Client.Mac", "bin"));
            }
            else
            {
                appFileName = clientSessionKind == ClientSessionKind.LiveInspection
                    ? "Xamarin Inspector.exe"
                    : "Xamarin Workbooks.exe";
                searchPaths.Add(Path.Combine(
                                    BuildPath, "Clients", "Xamarin.Interactive.Client.Windows", "bin"));
            }

            var foundPaths = LocateFiles(searchPaths, appFileName).ToList();

            if (clientInstallPath != null)
            {
                var installedPath = Path.Combine(clientInstallPath, appFileName);
                if (File.Exists(installedPath) || Directory.Exists(installedPath))
                {
                    foundPaths.Add(installedPath);
                }
                // Resort in descending mtime order
                foundPaths.Sort((x, y) =>
                                File.GetLastWriteTimeUtc(GetPathForOrdering(y)).CompareTo(
                                    File.GetLastWriteTimeUtc(GetPathForOrdering(x))));
            }

            return(clientAppPaths = foundPaths);
        }
        public ClientSessionUri WithSessionKind(ClientSessionKind sessionKind)
        {
            if (sessionKind == SessionKind)
            {
                return(this);
            }

            return(new ClientSessionUri(
                       AgentType,
                       sessionKind,
                       Host,
                       Port,
                       AssemblySearchPaths,
                       WorkbookPath,
                       WorkingDirectory,
                       Parameters));
        }
        public void TryParse(
            string uriString,
            bool expectedResult,
            string host,
            int port,
            ClientSessionKind clientSessionKind)
        {
            ClientSessionUri uri;

            ClientSessionUri.TryParse(uriString, out uri).ShouldEqual(expectedResult);

            if (!expectedResult)
            {
                return;
            }

            uri.Host.ShouldEqual(host);
            uri.Port.ShouldEqual((ushort)port);
            uri.SessionKind.ShouldEqual(clientSessionKind);

            Assert.DoesNotThrow(() => uri.ToString());
        }
 public string LocateClientApplication(
     ClientSessionKind clientSessionKind = ClientSessionKind.LiveInspection)
 => LocateClientApplications(clientSessionKind).FirstOrDefault();
 public ClientSessionUri(AgentType agentType, ClientSessionKind sessionKind)
 {
     AgentType   = agentType;
     SessionKind = sessionKind;
 }