From ea9ba34fa5bb659587f21d5dd979e635f067a8e9 Mon Sep 17 00:00:00 2001 From: Stuart Lodge Date: Sun, 11 Nov 2018 18:03:11 +0000 Subject: [PATCH 1/3] This made part of the VS build and run work... --- .../Xamarin.Interactive.Client.Windows.csproj | 14 ++++++-------- Package/Windows/AgentAppFiles.wxs | 17 +++++++++-------- .../Windows/DotNetCoreAgentAppFiles-win-x86.wxs | 6 ++++++ .../Xamarin.Workbooks.Wpf.csproj | 5 ++++- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj b/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj index 444d20be8..b7253db24 100644 --- a/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj +++ b/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj @@ -94,6 +94,12 @@ 4.0.5150.10665 + + 1.1.2 + + + 1.1.1 + @@ -264,14 +270,6 @@ {0fd4b1dd-45a8-4f02-beb0-5881cd512573} CommonMark.Base - - {2e1fb0df-f9bb-4909-9f32-2d9d022a8e57} - Core - - - {aa0c00cb-8699-4f37-bfae-40ca87acc06d} - Shell - {60af04be-1b6b-411b-bcba-c95eafbd7ac0} Xamarin.PropertyEditing.Windows diff --git a/Package/Windows/AgentAppFiles.wxs b/Package/Windows/AgentAppFiles.wxs index 17d761aae..cccc9389a 100644 --- a/Package/Windows/AgentAppFiles.wxs +++ b/Package/Windows/AgentAppFiles.wxs @@ -300,17 +300,18 @@ + + + - - - - - - - + + + + + + - diff --git a/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs b/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs index 3ccdbf0d1..cc94c2ea8 100644 --- a/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs +++ b/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs @@ -664,6 +664,12 @@ + + + + + + \ No newline at end of file diff --git a/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj b/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj index 2f07d49c3..06577618f 100644 --- a/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj +++ b/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj @@ -60,6 +60,9 @@ 4.4.0 + + 1.1.2 + @@ -121,4 +124,4 @@ - + \ No newline at end of file From 5b88c7f709e2b58130d085908141eca4d85fd436 Mon Sep 17 00:00:00 2001 From: Stuart Lodge Date: Sun, 18 Nov 2018 10:47:16 +0000 Subject: [PATCH 2/3] Work in progress... --- .../API/Xamarin.Interactive.api.cs | 7 +++++++ .../CodeAnalysis/Evaluation.cs | 3 ++- .../CodeAnalysis/EvaluationContext.cs | 19 ++++++++++-------- .../CodeAnalysis/IEvaluation.cs | 7 +++++++ .../Workbook/Models/WorkbookPageViewModel.cs | 20 +++++++++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Agents/Xamarin.Interactive/API/Xamarin.Interactive.api.cs b/Agents/Xamarin.Interactive/API/Xamarin.Interactive.api.cs index 5fe699a10..e135ec084 100644 --- a/Agents/Xamarin.Interactive/API/Xamarin.Interactive.api.cs +++ b/Agents/Xamarin.Interactive/API/Xamarin.Interactive.api.cs @@ -283,6 +283,13 @@ EvaluationPhase Phase { object Result { get; } + SimpleVariable[] GlobalVariables { get; } + } + public struct SimpleVariable + { + public string FieldName { get; set; } + public object Value { get; set; } + public string ValueReadException { get; set; } } public interface IEvaluationContext { diff --git a/Agents/Xamarin.Interactive/CodeAnalysis/Evaluation.cs b/Agents/Xamarin.Interactive/CodeAnalysis/Evaluation.cs index 4917fb929..d81572aaa 100644 --- a/Agents/Xamarin.Interactive/CodeAnalysis/Evaluation.cs +++ b/Agents/Xamarin.Interactive/CodeAnalysis/Evaluation.cs @@ -6,7 +6,7 @@ // Licensed under the MIT License. using System; - +using System.Collections.Generic; using Xamarin.Interactive.Protocol; using Xamarin.Interactive.Representations.Reflection; @@ -37,5 +37,6 @@ public Compilation Compilation { public int UICultureLCID { get; set; } public bool InitializedAgentIntegration { get; set; } public AssemblyDefinition [] LoadedAssemblies { get; set; } + public SimpleVariable[] GlobalVariables { get; set; } } } \ No newline at end of file diff --git a/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs b/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs index fab0d0563..6caccf48e 100644 --- a/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs +++ b/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs @@ -12,7 +12,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; - +using Xamarin.Interactive; using Xamarin.Interactive.Core; using Xamarin.Interactive.Representations; using Xamarin.Interactive.Representations.Reflection; @@ -145,6 +145,9 @@ public async Task RunAsync ( // captured output back to the client for rendering. stopwatch.Start (); result.Result = await CoreRunAsync (compilation, cancellationToken); + result.GlobalVariables = GetGlobalVariables ()?.Select(v => + new SimpleVariable() { FieldName = v.Field.Name, Value = v.Value, ValueReadException = v.ValueReadException?.ToString() }) + .ToArray(); } catch (AggregateException e) when (e.InnerExceptions?.Count == 1) { evaluationException = e; // the Roslyn-emitted script delegates are async, so all exceptions @@ -237,13 +240,6 @@ async Task CoreRunAsync ( void CapturedOutputWriter_SegmentCaptured (CapturedOutputSegment segment) => agent.MessageChannel.Push (segment); - public struct Variable - { - public FieldInfo Field { get; set; } - public object Value { get; set; } - public Exception ValueReadException { get; set; } - } - public IReadOnlyCollection GetGlobalVariables () { var globalVars = new Dictionary (); @@ -276,4 +272,11 @@ public IReadOnlyCollection GetGlobalVariables () return globalVars.Values as IReadOnlyCollection; } } + + public struct Variable + { + public FieldInfo Field { get; set; } + public object Value { get; set; } + public Exception ValueReadException { get; set; } + } } \ No newline at end of file diff --git a/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs b/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs index f11f540ac..e11526b16 100644 --- a/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs +++ b/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs @@ -28,5 +28,12 @@ public interface IEvaluation /// representation value. /// object Result { get; } + SimpleVariable [] GlobalVariables { get; } + } + public struct SimpleVariable + { + public string FieldName { get; set; } + public object Value { get; set; } + public string ValueReadException { get; set; } } } \ No newline at end of file diff --git a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs index cbad62c60..db9395810 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.Globalization; using System.Linq; using System.Threading; @@ -25,6 +26,8 @@ using Xamarin.Interactive.Representations; using Xamarin.Interactive.Representations.Reflection; using Xamarin.Interactive.Workbook.Views; +using StackFrame = Xamarin.Interactive.Representations.Reflection.StackFrame; +using StackTrace = Xamarin.Interactive.Representations.Reflection.StackTrace; namespace Xamarin.Interactive.Workbook.Models { @@ -615,11 +618,28 @@ e is CultureNotFoundException || result.ResultHandling); } + void UpdateGlobalVariables (SimpleVariable[] resultGlobalVariables) + { + if (resultGlobalVariables == null) { + Debug.WriteLine ("No Global Variables available..."); + return; + } else { + Debug.WriteLine ("Global Variables available..."); + Debug.WriteLine ("-----------------------------"); + foreach (var v in resultGlobalVariables) { + Debug.WriteLine($"{v.FieldName} {v.Value} {v.ValueReadException}"); + } + + } + } + void RenderResult (Evaluation result) { if (result == null) return; + UpdateGlobalVariables (result.GlobalVariables); + var codeCellState = GetCodeCellStateById (result.CodeCellId); if (codeCellState == null) return; From fb0e72d09a4b749246089b13fdd9590fd5f36a01 Mon Sep 17 00:00:00 2001 From: Stuart Lodge Date: Sun, 25 Nov 2018 10:33:43 +0000 Subject: [PATCH 3/3] Attempt at getting a Globals view working --- .../CodeAnalysis/EvaluationContext.cs | 9 ++- .../CodeAnalysis/IEvaluation.cs | 4 ++ .../Workbook/Models/WorkbookPageViewModel.cs | 12 +++- .../Workbook/Views/GlobalsCellView.cs | 67 +++++++++++++++++++ .../Workbook/Views/XcbWorkbookPageView.cs | 16 ++++- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 Clients/Xamarin.Interactive.Client/Workbook/Views/GlobalsCellView.cs diff --git a/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs b/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs index 6caccf48e..be34486c8 100644 --- a/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs +++ b/Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs @@ -145,8 +145,13 @@ public async Task RunAsync ( // captured output back to the client for rendering. stopwatch.Start (); result.Result = await CoreRunAsync (compilation, cancellationToken); - result.GlobalVariables = GetGlobalVariables ()?.Select(v => - new SimpleVariable() { FieldName = v.Field.Name, Value = v.Value, ValueReadException = v.ValueReadException?.ToString() }) + result.GlobalVariables = + GetGlobalVariables ()?.Select(v => + new SimpleVariable() { + FieldName = v.Field.Name, + Value = agent.RepresentationManager.Prepare(v.Value), + ValueReadException = v.ValueReadException?.ToString() + }) .ToArray(); } catch (AggregateException e) when (e.InnerExceptions?.Count == 1) { evaluationException = e; diff --git a/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs b/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs index e11526b16..12a93b8b2 100644 --- a/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs +++ b/Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs @@ -5,6 +5,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; + namespace Xamarin.Interactive.CodeAnalysis { /// @@ -30,6 +32,8 @@ public interface IEvaluation object Result { get; } SimpleVariable [] GlobalVariables { get; } } + + [Serializable] public struct SimpleVariable { public string FieldName { get; set; } diff --git a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs index db9395810..ad42a6d34 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPageViewModel.cs @@ -159,6 +159,7 @@ void PopulateCompilationWorkspace () void LoadWorkbookCells () { + CreateAndInsertGlobalsCell (); foreach (var cell in WorkbookPage.Contents) { switch (cell) { case CodeCell codeCell: @@ -171,6 +172,14 @@ void LoadWorkbookCells () } } + protected virtual void CreateAndInsertGlobalsCell () + { + } + + protected virtual void UpdateGlobals (SimpleVariable [] globals) + { + } + protected CodeCellState InsertCodeCell (Cell previousCell) => InsertCodeCell (new CodeCell ("csharp"), previousCell); @@ -225,6 +234,7 @@ void InsertMarkdownCell (MarkdownCell newCell, Cell previousCell) InsertCellInViewModel (newCell, previousCell); } + void InsertCellInDocumentModel (Cell newCell, Cell previousCell) { if (newCell.Document != null) @@ -629,8 +639,8 @@ void UpdateGlobalVariables (SimpleVariable[] resultGlobalVariables) foreach (var v in resultGlobalVariables) { Debug.WriteLine($"{v.FieldName} {v.Value} {v.ValueReadException}"); } - } + UpdateGlobals(resultGlobalVariables); } void RenderResult (Evaluation result) diff --git a/Clients/Xamarin.Interactive.Client/Workbook/Views/GlobalsCellView.cs b/Clients/Xamarin.Interactive.Client/Workbook/Views/GlobalsCellView.cs new file mode 100644 index 000000000..10f59f469 --- /dev/null +++ b/Clients/Xamarin.Interactive.Client/Workbook/Views/GlobalsCellView.cs @@ -0,0 +1,67 @@ +// Contributed under the MIT License. + +using System; +using System.Globalization; +using Xamarin.CrossBrowser; +using Xamarin.Interactive.Editor; +using Xamarin.Interactive.Rendering; +using Xamarin.Interactive.CodeAnalysis; + +namespace Xamarin.Interactive.Workbook.Views +{ + sealed class GlobalsCellView : CellView + { + HtmlElement resultElem; + readonly RendererContext rendererContext; + + public GlobalsCellView ( + HtmlDocument document + , RendererContext rendererContext) : base ( + document, + "submission csharp") + { + //var container = Document.CreateElement ("div", "editor"); + //container.InnerHTML = "HELLO WORLD"; + //System.Threading.SynchronizationContext.Current.Post (o => ((dynamic)container).style.opacity = 1, null); + //ContentElement.AppendChild(container); + ContentElement.AppendChild (resultElem = CreateContentContainer ("results")); + this.rendererContext = rendererContext + ?? throw new ArgumentNullException (nameof (rendererContext)); + } + + static void RemoveElement (ref HtmlElement element) + { + element?.ParentElement?.RemoveChild (element); + element = null; + } + + public void Reset () + { + RemoveElement (ref resultElem); + } + + + public void RenderResult ( + CultureInfo cultureInfo, + SimpleVariable [] results) + { + resultElem.RemoveChildren (); + + // would be nice to pass in a single thing here really + // - so work more like GlobalVars... + foreach (var result in results) { + var childElem = CreateContentContainer ("result"); + resultElem.AppendChild (childElem); + rendererContext.Render ( + RenderState.Create (result.Value, cultureInfo), + childElem); + } + } + + public override IEditor Editor => null; + public override void Focus (bool scrollIntoView = true) + { + // empty! + } + } +} \ No newline at end of file diff --git a/Clients/Xamarin.Interactive.Client/Workbook/Views/XcbWorkbookPageView.cs b/Clients/Xamarin.Interactive.Client/Workbook/Views/XcbWorkbookPageView.cs index e1cd9961e..4e3a1e0cb 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/Views/XcbWorkbookPageView.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/Views/XcbWorkbookPageView.cs @@ -196,6 +196,18 @@ protected override void BindMarkdownCellToView (MarkdownCell cell) cell.View = view; } + GlobalsCellView _globalsCellView; + + protected override void CreateAndInsertGlobalsCell () + { + // not used... went a different way... + } + + protected override void UpdateGlobals (SimpleVariable [] globals) + { + _globalsCellView?.RenderResult(CultureInfo.CurrentUICulture, globals); + } + protected override void BindCodeCellToView (CodeCell cell, CodeCellState codeCellState) { var codeCellView = new CodeCellView ( @@ -336,7 +348,9 @@ void UpdateFocusedCellViewFooter (bool focused) void AppendFirstCellActions (HtmlElement parentElem) { var document = webView.Document; - firstCellActionsArticle = document.CreateElement ("article"); + _globalsCellView = new GlobalsCellView (webView.Document, rendererContext); + firstCellActionsArticle = _globalsCellView.RootElement; + //firstCellActionsArticle = document.CreateElement ("article"); parentElem.AppendChild (firstCellActionsArticle); var firstCellActionsFooter = document.CreateElement ("footer");