Skip to content

Commit

Permalink
Multiple child windows from manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
kruplm committed Nov 23, 2022
1 parent 6e6c9bb commit 1fb9852
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
15 changes: 10 additions & 5 deletions Tryouts/Prototypes/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ public partial class MainWindow : Window
{
private List<WebContent> webContentList = new List<WebContent>();
private ManifestModel config;
private ModuleModel[]? arr;

public MainWindow()
{
InitializeComponent();

config = new ManifestParser().manifest;
arr = config.Modules;
}

private void ShowChild_Click(object sender, RoutedEventArgs e)
{
var webContent = new WebContent(config.Url);
webContent.Title = config.AppName;
webContent.Owner = this;
webContentList.Add(webContent);
arr.ToList().ForEach(item => {
var webContent = new WebContent(item.Url);
webContent.Title = item.AppName;

webContent.Show();
webContent.Owner = this;
webContentList.Add(webContent);

webContent.Show();
});
}

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
Expand Down
10 changes: 2 additions & 8 deletions Tryouts/Prototypes/Shell/Manifest/ManifestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ namespace Shell
[Serializable]
internal sealed class ManifestModel
{
public string AppName { get; set; } = string.Empty; //set?
public string Url { get; set; } = string.Empty; //set?

public ModuleModel[]? Modules { get; set; }

public static JsonSerializerOptions JsonSerializerOptions = new()
{
Converters =
{
new JsonStringEnumConverter()
},
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
PropertyNameCaseInsensitive = true
};
}
}
Expand Down
12 changes: 10 additions & 2 deletions Tryouts/Prototypes/Shell/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ public void OpenManifestFile()
{
using (StreamReader r = new StreamReader("./Manifest/exampleManifest.json"))
{
string fileContent = r.ReadToEnd();
manifest = JsonSerializer.Deserialize<ManifestModel>(fileContent);
try
{
string fileContent = r.ReadToEnd();
manifest = JsonSerializer.Deserialize<ManifestModel>(fileContent, ManifestModel.JsonSerializerOptions);
}
catch (Exception e)
{

throw;
}

r.Close();
}
}
Expand Down
13 changes: 13 additions & 0 deletions Tryouts/Prototypes/Shell/Manifest/ModuleModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Shell
{
[Serializable]
internal sealed class ModuleModel
{
public string AppName { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
}
}
16 changes: 14 additions & 2 deletions Tryouts/Prototypes/Shell/Manifest/exampleManifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"AppName": "TestApp",
"Url": "http://www.morganstanley.com"
"modules":[
{
"appName": "TestApp",
"url": "http://www.morganstanley.com"
},
{
"appName": "TestApp2",
"url": "http://www.microsoft.com"
},
{
"appName": "TestApp3",
"url": "http://www.google.com"
}
]
}

0 comments on commit 1fb9852

Please sign in to comment.