more refoctoring work
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
namespace Hyperbar.Widget.Contextual;
|
||||
|
||||
public class ContextualWidget :
|
||||
IWidget
|
||||
{
|
||||
public IWidgetBuilder Create() =>
|
||||
WidgetBuilder.Configure<ContextualWidgetConfiguration>(args =>
|
||||
{
|
||||
args.Id = Guid.Parse("d3030852-8d4a-4fbb-9aa5-96dff3dfa06c");
|
||||
args.Name = "Contextual commands";
|
||||
|
||||
}).ConfigureServices(args =>
|
||||
{
|
||||
args.AddWidgetTemplate<ContextualWidgetViewModel>();
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget.Contextual;
|
||||
|
||||
public class ContextualWidgetBuilder :
|
||||
IWidgetBuilder
|
||||
{
|
||||
public void Create(IServiceCollection services) =>
|
||||
WidgetBuilder.Config(services, config =>
|
||||
{
|
||||
config.Id = Guid.Parse("d3030852-8d4a-4fbb-9aa5-96dff3dfa06c");
|
||||
config.Name = "Contextual commands";
|
||||
|
||||
services.AddWidgetTemplate<ContextualWidgetViewModel>();
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Hyperbar.Widget.Contextual;
|
||||
|
||||
public class ContextualWidgetConfiguration
|
||||
public class ContextualWidgetConfiguration :
|
||||
WidgetConfiguration
|
||||
{
|
||||
}
|
||||
@@ -11,8 +11,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
|
||||
<PackageReference Include="WinUIEx" Version="2.3.3" />
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.Media.Control;
|
||||
|
||||
namespace Hyperbar.Windows.MediaController;
|
||||
|
||||
public class MediaControllerWidget :
|
||||
IWidget
|
||||
{
|
||||
public IWidgetBuilder Create() =>
|
||||
WidgetBuilder.Configure<MediaControllerWidgetConfiguration>(args =>
|
||||
{
|
||||
args.Id = Guid.Parse("1667a800-ec5a-4d39-aa75-4f5ee95bb9f1");
|
||||
args.Name = "Media controller";
|
||||
}).ConfigureServices(args =>
|
||||
{
|
||||
args.AddWidgetTemplate<MediaControllerWidgetViewModel, MediaControllerWidgetView>()
|
||||
.AddSingleton<IInitializer, MediaControllerManager>()
|
||||
.AddTransient<IServiceScopeFactory<MediaController>, ServiceScopeFactory<MediaController>>()
|
||||
.AddTransient<IServiceScopeProvider<MediaController>, ServiceScopeProvider<MediaController>>()
|
||||
.AddCache<MediaController, IServiceScope>()
|
||||
.AddTransient<IFactory<GlobalSystemMediaTransportControlsSession, MediaController?>, MediaControllerFactory>()
|
||||
.AddHandler<MediaControllerHandler>()
|
||||
.AddTransient<IFactory<MediaController, MediaControllerViewModel?>, MediaControllerViewModelFactory>()
|
||||
.AddCache<MediaController, MediaControllerViewModel>()
|
||||
.AddContentTemplate<MediaControllerViewModel, MediaControllerView>()
|
||||
.AddContentTemplate<MediaInformationViewModel, MediaInformationView>()
|
||||
.AddContentTemplate<MediaButtonViewModel, MediaButtonView>();
|
||||
});
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.Media.Control;
|
||||
|
||||
namespace Hyperbar.Windows.MediaController;
|
||||
|
||||
public class MediaControllerWidgetBuilder :
|
||||
IWidgetBuilder
|
||||
{
|
||||
public void Create(IServiceCollection services) =>
|
||||
WidgetBuilder.Config(services, config =>
|
||||
{
|
||||
config.Id = Guid.Parse("1667a800-ec5a-4d39-aa75-4f5ee95bb9f1");
|
||||
config.Name = "Media controller";
|
||||
|
||||
services.AddWidgetTemplate<MediaControllerWidgetViewModel, MediaControllerWidgetView>()
|
||||
.AddSingleton<IInitializer, MediaControllerManager>()
|
||||
.AddTransient<IServiceScopeFactory<MediaController>, ServiceScopeFactory<MediaController>>()
|
||||
.AddTransient<IServiceScopeProvider<MediaController>, ServiceScopeProvider<MediaController>>()
|
||||
.AddCache<MediaController, IServiceScope>()
|
||||
.AddTransient<IFactory<GlobalSystemMediaTransportControlsSession, MediaController?>, MediaControllerFactory>()
|
||||
.AddHandler<MediaControllerHandler>()
|
||||
.AddTransient<IFactory<MediaController, MediaControllerViewModel?>, MediaControllerViewModelFactory>()
|
||||
.AddCache<MediaController, MediaControllerViewModel>()
|
||||
.AddContentTemplate<MediaControllerViewModel, MediaControllerView>()
|
||||
.AddContentTemplate<MediaInformationViewModel, MediaInformationView>()
|
||||
.AddContentTemplate<MediaButtonViewModel, MediaButtonView>();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Hyperbar.Windows.MediaController;
|
||||
|
||||
public class MediaControllerWidgetConfiguration :
|
||||
WidgetConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) :
|
||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command),
|
||||
IViewModelInitialization
|
||||
IInitialization
|
||||
{
|
||||
public ICommand Initialize => new AsyncRelayCommand(InitializeAsync);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory) :
|
||||
WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory),
|
||||
IViewModelInitialization,
|
||||
WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory),
|
||||
IInitialization,
|
||||
INotificationHandler<Changed<MediaInformation>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class PrimaryWidget :
|
||||
IWidget
|
||||
{
|
||||
public IWidgetBuilder Create() =>
|
||||
WidgetBuilder.Configure<PrimaryWidgetConfiguration>(args =>
|
||||
{
|
||||
args.Id = Guid.Parse("cfdfe07c-d9d6-4174-ae41-988ca24d2e10");
|
||||
args.Name = "Primary commands";
|
||||
|
||||
}).ConfigureServices(args =>
|
||||
{
|
||||
args.AddCache<(Guid ParentId, Guid Id), PrimaryCommandConfiguration>()
|
||||
.AddCache<Guid, IWidgetComponentViewModel>()
|
||||
.AddTransient<IProvider<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentProvider>()
|
||||
.AddTransient<IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentFactory>()
|
||||
.AddTransient<IEnumerator<IWidgetComponentViewModel>, WidgetComponentEnumerator>()
|
||||
.AddWidgetTemplate<PrimaryWidgetViewModel>()
|
||||
.AddHandler<PrimaryWidgetConfigurationHandler>();
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class PrimaryWidgetConfiguration
|
||||
public class PrimaryWidgetConfiguration : WidgetConfiguration
|
||||
{
|
||||
public List<PrimaryCommandConfiguration> Commands { get; set; } = [];
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class PrimaryWidgetConfigurationBuilder :
|
||||
IWidgetBuilder
|
||||
{
|
||||
public void Create(IServiceCollection services) =>
|
||||
WidgetBuilder.Config(services, config =>
|
||||
{
|
||||
config.Id = Guid.Parse("cfdfe07c-d9d6-4174-ae41-988ca24d2e10");
|
||||
config.Name = "Primary commands";
|
||||
|
||||
services.AddConfiguration<PrimaryWidgetConfiguration>()
|
||||
.AddCache<(Guid ParentId, Guid Id), PrimaryCommandConfiguration>()
|
||||
.AddCache<Guid, IWidgetComponentViewModel>()
|
||||
.AddTransient<IProvider<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentViewModelProvider>()
|
||||
.AddTransient<IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentViewModelFactory>()
|
||||
.AddTransient<IViewModelEnumerator<IWidgetComponentViewModel>, WidgetComponentViewModelEnumerator>()
|
||||
.AddWidgetTemplate<PrimaryWidgetViewModel>()
|
||||
.AddHandler<PrimaryWidgetConfigurationHandler>();
|
||||
});
|
||||
}
|
||||
@@ -5,7 +5,7 @@ public class PrimaryWidgetViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelEnumerator<IWidgetComponentViewModel> enumerator) :
|
||||
IEnumerator<IWidgetComponentViewModel> enumerator) :
|
||||
ObservableCollectionViewModel<IWidgetComponentViewModel>(serviceFactory, mediator, disposer, enumerator),
|
||||
IWidgetViewModel,
|
||||
ITemplatedViewModel
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class WidgetComponentViewModelEnumerator(PrimaryWidgetConfiguration configuration,
|
||||
public class WidgetComponentEnumerator(PrimaryWidgetConfiguration configuration,
|
||||
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory,
|
||||
ICache<(Guid ParentId, Guid Id), PrimaryCommandConfiguration> cache) :
|
||||
IViewModelEnumerator<IWidgetComponentViewModel>
|
||||
IEnumerator<IWidgetComponentViewModel>
|
||||
{
|
||||
public IEnumerable<IWidgetComponentViewModel?> Next()
|
||||
{
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class WidgetComponentViewModelFactory(IServiceFactory service,
|
||||
public class WidgetComponentFactory(IServiceFactory service,
|
||||
IMediator mediator,
|
||||
ICache<Guid, IWidgetComponentViewModel> cache) :
|
||||
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class WidgetComponentViewModelProvider(ICache<Guid, IWidgetComponentViewModel> cache) :
|
||||
public class WidgetComponentProvider(ICache<Guid, IWidgetComponentViewModel> cache) :
|
||||
IProvider<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
|
||||
{
|
||||
public IWidgetComponentViewModel? Get(PrimaryCommandConfiguration value)
|
||||
@@ -1,12 +1,11 @@
|
||||
using Hyperbar.Windows.Controls;
|
||||
using Hyperbar.Windows.MediaController;
|
||||
using Hyperbar.Windows.Primary;
|
||||
using Hyperbar.Windows.UI;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
@@ -19,17 +18,12 @@ public partial class App :
|
||||
{
|
||||
base.OnLaunched(args);
|
||||
|
||||
DispatcherQueueSynchronizationContext context = new(DispatcherQueue.GetForCurrentThread());
|
||||
SynchronizationContext.SetSynchronizationContext(context);
|
||||
|
||||
IHost? host = Host.CreateDefaultBuilder()
|
||||
.UseContentRoot(AppContext.BaseDirectory)
|
||||
IHost? host = new HostBuilder()
|
||||
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
Assembly.GetEntryAssembly()?.GetName().Name!), true)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
{
|
||||
config.SetBasePath(AppContext.BaseDirectory);
|
||||
config.AddJsonFile("Settings.json", true, true);
|
||||
|
||||
config.Build();
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
@@ -41,7 +35,7 @@ public partial class App :
|
||||
services.AddSingleton<IDispatcher, Dispatcher>();
|
||||
|
||||
services.AddHostedService<AppService>();
|
||||
services.AddConfiguration<AppConfiguration>();
|
||||
services.AddConfiguration<AppConfiguration>(args => { args.Placement = DesktopBarPlacemenet.Top; });
|
||||
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
services.AddTransient<ITemplateFactory, TemplateFactory>();
|
||||
@@ -52,31 +46,36 @@ public partial class App :
|
||||
|
||||
services.AddHandler<AppConfigurationChangedHandler>();
|
||||
|
||||
services.AddWidget<MediaControllerWidgetBuilder>();
|
||||
services.AddWidget<PrimaryWidgetConfigurationBuilder>();
|
||||
//services.AddWidget<MediaControllerWidgetBuilder>();
|
||||
//services.AddWidget<PrimaryWidget>();
|
||||
|
||||
services.AddTransient(provider =>
|
||||
{
|
||||
static IEnumerable<WidgetContainerViewModel> Resolve(IServiceProvider services)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (WidgetContext widgetContext in services.GetServices<WidgetContext>())
|
||||
{
|
||||
if (widgetContext.ServiceProvider.GetServices<IWidgetViewModel>() is
|
||||
IEnumerable<IWidgetViewModel> viewModels)
|
||||
{
|
||||
yield return (WidgetContainerViewModel)ActivatorUtilities.CreateInstance(widgetContext.ServiceProvider,
|
||||
typeof(WidgetContainerViewModel), viewModels, index % 2 == 1);
|
||||
//services.AddTransient(provider =>
|
||||
//{
|
||||
// static IEnumerable<WidgetContainerViewModel> Resolve(IServiceProvider services)
|
||||
// {
|
||||
// int index = 0;
|
||||
// foreach (WidgetContext widgetContext in services.GetServices<WidgetContext>())
|
||||
// {
|
||||
// if (widgetContext.ServiceProvider.GetService<IWidget>() is IWidget widget)
|
||||
// {
|
||||
// if (widgetContext.ServiceProvider.GetServices<IWidgetViewModel>() is
|
||||
// IEnumerable<IWidgetViewModel> viewModels)
|
||||
// {
|
||||
// yield return (WidgetContainerViewModel)ActivatorUtilities.CreateInstance(widgetContext.ServiceProvider,
|
||||
// typeof(WidgetContainerViewModel), viewModels, index % 2 == 1, widget.Id);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// index++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return Resolve(provider);
|
||||
});
|
||||
// return Resolve(provider);
|
||||
//});
|
||||
})
|
||||
.Build();
|
||||
.Build();
|
||||
|
||||
var d = host.Services.GetService<JsonConfigurationProvider>();
|
||||
|
||||
await host.RunAsync();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
|
||||
@@ -36,31 +40,13 @@
|
||||
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||
<ProjectCapability Include="Msix" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Contextual\Hyperbar.Widget.Contextual.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.MediaController\Hyperbar.Windows.MediaController.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Widget.Primary.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.UI\Hyperbar.Windows.UI.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Views\WidgetSplitButtonView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Views\WidgetContainerView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Views\WidgetButtonView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar.Windows.UI\Hyperbar.Windows.UI.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
using Hyperbar.Windows.Controls;
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public class AppConfigurationChangedHandler(DesktopBar desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
|
||||
@@ -9,13 +9,11 @@ namespace Hyperbar.Windows
|
||||
{
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidget<TWidgetBuilder>(this IServiceCollection services)
|
||||
where TWidgetBuilder :
|
||||
IWidgetBuilder, new()
|
||||
public static IServiceCollection AddWidget<TWidget>(this IServiceCollection services)
|
||||
where TWidget :
|
||||
IWidget,
|
||||
new()
|
||||
{
|
||||
DispatcherQueueSynchronizationContext context = new(DispatcherQueue.GetForCurrentThread());
|
||||
SynchronizationContext.SetSynchronizationContext(context);
|
||||
|
||||
IHost? host = new HostBuilder()
|
||||
.UseContentRoot(AppContext.BaseDirectory)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
@@ -48,8 +46,9 @@ namespace Hyperbar.Windows
|
||||
isolatedServices.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||
isolatedServices.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
||||
|
||||
TWidgetBuilder builder = new();
|
||||
builder.Create(isolatedServices);
|
||||
TWidget widget = new();
|
||||
IWidgetBuilder builder = widget.Create();
|
||||
isolatedServices.AddRange(builder.Services);
|
||||
|
||||
}).Build();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationInitializer<TConfiguration>(DefaultConfiguration<TConfiguration> defaults,
|
||||
IConfigurationReader<TConfiguration> reader,
|
||||
IConfigurationWriter<TConfiguration> writer) :
|
||||
IInitializer
|
||||
where TConfiguration :
|
||||
@@ -9,9 +10,12 @@ public class ConfigurationInitializer<TConfiguration>(DefaultConfiguration<TConf
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
if (defaults.Configuration is not null)
|
||||
if (!reader.TryRead(out TConfiguration? _))
|
||||
{
|
||||
writer.Write(defaults.Configuration);
|
||||
if (defaults.Configuration is not null)
|
||||
{
|
||||
writer.Write(defaults.Configuration);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationMonitor<TConfiguration>(IConfigurationSource<TConfiguration> source,
|
||||
public class ConfigurationMonitor<TConfiguration>(IConfigurationFile<TConfiguration> configurationFile,
|
||||
IConfigurationReader<TConfiguration> reader,
|
||||
IMediator mediator) : IInitializer
|
||||
where TConfiguration :
|
||||
@@ -19,16 +19,21 @@ public class ConfigurationMonitor<TConfiguration>(IConfigurationSource<TConfigur
|
||||
}
|
||||
}
|
||||
|
||||
string fileName = Path.GetFileName(source.Path);
|
||||
|
||||
watcher = new FileSystemWatcher
|
||||
if (configurationFile.FileInfo.PhysicalPath is { } path)
|
||||
{
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
Path = source.Path.Replace(fileName, ""),
|
||||
Filter = fileName,
|
||||
EnableRaisingEvents = true
|
||||
};
|
||||
watcher.Changed += ChangedHandler;
|
||||
string fileName = Path.GetFileName(path);
|
||||
|
||||
watcher = new FileSystemWatcher
|
||||
{
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
Path = path.Replace(fileName, ""),
|
||||
Filter = fileName,
|
||||
EnableRaisingEvents = true
|
||||
};
|
||||
|
||||
watcher.Changed += ChangedHandler;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,14 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace Hyperbar;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationReader<TConfiguration>(IConfigurationSource<TConfiguration> source,
|
||||
JsonSerializerOptions? serializerOptions = null) :
|
||||
public class ConfigurationReader<TConfiguration>(IConfigurationSource<TConfiguration> source) :
|
||||
IConfigurationReader<TConfiguration>
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
private static readonly Func<JsonSerializerOptions> defaultSerializerOptions = new(() =>
|
||||
{
|
||||
return new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
public TConfiguration Read()
|
||||
{
|
||||
if ((TryGet(out TConfiguration? value) ? value : new TConfiguration()) is TConfiguration configuration)
|
||||
if ((source.TryGet(out TConfiguration? value) ? value :
|
||||
new TConfiguration()) is TConfiguration configuration)
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
@@ -32,21 +16,15 @@ public class ConfigurationReader<TConfiguration>(IConfigurationSource<TConfigura
|
||||
return new TConfiguration();
|
||||
}
|
||||
|
||||
private bool TryGet(out TConfiguration? value)
|
||||
public bool TryRead(out TConfiguration? configuration)
|
||||
{
|
||||
if (File.Exists(source.Path))
|
||||
if (source.TryGet(out TConfiguration? value) && value is not null)
|
||||
{
|
||||
byte[] jsonContent = File.ReadAllBytes(source.Path);
|
||||
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
|
||||
if (jsonDocument.RootElement.TryGetProperty(source.Section, out JsonElement sectionValue))
|
||||
{
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions ?? defaultSerializerOptions());
|
||||
return true;
|
||||
}
|
||||
configuration = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = default;
|
||||
configuration = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,129 @@
|
||||
namespace Hyperbar;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class ConfigurationSource<TConfiguration>(string path,
|
||||
string section) :
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationSource<TConfiguration>(IConfigurationFile<TConfiguration> configurationFile,
|
||||
string section,
|
||||
JsonSerializerOptions? serializerOptions = null) :
|
||||
IConfigurationSource<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
public string Path => path;
|
||||
private readonly object lockingObject = new();
|
||||
|
||||
public string Section => section;
|
||||
private static readonly Func<JsonSerializerOptions> defaultSerializerOptions = new(() =>
|
||||
{
|
||||
return new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
public void Set(TConfiguration value)
|
||||
{
|
||||
lock (lockingObject)
|
||||
{
|
||||
IFileInfo fileInfo = configurationFile.FileInfo;
|
||||
|
||||
if (!File.Exists(fileInfo.PhysicalPath))
|
||||
{
|
||||
string? fileDirectoryPath = Path.GetDirectoryName(fileInfo.PhysicalPath);
|
||||
if (!string.IsNullOrEmpty(fileDirectoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(fileDirectoryPath);
|
||||
}
|
||||
|
||||
File.WriteAllText(fileInfo.PhysicalPath!, "{}");
|
||||
}
|
||||
|
||||
static Stream OpenReadWrite(IFileInfo fileInfo)
|
||||
{
|
||||
return fileInfo.PhysicalPath is not null
|
||||
? new FileStream(fileInfo.PhysicalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
|
||||
: fileInfo.CreateReadStream();
|
||||
}
|
||||
|
||||
using Stream stream = OpenReadWrite(fileInfo);
|
||||
using StreamReader? reader = new(stream);
|
||||
|
||||
string? content = reader.ReadToEnd();
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(content);
|
||||
|
||||
using Stream stream2 = OpenReadWrite(fileInfo);
|
||||
Utf8JsonWriter writer = new(stream2, new JsonWriterOptions()
|
||||
{
|
||||
Indented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
});
|
||||
|
||||
writer.WriteStartObject();
|
||||
bool isWritten = false;
|
||||
|
||||
JsonDocument optionsElement = JsonDocument.Parse(JsonSerializer.SerializeToUtf8Bytes(value,
|
||||
serializerOptions ?? defaultSerializerOptions()));
|
||||
|
||||
foreach (JsonProperty element in jsonDocument.RootElement.EnumerateObject())
|
||||
{
|
||||
if (element.Name != section)
|
||||
{
|
||||
element.WriteTo(writer);
|
||||
continue;
|
||||
}
|
||||
writer.WritePropertyName(element.Name);
|
||||
optionsElement.WriteTo(writer);
|
||||
isWritten = true;
|
||||
}
|
||||
|
||||
if (!isWritten)
|
||||
{
|
||||
writer.WritePropertyName(section);
|
||||
optionsElement.WriteTo(writer);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
writer.Flush();
|
||||
stream2.SetLength(stream2.Position);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGet(out TConfiguration? value)
|
||||
{
|
||||
lock (lockingObject)
|
||||
{
|
||||
IFileInfo fileInfo = configurationFile.FileInfo;
|
||||
|
||||
if (File.Exists(fileInfo.PhysicalPath))
|
||||
{
|
||||
static Stream OpenRead(IFileInfo fileInfo)
|
||||
{
|
||||
return fileInfo.PhysicalPath is not null
|
||||
? new FileStream(fileInfo.PhysicalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
|
||||
: fileInfo.CreateReadStream();
|
||||
}
|
||||
|
||||
using Stream stream = OpenRead(fileInfo);
|
||||
using StreamReader? reader = new(stream);
|
||||
|
||||
string? content = reader.ReadToEnd();
|
||||
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(content);
|
||||
if (jsonDocument.RootElement.TryGetProperty(section, out JsonElement sectionValue))
|
||||
{
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions ?? defaultSerializerOptions());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,13 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace Hyperbar;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationWriter<TConfiguration>(IConfigurationSource<TConfiguration> source,
|
||||
JsonSerializerOptions? serializerOptions = null) :
|
||||
public class ConfigurationWriter<TConfiguration>(IConfigurationSource<TConfiguration> source) :
|
||||
IConfigurationWriter<TConfiguration>
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
private static readonly Func<JsonSerializerOptions> defaultSerializerOptions = new(() =>
|
||||
{
|
||||
return new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
});
|
||||
|
||||
public void Write(Action<TConfiguration> updateDelegate)
|
||||
{
|
||||
if ((TryGet(out TConfiguration? value) ? value : new TConfiguration()) is TConfiguration updatedValue)
|
||||
if ((source.TryGet(out TConfiguration? value) ? value : new TConfiguration()) is TConfiguration updatedValue)
|
||||
{
|
||||
updateDelegate?.Invoke(updatedValue);
|
||||
Write(updatedValue);
|
||||
@@ -31,69 +16,6 @@ public class ConfigurationWriter<TConfiguration>(IConfigurationSource<TConfigura
|
||||
|
||||
public void Write(TConfiguration value)
|
||||
{
|
||||
if (!File.Exists(source.Path))
|
||||
{
|
||||
string? fileDirectoryPath = Path.GetDirectoryName(source.Path);
|
||||
if (!string.IsNullOrEmpty(fileDirectoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(fileDirectoryPath);
|
||||
}
|
||||
|
||||
File.WriteAllText(source.Path, "{}");
|
||||
}
|
||||
|
||||
byte[] jsonContent = File.ReadAllBytes(source.Path);
|
||||
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
|
||||
using FileStream stream = File.OpenWrite(source.Path);
|
||||
Utf8JsonWriter writer = new(stream, new JsonWriterOptions()
|
||||
{
|
||||
Indented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
});
|
||||
|
||||
writer.WriteStartObject();
|
||||
bool isWritten = false;
|
||||
JsonDocument optionsElement = JsonDocument.Parse(JsonSerializer.SerializeToUtf8Bytes(value, serializerOptions ?? defaultSerializerOptions()));
|
||||
|
||||
foreach (JsonProperty element in jsonDocument.RootElement.EnumerateObject())
|
||||
{
|
||||
if (element.Name != source.Section)
|
||||
{
|
||||
element.WriteTo(writer);
|
||||
continue;
|
||||
}
|
||||
writer.WritePropertyName(element.Name);
|
||||
optionsElement.WriteTo(writer);
|
||||
isWritten = true;
|
||||
}
|
||||
|
||||
if (!isWritten)
|
||||
{
|
||||
writer.WritePropertyName(source.Section);
|
||||
optionsElement.WriteTo(writer);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
writer.Flush();
|
||||
stream.SetLength(stream.Position);
|
||||
}
|
||||
|
||||
private bool TryGet(out TConfiguration? value)
|
||||
{
|
||||
if (File.Exists(source.Path))
|
||||
{
|
||||
byte[] jsonContent = File.ReadAllBytes(source.Path);
|
||||
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
|
||||
if (jsonDocument.RootElement.TryGetProperty(source.Section, out JsonElement sectionValue))
|
||||
{
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions ?? defaultSerializerOptions());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
value = default;
|
||||
return false;
|
||||
source.Set(value);
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,7 @@ public interface IConfigurationReader<TConfiguration>
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
bool TryRead(out TConfiguration? configuration);
|
||||
|
||||
TConfiguration Read();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
namespace Hyperbar;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IConfigurationSource<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
string Path { get; }
|
||||
bool TryGet(out TConfiguration? value);
|
||||
|
||||
string Section { get; }
|
||||
void Set(TConfiguration value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public static class IHostBuilderExtensions
|
||||
{
|
||||
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder,
|
||||
string contentRoot,
|
||||
bool createDirectory)
|
||||
{
|
||||
if (createDirectory)
|
||||
{
|
||||
Directory.CreateDirectory(contentRoot);
|
||||
}
|
||||
|
||||
hostBuilder.UseContentRoot(contentRoot);
|
||||
return hostBuilder;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,27 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.FileProviders.Physical;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IConfigurationFile<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
IFileInfo FileInfo { get; }
|
||||
}
|
||||
|
||||
public class ConfigurationFile<TConfiguration>(IFileInfo fileInfo) :
|
||||
IConfigurationFile<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
public IFileInfo FileInfo => fileInfo;
|
||||
}
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddCache<TKey, TValue>(this IServiceCollection services)
|
||||
@@ -36,7 +51,7 @@ public static class IServiceCollectionExtensions
|
||||
return services.AddConfiguration<TConfiguration>(typeof(TConfiguration).Name, "Settings.json", null);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
Action<TConfiguration> configurationDelegate)
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
@@ -66,47 +81,34 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
services.AddSingleton<IConfigurationSource<TConfiguration>>(provider =>
|
||||
{
|
||||
string? jsonFilePath = null;
|
||||
JsonSerializerOptions? defaultSerializer = null;
|
||||
if (serializerDelegate is not null)
|
||||
{
|
||||
defaultSerializer = new JsonSerializerOptions();
|
||||
serializerDelegate.Invoke(defaultSerializer);
|
||||
}
|
||||
|
||||
return new ConfigurationSource<TConfiguration>(provider.GetRequiredService<IConfigurationFile<TConfiguration>>(), section, defaultSerializer);
|
||||
});
|
||||
|
||||
services.AddSingleton<IConfigurationFile<TConfiguration>>(provider =>
|
||||
{
|
||||
IFileInfo? fileInfo = null;
|
||||
if (provider.GetService<IHostEnvironment>() is IHostEnvironment hostEnvironment)
|
||||
{
|
||||
IFileProvider fileProvider = hostEnvironment.ContentRootFileProvider;
|
||||
IFileInfo fileInfo = fileProvider.GetFileInfo(path);
|
||||
|
||||
jsonFilePath = fileInfo.PhysicalPath;
|
||||
fileInfo = fileProvider.GetFileInfo(path);
|
||||
}
|
||||
|
||||
jsonFilePath ??= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
|
||||
return new ConfigurationSource<TConfiguration>(jsonFilePath, section);
|
||||
});
|
||||
|
||||
services.AddSingleton<IConfigurationReader<TConfiguration>>(provider =>
|
||||
{
|
||||
JsonSerializerOptions? defaultSerializer = null;
|
||||
if (serializerDelegate is not null)
|
||||
{
|
||||
defaultSerializer = new JsonSerializerOptions();
|
||||
serializerDelegate.Invoke(defaultSerializer);
|
||||
}
|
||||
|
||||
return new ConfigurationReader<TConfiguration>(provider.GetRequiredService<IConfigurationSource<TConfiguration>>(),
|
||||
defaultSerializer);
|
||||
});
|
||||
|
||||
services.AddSingleton<IConfigurationWriter<TConfiguration>>(provider =>
|
||||
{
|
||||
JsonSerializerOptions? defaultSerializer = null;
|
||||
if (serializerDelegate is not null)
|
||||
{
|
||||
defaultSerializer = new JsonSerializerOptions();
|
||||
serializerDelegate.Invoke(defaultSerializer);
|
||||
}
|
||||
|
||||
return new ConfigurationWriter<TConfiguration>(provider.GetRequiredService<IConfigurationSource<TConfiguration>>(),
|
||||
defaultSerializer);
|
||||
fileInfo ??= new PhysicalFileInfo(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path)));
|
||||
return new ConfigurationFile<TConfiguration>(fileInfo);
|
||||
});
|
||||
|
||||
services.AddSingleton<IInitializer, ConfigurationMonitor<TConfiguration>>();
|
||||
|
||||
services.AddSingleton<IConfigurationReader<TConfiguration>, ConfigurationReader<TConfiguration>>();
|
||||
services.AddSingleton<IConfigurationWriter<TConfiguration>, ConfigurationWriter<TConfiguration>>();
|
||||
|
||||
services.AddTransient(provider => new DefaultConfiguration<TConfiguration>(defaults));
|
||||
services.AddTransient<IInitializer, ConfigurationInitializer<TConfiguration>>();
|
||||
|
||||
@@ -151,8 +153,6 @@ public static class IServiceCollectionExtensions
|
||||
if (contract.GetGenericArguments() is { Length: 1 } arguments)
|
||||
{
|
||||
Type notificationType = arguments[0];
|
||||
|
||||
//services.TryAdd(new ServiceDescriptor(typeof(THandler), typeof(THandler), lifetime));
|
||||
services.Add(new ServiceDescriptor(typeof(INotificationHandler<>).MakeGenericType(notificationType), typeof(THandler), lifetime));
|
||||
}
|
||||
}
|
||||
@@ -182,14 +182,16 @@ public static class IServiceCollectionExtensions
|
||||
return services;
|
||||
}
|
||||
|
||||
//public static IServiceCollection AddNotificationPipeline<TFromNotification, TToNotification>(this IServiceCollection services)
|
||||
// where TFromNotification :
|
||||
// INotification
|
||||
// where TToNotification :
|
||||
// INotification, new()
|
||||
//{
|
||||
// return services.AddHandler<NotficationPipelineHandler<TFromNotification, TToNotification>>();
|
||||
//}
|
||||
public static IServiceCollection AddRange(this IServiceCollection services,
|
||||
IServiceCollection fromServices)
|
||||
{
|
||||
foreach (ServiceDescriptor service in fromServices)
|
||||
{
|
||||
services.Add(service);
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddWidgetTemplate<TWidgetContent>(this IServiceCollection services)
|
||||
where TWidgetContent :
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Cache<TValue>(IDisposer disposer) :
|
||||
|
||||
public void Clear() => cache.Clear();
|
||||
|
||||
public IEnumerator<TValue> GetEnumerator() => cache.GetEnumerator();
|
||||
public System.Collections.Generic.IEnumerator<TValue> GetEnumerator() => cache.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Cache<TKey, TValue>(IDisposer disposer) :
|
||||
|
||||
public bool ContainsKey(TKey key) => cache.ContainsKey(key);
|
||||
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => cache.GetEnumerator();
|
||||
public System.Collections.Generic.IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => cache.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IViewModelEnumerator<TItem>
|
||||
public interface IEnumerator<TItem>
|
||||
{
|
||||
IEnumerable<TItem?> Next();
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IViewModelInitialization
|
||||
public interface IInitialization
|
||||
{
|
||||
ICommand Initialize { get; }
|
||||
|
||||
@@ -18,7 +18,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
IDisposable
|
||||
{
|
||||
public ObservableCollection<TItem> collection = [];
|
||||
private readonly IViewModelEnumerator<TItem>? enumerator;
|
||||
private readonly IEnumerator<TItem>? enumerator;
|
||||
|
||||
public ObservableCollectionViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
@@ -36,7 +36,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
public ObservableCollectionViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelEnumerator<TItem> enumerator)
|
||||
IEnumerator<TItem> enumerator)
|
||||
{
|
||||
ServiceFactory = serviceFactory;
|
||||
Mediator = mediator;
|
||||
@@ -201,7 +201,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
|
||||
public void Dispose() => Disposer.Dispose(this);
|
||||
|
||||
public IEnumerator<TItem> GetEnumerator() =>
|
||||
public System.Collections.Generic.IEnumerator<TItem> GetEnumerator() =>
|
||||
collection.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
|
||||
@@ -2,9 +2,5 @@
|
||||
|
||||
public interface IWidget
|
||||
{
|
||||
Guid Id { get; set; }
|
||||
|
||||
string? Name { get; set; }
|
||||
|
||||
string? Description { get; set; }
|
||||
IWidgetBuilder Create();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar
|
||||
{
|
||||
public interface IWidgetAssemblyLoader
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,7 @@ namespace Hyperbar;
|
||||
|
||||
public interface IWidgetBuilder
|
||||
{
|
||||
void Create(IServiceCollection services);
|
||||
WidgetConfiguration Configuration { get; }
|
||||
|
||||
IServiceCollection Services { get; }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class AssemblyProvider
|
||||
{
|
||||
public static void Load()
|
||||
{
|
||||
string extensionsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions");
|
||||
Directory.CreateDirectory(extensionsPath);
|
||||
}
|
||||
|
||||
public static IEnumerable<Assembly> Get(string path)
|
||||
{
|
||||
string extensionsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions");
|
||||
|
||||
Directory.CreateDirectory(extensionsPath);
|
||||
foreach (string assemblyPath in Directory.GetFiles(extensionsPath, "*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
yield return AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IWidgetBuilderExtensions
|
||||
{
|
||||
public static IWidgetBuilder ConfigureServices(this IWidgetBuilder builder,
|
||||
Action<IServiceCollection> servicesDelegate)
|
||||
{
|
||||
servicesDelegate(builder.Services);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class Widget :
|
||||
IWidget
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetBuilder(WidgetConfiguration configuration) :
|
||||
IWidgetBuilder
|
||||
{
|
||||
public IServiceCollection Services => new ServiceCollection();
|
||||
|
||||
public WidgetConfiguration Configuration => configuration;
|
||||
|
||||
public static IWidgetBuilder Configure<TWidgetConfiguration>(Action<TWidgetConfiguration> configurationDelegate)
|
||||
where TWidgetConfiguration :
|
||||
WidgetConfiguration,
|
||||
new()
|
||||
{
|
||||
TWidgetConfiguration configuration = new();
|
||||
configurationDelegate(configuration);
|
||||
|
||||
return new WidgetBuilder(configuration);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Hyperbar;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetBuilder
|
||||
public abstract class WidgetConfiguration
|
||||
{
|
||||
public static void Config(IServiceCollection services,
|
||||
Action<IWidget> widgetDelegate)
|
||||
{
|
||||
Widget widget = new();
|
||||
widgetDelegate(widget);
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
services.AddSingleton(widget);
|
||||
}
|
||||
}
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetContext(IServiceProvider serviceProvider) :
|
||||
IInitializer
|
||||
{
|
||||
public IServiceProvider ServiceProvider => serviceProvider;
|
||||
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class WidgetMonitor :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class WidgetManager :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetEnumerator() :
|
||||
IEnumerator<IWidgetComponentViewModel>
|
||||
{
|
||||
public IEnumerable<IWidgetComponentViewModel?> Next()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user