Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Agents/Xamarin.Interactive/API/Xamarin.Interactive.api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion Agents/Xamarin.Interactive/CodeAnalysis/Evaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Licensed under the MIT License.

using System;

using System.Collections.Generic;
using Xamarin.Interactive.Protocol;
using Xamarin.Interactive.Representations.Reflection;

Expand Down Expand Up @@ -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; }
}
}
24 changes: 16 additions & 8 deletions Agents/Xamarin.Interactive/CodeAnalysis/EvaluationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,6 +145,14 @@ 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 = agent.RepresentationManager.Prepare(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
Expand Down Expand Up @@ -237,13 +245,6 @@ async Task<object> 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<Variable> GetGlobalVariables ()
{
var globalVars = new Dictionary<string, Variable> ();
Expand Down Expand Up @@ -276,4 +277,11 @@ public IReadOnlyCollection<Variable> GetGlobalVariables ()
return globalVars.Values as IReadOnlyCollection<Variable>;
}
}

public struct Variable
{
public FieldInfo Field { get; set; }
public object Value { get; set; }
public Exception ValueReadException { get; set; }
}
}
11 changes: 11 additions & 0 deletions Agents/Xamarin.Interactive/CodeAnalysis/IEvaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Xamarin.Interactive.CodeAnalysis
{
/// <summary>
Expand All @@ -28,5 +30,14 @@ public interface IEvaluation
/// representation value.
/// </summary>
object Result { get; }
SimpleVariable [] GlobalVariables { get; }
}

[Serializable]
public struct SimpleVariable
{
public string FieldName { get; set; }
public object Value { get; set; }
public string ValueReadException { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<PackageReference Include="MouseKeyboardActivityMonitor">
<Version>4.0.5150.10665</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Core">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Shell">
<Version>1.1.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Page Include="App.xaml">
Expand Down Expand Up @@ -264,14 +270,6 @@
<Project>{0fd4b1dd-45a8-4f02-beb0-5881cd512573}</Project>
<Name>CommonMark.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\WindowsAPICodePack\Core\Core.csproj">
<Project>{2e1fb0df-f9bb-4909-9f32-2d9d022a8e57}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\WindowsAPICodePack\Shell\Shell.csproj">
<Project>{aa0c00cb-8699-4f37-bfae-40ca87acc06d}</Project>
<Name>Shell</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\Xamarin.PropertyEditing\Xamarin.PropertyEditing.Windows\Xamarin.PropertyEditing.Windows.csproj">
<Project>{60af04be-1b6b-411b-bcba-c95eafbd7ac0}</Project>
<Name>Xamarin.PropertyEditing.Windows</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -156,6 +159,7 @@ void PopulateCompilationWorkspace ()

void LoadWorkbookCells ()
{
CreateAndInsertGlobalsCell ();
foreach (var cell in WorkbookPage.Contents) {
switch (cell) {
case CodeCell codeCell:
Expand All @@ -168,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);

Expand Down Expand Up @@ -222,6 +234,7 @@ void InsertMarkdownCell (MarkdownCell newCell, Cell previousCell)
InsertCellInViewModel (newCell, previousCell);
}


void InsertCellInDocumentModel (Cell newCell, Cell previousCell)
{
if (newCell.Document != null)
Expand Down Expand Up @@ -615,11 +628,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}");
}
}
UpdateGlobals(resultGlobalVariables);
}

void RenderResult (Evaluation result)
{
if (result == null)
return;

UpdateGlobalVariables (result.GlobalVariables);

var codeCellState = GetCodeCellStateById (result.CodeCellId);
if (codeCellState == null)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -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!
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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");
Expand Down
17 changes: 9 additions & 8 deletions Package/Windows/AgentAppFiles.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,18 @@
<Component Id="WpfAgentApp.System.Xml.XPath.XDocument.dll" Guid="54907165-7367-4BFB-AF25-88BBFE04AE0E">
<File Id="WpfAgentApp.System.Xml.XPath.XDocument.dll" Source="$(var.WpfAgentAppDirectory)\System.Xml.XPath.XDocument.dll" />
</Component>
<Component Id="WpfAgentApp.Microsoft.WindowsAPICodePack.dll" Guid="DC2BA773-3248-4AF3-ACE8-F9EB248A1A09">
<File Id="WpfAgentApp.Microsoft.WindowsAPICodePack.dll" Source="$(var.WpfAgentAppDirectory)\Microsoft.WindowsAPICodePack.dll" />
</Component>
</ComponentGroup>

<?ifdef AndroidSupport ?>
<?define AndroidAgentAppDirectory="..\..\_build\$(var.Configuration)\WorkbookApps\Android" ?>
<ComponentGroup Id="AndroidAgentAppComponents" Directory="AndroidAgentAppInstallFolder">
<Component Id="AndroidAgentApp.apk" Guid="6CD2D3A9-40D7-4583-BDD1-5B4711431381">
<File Id="AndroidAgentApp.apk" Source="$(var.AndroidAgentAppDirectory)\com.xamarin.workbook_app_android-Signed.apk" />
</Component>
</ComponentGroup>
<?define AndroidAgentAppDirectory="..\..\_build\$(var.Configuration)\WorkbookApps\Android" ?>
<ComponentGroup Id="AndroidAgentAppComponents" Directory="AndroidAgentAppInstallFolder">
<Component Id="AndroidAgentApp.apk" Guid="6CD2D3A9-40D7-4583-BDD1-5B4711431381">
<File Id="AndroidAgentApp.apk" Source="$(var.AndroidAgentAppDirectory)\com.xamarin.workbook_app_android-Signed.apk" />
</Component>
</ComponentGroup>
<?endif?>

<ComponentGroup Id="WorkbookManifestComponents" Directory="AgentAppInstallFolder">
<Component Id="workbookapps.json" Guid="47A8314B-0E4A-48BD-AA24-84A18AE06291">
<File Id="workbookapps.json" Source="..\..\_build\$(var.Configuration)\WorkbookApps\workbookapps.json" />
Expand Down
6 changes: 6 additions & 0 deletions Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@
<Component Id="DNCAgentAppwinx86.System.Memory.dll" Guid="FDA9A09B-F94B-4509-BAB8-919511A724DF">
<File Id="DNCAgentAppwinx86.System.Memory.dll" Source="$(var.DotNetCoreAssembliesDir)\System.Memory.dll" />
</Component>
<Component Id="DNCAgentAppwinx86.mscordaccore_x86_x86_4.6.26515.07.dll" Guid="A79CC6CE-1A0A-4FCC-9EE9-B40A26274239">
<File Id="DNCAgentAppwinx86.mscordaccore_x86_x86_4.6.26515.07.dll" Source="$(var.DotNetCoreAssembliesDir)\mscordaccore_x86_x86_4.6.26515.07.dll" />
</Component>
<Component Id="DNCAgentAppwinx86.sos_x86_x86_4.6.26515.07.dll" Guid="B4810B78-BFF9-41CD-98FD-38674A4BB261">
<File Id="DNCAgentAppwinx86.sos_x86_x86_4.6.26515.07.dll" Source="$(var.DotNetCoreAssembliesDir)\sos_x86_x86_4.6.26515.07.dll" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Core">
<Version>1.1.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -121,4 +124,4 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="Build.targets" />
</Project>
</Project>