diff --git a/src/DynamoCoreWpf/App.config b/src/DynamoCoreWpf/App.config index 3760693fa50..627537f9977 100644 --- a/src/DynamoCoreWpf/App.config +++ b/src/DynamoCoreWpf/App.config @@ -1,7 +1,69 @@ - + + diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj index 3460b261c7b..12a5c3ae931 100644 --- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj +++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj @@ -59,7 +59,7 @@ - 1.0.15 + 1.0.16 DynamoHome @@ -69,7 +69,7 @@ - + diff --git a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs index 4a631cc340a..cc57b5cadac 100644 --- a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs +++ b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Diagnostics; using System.Globalization; using System.IO; @@ -7,6 +8,7 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Text.Json; +using System.Text.Json.Serialization; using System.Windows; using System.Windows.Controls; using Autodesk.DesignScript.Runtime; @@ -34,6 +36,8 @@ public partial class HomePage : UserControl, IDisposable private static readonly string fontUrl = $"http://{virtualFolderName}/ArtifaktElement-Regular.woff"; private static readonly string virtualFolderPath = Path.Combine(Path.GetTempPath(), virtualFolderName); + private const string videoSettingsConfigString = "VideoSettings"; + private string fontFilePath; private StartPageViewModel startPage; @@ -254,6 +258,7 @@ internal void LoadingDone() SendGuidesData(); SendSamplesData(); SendRecentGraphsData(); + SendVideoData(); SetLocale(); } @@ -346,6 +351,69 @@ private async void SendGuidesData() await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.receiveInteractiveGuidesDataFromDotNet({jsonData})"); } } + + /// + /// Utility class with the correct structure for a video object + /// + private class Video + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("title")] + public string Title { get; set; } + + [JsonPropertyName("videoId")] + public string VideoId { get; set; } + + [JsonPropertyName("description")] + public string Description { get; set; } + } + + /// + /// Send the training videos stored in the config + /// + private async void SendVideoData() + { + var videoSettingsJson = GetStringResourceFromConfig(this, videoSettingsConfigString); + if (string.IsNullOrEmpty(videoSettingsJson)) + { + this.startPage.DynamoViewModel.Model.Logger.Log("No video settings found in the configuration."); + return; + } + + var videoSettings = JsonSerializer.Deserialize>(videoSettingsJson); + string jsonData = JsonSerializer.Serialize(videoSettings); + + if (dynWebView?.CoreWebView2 != null) + { + await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.receiveTrainingVideoDataFromDotNet({jsonData})"); + } + } + + /// + /// Retrieves a string stored in the app.config file + /// + /// The object ref to get the assembly from + /// The resource key + /// + private static string GetStringResourceFromConfig(object o, string serviceKey) + { + string resource = null; + if (o != null) + { + var path = o.GetType().Assembly.Location; + var config = ConfigurationManager.OpenExeConfiguration(path); + var key = config.AppSettings.Settings[serviceKey]; + + if (key != null) + { + resource = key.Value; + } + } + + return resource; + } #endregion #region Interactive Guides Commands @@ -761,4 +829,5 @@ public GuidedTourItem(string name, string description, string type, string thumb Thumbnail = thumbnail; } } + }