async Task ConnectToAgentAsync(CancellationToken cancellationToken) { if (agent.IsConnected) { agent = agent.TerminateConnection(); } if (SessionKind == ClientSessionKind.Workbook) { WorkbookApp = WorkbookAppInstallation.Locate(agent.Type); } agent = await agent.ConnectAsync( WorkbookApp, Uri, ViewControllers.Messages, HandleAgentDisconnected, cancellationTokenSource.Token); agent.Api.EvaluationContextManager.Events.Subscribe( new Observer <ICodeCellEvent> (HandleCodeCellEvent)); await agent.Api.SetLogLevelAsync(Log.GetLogLevel()); UpdateTitle(); PostEvent(ClientSessionEventKind.AgentConnected); new Telemetry.Models.AgentSession { AppSessionId = ClientApp.SharedInstance.AppSessionId, Timestamp = DateTimeOffset.UtcNow, Flavor = agent.Identity.FlavorId, Kind = (Telemetry.Models.AgentSessionKind)(int) SessionKind }.Post(); }
public static string GetDisplayLabel(WorkbookAppInstallation workbookApp, Context context) { switch (context) { case Context.NewWorkbookDialog: return(string.IsNullOrEmpty(workbookApp.Sdk.Profile) ? workbookApp.Sdk.Name : $"{workbookApp.Sdk.Name} ({workbookApp.Sdk.Profile})"); case Context.Menu: case Context.ComboBox: var name = workbookApp.Flavor; if (name == "Console" && !string.IsNullOrEmpty(workbookApp.Sdk.Name)) { name += " (" + workbookApp.Sdk.Name + ")"; } if (!string.IsNullOrEmpty(workbookApp.Sdk.Profile)) { name += " (" + workbookApp.Sdk.Profile + ")"; } return(name); case Context.StatusBar: return(string.IsNullOrEmpty(workbookApp.Sdk.Profile) ? workbookApp.Sdk.Name : $"{workbookApp.Sdk.Name} ({workbookApp.Sdk.Profile})"); default: throw new NotImplementedException($"{nameof (Context)}.{context}"); } }
public static IApplicationBuilder UseWasmStaticFiles(this IApplicationBuilder builder) { const string wasmWorkbookAppId = "webassembly-monowebassembly"; var wasmWorkbookApp = WorkbookAppInstallation.LookupById(wasmWorkbookAppId); if (wasmWorkbookApp != null) { var provider = new FileExtensionContentTypeProvider(); provider.Mappings.Add(".wasm", "application/wasm"); builder.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(wasmWorkbookApp.AppPath), RequestPath = "/wasm", ContentTypeProvider = provider, ServeUnknownFileTypes = true }); } else { Logging.Log.Warning( nameof(WasmStaticFileMiddleware), "Could not find WASM workbook app to register static file serving."); } return(builder); }
async Task ConnectToAgentAsync(CancellationToken cancellationToken) { if (agent.IsConnected) { agent = agent.TerminateConnection(); } if (SessionKind == ClientSessionKind.Workbook) { WorkbookApp = WorkbookAppInstallation.Locate(agent.Type); } agent = await agent.ConnectAsync( WorkbookApp, Uri, ViewControllers.Messages, HandleAgentDisconnected, cancellationTokenSource.Token); agent.Api.Messages.Subscribe(new Observer <object> (HandleAgentMessage)); await agent.Api.SetLogLevelAsync(Log.GetLogLevel()); UpdateTitle(); PostEvent(ClientSessionEventKind.AgentConnected); }
public WebAssemblyEvaluationContextManager() { var workbookApp = WorkbookAppInstallation.LookupById(workbookAppId); appPath = workbookApp.AppPath; webAssemblySdk = workbookApp.Sdk; this.assemblySearchPaths = webAssemblySdk.AssemblySearchPaths; }
public async Task <AgentConnection> ConnectAsync( WorkbookAppInstallation workbookApp, ClientSessionUri clientSessionUri, IMessageService messageService, Action disconnectedHandler, CancellationToken cancellationToken) { if (disconnectedHandler == null) { throw new ArgumentNullException(nameof(disconnectedHandler)); } IAgentTicket ticket; if (clientSessionUri.SessionKind == ClientSessionKind.Workbook && Type != AgentType.Unknown) { ticket = await workbookApp.RequestAgentTicketAsync( clientSessionUri, messageService, disconnectedHandler, cancellationToken); } else { ticket = new UncachedAgentTicket( clientSessionUri, messageService, disconnectedHandler); } var assemblySearchPaths = ticket.AssemblySearchPaths; var identity = await ticket.GetAgentIdentityAsync(cancellationToken); if (identity == null) { throw new Exception("IAgentTicket.GetAgentIdentityAsync did not return an identity"); } var apiClient = await ticket.GetClientAsync(cancellationToken); if (apiClient == null) { throw new Exception("IAgentTicket.GetClientAsync did not return a client"); } apiClient.SessionCancellationToken = cancellationToken; return(new AgentConnection( ticket, identity.AgentType, identity, apiClient, assemblySearchPaths == null ? ImmutableArray <string> .Empty : assemblySearchPaths.ToImmutableArray(), await apiClient.GetAgentFeaturesAsync(cancellationToken))); }
public static async Task <AgentProcessTicket> RequestTestTicketAsync( this WorkbookAppInstallation workbookApp, Action disconnectedHandler = null, CancellationToken cancellationToken = default(CancellationToken)) => (AgentProcessTicket)await workbookApp.RequestAgentTicketAsync( new ClientSessionUri (AgentType.Test, ClientSessionKind.Workbook), new TestMessageService(), disconnectedHandler ?? (() => { }), cancellationToken);
public Task <AgentIdentity> GetAgentIdentityAsync(CancellationToken cancellationToken = default) { var wasmWorkbookApp = WorkbookAppInstallation.LookupById("webassembly-monowebassembly"); return(Task.FromResult( new AgentIdentity( AgentType.Console, wasmWorkbookApp.Sdk, "Xamarin Workbooks (WASM)"))); }
protected override void OnInitialized() { var workbookAppsDirectory = new FilePath(NSBundle.MainBundle.SharedSupportPath) .Combine("WorkbookApps"); if (workbookAppsDirectory.DirectoryExists) { WorkbookAppInstallation.RegisterSearchPath(workbookAppsDirectory); } WorkbookAppInstallation.RegisterPathMapper( WorkbookAppInstallation_MacosVersionPathMapper); }
public void FixtureSetUp() { observedAgentIdentityIds = new List <Guid> (); workbookApp = WorkbookAppInstallation.FromManifestObject( ".", "test", JObject.FromObject(new { flavor = "Test", appPath = ".", sdk = new { targetFramework = ".NETFramework,Version=4.6.1", assemblySearchPaths = new [] { "." } } })).ShouldNotBeNull(); }
async Task ConnectToAgentAsync(CancellationToken cancellationToken) { if (agent.IsConnected) { agent = agent.TerminateConnection(); } if (SessionKind == ClientSessionKind.Workbook) { WorkbookApp = WorkbookAppInstallation.Locate(agent.Type); } agent = await agent.ConnectAsync( WorkbookApp, Uri, ViewControllers.Messages, HandleAgentDisconnected, cancellationTokenSource.Token); agent.Api.EvaluationContextManager.Events.Subscribe( new Observer <ICodeCellEvent> (HandleCodeCellEvent)); await agent.Api.SetLogLevelAsync(Log.GetLogLevel()); UpdateTitle(); PostEvent(ClientSessionEventKind.AgentConnected); // May be set by Inspector extensions to allow correlating client telemetry with IDE telemetry var externalTelemetrySessionId = Uri .Parameters .FirstOrDefault(p => p.Key == "TelemetrySessionId") .Value; new Telemetry.Models.AgentSession { AgentFlavor = agent.Identity.FlavorId, ClientKind = SessionKind, ExternalTelemetrySessionId = externalTelemetrySessionId }.Post(); }
public WorkbookAppViewController( WorkbookAppInstallation workbookApp, Context context, bool enabled) { if (workbookApp == null) { throw new ArgumentNullException(nameof(workbookApp)); } AgentType = workbookApp.GetAgentType(); Icon = workbookApp.Icon ?? "project"; Enabled = enabled; Label = GetDisplayLabel(workbookApp, context); OptionalFeatures = workbookApp .OptionalFeatures .Where(id => NewWorkbookFeature.AllFeatures.ContainsKey(id)) .Select(id => NewWorkbookFeature.AllFeatures [id]) .ToArray(); }
public void ConfigureServices(IServiceCollection services) { var searchPath = Path.Combine( Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "WorkbookApps"); if (Directory.Exists(searchPath)) { WorkbookAppInstallation.RegisterSearchPath(searchPath); } services.AddSingleton(new WebClientAppContainer()); services.AddMemoryCache(); services.AddMvc(); services .AddSignalR() .AddJsonProtocol(options => { options.PayloadSerializerSettings = new InteractiveJsonSerializerSettings(); }); }
public static void Execute( Action <Action> dispatcher, IEnumerable <string> arguments) { WorkbookAppInstallation.RegisterProcessManagers(typeof(TestRunner).Assembly); AgentIdentificationManager.DefaultTimeout = TimeSpan.FromSeconds(5); ProcessControl.Exec.Log += (sender, e) => { if (e.ExitCode == null) { Console.WriteLine($"Exec[{e.ExecId}]: {e.Arguments}"); } else { Console.WriteLine($"Exec[{e.ExecId}]: exited {e.ExitCode}"); } }; var args = new List <string> (); args.AddRange(new string[] { "-labels=All", "-noheader", "-workers=1" }); args.AddRange(arguments.Where(a => !a.StartsWith("-psn_", StringComparison.Ordinal))); Environment.CurrentDirectory = new FilePath( typeof(TestRunner).Assembly.Location).ParentDirectory; TextRunner.MainLoop = new MainLoopIntegration(dispatcher); Console.WriteLine(string.Join(" ", args)); new TextRunner().Execute(args.ToArray()); }
#pragma warning restore 0067 public iOSAgentProcess(WorkbookAppInstallation workbookApp) => WorkbookApp = workbookApp ?? throw new ArgumentNullException(nameof(workbookApp));
public AgentProcessState(WorkbookAppInstallation workbookApp) => AgentProcess = (TAgentProcess)Activator.CreateInstance(