public static void Save(this WorkbookPackage workbookPackage, FilePath path) { var saveOperation = workbookPackage.CreateSaveOperation(null); saveOperation.Destination = path; workbookPackage.Save(saveOperation); }
WorkbookPackage ReadWorkbookDocument(string path) { var workbook = new WorkbookPackage(); workbook.Open(quarantineInfo => Task.FromResult(true), path).Wait(); return(workbook); }
/// <summary> /// Provides very basic workbook parsing and shunting of code cells /// into the evaluation service. Does not display non-code-cell contents /// but does evaluate a workbook from top-to-bottom. Restores nuget /// packages from the workbook's manifest. /// </summary> static async Task <int> WorkbookPlayerMain(InteractiveSession session, ClientSessionUri sessionUri) { var path = new FilePath(sessionUri.WorkbookPath); if (!path.FileExists) { Error.WriteLine($"File does not exist: {path}"); return(1); } // load the workbook file var workbook = new WorkbookPackage(path); await workbook.Open( quarantineInfo => Task.FromResult(true), path); #pragma warning disable 0618 // TODO: WorkbookDocumentManifest needs to eliminate AgentType like we've done on web // to avoid having to use the the flavor mapping in AgentIdentity. var targetPlatformIdentifier = AgentIdentity.GetFlavorId(workbook.PlatformTargets [0]); #pragma warning restore 0618 // initialize the session based on manifest metadata from the workbook file language = workbook.GetLanguageDescriptions().First(); await session.InitializeAsync(new InteractiveSessionDescription ( language, targetPlatformIdentifier, new EvaluationEnvironment(Environment.CurrentDirectory))); // restore NuGet packages await session.PackageManagerService.RestoreAsync( workbook.Pages.SelectMany(page => page.Packages)); // insert and evaluate cells in the workbook foreach (var cell in workbook.IndexPage.Contents.OfType <CodeCell> ()) { var buffer = cell.CodeAnalysisBuffer.Value; lastCodeCellId = await session.EvaluationService.InsertCodeCellAsync( buffer, lastCodeCellId); ForegroundColor = ConsoleColor.DarkYellow; Write(GetPrompt()); ResetColor(); WriteLine(buffer); await session.EvaluationService.EvaluateAsync(lastCodeCellId); if (lastCellEvaluationStatus != CodeCellEvaluationStatus.Success) { break; } } return(0); }
public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError) { Log.Info(TAG, $"url: {url}, typeName: {typeName}"); outError = AppDelegate.SuppressionNSError; try { if (!url.IsFileUrl || new FilePath(url.Path).IsChildOfDirectory(NSBundle.MainBundle.ResourcePath)) { FileUrl = null; } else if (!WorkbookPackage.IsPossiblySupported(url.Path)) { throw new FileNotFoundException( Catalog.GetString("The file does not exist."), url.Path); } var urlStr = url.AbsoluteString; Uri uri; // VSM 7.1.1297 shipped with a bug that double-escaped URIs. Detect this case, and // unescape before parsing if necessary. if (urlStr != null && urlStr.Contains("assemblySearchPath=%252F")) { urlStr = Uri.UnescapeDataString(urlStr); uri = new Uri(urlStr); } else { uri = url; } Session = new ClientSession((ClientSessionUri)uri); } catch (Exception e) { e.ToUserPresentable(Catalog.Format(Catalog.GetString( "“{0}” could not be opened.", comment: "'{0}' is a URL "), url)).Present(); return(false); } outError = null; return(true); }
public Dictionary <WorkbookPage, List <FilePath> > Visit(WorkbookPackage package) { if (package == null) { throw new ArgumentNullException(nameof(package)); } var dependencies = new Dictionary <WorkbookPage, List <FilePath> > (); foreach (var page in package.Pages) { dependencies.Add(page, Visit(page) .Where(path => package.WorkingBasePath.Combine(path).FileExists) .ToList()); } return(dependencies); }
public ClientSession(ClientSessionUri clientSessionUri) { if (clientSessionUri == null) { throw new ArgumentNullException(nameof(clientSessionUri)); } Uri = clientSessionUri; SessionKind = clientSessionUri.SessionKind; agent = new AgentConnection(clientSessionUri.AgentType); Id = Guid.NewGuid(); clientWebServerUri = ClientApp.SharedInstance.WebServer.AddSession(this); Workbook = new WorkbookPackage(Uri.WorkbookPath); Workbook.PropertyChanged += Workbook_PropertyChanged; UpdateTitle(); }
/// <summary> /// Provides very basic workbook parsing and shunting of code cells /// into the evaluation service. Does not display non-code-cell contents /// but does evaluate a workbook from top-to-bottom. Restores nuget /// packages from the workbook's manifest. /// </summary> static async Task <int> WorkbookPlayerMain(string workbookPath) { var path = new FilePath(workbookPath); if (!path.FileExists) { Error.WriteLine($"File does not exist: {path}"); return(1); } // load the workbook file var workbook = new WorkbookPackage(path); await workbook.Open( quarantineInfo => Task.FromResult(true), path); // create and get ready to deal with the session; a more complete // client should handle more than just OnNext from the observer. var session = InteractiveSession.CreateWorkbookSession(); session.Events.Subscribe(new Observer <InteractiveSessionEvent> (OnSessionEvent)); #pragma warning disable 0618 // TODO: WorkbookDocumentManifest needs to eliminate AgentType like we've done on web // to avoid having to use the the flavor mapping in AgentIdentity. var targetPlatformIdentifier = AgentIdentity.GetFlavorId(workbook.PlatformTargets [0]); #pragma warning restore 0618 // initialize the session based on manifest metadata from the workbook file language = workbook.GetLanguageDescriptions().First(); await session.InitializeAsync(new InteractiveSessionDescription ( language, targetPlatformIdentifier, new EvaluationEnvironment(Environment.CurrentDirectory))); // restore NuGet packages await session.PackageManagerService.RestoreAsync( workbook.Pages.SelectMany(page => page.Packages)); // insert and evaluate cells in the workbook foreach (var cell in workbook.IndexPage.Contents.OfType <CodeCell> ()) { var buffer = cell.CodeAnalysisBuffer.Value; lastCodeCellId = await session.EvaluationService.InsertCodeCellAsync( buffer, lastCodeCellId); WriteReplPrompt(); WriteLine(buffer); await session.EvaluationService.EvaluateAsync(lastCodeCellId); await EvaluationServiceRaceBug(); if (lastCellEvaluationStatus != CodeCellEvaluationStatus.Success) { break; } } return(0); }