Skip to content

Commit

Permalink
Added msbuild target to embed and build composeui-fdc3 package to the…
Browse files Browse the repository at this point in the history
… Shell project, changed project's files to use filescoped namespace, little refactoring around naming variables
  • Loading branch information
lilla28 committed Aug 22, 2023
1 parent dfad4e3 commit 0ab99a1
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 189 deletions.
6 changes: 3 additions & 3 deletions src/shell/dotnet/Shell/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent;
using MorganStanley.ComposeUI.Messaging.Server.WebSocket;
using Shell.Utilities;
using System.Reflection;
using System.Diagnostics;
using Shell.Fdc3;

namespace Shell;
Expand Down Expand Up @@ -180,8 +181,7 @@ private void InjectMessageRouterConfig()

private void InjectFdc3()
{
string iife = ResourceReader.ReadResource(PreloadFdc3.Fdc3BundleResourceName);

var iife = ResourceReader.ReadResource(PreloadFdc3.Fdc3BundleResourceName);
WebWindow.AddPreloadScript(iife);
}
}
14 changes: 4 additions & 10 deletions src/shell/dotnet/Shell/Fdc3/PreloadFdc3.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shell.Fdc3;

namespace Shell.Fdc3
public static class PreloadFdc3
{
public static class PreloadFdc3
{
public static readonly string Fdc3BundleResourceName = @"Shell.fdc3-iife-bundle.js";
}
public static readonly string Fdc3BundleResourceName = @"Shell.fdc3-iife-bundle.js";

}
12 changes: 5 additions & 7 deletions src/shell/dotnet/Shell/ImageSource/DefaultImageSourcePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;

namespace Shell.ImageSource
{
public sealed class DefaultImageSourcePolicy : IImageSourcePolicy
namespace Shell.ImageSource;

public sealed class DefaultImageSourcePolicy : IImageSourcePolicy
{
public bool IsAllowed(Uri uri, Uri appUri)
{
public bool IsAllowed(Uri uri, Uri appUri)
{
return uri.Scheme.StartsWith("http") && uri.Host == appUri.Host;
}
return uri.Scheme.StartsWith("http") && uri.Host == appUri.Host;
}
}
45 changes: 22 additions & 23 deletions src/shell/dotnet/Shell/ImageSource/EnvironmentImageSourcePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
using System;
using System.Linq;

namespace Shell.ImageSource
namespace Shell.ImageSource;

public sealed class EnvironmentImageSourcePolicy : IImageSourcePolicy
{
public sealed class EnvironmentImageSourcePolicy : IImageSourcePolicy
private const string _allowListEnvVar = "COMPOSE_ALLOWED_IMAGE_SOURCES";
public bool IsAllowed(Uri uri, Uri appUri)
{
private const string _allowListEnvVar = "COMPOSE_ALLOWED_IMAGE_SOURCES";
public bool IsAllowed(Uri uri, Uri appUri)
{
var allowListString = Environment.GetEnvironmentVariable(_allowListEnvVar);

// Only allow http or https sources. If no sources are allowed,
if (!uri.Scheme.StartsWith("http"))
{
return false;
}
// If the source host is the same as the app host, allow it.
if (uri.Host == appUri.Host)
{
return true;
}
if (string.IsNullOrEmpty(allowListString))
{
return false;
}
var allowListString = Environment.GetEnvironmentVariable(_allowListEnvVar);

var allowedSources = allowListString.Split(';');
return allowedSources.Contains(uri.Host);
// Only allow http or https sources. If no sources are allowed,
if (!uri.Scheme.StartsWith("http"))
{
return false;
}
// If the source host is the same as the app host, allow it.
if (uri.Host == appUri.Host)
{
return true;
}
if (string.IsNullOrEmpty(allowListString))
{
return false;
}

var allowedSources = allowListString.Split(';');
return allowedSources.Contains(uri.Host);
}
}
9 changes: 4 additions & 5 deletions src/shell/dotnet/Shell/ImageSource/IImageSourcePolicy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;

namespace Shell.ImageSource
namespace Shell.ImageSource;

public interface IImageSourcePolicy
{
public interface IImageSourcePolicy
{
bool IsAllowed(Uri uri, Uri appUri);
}
bool IsAllowed(Uri uri, Uri appUri);
}
31 changes: 15 additions & 16 deletions src/shell/dotnet/Shell/ImageSource/ImageSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using System;
using System.Windows.Media.Imaging;

namespace Shell.ImageSource
namespace Shell.ImageSource;

public class ImageSourceProvider
{
public class ImageSourceProvider
private readonly IImageSourcePolicy _imageSourcePolicy;
public ImageSourceProvider(IImageSourcePolicy imageSourcePolicy)
{
IImageSourcePolicy _imageSourcePolicy;
public ImageSourceProvider(IImageSourcePolicy imageSourcePolicy)
_imageSourcePolicy = imageSourcePolicy;
}

public System.Windows.Media.ImageSource? GetImageSource(Uri uri, Uri appUri)
{
if (!uri.IsAbsoluteUri)
{
_imageSourcePolicy = imageSourcePolicy;
uri = new Uri(appUri, uri);
}

public System.Windows.Media.ImageSource? GetImageSource(Uri uri, Uri appUri)
if (_imageSourcePolicy.IsAllowed(uri, appUri))
{
if (!uri.IsAbsoluteUri)
{
uri = new Uri(appUri, uri);
}

if (_imageSourcePolicy.IsAllowed(uri, appUri))
{
return BitmapFrame.Create(uri);
}
return null;
return BitmapFrame.Create(uri);
}
return null;
}
}
89 changes: 38 additions & 51 deletions src/shell/dotnet/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,55 @@
using Manifest;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Ribbon;

namespace Shell
namespace Shell;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : RibbonWindow
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : RibbonWindow
{
internal List<WebWindow> webWindows { get; set; } = new List<WebWindow>();
private ManifestModel config;
private ModuleModel[]? modules;
internal List<WebWindow> WebWindows { get; set; } = new List<WebWindow>();
private ManifestModel _config;
private ModuleModel[]? _modules;

public MainWindow()
{
InitializeComponent();
public MainWindow()
{
InitializeComponent();

config = ManifestParser.OpenManifestFile("exampleManifest.json");
modules = config.Modules;
DataContext = modules;
}
_config = ManifestParser.OpenManifestFile("exampleManifest.json");
_modules = _config.Modules;
DataContext = _modules;
}

private void CreateWebWindow(ModuleModel item)
private void CreateWebWindow(ModuleModel item)
{
var options = new WebWindowOptions
{
var options = new WebWindowOptions
{
Title = item.AppName,
Url = item.Url,
IconUrl = item.IconUrl
};
Title = item.AppName,
Url = item.Url,
IconUrl = item.IconUrl
};

var webWindow = new WebWindow(options);
webWindow.Owner = this;
webWindow.Closed += WebWindowClosed;
webWindows.Add(webWindow);
webWindow.Show();
}
var webWindow = new WebWindow(options);
webWindow.Owner = this;
webWindow.Closed += WebWindowClosed;
WebWindows.Add(webWindow);
webWindow.Show();
}

private void WebWindowClosed(object? sender, EventArgs e)
{
webWindows.Remove((WebWindow)sender!);
}
private void WebWindowClosed(object? sender, EventArgs e)
{
WebWindows.Remove((WebWindow)sender!);
}

private void ShowChild_Click(object sender, RoutedEventArgs e)
{
var context = ((Button)sender).DataContext;

private void ShowChild_Click(object sender, RoutedEventArgs e)
{
var context = ((Button)sender).DataContext;

CreateWebWindow((ModuleModel)context);
}
CreateWebWindow((ModuleModel)context);
}
}
17 changes: 8 additions & 9 deletions src/shell/dotnet/Shell/Manifest/ManifestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

using System.Text.Json;

namespace Manifest
namespace Manifest;

internal sealed class ManifestModel
{
internal sealed class ManifestModel
{
public ModuleModel[]? Modules { get; set; }
public ModuleModel[]? Modules { get; set; }

public static JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true
};
}
public static JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true
};
}


