Skip to content
Merged
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
1 change: 0 additions & 1 deletion AdamController.Services/AdamController.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2420.47" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="NetCoreServer" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Prism.Core" Version="8.1.97" />
<PackageReference Include="Prism.DryIoc" Version="8.1.97" />
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Newtonsoft.Json;
using System;
using System;
using System.Text.Json.Serialization;

namespace AdamController.Services.WebViewProviderDependency
{
public class WebMessageJsonReceived : EventArgs
{
[JsonProperty("action")]
[JsonPropertyName("action")]
public string Action { get; set; }

[JsonProperty("data")]
[JsonPropertyName("data")]
public string Data { get; set; }
}
}
3 changes: 0 additions & 3 deletions Legacy/AdamBlocklyLibrary/AdamBlocklyLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
5 changes: 2 additions & 3 deletions Legacy/AdamBlocklyLibrary/Enum/BlocklyTheme.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Enum
{
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum BlocklyTheme
{
Classic,
Expand Down
5 changes: 2 additions & 3 deletions Legacy/AdamBlocklyLibrary/Enum/CategoryStyle.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Enum
{
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum CategoryStyle
{
colour_category,
Expand Down
5 changes: 2 additions & 3 deletions Legacy/AdamBlocklyLibrary/Enum/Render.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Enum
{
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Render
{
geras,
Expand Down
8 changes: 5 additions & 3 deletions Legacy/AdamBlocklyLibrary/Scripts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json;

namespace AdamBlocklyLibrary
{
Expand Down Expand Up @@ -56,7 +56,8 @@ public static string SerealizeObjectToJsonString(string functionName, params obj
string script = functionName + "('";
for (int i = 0; i < parameters.Length; i++)
{
script += JsonConvert.SerializeObject(parameters[i]);
script += JsonSerializer.Serialize(parameters[i]);

if (i < parameters.Length - 1)
{
script += ", ";
Expand All @@ -72,7 +73,8 @@ public static string SerealizeObject(string functionName, params object[] parame
string script = functionName + "(";
for (int i = 0; i < parameters.Length; i++)
{
script += JsonConvert.SerializeObject(parameters[i]);
script += JsonSerializer.Serialize(parameters[i]);

if (i < parameters.Length - 1)
{
script += ", ";
Expand Down
20 changes: 10 additions & 10 deletions Legacy/AdamBlocklyLibrary/Toolbox/CategoryToolbox.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@

using AdamBlocklyLibrary.Enum;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Toolbox
{
public class CategoryToolbox
{
[JsonProperty("kind")]
[JsonPropertyName("kind")]
public string Kind { get; } = "category";

/// <summary>
/// Name toolbox
/// </summary>
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonProperty("toolboxitemid")]
internal string ToolboxItemId => Guid.NewGuid().ToString();
[JsonPropertyName("toolboxitemid")]
public string ToolboxItemId => Guid.NewGuid().ToString();

[JsonProperty("categorystyle")]
[JsonPropertyName("categorystyle")]
public CategoryStyle CategoryStyle { get; set; }

/// <summary>
/// For set contents use <see cref="CategoryToolboxContents"/> or <see cref="SimpleToolboxContents"/>.
/// If <see cref="CategoryToolboxContents"/> is given, then <see cref="SimpleToolboxContents"/> in <see cref="Contents"/> will not be serialized
/// </summary>
[JsonProperty("contents")]
[JsonPropertyName("contents")]
public object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents;

/// <summary>
Expand All @@ -47,7 +47,7 @@ public class CategoryToolbox
/// Note the British spelling. The colour is a number (0-360) defining the hue
/// By default categry null, is visible without color
/// </summary>
[JsonProperty("colour")]
[JsonPropertyName("colour")]
public string Colour { get; set; } = null;

/// <summary>
Expand All @@ -60,7 +60,7 @@ public class CategoryToolbox
/// <summary>
/// For set ExpandedCategory use Expanded
/// </summary>
[JsonProperty("expanded")]
[JsonPropertyName("expanded")]
internal string ExpandedCategory => Expanded ? Expanded.ToString().ToLower() : null;

/// <summary>
Expand All @@ -72,7 +72,7 @@ public class CategoryToolbox
/// <summary>
/// For set HiddenCategory use Hidden
/// </summary>
[JsonProperty("hidden")]
[JsonPropertyName("hidden")]
internal string HiddenCategory => Hidden.ToString().ToLower();

}
Expand Down
6 changes: 3 additions & 3 deletions Legacy/AdamBlocklyLibrary/Toolbox/SimpleToolbox.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using AdamBlocklyLibrary.Enum;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Toolbox
{
public class SimpleToolbox
{
[JsonProperty("kind")]
[JsonPropertyName("kind")]
public string Kind { get; } = "block";

[JsonIgnore]
public BlockType Type { get; set; }

[JsonProperty("type")]
[JsonPropertyName("type")]
public string TypeString => Type.ToString();
}
}
10 changes: 5 additions & 5 deletions Legacy/AdamBlocklyLibrary/Toolbox/Toolbox.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace AdamBlocklyLibrary.Toolbox
{
public class Toolbox
{
[JsonProperty("kind")]
[JsonPropertyName("kind")]
public string Kind { get; private set; } = "categoryToolbox";

/// <summary>
/// For set contents use <see cref="CategoryToolboxContents"/> or <see cref="SimpleToolboxContents"/>.
/// If <see cref="CategoryToolboxContents"/> is given, then <see cref="SimpleToolboxContents"/> in <see cref="Contents"/> will not be serialized
/// </summary>
[JsonProperty("contents")]
internal object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents;
[JsonPropertyName("contents")]
public object Contents => CategoryToolboxContents ?? (object)SimpleToolboxContents;

/// <summary>
/// If <see cref="CategoryToolboxContents"/> is given, then <see cref="SimpleToolboxContents"/> in <see cref="Contents"/> will not be serialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using AdamController.Services.Interfaces;
using AdamController.Services.WebViewProviderDependency;
using Microsoft.Web.WebView2.Core;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -19,19 +20,21 @@ public partial class ScratchControlView : UserControl
#region Services

private readonly IWebViewProvider mWebViewProvider;

private readonly IStatusBarNotificationDeliveryService mStatusBarNotification;

#endregion

private readonly string mPathToSource = Path.Combine(FolderHelper.CommonDirAppData, "BlocklySource");
private readonly string mPath = Path.Combine(Path.GetTempPath(), "AdamBrowser");


public ScratchControlView(IWebViewProvider webViewProvider)
public ScratchControlView(IWebViewProvider webViewProvider, IStatusBarNotificationDeliveryService statusBarNotification)
{
InitializeComponent();
InitializeWebViewCore();

mWebViewProvider = webViewProvider;
mStatusBarNotification = statusBarNotification;

WebView.CoreWebView2InitializationCompleted += WebViewCoreWebView2InitializationCompleted;
WebView.NavigationCompleted += WebViewNavigationCompleted;
Expand Down Expand Up @@ -72,18 +75,34 @@ private async void InitializeWebViewCore()

private void WebViewCoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
WebView.CoreWebView2.Settings.AreDevToolsEnabled = true;
//unused options?
//WebView.CoreWebView2.Settings.AreDevToolsEnabled = true;
//WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true;

WebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = !Settings.Default.DontShowBrowserMenuInBlockly;
WebView.CoreWebView2.Settings.AreHostObjectsAllowed = true;
WebView.CoreWebView2.SetVirtualHostNameToFolderMapping("localhost", mPathToSource, CoreWebView2HostResourceAccessKind.Allow);
WebView.CoreWebView2.Navigate("https://localhost/index.html");
}

private void WebViewWebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
dynamic jsonClean = JsonConvert.DeserializeObject(e.WebMessageAsJson);
WebMessageJsonReceived receivedResult = JsonConvert.DeserializeObject<WebMessageJsonReceived>(jsonClean);
if (receivedResult == null) return;
JsonSerializerOptions options = new()
{
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString
};

WebMessageJsonReceived receivedResult;

try
{
string receivedString = e.TryGetWebMessageAsString();
receivedResult = JsonSerializer.Deserialize<WebMessageJsonReceived>(receivedString, options);
}
catch
{
mStatusBarNotification.AppLogMessage = "Error reading blokly code";
receivedResult = new WebMessageJsonReceived { Action = string.Empty, Data = string.Empty };
}

mWebViewProvider.WebViewMessageReceived(receivedResult);
}
Expand Down