Skip to content

Commit

Permalink
build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszskoczek committed Mar 11, 2024
1 parent 656d385 commit fa71543
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 73 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/push_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Setup msbuild
uses: microsoft/setup-msbuild@v2
- name: Deploy application
shell: cmd
run: |
"%MSBUILD_PATH%" VDownload.sln /Deploy Release
- name: Build application
run: dotnet build -o build
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: build
path: bin
path: build
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ namespace VDownload.Services.UI.DictionaryResources
{
public interface IDictionaryResourcesService
{
ResourceDictionary Resources { get; set; }
T Get<T>(string key);
}



public class DictionaryResourcesService : IDictionaryResourcesService
{
#region PROPERTIES

public ResourceDictionary Resources { get; set; }

#endregion



#region CONSTRUCTORS

public DictionaryResourcesService() { }
Expand All @@ -28,7 +37,7 @@ public DictionaryResourcesService() { }

public T Get<T>(string key)
{
Application.Current.Resources.TryGetValue(key, out object value);
Resources.TryGetValue(key, out object value);
if (value is not null && value is T cast)
{
return cast;
Expand Down
139 changes: 74 additions & 65 deletions VDownload/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppNotifications;
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using VDownload.Core.Tasks;
Expand Down Expand Up @@ -47,11 +50,21 @@ namespace VDownload
{
public partial class App : Application
{
#region FIELDS
#region PROPERTIES

protected IServiceProvider _serviceProvider;
public static BaseWindow Window { get; protected set; }

protected BaseWindow _window;
public static T GetService<T>() where T : class
{
if ((App.Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
{
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
}

return service;
}

public IHost Host { get; set; }

#endregion

Expand All @@ -63,22 +76,70 @@ public App()
{
this.InitializeComponent();

Host = Microsoft.Extensions.Hosting.Host
.CreateDefaultBuilder()
.UseContentRoot(AppContext.BaseDirectory)
.ConfigureAppConfiguration((builder) =>
{
builder.Sources.Add(new JsonConfigurationSource
{
Path = "configuration.json"
});
})
.ConfigureServices((context, services) =>
{
BuildCore(services);

BuildDataServices(services);
BuildUIServices(services);
BuildUtilityServices(services);
BuildSourcesServices(services);

BuildTasksManager(services);
BuildPresentation(services);
})
.Build();
}

#endregion

IServiceCollection services = new ServiceCollection();

BuildCore(services);

BuildConfiguration(services);
#region EVENT HANDLERS

BuildDataServices(services);
BuildUIServices(services);
BuildUtilityServices(services);
BuildSourcesServices(services);
private void WindowRootLoaded(object sender, EventArgs e)
{
GetService<IDialogsService>().DefaultRoot = Window.XamlRoot;
}

BuildTasksManager(services);
BuildPresentation(services);
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);

GetService<IDictionaryResourcesService>().Resources = (App.Current as App).Resources;

Window = GetService<BaseWindow>();
Window.RootLoaded += WindowRootLoaded;

IApplicationDataService applicationDataService = GetService<IApplicationDataService>();
ISettingsService settingsService = GetService<ISettingsService>();
IAuthenticationDataService authenticationDataService = GetService<IAuthenticationDataService>();
ISubscriptionsDataService subscriptionsDataService = GetService<ISubscriptionsDataService>();
Task initViewModelToViewConverterTask = Task.Run(() => ViewModelToViewConverter.ServiceProvider = (App.Current as App)!.Host.Services);
Task initStoragePickerServiceTask = Task.Run(() => GetService<IStoragePickerService>().DefaultRoot = Window);
Task initNotificationsServiceTask = Task.Run(() => GetService<INotificationsService>().Initialize(() => WindowHelper.ShowWindow(Window)));

await Task.WhenAll(
applicationDataService.Load(),
settingsService.Load(),
authenticationDataService.Load(),
subscriptionsDataService.Load(),
initStoragePickerServiceTask,
initViewModelToViewConverterTask,
initNotificationsServiceTask
);

_serviceProvider = services.BuildServiceProvider();
Window.Activate();
}

#endregion
Expand All @@ -92,22 +153,6 @@ protected void BuildCore(IServiceCollection services)
services.AddSingleton<HttpClient>();
}

protected void BuildConfiguration(IServiceCollection services)
{
IConfigurationBuilder configBuilder = new ConfigurationBuilder
{
Sources =
{
new JsonConfigurationSource
{
Path = "configuration.json"
}
}
};
IConfiguration config = configBuilder.Build();
services.AddSingleton(config);
}

protected void BuildDataServices(IServiceCollection services)
{
services.AddSingleton<IConfigurationService, ConfigurationService>();
Expand Down Expand Up @@ -178,42 +223,6 @@ protected void BuildPresentation(IServiceCollection services)
services.AddTransient<BaseWindow>();
}

protected async Task InitializeServices()
{
IApplicationDataService applicationDataService = _serviceProvider.GetService<IApplicationDataService>();
ISettingsService settingsService = _serviceProvider.GetService<ISettingsService>();
IAuthenticationDataService authenticationDataService = _serviceProvider.GetService<IAuthenticationDataService>();
ISubscriptionsDataService subscriptionsDataService = _serviceProvider.GetService<ISubscriptionsDataService>();
Task initViewModelToViewConverterTask = Task.Run(() => ViewModelToViewConverter.ServiceProvider = _serviceProvider);
Task initStoragePickerServiceTask = Task.Run(() => _serviceProvider.GetService<IStoragePickerService>().DefaultRoot = _window);
Task initNotificationsServiceTask = Task.Run(() => _serviceProvider.GetService<INotificationsService>().Initialize(() => WindowHelper.ShowWindow(_window)));

await Task.WhenAll(
applicationDataService.Load(),
settingsService.Load(),
authenticationDataService.Load(),
subscriptionsDataService.Load(),
initStoragePickerServiceTask,
initViewModelToViewConverterTask,
initNotificationsServiceTask
);
}

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
_window = _serviceProvider.GetService<BaseWindow>();
_window.RootLoaded += Window_RootLoaded;
_window.Activate();

await InitializeServices();
}

protected void Window_RootLoaded(object sender, EventArgs e)
{
IDialogsService dialogsService = _serviceProvider.GetService<IDialogsService>();
dialogsService.DefaultRoot = _window.XamlRoot;
}

#endregion
}
}
1 change: 1 addition & 0 deletions VDownload/VDownload.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.0.240109" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
Expand Down

0 comments on commit fa71543

Please sign in to comment.