Expand Down
29 changes: 14 additions & 15 deletions src/shell/dotnet/Shell/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@
using System.IO;
using System.Text.Json;

namespace Manifest
namespace Manifest;

internal static class ManifestParser
{
internal static class ManifestParser
internal static ManifestModel Manifest { get; set; }

public static ManifestModel OpenManifestFile(string fileName)
{
internal static ManifestModel Manifest { get; set; }
string processPath = Environment.ProcessPath;
string folder = Path.GetDirectoryName(processPath);
string path = Path.Combine(folder, @"Manifest\", fileName);

public static ManifestModel OpenManifestFile(string fileName)
using (FileStream stream = File.Open(path, FileMode.Open))
{
string processPath = Environment.ProcessPath;
string folder = Path.GetDirectoryName(processPath);
string path = Path.Combine(folder, @"Manifest\", fileName);

using (FileStream stream = File.Open(path, FileMode.Open))
{
Manifest = JsonSerializer.Deserialize<ManifestModel>(stream, ManifestModel.JsonSerializerOptions);
Manifest = JsonSerializer.Deserialize<ManifestModel>(stream, ManifestModel.JsonSerializerOptions);

stream.Close();
}

return Manifest;
stream.Close();
}

return Manifest;
}
}
15 changes: 7 additions & 8 deletions src/shell/dotnet/Shell/Manifest/ModuleModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

using System;

namespace Manifest
namespace Manifest;

[Serializable]
internal sealed class ModuleModel
{
[Serializable]
internal sealed class ModuleModel
{
public string AppName { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
public string IconUrl { get; set; } = string.Empty;
}
public string AppName { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
public string IconUrl { get; set; } = string.Empty;
}
Loading

0 comments on commit 0ab99a1

Please sign in to comment.