mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-09-16 21:35:20 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8ba125abc | ||
|
|
7d290031f1 | ||
|
|
5220a8c7ac | ||
|
|
33e221f60f | ||
|
|
7f77547c50 | ||
|
|
c5964e33ac | ||
|
|
1c6f3ec797 | ||
|
|
8601f61739 | ||
|
|
91bac0d50b | ||
|
|
0bf03e0fb5 | ||
|
|
81401178a5 | ||
|
|
882357a8e5 | ||
|
|
abf629c5c6 | ||
|
|
758f9004cd | ||
|
|
f174f8cbb3 | ||
|
|
f2f6bde25d | ||
|
|
85f378b303 | ||
|
|
71ab3fdefb | ||
|
|
2f83d6c860 | ||
|
|
3db4975b48 |
+134
@@ -0,0 +1,134 @@
|
||||
[*.cs]
|
||||
|
||||
# CA2254: Template should be a static expression
|
||||
dotnet_diagnostic.CA2254.severity = none
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_using_directive_placement = outside_namespace:error
|
||||
csharp_prefer_simple_using_statement = true:error
|
||||
csharp_prefer_braces = true:silent
|
||||
csharp_style_namespace_declarations = block_scoped:silent
|
||||
csharp_style_prefer_method_group_conversion = true:silent
|
||||
csharp_style_expression_bodied_methods = false:silent
|
||||
csharp_style_expression_bodied_constructors = false:silent
|
||||
csharp_style_expression_bodied_operators = false:silent
|
||||
csharp_style_expression_bodied_properties = true:silent
|
||||
csharp_style_expression_bodied_indexers = true:silent
|
||||
csharp_style_expression_bodied_accessors = true:silent
|
||||
csharp_style_expression_bodied_lambdas = true:silent
|
||||
csharp_style_expression_bodied_local_functions = false:silent
|
||||
csharp_indent_braces = false
|
||||
insert_final_newline = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_style_throw_expression = true:suggestion
|
||||
csharp_style_prefer_null_check_over_type_check = true:suggestion
|
||||
csharp_prefer_simple_default_expression = true:suggestion
|
||||
csharp_style_prefer_local_over_anonymous_function = true:error
|
||||
csharp_style_prefer_index_operator = true:suggestion
|
||||
csharp_style_prefer_range_operator = true:suggestion
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
|
||||
csharp_style_prefer_tuple_swap = true:suggestion
|
||||
csharp_style_inlined_variable_declaration = true:suggestion
|
||||
csharp_style_deconstructed_variable_declaration = true:error
|
||||
csharp_style_unused_value_assignment_preference = discard_variable:error
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
|
||||
csharp_prefer_static_local_function = true:suggestion
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:suggestion
|
||||
csharp_style_conditional_delegate_call = true:suggestion
|
||||
csharp_style_prefer_parameter_null_checking = true:suggestion
|
||||
csharp_style_prefer_switch_expression = true:suggestion
|
||||
csharp_style_prefer_pattern_matching = true:silent
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
|
||||
csharp_style_prefer_not_pattern = true:suggestion
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
||||
csharp_style_prefer_extended_property_pattern = true:suggestion
|
||||
csharp_style_var_for_built_in_types = false:silent
|
||||
csharp_style_var_when_type_is_apparent = false:silent
|
||||
csharp_style_var_elsewhere = false:silent
|
||||
|
||||
[*.{cs,vb}]
|
||||
#### Naming styles ####
|
||||
|
||||
# Naming rules
|
||||
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = error
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = error
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
|
||||
# Symbol specifications
|
||||
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
|
||||
# Naming styles
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
tab_width = 4
|
||||
indent_size = 4
|
||||
end_of_line = crlf
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
|
||||
dotnet_style_prefer_auto_properties = true:error
|
||||
dotnet_style_object_initializer = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = true:silent
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_tuple_names = true:suggestion
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
|
||||
dotnet_style_prefer_compound_assignment = true:suggestion
|
||||
dotnet_style_prefer_simplified_interpolation = true:suggestion
|
||||
dotnet_style_namespace_match_folder = true:suggestion
|
||||
dotnet_style_readonly_field = true:suggestion
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
||||
dotnet_style_predefined_type_for_member_access = true:silent
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = false:suggestion
|
||||
dotnet_code_quality_unused_parameters = all:error
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
|
||||
dotnet_style_qualification_for_field = true:error
|
||||
dotnet_style_qualification_for_property = true:error
|
||||
dotnet_style_qualification_for_method = true:error
|
||||
dotnet_style_qualification_for_event = true:error
|
||||
dotnet_diagnostic.CA1000.severity = error
|
||||
|
||||
[*.vb]
|
||||
dotnet_diagnostic.CA1047.severity = error
|
||||
@@ -0,0 +1 @@
|
||||
* amacocian@yahoo.com
|
||||
@@ -0,0 +1,16 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
- package-ecosystem: "nuget"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -9,6 +9,9 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- "Daybreak/**"
|
||||
- "Daybreak.Installer/**"
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -24,12 +27,12 @@ jobs:
|
||||
Configuration: Release
|
||||
Solution_Path: Daybreak.sln
|
||||
Test_Project_Path: Daybreak.Tests\Daybreak.Tests.csproj
|
||||
Wpf_Project_Path: Daybreak\Daybreal.csproj
|
||||
Wpf_Project_Path: Daybreak\Daybreak.csproj
|
||||
Actions_Allow_Unsecure_Commands: true
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -50,13 +53,18 @@ jobs:
|
||||
echo "${{ env.Changelog }}"
|
||||
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: '6.x'
|
||||
|
||||
- name: Setup MSBuild.exe
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
|
||||
- name: Setup project secrets
|
||||
run: |
|
||||
dotnet user-secrets --project Daybreak\Daybreak.csproj set AadApplicationId "${{ secrets.AadApplicationId }}"
|
||||
dotnet user-secrets --project Daybreak\Daybreak.csproj set AadTenantId "${{ secrets.AadTenantId }}"
|
||||
|
||||
- name: Restore project
|
||||
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
|
||||
env:
|
||||
@@ -87,7 +95,7 @@ jobs:
|
||||
shell: pwsh
|
||||
|
||||
- name: Publish release
|
||||
uses: Xotl/cool-github-releases@v1.1.2
|
||||
uses: Xotl/cool-github-releases@v1.1.7
|
||||
with:
|
||||
mode: update
|
||||
tag_name: v${{ env.Version }}
|
||||
|
||||
@@ -31,12 +31,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: '6.x'
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: '41 12 * * 6'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: windows-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'csharp' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: '6.x'
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
# - run: |
|
||||
# echo "Run, Build Application using script"
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
@@ -4,6 +4,9 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- "Daybreak/**"
|
||||
- "Daybreak.Installer/**"
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -22,7 +25,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ catch
|
||||
}
|
||||
Console.WriteLine("Deleting package");
|
||||
File.Delete(tempFile);
|
||||
|
||||
Console.WriteLine("Deleting browser caches");
|
||||
Directory.Delete("BrowserData", true);
|
||||
Directory.Delete("Daybreak.exe.WebView2", true);
|
||||
|
||||
Console.WriteLine("Launching application");
|
||||
var process = new Process
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0-preview-20220707-01" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0-preview-20220726-02" />
|
||||
<PackageReference Include="Moq" Version="4.18.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Daybreak.Tests.Services
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
buildTemplateManager = new BuildTemplateManager(new Mock<ILogger<BuildTemplateManager>>().Object);
|
||||
this.buildTemplateManager = new BuildTemplateManager(new Mock<ILogger<BuildTemplateManager>>().Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
+9
-1
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipelines", "Pipelines", "{
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.github\workflows\cd.yaml = .github\workflows\cd.yaml
|
||||
.github\workflows\ci.yaml = .github\workflows\ci.yaml
|
||||
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
|
||||
.github\dependabot.yml = .github\dependabot.yml
|
||||
.github\workflows\version_check.yaml = .github\workflows\version_check.yaml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -19,8 +21,14 @@ EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{41AE8C5D-25E1-4B08-8D65-868552421A63}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Scripts\BuildRelease.ps1 = Scripts\BuildRelease.ps1
|
||||
Scripts\GetBuildVersion.ps1 = Scripts\GetBuildVersion.ps1
|
||||
Scripts\CompareVersions.ps1 = Scripts\CompareVersions.ps1
|
||||
Scripts\GetBuildVersion.ps1 = Scripts\GetBuildVersion.ps1
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0E30DDA0-2111-4E6C-851E-01DC34124FC2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
.github\CODEOWNERS = .github\CODEOWNERS
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Behaviors
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
this.AssociatedObject.SelectionChanged += AssociatedObject_SelectionChanged;
|
||||
this.AssociatedObject.SelectionChanged += this.AssociatedObject_SelectionChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +48,7 @@ namespace Daybreak.Behaviors
|
||||
{
|
||||
base.OnDetaching();
|
||||
this.AssociatedObject.SelectionChanged -=
|
||||
AssociatedObject_SelectionChanged;
|
||||
this.AssociatedObject_SelectionChanged;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,5 +37,7 @@ namespace Daybreak.Configuration
|
||||
public bool PlaceShortcut { get; set; }
|
||||
[JsonProperty("AutoCheckUpdate")]
|
||||
public bool AutoCheckUpdate { get; set; } = true;
|
||||
[JsonProperty("ProtectedGraphAccessToken")]
|
||||
public string ProtectedGraphAccessToken { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ using Daybreak.Services.Options;
|
||||
using Daybreak.Models;
|
||||
using Microsoft.CorrelationVector;
|
||||
using System.Logging;
|
||||
using Daybreak.Services.Updater.PostUpdate;
|
||||
using System.Core.Extensions;
|
||||
using Daybreak.Services.Updater.PostUpdate.Actions;
|
||||
using Daybreak.Services.Graph;
|
||||
|
||||
namespace Daybreak.Configuration
|
||||
{
|
||||
@@ -30,7 +34,7 @@ namespace Daybreak.Configuration
|
||||
{
|
||||
public static void RegisterResolvers(IServiceManager serviceManager)
|
||||
{
|
||||
serviceManager.ThrowIfNull(nameof(serviceManager));
|
||||
serviceManager.ThrowIfNull();
|
||||
|
||||
serviceManager.RegisterHttpFactory((serviceProvider, categoryType) =>
|
||||
{
|
||||
@@ -44,7 +48,7 @@ namespace Daybreak.Configuration
|
||||
|
||||
public static void RegisterServices(IServiceProducer serviceProducer)
|
||||
{
|
||||
serviceProducer.ThrowIfNull(nameof(serviceProducer));
|
||||
serviceProducer.ThrowIfNull();
|
||||
|
||||
serviceProducer.RegisterSingleton<ILogsManager, JsonLogsManager>();
|
||||
serviceProducer.RegisterSingleton<IDebugLogsWriter, Services.Logging.DebugLogsWriter>();
|
||||
@@ -60,6 +64,7 @@ namespace Daybreak.Configuration
|
||||
|
||||
serviceProducer.RegisterScoped((sp) => new ScopeMetadata(new CorrelationVector()));
|
||||
serviceProducer.RegisterSingleton<ViewManager>(registerAllInterfaces: true);
|
||||
serviceProducer.RegisterSingleton<PostUpdateActionManager>(registerAllInterfaces: true);
|
||||
serviceProducer.RegisterSingleton<IConfigurationManager, ConfigurationManager>();
|
||||
serviceProducer.RegisterSingleton<ILiteDatabase, LiteDatabase>(sp => new LiteDatabase("Daybreak.db"));
|
||||
serviceProducer.RegisterSingleton<IMutexHandler, MutexHandler>();
|
||||
@@ -75,11 +80,12 @@ namespace Daybreak.Configuration
|
||||
serviceProducer.RegisterScoped<IIconCache, IconCache>();
|
||||
serviceProducer.RegisterScoped<IPrivilegeManager, PrivilegeManager>();
|
||||
serviceProducer.RegisterScoped<IScreenManager, ScreenManager>();
|
||||
serviceProducer.RegisterScoped<IGraphClient, GraphClient>();
|
||||
}
|
||||
|
||||
public static void RegisterViews(IViewProducer viewProducer)
|
||||
{
|
||||
viewProducer.ThrowIfNull(nameof(viewProducer));
|
||||
viewProducer.ThrowIfNull();
|
||||
|
||||
viewProducer.RegisterView<MainView>();
|
||||
viewProducer.RegisterView<SettingsView>();
|
||||
@@ -96,6 +102,15 @@ namespace Daybreak.Configuration
|
||||
viewProducer.RegisterView<VersionManagementView>();
|
||||
viewProducer.RegisterView<LogsView>();
|
||||
viewProducer.RegisterView<IconDownloadView>();
|
||||
viewProducer.RegisterView<GraphAuthorizationView>();
|
||||
viewProducer.RegisterView<BuildsSynchronizationView>();
|
||||
}
|
||||
|
||||
public static void RegisterPostUpdateActions(IPostUpdateActionProducer postUpdateActionProducer)
|
||||
{
|
||||
postUpdateActionProducer.ThrowIfNull();
|
||||
|
||||
postUpdateActionProducer.AddPostUpdateAction<RenameInstallerAction>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Daybreak.Configuration;
|
||||
|
||||
public class SecretKeys
|
||||
{
|
||||
public static readonly SecretKeys AadApplicationId = new() { Key = "AadApplicationId" };
|
||||
public static readonly SecretKeys AadTenantId = new() { Key = "AadTenantId" };
|
||||
|
||||
public string Key { get; private set; }
|
||||
private SecretKeys()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Daybreak.Configuration;
|
||||
|
||||
public static class SecretManager
|
||||
{
|
||||
private static JObject SecretsHolder;
|
||||
|
||||
public static string GetSecret(SecretKeys secretKey)
|
||||
{
|
||||
if (SecretsHolder is null)
|
||||
{
|
||||
LoadSecrets();
|
||||
}
|
||||
|
||||
return SecretsHolder.Value<string>(secretKey.Key);
|
||||
}
|
||||
|
||||
public static T GetSecret<T>(SecretKeys secretKey)
|
||||
{
|
||||
if (SecretsHolder is null)
|
||||
{
|
||||
LoadSecrets();
|
||||
}
|
||||
|
||||
return SecretsHolder.Value<T>(secretKey.Key);
|
||||
}
|
||||
|
||||
private static void LoadSecrets()
|
||||
{
|
||||
var serializedSecrets = Assembly.GetExecutingAssembly().GetManifestResourceStream("Daybreak.secrets.json").ReadAllBytes().GetString();
|
||||
serializedSecrets = TrimUnwantedCharacters(serializedSecrets);
|
||||
SecretsHolder = JObject.Parse(serializedSecrets);
|
||||
}
|
||||
|
||||
private static string TrimUnwantedCharacters(string s)
|
||||
{
|
||||
return new string(s.Where(c =>
|
||||
char.IsWhiteSpace(c) ||
|
||||
char.IsLetterOrDigit(c) ||
|
||||
char.IsSymbol(c) ||
|
||||
char.IsSeparator(c) ||
|
||||
char.IsPunctuation(c))
|
||||
.ToArray());
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public AddButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public BackButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Daybreak.Controls
|
||||
public event EventHandler Clicked;
|
||||
public BinButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public CancelButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public HelpButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -13,17 +13,17 @@ namespace Daybreak.Controls
|
||||
|
||||
public MaximizeButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
BackgroundEllipse.Visibility = System.Windows.Visibility.Visible;
|
||||
this.BackgroundEllipse.Visibility = System.Windows.Visibility.Visible;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
BackgroundEllipse.Visibility = System.Windows.Visibility.Hidden;
|
||||
this.BackgroundEllipse.Visibility = System.Windows.Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public MinusButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public OpaqueButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -13,17 +13,17 @@ namespace Daybreak.Controls
|
||||
|
||||
public SaveButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
BackgroundEllipse.Visibility = System.Windows.Visibility.Visible;
|
||||
this.BackgroundEllipse.Visibility = System.Windows.Visibility.Visible;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
BackgroundEllipse.Visibility = System.Windows.Visibility.Hidden;
|
||||
this.BackgroundEllipse.Visibility = System.Windows.Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<UserControl x:Class="Daybreak.Controls.SynchronizeButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Controls"
|
||||
mc:Ignorable="d"
|
||||
x:Name="_this"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Viewbox>
|
||||
<Grid>
|
||||
<Ellipse x:Name="BackgroundEllipse" Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}" Visibility="Visible" Opacity="0.1" Width="35" Height="35" />
|
||||
<Ellipse Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
StrokeThickness="3"/>
|
||||
<Grid VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center">
|
||||
<Path Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
StrokeThickness="1.5"
|
||||
Data="m19,15.6073c1.4937,-0.5852 3,-1.9184 3,-4.6073c0,-4 -3.3333,-5 -5,-5c0,-2 0,-6 -6,-6c-6,0 -6,4 -6,6c-1.66667,0 -5,1 -5,5c0,2.6889 1.50628,4.0221 3,4.6073" />
|
||||
<Path StrokeThickness="1.5"
|
||||
Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
Data="m6,17l1.76777,1.7678c1.56214,1.5621 4.09474,1.5621 5.65684,0l0.3536,-0.3536" />
|
||||
<Path StrokeThickness="1.5"
|
||||
Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
Data="m6.35355,19.4749l-0.35355,-2.4749l2.47482,0.3536l-2.12127,2.1213z" />
|
||||
<Path StrokeThickness="1.5"
|
||||
Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
Data="m14.77821,14.93927l-1.7678,-1.7677c-1.5621,-1.5621 -4.0948,-1.5621 -5.65685,0l-0.35356,0.3535" />
|
||||
<Path StrokeThickness="1.5"
|
||||
Stroke="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
|
||||
Data="m14.1213,12l0.3536,2.4749l-2.4749,-0.3536l2.1213,-2.1213z" />
|
||||
</Grid>
|
||||
<Ellipse Fill="Transparent" MouseEnter="Ellipse_MouseEnter" MouseLeave="Ellipse_MouseLeave" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown"></Ellipse>
|
||||
</Grid>
|
||||
</Viewbox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Daybreak.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for SynchronizeButton.xaml
|
||||
/// </summary>
|
||||
public partial class SynchronizeButton : UserControl
|
||||
{
|
||||
public event EventHandler Clicked;
|
||||
|
||||
public SynchronizeButton()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
this.BackgroundEllipse.Opacity = 0.6;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
this.BackgroundEllipse.Opacity = 0;
|
||||
}
|
||||
|
||||
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
this.Clicked?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<ContentPresenter x:Name="Content" Margin="5"
|
||||
Content="{Binding ElementName=_this, Path=InnerContent}"></ContentPresenter>
|
||||
<ContentPresenter Margin="5"
|
||||
Content="{Binding ElementName=_this, Path=InnerContent}"></ContentPresenter>
|
||||
<Border BorderBrush="{Binding ElementName=_this, Path=BorderBrush}"
|
||||
BorderThickness="{Binding ElementName=_this, Path=BorderThickness}"
|
||||
Opacity="{Binding ElementName=_this, Path=Highlighted, Converter={StaticResource HighlightConverter}}"
|
||||
|
||||
@@ -81,7 +81,16 @@ namespace Daybreak.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InitializeBrowser(
|
||||
public async Task InitializeDefaultBrowser()
|
||||
{
|
||||
var options = Launch.Launcher.Instance.ApplicationServiceManager.GetService<ILiveOptions<ApplicationConfiguration>>();
|
||||
var buildTemplateManager = Launch.Launcher.Instance.ApplicationServiceManager.GetService<IBuildTemplateManager>();
|
||||
var logger = Launch.Launcher.Instance.ApplicationServiceManager.GetService<ILogger<ChromiumBrowserWrapper>>();
|
||||
|
||||
await this.InitializeDefaultBrowser(options, buildTemplateManager, logger);
|
||||
}
|
||||
|
||||
public async Task InitializeDefaultBrowser(
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
ILogger<ChromiumBrowserWrapper> logger)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public CircularLoadingWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public AvatarGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public ExperimentGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public FileGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public FireballGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public GoldenArrowGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Daybreak.Controls
|
||||
{
|
||||
public LogsGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public StarGlyph()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public ImageViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
this.Image1.Visibility = Visibility.Visible;
|
||||
this.Image1.Opacity = 1;
|
||||
this.Image2.Visibility = Visibility.Hidden;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Daybreak.Controls
|
||||
public AccountTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += AccountTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.AccountTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
private void AccountTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Daybreak.Controls
|
||||
public AttributeTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += AttributeTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.AttributeTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
private void AttributeTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Controls
|
||||
|
||||
public BuildEntryTemplate()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void BinButton_Clicked(object sender, EventArgs e)
|
||||
|
||||
@@ -167,19 +167,25 @@
|
||||
Background="Transparent"
|
||||
SearchText="{Binding ElementName=_this, Path=SkillSearchText, Mode=TwoWay}"
|
||||
TextChanged="SearchTextBox_TextChanged"></local:SearchTextBox>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Hidden"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
Grid.Row="1"
|
||||
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
|
||||
<ListView x:Name="SkillsListView" Background="Transparent"
|
||||
ItemsSource="{Binding ElementName=_this, Path=AvailableSkills, Mode=OneWay}" MouseDoubleClick="ListView_MouseDoubleClick">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="16" Foreground="White" TextWrapping="Wrap" Text="{Binding Name}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ScrollViewer>
|
||||
<ListView x:Name="SkillsListView"
|
||||
Grid.Row="1"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Hidden"
|
||||
Background="Transparent"
|
||||
ItemsSource="{Binding ElementName=_this, Path=AvailableSkills, Mode=OneWay}"
|
||||
MouseDoubleClick="ListView_MouseDoubleClick">
|
||||
<ListView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel>
|
||||
</VirtualizingStackPanel>
|
||||
</ItemsPanelTemplate>
|
||||
</ListView.ItemsPanel>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="16" Foreground="White" TextWrapping="Wrap" Text="{Binding Name}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Core.Extensions;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Extensions;
|
||||
@@ -78,7 +79,7 @@ namespace Daybreak.Controls
|
||||
ILogger<ChromiumBrowserWrapper> logger)
|
||||
{
|
||||
this.iconBrowser = iconBrowser.ThrowIfNull();
|
||||
await this.SkillBrowser.InitializeBrowser(liveOptions, buildTemplateManager, logger);
|
||||
await this.SkillBrowser.InitializeDefaultBrowser(liveOptions, buildTemplateManager, logger);
|
||||
this.SkillTemplate0.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate1.InitializeSkillTemplate(iconRetriever);
|
||||
this.SkillTemplate2.InitializeSkillTemplate(iconRetriever);
|
||||
@@ -208,17 +209,8 @@ namespace Daybreak.Controls
|
||||
this.loadedBuild.Build.Attributes = this.Attributes.ToList();
|
||||
}
|
||||
|
||||
private void LoadSkills()
|
||||
private async void LoadSkills()
|
||||
{
|
||||
var possibleSkills = Skill.Skills
|
||||
.Where(s => s.Profession == this.PrimaryProfession || s.Profession == this.SecondaryProfession || s.Profession == Profession.None)
|
||||
.Where(s => s != Skill.NoSkill)
|
||||
.Where(s => this.SkillSearchText.IsNullOrWhiteSpace() ?
|
||||
true :
|
||||
StringUtils.MatchesSearchString(s.Name.Replace("\"", "").Replace("!", ""), this.SkillSearchText.Replace("\"", "").Replace("!", "")))
|
||||
.OrderBy(s => s.Name);
|
||||
this.AvailableSkills.ClearAnd().AddRange(possibleSkills);
|
||||
|
||||
if (this.Skill0.Profession != this.PrimaryProfession &&
|
||||
this.Skill0.Profession != this.SecondaryProfession &&
|
||||
this.Skill0.Profession != Profession.None)
|
||||
@@ -274,8 +266,12 @@ namespace Daybreak.Controls
|
||||
{
|
||||
this.Skill7 = Skill.NoSkill;
|
||||
}
|
||||
|
||||
var filteredSkills = await this.FilterSkills(this.SkillSearchText).ToListAsync().ConfigureAwait(true);
|
||||
this.AvailableSkills.ClearAnd().AddRange(filteredSkills);
|
||||
}
|
||||
|
||||
|
||||
private void LoadBuild()
|
||||
{
|
||||
this.suppressBuildChanged = true;
|
||||
@@ -357,13 +353,14 @@ namespace Daybreak.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private void AttributeTemplate_HelpClicked(object sender, AttributeEntry e)
|
||||
private void AttributeTemplate_HelpClicked(object _, AttributeEntry e)
|
||||
{
|
||||
this.BrowseToInfo(e.Attribute.Name);
|
||||
}
|
||||
|
||||
private void AttributeTemplate_AttributeChanged(object sender, AttributeEntry e)
|
||||
private void AttributeTemplate_AttributeChanged(object _, AttributeEntry e)
|
||||
{
|
||||
e.ThrowIfNull();
|
||||
this.BuildChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
@@ -384,8 +381,9 @@ namespace Daybreak.Controls
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void SearchTextBox_TextChanged(object sender, string e)
|
||||
private void SearchTextBox_TextChanged(object _, string e)
|
||||
{
|
||||
e.ThrowIfNull();
|
||||
this.LoadSkills();
|
||||
}
|
||||
|
||||
@@ -441,5 +439,39 @@ namespace Daybreak.Controls
|
||||
e.Handled = true;
|
||||
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - e.Delta);
|
||||
}
|
||||
|
||||
private async IAsyncEnumerable<Skill> FilterSkills(string searchTerm)
|
||||
{
|
||||
// Replace symbols to ease search
|
||||
searchTerm = searchTerm?.Replace("\"", "").Replace("!", "");
|
||||
|
||||
foreach (var skill in Skill.Skills)
|
||||
{
|
||||
if (skill == Skill.NoSkill)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skill.Profession != this.PrimaryProfession &&
|
||||
skill.Profession != this.SecondaryProfession &&
|
||||
skill.Profession != Profession.None)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (searchTerm.IsNullOrWhiteSpace())
|
||||
{
|
||||
yield return skill;
|
||||
continue;
|
||||
}
|
||||
|
||||
var matchesName = await Task.Run(() => StringUtils.MatchesSearchString(skill.Name.Replace("\"", "").Replace("!", ""), searchTerm));
|
||||
if (matchesName)
|
||||
{
|
||||
yield return skill;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Daybreak.Controls
|
||||
public GuildwarsPathTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += GuildwarsPathTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.GuildwarsPathTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
private void GuildwarsPathTemplate_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Daybreak.Controls.Templates
|
||||
public ScreenTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += ScreenTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.ScreenTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Daybreak.Controls
|
||||
public SkillTemplate()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.DataContextChanged += SkillTemplate_DataContextChanged;
|
||||
this.DataContextChanged += this.SkillTemplate_DataContextChanged;
|
||||
}
|
||||
|
||||
public void InitializeSkillTemplate(IIconCache iconRetriever)
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace Daybreak.Converters
|
||||
}
|
||||
|
||||
var objValue = value.Cast<bool>();
|
||||
if ((objValue && TriggerValue && IsHidden) || (!objValue && !TriggerValue && IsHidden))
|
||||
if ((objValue && this.TriggerValue && this.IsHidden) || (!objValue && !this.TriggerValue && this.IsHidden))
|
||||
{
|
||||
return Visibility.Hidden;
|
||||
}
|
||||
|
||||
if ((objValue && TriggerValue && !IsHidden) || (!objValue && !TriggerValue && !IsHidden))
|
||||
if ((objValue && this.TriggerValue && !this.IsHidden) || (!objValue && !this.TriggerValue && !this.IsHidden))
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Daybreak.Converters
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return GetVerticalAlignment(value);
|
||||
return this.GetVerticalAlignment(value);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
|
||||
@@ -10,20 +10,42 @@
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
|
||||
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
|
||||
<Version>0.9.4</Version>
|
||||
<Version>0.9.6.3</Version>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="AddUserSecrets" BeforeTargets="PrepareForBuild" Condition=" '$(UserSecretsId)' != '' ">
|
||||
<PropertyGroup>
|
||||
<UserSecretsFilePath Condition=" '$(OS)' == 'Windows_NT' ">
|
||||
$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))\AppData\Roaming\Microsoft\UserSecrets\$(UserSecretsId)\secrets.json
|
||||
</UserSecretsFilePath>
|
||||
<UserSecretsFilePath Condition=" '$(OS)' == 'Unix' ">
|
||||
$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))/.microsoft/usersecrets/$(UserSecretsId)/secrets.json
|
||||
</UserSecretsFilePath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="$(UserSecretsFilePath)" Condition="Exists($(UserSecretsFilePath))" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.12" />
|
||||
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1264.42" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1293.44" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NReco.Logging.File" Version="1.1.5" />
|
||||
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
|
||||
<PackageReference Include="Slim" Version="1.7.3" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
<PackageReference Include="SystemExtensions.NetCore" Version="1.0.1" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.5.0" />
|
||||
<PackageReference Include="WCL" Version="1.0.2" />
|
||||
@@ -33,6 +55,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Controls\Buttons\SynchronizeButton.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Controls\Buttons\HelpButton.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -51,6 +76,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="Controls\Buttons\SynchronizeButton.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Controls\Buttons\HelpButton.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Services.Updater.PostUpdate;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Slim;
|
||||
@@ -15,8 +16,11 @@ namespace Daybreak.Launch
|
||||
{
|
||||
public sealed class Launcher : ExtendedApplication<MainWindow>
|
||||
{
|
||||
public readonly static Launcher Instance = new();
|
||||
|
||||
private ILogger logger;
|
||||
private readonly static Launcher launcher = new();
|
||||
|
||||
public IServiceManager ApplicationServiceManager => this.ServiceManager;
|
||||
|
||||
[STAThread]
|
||||
public static int Main()
|
||||
@@ -31,8 +35,9 @@ namespace Daybreak.Launch
|
||||
protected override void RegisterServices(IServiceProducer serviceProducer)
|
||||
{
|
||||
ProjectConfiguration.RegisterServices(this.ServiceManager);
|
||||
ServiceManager.BuildSingletons();
|
||||
this.ServiceManager.BuildSingletons();
|
||||
ProjectConfiguration.RegisterViews(this.ServiceManager.GetService<IViewManager>());
|
||||
ProjectConfiguration.RegisterPostUpdateActions(this.ServiceManager.GetService<IPostUpdateActionProducer>());
|
||||
}
|
||||
protected override bool HandleException(Exception e)
|
||||
{
|
||||
@@ -104,7 +109,7 @@ namespace Daybreak.Launch
|
||||
}
|
||||
private static int LaunchMainWindow()
|
||||
{
|
||||
return launcher.Run();
|
||||
return Instance.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,10 +103,13 @@
|
||||
<Grid x:Name="Container" Grid.Row="1">
|
||||
</Grid>
|
||||
<wcl:Border OnResize="Border_OnResize" Grid.RowSpan="2" Active="True"></wcl:Border>
|
||||
<webview:WebView2 x:Name="BackgroundWebView"
|
||||
<controls:ChromiumBrowserWrapper x:Name="BackgroundWebView"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Visibility="Collapsed"
|
||||
Grid.Row="1"></webview:WebView2>
|
||||
Visibility="Visible"
|
||||
ControlsEnabled="False"
|
||||
CanNavigate="False"
|
||||
CanDownloadBuild="False"
|
||||
Grid.Row="1"></controls:ChromiumBrowserWrapper>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Daybreak.Models.Builds;
|
||||
|
||||
namespace Daybreak.Models;
|
||||
|
||||
public sealed class BuildWithTemplateCode
|
||||
{
|
||||
public BuildEntry Build { get; set; }
|
||||
public string TemplateCode { get; set; }
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Models.Builds
|
||||
set
|
||||
{
|
||||
this.attribute = value;
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Attribute)));
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Attribute)));
|
||||
}
|
||||
}
|
||||
public int Points
|
||||
@@ -22,7 +22,7 @@ namespace Daybreak.Models.Builds
|
||||
set
|
||||
{
|
||||
this.points = value;
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Points)));
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Points)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Daybreak.Models.Builds
|
||||
set
|
||||
{
|
||||
this.name = value;
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name)));
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Name)));
|
||||
}
|
||||
}
|
||||
public Build Build
|
||||
@@ -24,7 +24,7 @@ namespace Daybreak.Models.Builds
|
||||
set
|
||||
{
|
||||
this.build = value;
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Build)));
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Build)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2978,7 +2978,7 @@ namespace Daybreak.Models.Builds
|
||||
WeaponsofThreeForges,
|
||||
VowofRevolution,
|
||||
HeroicRefrain,
|
||||
};
|
||||
}.OrderBy(s => s.Name).ToList();
|
||||
|
||||
public static bool TryParse(int id, out Skill skill)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Daybreak.Models
|
||||
/// <summary>
|
||||
/// The VirtualCode converted to typeof(Keys) for higher usability.
|
||||
/// </summary>
|
||||
public Keys Key { get { return (Keys)VirtualCode; } }
|
||||
public Keys Key { get { return (Keys)this.VirtualCode; } }
|
||||
|
||||
/// <summary>
|
||||
/// A hardware scan code for the key.
|
||||
|
||||
@@ -17,11 +17,11 @@ namespace Daybreak.Models.Progress
|
||||
|
||||
public IconDownloadStep CurrentStep
|
||||
{
|
||||
get => currentStep;
|
||||
get => this.currentStep;
|
||||
set
|
||||
{
|
||||
currentStep = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentStep)));
|
||||
this.currentStep = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.CurrentStep)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ namespace Daybreak.Models.Progress
|
||||
|
||||
public UpdateStep CurrentStep
|
||||
{
|
||||
get => currentStep;
|
||||
get => this.currentStep;
|
||||
set
|
||||
{
|
||||
currentStep = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentStep)));
|
||||
this.currentStep = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.CurrentStep)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Daybreak.Models.Progress
|
||||
{
|
||||
internal DownloadUpdateStep(string name, double progress) : base(name)
|
||||
{
|
||||
Progress = progress;
|
||||
this.Progress = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,33 +16,33 @@ namespace Daybreak.Models
|
||||
|
||||
private byte[] DecryptedValue
|
||||
{
|
||||
get => this.encryptedBytes.DecryptBytes(key);
|
||||
set => this.encryptedBytes = value.EncryptBytes(key);
|
||||
get => this.encryptedBytes.DecryptBytes(this.key);
|
||||
set => this.encryptedBytes = value.EncryptBytes(this.key);
|
||||
}
|
||||
[JsonProperty("value")]
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.encryptedBytes.DecryptBytes(key).AsString();
|
||||
return this.encryptedBytes.DecryptBytes(this.key).AsString();
|
||||
}
|
||||
set
|
||||
{
|
||||
this.encryptedBytes = value.AsBytes().EncryptBytes(key);
|
||||
this.encryptedBytes = value.AsBytes().EncryptBytes(this.key);
|
||||
}
|
||||
}
|
||||
private SecureString(byte[] value)
|
||||
{
|
||||
this.key = new byte[32];
|
||||
using var crypto = RandomNumberGenerator.Create();
|
||||
crypto.GetBytes(key);
|
||||
crypto.GetBytes(this.key);
|
||||
this.DecryptedValue = value;
|
||||
}
|
||||
public SecureString(string value)
|
||||
{
|
||||
this.key = new byte[32];
|
||||
using var crypto = RandomNumberGenerator.Create();
|
||||
crypto.GetBytes(key);
|
||||
crypto.GetBytes(this.key);
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace Daybreak.Models.Versioning
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var version = string.Join('.', parts.OfType<VersionNumberToken>());
|
||||
if (parts.Last() is VersionStringToken)
|
||||
var version = string.Join('.', this.parts.OfType<VersionNumberToken>());
|
||||
if (this.parts.Last() is VersionStringToken)
|
||||
{
|
||||
version += "-" + parts.Last();
|
||||
version += "-" + this.parts.Last();
|
||||
}
|
||||
|
||||
if (this.HasPrefix)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Daybreak.Services.Bloogum
|
||||
this.logger.LogInformation($"Retrieving image from {BaseAddress}/{url}");
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetAsync($"{BaseAddress}/{url}").ConfigureAwait(false);
|
||||
var response = await this.httpClient.GetAsync($"{BaseAddress}/{url}").ConfigureAwait(false);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger.LogInformation("Received success status code");
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Extensions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.BuildTemplates
|
||||
{
|
||||
@@ -41,16 +42,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
public BuildEntry CreateBuild()
|
||||
{
|
||||
var emptyBuild = new Build();
|
||||
var builds = GetBuilds();
|
||||
var baseName = "New build";
|
||||
var name = baseName;
|
||||
int count = 0;
|
||||
while(builds.Where(b => b.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).Any())
|
||||
{
|
||||
name = baseName + count;
|
||||
count++;
|
||||
}
|
||||
|
||||
var name = Guid.NewGuid().ToString();
|
||||
var entry = new BuildEntry { Build = emptyBuild, Name = name, PreviousName = string.Empty };
|
||||
this.SaveBuild(entry);
|
||||
return entry;
|
||||
@@ -88,19 +80,42 @@ namespace Daybreak.Services.BuildTemplates
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<BuildEntry> GetBuilds()
|
||||
public async Task<Result<BuildEntry, Exception>> GetBuild(string name)
|
||||
{
|
||||
if (File.Exists($"{BuildsPath}/{name}.txt") is false)
|
||||
{
|
||||
return new InvalidOperationException("Unable to find build file");
|
||||
}
|
||||
|
||||
var content = await File.ReadAllTextAsync($"{BuildsPath}/{name}.txt");
|
||||
if (this.TryDecodeTemplate(content, out var build) is false)
|
||||
{
|
||||
return new InvalidOperationException("Unable to parse build file");
|
||||
}
|
||||
|
||||
return new BuildEntry { Build = build, Name = name, PreviousName = name };
|
||||
}
|
||||
|
||||
public void ClearBuilds()
|
||||
{
|
||||
foreach(var file in Directory.GetFiles(BuildsPath))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<BuildEntry> GetBuilds()
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(BuildsPath))
|
||||
{
|
||||
Build build = default;
|
||||
try
|
||||
{
|
||||
build = this.DecodeTemplate(File.ReadAllText(file));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.logger.LogError($"Failed to decode template from file {file}. Details: {e}");
|
||||
}
|
||||
var maybeBuild = this.DecodeTemplateInner(await File.ReadAllTextAsync(file));
|
||||
var build = maybeBuild.Switch(
|
||||
onSuccess: build => build,
|
||||
onFailure: exception =>
|
||||
{
|
||||
this.logger.LogError(exception, "Failed to parse build");
|
||||
return default;
|
||||
});
|
||||
|
||||
if (build is not null)
|
||||
{
|
||||
@@ -111,7 +126,21 @@ namespace Daybreak.Services.BuildTemplates
|
||||
|
||||
public Build DecodeTemplate(string template)
|
||||
{
|
||||
return this.DecodeTemplateInner(template);
|
||||
var maybeTemplate = this.DecodeTemplateInner(template);
|
||||
return maybeTemplate.Switch(
|
||||
onSuccess: build => build,
|
||||
onFailure: exception => throw exception);
|
||||
}
|
||||
|
||||
public bool TryDecodeTemplate(string template, out Build build)
|
||||
{
|
||||
var maybeBuild = this.DecodeTemplateInner(template);
|
||||
(var result, var parsedBuild) = maybeBuild.Switch(
|
||||
onSuccess: parsedBuild => (true, parsedBuild),
|
||||
onFailure: _ => (false, null));
|
||||
|
||||
build = parsedBuild;
|
||||
return result;
|
||||
}
|
||||
|
||||
public string EncodeTemplate(Build build)
|
||||
@@ -119,7 +148,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
return this.EncodeTemplateInner(build);
|
||||
}
|
||||
|
||||
private Build DecodeTemplateInner(string template)
|
||||
private Result<Build, Exception> DecodeTemplateInner(string template)
|
||||
{
|
||||
this.logger.LogInformation("Attempting to decode template");
|
||||
var buildMetadata = ParseEncodedTemplate(template);
|
||||
@@ -127,7 +156,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
if (buildMetadata.VersionNumber != 0)
|
||||
{
|
||||
this.logger.LogError($"Expected version number to be 0 but found {buildMetadata.VersionNumber}");
|
||||
throw new InvalidOperationException($"Failed to parse template");
|
||||
return new InvalidOperationException($"Failed to parse template");
|
||||
}
|
||||
|
||||
var build = new Build()
|
||||
@@ -139,14 +168,14 @@ namespace Daybreak.Services.BuildTemplates
|
||||
if (Profession.TryParse(buildMetadata.PrimaryProfessionId, out var primaryProfession) is false)
|
||||
{
|
||||
this.logger.LogError($"Failed to parse profession with id {buildMetadata.PrimaryProfessionId}");
|
||||
throw new InvalidOperationException($"Failed to parse template");
|
||||
return new InvalidOperationException($"Failed to parse template");
|
||||
}
|
||||
|
||||
build.Primary = primaryProfession;
|
||||
if (Profession.TryParse(buildMetadata.SecondaryProfessionId, out var secondaryProfession) is false)
|
||||
{
|
||||
this.logger.LogError($"Failed to parse profession with id {buildMetadata.SecondaryProfessionId}");
|
||||
throw new InvalidOperationException($"Failed to parse template");
|
||||
return new InvalidOperationException($"Failed to parse template");
|
||||
}
|
||||
|
||||
build.Secondary = secondaryProfession;
|
||||
@@ -155,7 +184,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
if (Daybreak.Models.Builds.Attribute.TryParse(buildMetadata.AttributesIds[i], out var attribute) is false)
|
||||
{
|
||||
this.logger.LogError($"Failed to parse attribute with id {buildMetadata.AttributesIds[i]}");
|
||||
throw new InvalidOperationException($"Failed to parse template");
|
||||
return new InvalidOperationException($"Failed to parse template");
|
||||
}
|
||||
|
||||
build.Attributes.Add(new AttributeEntry { Attribute = attribute, Points = buildMetadata.AttributePoints[i] });
|
||||
@@ -166,7 +195,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
if (Skill.TryParse(buildMetadata.SkillIds[i], out var skill) is false)
|
||||
{
|
||||
this.logger.LogError($"Failed to parse skill with id {buildMetadata.SkillIds[i]}");
|
||||
throw new InvalidOperationException($"Failed to parse template");
|
||||
return new InvalidOperationException($"Failed to parse template");
|
||||
}
|
||||
|
||||
build.Skills.Add(skill);
|
||||
@@ -247,7 +276,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
buildMetadata.NewTemplate = false;
|
||||
}
|
||||
|
||||
buildMetadata.ProfessionIdLength = stream.Read(2) * 2 + 4;
|
||||
buildMetadata.ProfessionIdLength = (stream.Read(2) * 2) + 4;
|
||||
buildMetadata.PrimaryProfessionId = stream.Read(buildMetadata.ProfessionIdLength);
|
||||
buildMetadata.SecondaryProfessionId = stream.Read(buildMetadata.ProfessionIdLength);
|
||||
buildMetadata.AttributeCount = stream.Read(4);
|
||||
@@ -284,7 +313,7 @@ namespace Daybreak.Services.BuildTemplates
|
||||
|
||||
var desiredProfessionIdLength = GetBitLength(new List<int> { buildMetadata.PrimaryProfessionId, buildMetadata.SecondaryProfessionId }.Max());
|
||||
var professionIdLength = Math.Max((desiredProfessionIdLength - 4) / 2, 0);
|
||||
var finalProfessionIdLength = professionIdLength * 2 + 4;
|
||||
var finalProfessionIdLength = (professionIdLength * 2) + 4;
|
||||
stream.Write(professionIdLength, 2);
|
||||
stream.Write(buildMetadata.PrimaryProfessionId, finalProfessionIdLength);
|
||||
stream.Write(buildMetadata.SecondaryProfessionId, finalProfessionIdLength);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Daybreak.Models.Builds;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.BuildTemplates
|
||||
{
|
||||
@@ -8,10 +11,13 @@ namespace Daybreak.Services.BuildTemplates
|
||||
bool IsTemplate(string template);
|
||||
BuildEntry CreateBuild();
|
||||
BuildEntry CreateBuild(string name);
|
||||
void ClearBuilds();
|
||||
void SaveBuild(BuildEntry buildEntry);
|
||||
void RemoveBuild(BuildEntry buildEntry);
|
||||
IEnumerable<BuildEntry> GetBuilds();
|
||||
IAsyncEnumerable<BuildEntry> GetBuilds();
|
||||
Task<Result<BuildEntry, Exception>> GetBuild(string name);
|
||||
Build DecodeTemplate(string template);
|
||||
bool TryDecodeTemplate(string template, out Build build);
|
||||
string EncodeTemplate(Build build);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Daybreak.Services.BuildTemplates.Models
|
||||
|
||||
public string GetEncodedString()
|
||||
{
|
||||
return innerStringBuilder.ToString();
|
||||
return this.innerStringBuilder.ToString();
|
||||
}
|
||||
|
||||
private void EncodeToBinary(int value, int count)
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using Daybreak.Services.Graph.Models;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Core.Extensions;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Daybreak.Services.Graph;
|
||||
|
||||
public sealed class GraphClient : IGraphClient
|
||||
{
|
||||
private const string Scopes = "Files.Read Files.Read.All Files.ReadWrite Files.ReadWrite.All User.Read";
|
||||
private const string RedirectUri = "http://localhost";
|
||||
|
||||
private const string QueryStateKey = "state";
|
||||
private const string QueryCodeKey = "code";
|
||||
private const string ClientIdPlaceholder = "[ClientID]";
|
||||
private const string RedirectUriPlaceholder = "[RedirectUri]";
|
||||
private const string ScopesPlaceholder = "[Scopes]";
|
||||
private const string StatePlaceholder = "[State]";
|
||||
private const string ProfileEndpoint = "me";
|
||||
private const string GraphBaseUrl = "https://graph.microsoft.com/v1.0/";
|
||||
private const string TokenUrlPlaceholder = $"https://login.microsoftonline.com/consumers/oauth2/v2.0/token";
|
||||
private const string AuthorizationUrlPlaceholder = $"https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id={ClientIdPlaceholder}&response_type=code&redirect_uri={RedirectUriPlaceholder}&response_mode=query&scope={ScopesPlaceholder}&state={StatePlaceholder}";
|
||||
private const string SyncFolderUri = $"me/drive/root:/Daybreak/Builds{SuffixPlaceholder}";
|
||||
private const string SyncFileUri = $"me/drive/root:/Daybreak/Builds/{FilenamePlaceholder}{ContentSuffix}";
|
||||
private const string ContentSuffix = ":/content";
|
||||
private const string ChildrenSuffix = ":/children";
|
||||
private const string SuffixPlaceholder = "[Suffix]";
|
||||
private const string FilenamePlaceholder = "[File]";
|
||||
|
||||
private static readonly byte[] Entropy = Convert.FromBase64String("R3VpbGR3YXJz");
|
||||
private static readonly string ApplicationId = SecretManager.GetSecret(SecretKeys.AadApplicationId);
|
||||
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions;
|
||||
private readonly IHttpClient<GraphClient> httpClient;
|
||||
private readonly ILogger<GraphClient> logger;
|
||||
|
||||
public GraphClient(
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
IViewManager viewManager,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveUpdateableOptions,
|
||||
IHttpClient<GraphClient> httpClient,
|
||||
ILogger<GraphClient> logger)
|
||||
{
|
||||
this.buildTemplateManager = buildTemplateManager.ThrowIfNull();
|
||||
this.viewManager = viewManager.ThrowIfNull();
|
||||
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull();
|
||||
this.httpClient = httpClient.ThrowIfNull();
|
||||
this.logger = logger.ThrowIfNull();
|
||||
|
||||
this.httpClient.BaseAddress = new Uri(GraphBaseUrl);
|
||||
this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public async Task<Result<bool, Exception>> PerformAuthorizationFlow(
|
||||
ChromiumBrowserWrapper chromiumBrowserWrapper,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var maybeAuthCode = await RetrieveAuthorizationCode(chromiumBrowserWrapper, cancellationToken);
|
||||
if (maybeAuthCode.TryExtractSuccess(out var authCode) is false)
|
||||
{
|
||||
return maybeAuthCode.SwitchAny(onFailure: exception => exception);
|
||||
}
|
||||
|
||||
var maybeAccessToken = await this.RetrieveAccessToken(authCode);
|
||||
|
||||
return maybeAccessToken.Switch(
|
||||
onSuccess: token =>
|
||||
{
|
||||
var accessToken = AccessToken.FromTokenResponse(token);
|
||||
this.SaveAccessToken(accessToken);
|
||||
return true;
|
||||
},
|
||||
onFailure: exception => exception);
|
||||
}
|
||||
|
||||
public async Task<Result<User, Exception>> GetUserProfile<TViewType>()
|
||||
where TViewType : UserControl
|
||||
{
|
||||
var authCode = this.LoadAccessToken();
|
||||
if (authCode.ExtractValue() is not AccessToken accessToken)
|
||||
{
|
||||
this.viewManager.ShowView<GraphAuthorizationView>(new ViewRedirectContext { CallingView = typeof(TViewType) });
|
||||
return new InvalidOperationException("Client is not authorized");
|
||||
}
|
||||
|
||||
if (DateTime.Now > accessToken.ExpirationDate)
|
||||
{
|
||||
this.viewManager.ShowView<GraphAuthorizationView>(new ViewRedirectContext { CallingView = typeof(TViewType) });
|
||||
return new InvalidOperationException("Client authorization expired");
|
||||
}
|
||||
|
||||
this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token);
|
||||
var response = await this.httpClient.GetAsync(ProfileEndpoint);
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
this.viewManager.ShowView<GraphAuthorizationView>(new ViewRedirectContext { CallingView = typeof(TViewType) });
|
||||
return new InvalidOperationException($"Failed to load profile. Response status code [{response.StatusCode}]");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var profile = JsonConvert.DeserializeObject<User>(await response.Content.ReadAsStringAsync());
|
||||
return profile;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result<bool, Exception>> UploadBuilds()
|
||||
{
|
||||
await this.buildTemplateManager.GetBuilds()
|
||||
.ForEachAsync(async buildEntry => await this.PutFileItem(buildEntry));
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Result<bool, Exception>> DownloadBuilds()
|
||||
{
|
||||
var builds = this.RetrieveBuildsList();
|
||||
|
||||
this.buildTemplateManager.ClearBuilds();
|
||||
var compiledBuilds = await builds.Select(buildFile =>
|
||||
{
|
||||
if (this.buildTemplateManager.TryDecodeTemplate(buildFile.TemplateCode, out var build) is false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BuildEntry
|
||||
{
|
||||
Build = build,
|
||||
Name = buildFile.FileName,
|
||||
PreviousName = buildFile.FileName
|
||||
};
|
||||
}).Where(entry => entry is not null).ToListAsync();
|
||||
_ = compiledBuilds.Do(this.buildTemplateManager.SaveBuild).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Result<bool, Exception>> DownloadBuild(string buildName)
|
||||
{
|
||||
var builds = this.RetrieveBuildsList();
|
||||
|
||||
var compiledBuilds = await builds
|
||||
.Where(build => build.FileName == buildName)
|
||||
.Select(buildFile =>
|
||||
{
|
||||
if (this.buildTemplateManager.TryDecodeTemplate(buildFile.TemplateCode, out var build) is false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BuildEntry
|
||||
{
|
||||
Build = build,
|
||||
Name = buildFile.FileName,
|
||||
PreviousName = buildFile.FileName
|
||||
};
|
||||
}).Where(entry => entry is not null).ToListAsync();
|
||||
_ = compiledBuilds.Do(this.buildTemplateManager.SaveBuild).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Result<bool, Exception>> UploadBuild(string buildName)
|
||||
{
|
||||
var getBuildResult = await this.buildTemplateManager.GetBuild(buildName);
|
||||
if (getBuildResult.TryExtractSuccess(out var buildEntry) is false)
|
||||
{
|
||||
return getBuildResult.SwitchAny(
|
||||
onFailure: exception => exception);
|
||||
}
|
||||
|
||||
return await this.PutFileItem(buildEntry);
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<BuildFile> RetrieveBuildsList()
|
||||
{
|
||||
var folderResult = await this.GetFolderItem();
|
||||
if (folderResult.ExtractValue() is not FolderItem folder)
|
||||
{
|
||||
folder = new FolderItem { Files = new List<FileItem>() };
|
||||
}
|
||||
|
||||
var retrieveContentTasks = folder.Files
|
||||
.Where(file => file.Name.EndsWith(".txt"))
|
||||
.Select(async file =>
|
||||
{
|
||||
var response = await this.httpClient.GetAsync(file.DownloadUrl);
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BuildFile { FileName = file.Name.Replace(".txt", string.Empty), TemplateCode = await response.Content.ReadAsStringAsync() };
|
||||
})
|
||||
.ToList();
|
||||
|
||||
foreach(var task in retrieveContentTasks)
|
||||
{
|
||||
yield return await task;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetAuthorization()
|
||||
{
|
||||
this.ResetAccessToken();
|
||||
}
|
||||
|
||||
private async Task<bool> PutFileItem(BuildEntry buildEntry)
|
||||
{
|
||||
using var stringContent = new StringContent(this.buildTemplateManager.EncodeTemplate(buildEntry.Build));
|
||||
var response = await this.httpClient.PutAsync(SyncFileUri.Replace(FilenamePlaceholder, $"{buildEntry.Name}.txt"), stringContent);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
private async Task<Optional<FolderItem>> GetFolderItem()
|
||||
{
|
||||
var response = await this.httpClient.GetAsync(SyncFolderUri.Replace(SuffixPlaceholder, ChildrenSuffix));
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
return Optional.None<FolderItem>();
|
||||
}
|
||||
|
||||
var driveItemContent = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<FolderItem>(driveItemContent);
|
||||
}
|
||||
|
||||
private static async Task<Result<string, Exception>> RetrieveAuthorizationCode(
|
||||
ChromiumBrowserWrapper chromiumBrowserWrapper,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
chromiumBrowserWrapper.ThrowIfNull();
|
||||
await chromiumBrowserWrapper.InitializeDefaultBrowser();
|
||||
|
||||
var state = GetNewState();
|
||||
|
||||
chromiumBrowserWrapper.Address = AuthorizationUrlPlaceholder
|
||||
.Replace(ClientIdPlaceholder, ApplicationId)
|
||||
.Replace(RedirectUriPlaceholder, RedirectUri
|
||||
.Replace(":", "%3a")
|
||||
.Replace("/", "%2f"))
|
||||
.Replace(ScopesPlaceholder, Scopes
|
||||
.Replace(' ', '+'))
|
||||
.Replace(StatePlaceholder, state);
|
||||
|
||||
while (chromiumBrowserWrapper.Address.StartsWith(RedirectUri) is false)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return new TaskCanceledException();
|
||||
}
|
||||
|
||||
await Task.Delay(1000, cancellationToken).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
var query = HttpUtility.ParseQueryString(chromiumBrowserWrapper.Address.Split('?').Skip(1).FirstOrDefault());
|
||||
if (query.GetValues(QueryStateKey) is string[] states is false)
|
||||
{
|
||||
throw new InvalidOperationException("Response doesn't have state key in response");
|
||||
}
|
||||
|
||||
if (states.Length < 1 || states.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException("Response contains invalid state");
|
||||
}
|
||||
|
||||
if (states.First() != state)
|
||||
{
|
||||
throw new InvalidOperationException("Response contains incorrect state");
|
||||
}
|
||||
|
||||
if (query.GetValues(QueryCodeKey) is string[] codes is false)
|
||||
{
|
||||
throw new InvalidOperationException("Response doesn't have code key in response");
|
||||
}
|
||||
|
||||
if (codes.Length < 1 || codes.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException("Response contains invalid code");
|
||||
}
|
||||
|
||||
var authCode = codes.First();
|
||||
return authCode;
|
||||
}
|
||||
|
||||
private async Task<Result<TokenResponse, Exception>> RetrieveAccessToken(string authorizationCode)
|
||||
{
|
||||
using var formContent = new FormUrlEncodedContent(
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "grant_type", "authorization_code" },
|
||||
{ "code", authorizationCode },
|
||||
{ "redirect_uri", RedirectUri },
|
||||
{ "client_id", ApplicationId },
|
||||
{ "scope", Scopes }
|
||||
});
|
||||
|
||||
using var httpRequest = new HttpRequestMessage
|
||||
{
|
||||
Content = formContent,
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(TokenUrlPlaceholder)
|
||||
};
|
||||
|
||||
using var response = await this.httpClient.SendAsync(httpRequest);
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
return new InvalidOperationException($"Invalid access token response. Status code [{response.StatusCode}]");
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<TokenResponse>(await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
private void ResetAccessToken()
|
||||
{
|
||||
this.liveUpdateableOptions.Value.ProtectedGraphAccessToken = null;
|
||||
this.liveUpdateableOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private void SaveAccessToken(AccessToken token)
|
||||
{
|
||||
var codeBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(token));
|
||||
this.liveUpdateableOptions.Value.ProtectedGraphAccessToken = Convert.ToBase64String(ProtectedData.Protect(codeBytes, Entropy, DataProtectionScope.CurrentUser));
|
||||
this.liveUpdateableOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private Optional<AccessToken> LoadAccessToken()
|
||||
{
|
||||
var protectedCode = this.liveUpdateableOptions.Value.ProtectedGraphAccessToken;
|
||||
if (protectedCode.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Optional.None<AccessToken>();
|
||||
}
|
||||
|
||||
var codeBytes = ProtectedData.Unprotect(Convert.FromBase64String(protectedCode), Entropy, DataProtectionScope.CurrentUser);
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<AccessToken>(Encoding.UTF8.GetString(codeBytes));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.logger.LogError(e, "Failed to load access token. Resetting access token");
|
||||
this.ResetAccessToken();
|
||||
return Optional.None<AccessToken>();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetNewState()
|
||||
{
|
||||
return Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Services.Graph.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Extensions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Daybreak.Services.Graph;
|
||||
|
||||
public interface IGraphClient
|
||||
{
|
||||
Task<Result<User, Exception>> GetUserProfile<TViewType>()
|
||||
where TViewType : UserControl;
|
||||
Task<Result<bool, Exception>> PerformAuthorizationFlow(ChromiumBrowserWrapper chromiumBrowserWrapper, CancellationToken cancellationToken = default);
|
||||
Task<Result<bool, Exception>> UploadBuilds();
|
||||
Task<Result<bool, Exception>> DownloadBuilds();
|
||||
Task<Result<bool, Exception>> UploadBuild(string buildName);
|
||||
Task<Result<bool, Exception>> DownloadBuild(string buildName);
|
||||
IAsyncEnumerable<BuildFile> RetrieveBuildsList();
|
||||
void ResetAuthorization();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class AccessToken
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
|
||||
public static AccessToken FromTokenResponse(TokenResponse tokenResponse)
|
||||
{
|
||||
return new AccessToken
|
||||
{
|
||||
Token = tokenResponse.AccessToken,
|
||||
ExpirationDate = DateTime.Now + TimeSpan.FromSeconds(tokenResponse.ExpiresIn)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class BuildFile
|
||||
{
|
||||
public string TemplateCode { get; set; }
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class BuildFilesPayload
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class FileItem
|
||||
{
|
||||
[JsonProperty("@microsoft.graph.downloadUrl")]
|
||||
public string DownloadUrl { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("lastModifiedDateTime")]
|
||||
public DateTime LastModifiedDateTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class FolderItem
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public List<FileItem> Files { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class TokenResponse
|
||||
{
|
||||
[JsonProperty("token_type")]
|
||||
public string TokenType { get; set; }
|
||||
[JsonProperty("scope")]
|
||||
public string Scope { get; set; }
|
||||
[JsonProperty("expires_in")]
|
||||
public int ExpiresIn { get; set; }
|
||||
[JsonProperty("access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
[JsonProperty("refresh_token")]
|
||||
public string RefreshToken { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class User
|
||||
{
|
||||
[JsonProperty("displayName")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
[JsonProperty("mail")]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace Daybreak.Services.Graph.Models;
|
||||
|
||||
public sealed class ViewRedirectContext
|
||||
{
|
||||
public Type CallingView { get; set; }
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
using System.Threading;
|
||||
|
||||
namespace Daybreak.Services.IconRetrieve
|
||||
{
|
||||
public interface IIconBrowser
|
||||
{
|
||||
void InitializeWebView(WebView2 webView2, CancellationToken cancellationToken);
|
||||
void InitializeWebView(ChromiumBrowserWrapper webView2, CancellationToken cancellationToken);
|
||||
/// <summary>
|
||||
/// Queue an icon request. The browser will attempt to download the icon. Monitor the <see cref="IconRequest.Finished"/> to be notified when the request has been served.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models.Progress;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.IconRetrieve
|
||||
{
|
||||
public interface IIconDownloader
|
||||
{
|
||||
void SetBrowser(WebView2 chromiumBrowserWrapper);
|
||||
void SetBrowser(ChromiumBrowserWrapper chromiumBrowserWrapper);
|
||||
|
||||
bool DownloadComplete { get; }
|
||||
Task<IconDownloadStatus> StartIconDownload();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Configuration;
|
||||
using Daybreak.Controls;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Models.Builds;
|
||||
using Daybreak.Utils;
|
||||
@@ -8,6 +9,7 @@ using Microsoft.Web.WebView2.Wpf;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Configuration;
|
||||
using System.Core.Extensions;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
@@ -31,7 +33,8 @@ namespace Daybreak.Services.IconRetrieve
|
||||
|
||||
private readonly ConcurrentQueue<IconRequest> iconRequests = new();
|
||||
private readonly ILogger<IconBrowser> logger;
|
||||
private WebView2 browserWrapper;
|
||||
|
||||
private ChromiumBrowserWrapper browserWrapper;
|
||||
private CancellationToken cancellationToken;
|
||||
|
||||
public IconBrowser(
|
||||
@@ -40,7 +43,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
this.logger = logger.ThrowIfNull();
|
||||
}
|
||||
|
||||
public void InitializeWebView(WebView2 webView2, CancellationToken cancellationToken)
|
||||
public void InitializeWebView(ChromiumBrowserWrapper webView2, CancellationToken cancellationToken)
|
||||
{
|
||||
this.browserWrapper = webView2.ThrowIfNull();
|
||||
this.cancellationToken = cancellationToken;
|
||||
@@ -91,11 +94,11 @@ namespace Daybreak.Services.IconRetrieve
|
||||
|
||||
try
|
||||
{
|
||||
await this.browserWrapper.EnsureCoreWebView2Async();
|
||||
await this.browserWrapper.InitializeDefaultBrowser();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
this.logger.LogError(e, "Encountered error when initializing browser");
|
||||
}
|
||||
|
||||
var curedSkillName = request.Skill.AlternativeName.IsNullOrWhiteSpace() ?
|
||||
@@ -104,7 +107,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
var skillIconUrl = $"{BaseUrl}/{QueryUrl.Replace(NamePlaceholder, curedSkillName)}";
|
||||
logger.LogInformation($"Looking for icon at {skillIconUrl}");
|
||||
|
||||
this.browserWrapper.CoreWebView2.Navigate(skillIconUrl);
|
||||
this.browserWrapper.Address = skillIconUrl;
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
@@ -116,7 +119,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
logger.LogInformation("Executing extraction script");
|
||||
var responseTask = await Application.Current.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
return await this.browserWrapper.ExecuteScriptAsync(Scripts.GetHrefFromSkillPage);
|
||||
return await this.browserWrapper.WebBrowser.ExecuteScriptAsync(Scripts.GetHrefFromSkillPage);
|
||||
});
|
||||
var response = await responseTask;
|
||||
logger.LogInformation("Parsing response");
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
private readonly ILogger<IconDownloader> logger;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly ILogger<ChromiumBrowserWrapper> browserLogger;
|
||||
private WebView2 browserWrapper;
|
||||
private ChromiumBrowserWrapper browserWrapper;
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private IconDownloadStatus iconDownloadStatus;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
this.HookIntoConfigurationChanges();
|
||||
}
|
||||
|
||||
public void SetBrowser(WebView2 chromiumBrowserWrapper)
|
||||
public void SetBrowser(ChromiumBrowserWrapper chromiumBrowserWrapper)
|
||||
{
|
||||
if (this.browserWrapper is not null)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
|
||||
this.cancellationTokenSource = new();
|
||||
this.iconDownloadStatus = new IconDownloadStatus();
|
||||
Task.Run(this.DownloadIcons);
|
||||
_ = Task.Run(this.DownloadIcons);
|
||||
return this.iconDownloadStatus;
|
||||
}
|
||||
|
||||
@@ -144,9 +144,9 @@ namespace Daybreak.Services.IconRetrieve
|
||||
{
|
||||
progressValue += progressIncrement;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogInformation("Downloading icon");
|
||||
this.logger.LogInformation("Downloading icon");
|
||||
this.iconDownloadStatus.CurrentStep = IconDownloadStatus.Downloading(skill.Name, progressValue);
|
||||
var request = new IconRequest { Skill = skill };
|
||||
this.iconBrowser.QueueIconRequest(request);
|
||||
@@ -158,12 +158,12 @@ namespace Daybreak.Services.IconRetrieve
|
||||
|
||||
if (request.IconBase64.IsNullOrWhiteSpace())
|
||||
{
|
||||
logger.LogWarning("Failed to download icon");
|
||||
this.logger.LogWarning("Failed to download icon");
|
||||
incomplete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("Downloaded icon");
|
||||
this.logger.LogInformation("Downloaded icon");
|
||||
}
|
||||
|
||||
progressValue += progressIncrement;
|
||||
@@ -179,7 +179,7 @@ namespace Daybreak.Services.IconRetrieve
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
this.browserWrapper.IsEnabled = false;
|
||||
this.browserWrapper.Dispose();
|
||||
this.browserWrapper.WebBrowser.Dispose();
|
||||
});
|
||||
this.iconDownloadStatus.CurrentStep = IconDownloadStatus.Finished;
|
||||
this.DownloadComplete = true;
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Daybreak.Services.KeyboardHook
|
||||
}
|
||||
|
||||
this.windowsHookHandle = IntPtr.Zero;
|
||||
this.hookProc -= LowLevelKeyboardProc;
|
||||
this.hookProc -= this.LowLevelKeyboardProc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ namespace Daybreak.Services.KeyboardHook
|
||||
|
||||
~KeyboardHookService()
|
||||
{
|
||||
Dispose(false);
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Daybreak.Exceptions;
|
||||
using Daybreak.Models.Github;
|
||||
using Daybreak.Models.Progress;
|
||||
using Daybreak.Services.Updater.PostUpdate;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Views;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -9,6 +10,7 @@ using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Core.Extensions;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
@@ -24,6 +26,7 @@ namespace Daybreak.Services.Updater
|
||||
{
|
||||
public sealed class ApplicationUpdater : IApplicationUpdater
|
||||
{
|
||||
private const string TemporaryInstallerFileName = "Daybreak.Installer.Temp.exe";
|
||||
private const string InstallerFileName = "Daybreak.Installer.exe";
|
||||
private const string UpdatedKey = "Updating";
|
||||
private const string RegistryKey = "Daybreak";
|
||||
@@ -35,24 +38,29 @@ namespace Daybreak.Services.Updater
|
||||
private const string DownloadUrl = $"https://github.com/AlexMacocian/Daybreak/releases/download/{VersionTag}/Daybreak{VersionTag}.zip";
|
||||
|
||||
private readonly CancellationTokenSource updateCancellationTokenSource = new();
|
||||
private readonly ILogger<ApplicationUpdater> logger;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IPostUpdateActionProvider postUpdateActionProvider;
|
||||
private readonly ILiveOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IHttpClient<ApplicationUpdater> httpClient;
|
||||
private readonly ILogger<ApplicationUpdater> logger;
|
||||
|
||||
public Version CurrentVersion { get; }
|
||||
|
||||
public ApplicationUpdater(
|
||||
ILogger<ApplicationUpdater> logger,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IViewManager viewManager,
|
||||
IHttpClient<ApplicationUpdater> httpClient)
|
||||
IPostUpdateActionProvider postUpdateActionProvider,
|
||||
ILiveOptions<ApplicationConfiguration> liveOptions,
|
||||
IHttpClient<ApplicationUpdater> httpClient,
|
||||
ILogger<ApplicationUpdater> logger)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.logger = logger.ThrowIfNull(nameof(logger));
|
||||
this.httpClient = httpClient.ThrowIfNull(nameof(httpClient));
|
||||
this.viewManager = viewManager.ThrowIfNull();
|
||||
this.postUpdateActionProvider = postUpdateActionProvider.ThrowIfNull();
|
||||
this.liveOptions = liveOptions.ThrowIfNull();
|
||||
this.httpClient = httpClient.ThrowIfNull();
|
||||
this.logger = logger.ThrowIfNull();
|
||||
|
||||
this.httpClient.DefaultRequestHeaders.Add("user-agent", "Daybreak Client");
|
||||
|
||||
if (Version.TryParse(Assembly.GetExecutingAssembly().GetName().Version.ToString(), out var currentVersion))
|
||||
{
|
||||
if (currentVersion.HasPrefix is false)
|
||||
@@ -178,6 +186,7 @@ namespace Daybreak.Services.Updater
|
||||
if (UpdateMarkedInRegistry())
|
||||
{
|
||||
UnmarkUpdateInRegistry();
|
||||
this.ExecutePostUpdateActions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +222,18 @@ namespace Daybreak.Services.Updater
|
||||
}
|
||||
}
|
||||
|
||||
private async void ExecutePostUpdateActions()
|
||||
{
|
||||
this.logger.LogInformation("Executing post-update actions");
|
||||
foreach(var action in this.postUpdateActionProvider.GetPostUpdateActions())
|
||||
{
|
||||
this.logger.LogInformation($"Starting [{action.GetType().Name}]");
|
||||
action.DoPostUpdateAction();
|
||||
await action.DoPostUpdateActionAsync();
|
||||
this.logger.LogInformation($"Finished [{action.GetType().Name}]");
|
||||
}
|
||||
}
|
||||
|
||||
private static void MarkUpdateInRegistry()
|
||||
{
|
||||
var homeRegistryKey = GetOrCreateHomeKey();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Core.Extensions;
|
||||
using System.IO;
|
||||
|
||||
namespace Daybreak.Services.Updater.PostUpdate.Actions
|
||||
{
|
||||
public sealed class RenameInstallerAction : PostUpdateActionBase
|
||||
{
|
||||
private const string TemporaryInstallerFileName = "Daybreak.Installer.Temp.exe";
|
||||
private const string InstallerFileName = "Daybreak.Installer.exe";
|
||||
|
||||
private readonly ILogger<RenameInstallerAction> logger;
|
||||
|
||||
public RenameInstallerAction(
|
||||
ILogger<RenameInstallerAction> logger)
|
||||
{
|
||||
this.logger = logger.ThrowIfNull();
|
||||
}
|
||||
|
||||
public override void DoPostUpdateAction()
|
||||
{
|
||||
if (File.Exists(TemporaryInstallerFileName))
|
||||
{
|
||||
this.logger.LogInformation("Detected new installer version. Overwriting old installer with new one");
|
||||
File.Copy(TemporaryInstallerFileName, InstallerFileName, true);
|
||||
|
||||
this.logger.LogInformation("Deleting new installer temporary file");
|
||||
File.Delete(TemporaryInstallerFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Daybreak.Services.Updater.PostUpdate
|
||||
{
|
||||
public interface IPostUpdateActionManager : IPostUpdateActionProducer, IPostUpdateActionProvider
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Daybreak.Services.Updater.PostUpdate
|
||||
{
|
||||
public interface IPostUpdateActionProducer
|
||||
{
|
||||
void AddPostUpdateAction<T>()
|
||||
where T : PostUpdateActionBase;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Daybreak.Services.Updater.PostUpdate
|
||||
{
|
||||
public interface IPostUpdateActionProvider
|
||||
{
|
||||
IEnumerable<PostUpdateActionBase> GetPostUpdateActions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Daybreak.Services.Updater.PostUpdate
|
||||
{
|
||||
public abstract class PostUpdateActionBase
|
||||
{
|
||||
public virtual void DoPostUpdateAction()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Task DoPostUpdateActionAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Slim;
|
||||
using System.Collections.Generic;
|
||||
using System.Core.Extensions;
|
||||
|
||||
namespace Daybreak.Services.Updater.PostUpdate
|
||||
{
|
||||
public sealed class PostUpdateActionManager : IPostUpdateActionManager
|
||||
{
|
||||
private readonly IServiceManager serviceManager;
|
||||
private readonly ILogger<PostUpdateActionManager> logger;
|
||||
|
||||
public PostUpdateActionManager(
|
||||
IServiceManager serviceManager,
|
||||
ILogger<PostUpdateActionManager> logger)
|
||||
{
|
||||
this.serviceManager = serviceManager.ThrowIfNull();
|
||||
this.logger = logger.ThrowIfNull();
|
||||
}
|
||||
|
||||
public void AddPostUpdateAction<T>()
|
||||
where T : PostUpdateActionBase
|
||||
{
|
||||
this.serviceManager.RegisterSingleton<T>();
|
||||
this.logger.LogDebug($"Added post update action {typeof(T).Name}");
|
||||
}
|
||||
|
||||
public IEnumerable<PostUpdateActionBase> GetPostUpdateActions()
|
||||
{
|
||||
return this.serviceManager.GetServicesOfType<PostUpdateActionBase>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace Daybreak.Views
|
||||
Build = this.buildTemplateManager.DecodeTemplate(this.CurrentBuildCode)
|
||||
};
|
||||
|
||||
this.logger.LogInformation($"Template {CurrentBuildCode} decoded");
|
||||
this.logger.LogInformation($"Template {this.CurrentBuildCode} decoded");
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
Clicked="BackButton_Clicked"></controls:BackButton>
|
||||
<controls:AddButton Foreground="White" Height="30" Width="30" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5"
|
||||
Clicked="AddButton_Clicked"></controls:AddButton>
|
||||
<controls:SynchronizeButton Foreground="White" Height="30" Width="30" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5, 5, 45, 5"
|
||||
Clicked="SynchronizeButton_Clicked"></controls:SynchronizeButton>
|
||||
<controls:SearchTextBox Grid.Row="1"
|
||||
FontSize="24"
|
||||
Foreground="White"
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace Daybreak.Views
|
||||
this.LoadBuilds();
|
||||
}
|
||||
|
||||
private void LoadBuilds()
|
||||
private async void LoadBuilds()
|
||||
{
|
||||
this.buildEntries = this.buildTemplateManager.GetBuilds();
|
||||
this.buildEntries = await this.buildTemplateManager.GetBuilds().ToListAsync();
|
||||
this.BuildEntries.ClearAnd().AddRange(this.buildEntries);
|
||||
}
|
||||
|
||||
@@ -55,17 +55,22 @@ namespace Daybreak.Views
|
||||
this.viewManager.ShowView<BuildTemplateView>(build);
|
||||
}
|
||||
|
||||
private void BuildEntryTemplate_RemoveClicked(object sender, BuildEntry e)
|
||||
private void BuildEntryTemplate_RemoveClicked(object _, BuildEntry e)
|
||||
{
|
||||
this.buildTemplateManager.RemoveBuild(e);
|
||||
this.LoadBuilds();
|
||||
}
|
||||
|
||||
private void SearchTextBox_TextChanged(object sender, string e)
|
||||
private void SearchTextBox_TextChanged(object _, string e)
|
||||
{
|
||||
this.BuildEntries.Clear();
|
||||
this.BuildEntries.AddRange(
|
||||
this.buildEntries.Where(b => StringUtils.MatchesSearchString(b.Name, e)));
|
||||
}
|
||||
|
||||
private void SynchronizeButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<BuildsSynchronizationView>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
<UserControl x:Class="Daybreak.Views.BuildsSynchronizationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Views"
|
||||
xmlns:controls="clr-namespace:Daybreak.Controls"
|
||||
xmlns:converters="clr-namespace:Daybreak.Converters"
|
||||
Loaded="UserControl_Loaded"
|
||||
mc:Ignorable="d"
|
||||
x:Name="_this"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
|
||||
</UserControl.Resources>
|
||||
<Grid
|
||||
Background="#A0202020">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<controls:BackButton Foreground="White" Height="30" Width="30" Grid.Column="0" HorizontalAlignment="Left" Margin="5"
|
||||
Clicked="BackButton_Clicked" VerticalAlignment="Top"
|
||||
IsEnabled="{Binding ElementName=_this, Path=ButtonsEnabled, Mode=OneWay}"></controls:BackButton>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
Text="Build templates synchronization"
|
||||
FontSize="24"
|
||||
Foreground="White" />
|
||||
<WrapPanel HorizontalAlignment="Center"
|
||||
Grid.Row="1">
|
||||
<TextBlock Text="Logged in as: "
|
||||
FontSize="20"
|
||||
Foreground="White"></TextBlock>
|
||||
<TextBlock Text="{Binding ElementName=_this, Path=DisplayName, Mode=OneWay}"
|
||||
FontSize="20"
|
||||
Foreground="White"></TextBlock>
|
||||
</WrapPanel>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Local"
|
||||
FontSize="14"
|
||||
Foreground="White"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
<controls:OpaqueButton Grid.Column="0"
|
||||
Text="Upload all"
|
||||
Foreground="White"
|
||||
Background="DarkGray"
|
||||
HorizontalAlignment="Right"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Clicked="UploadAllButton_Clicked"
|
||||
Width="80"
|
||||
IsEnabled="{Binding ElementName=_this, Path=ButtonsEnabled, Mode=OneWay}"/>
|
||||
<ListView
|
||||
Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
Background="Transparent"
|
||||
ItemsSource="{Binding ElementName=_this, Path=LocalBuildEntries, Mode=OneWay}"
|
||||
SelectedItem="{Binding ElementName=_this, Path=SelectedLocalBuild, Mode=TwoWay}"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock FontSize="14"
|
||||
Foreground="White"
|
||||
Text="{Binding Build.Name}"
|
||||
HorizontalAlignment="Left"></TextBlock>
|
||||
<TextBlock FontSize="14"
|
||||
Foreground="White"
|
||||
Text="{Binding TemplateCode}"
|
||||
HorizontalAlignment="Right"></TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="Remote"
|
||||
FontSize="14"
|
||||
Foreground="White"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
<controls:OpaqueButton Grid.Column="2"
|
||||
Text="Download all"
|
||||
Foreground="White"
|
||||
Background="DarkGray"
|
||||
HorizontalAlignment="Left"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Clicked="DownloadAllButton_Clicked"
|
||||
Width="80"
|
||||
IsEnabled="{Binding ElementName=_this, Path=ButtonsEnabled, Mode=OneWay}"/>
|
||||
<ListView
|
||||
Grid.Column="2"
|
||||
Grid.Row="1"
|
||||
Background="Transparent"
|
||||
ItemsSource="{Binding ElementName=_this, Path=RemoteBuildEntries, Mode=OneWay}"
|
||||
SelectedItem="{Binding ElementName=_this, Path=SelectedRemoteBuild, Mode=TwoWay}"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock FontSize="14"
|
||||
Foreground="White"
|
||||
Text="{Binding TemplateCode}"
|
||||
HorizontalAlignment="Left"></TextBlock>
|
||||
<TextBlock FontSize="14"
|
||||
Foreground="White"
|
||||
Text="{Binding FileName}"
|
||||
HorizontalAlignment="Right"></TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center">
|
||||
<controls:OpaqueButton Text="Download Build"
|
||||
Foreground="White"
|
||||
Background="DarkGray"
|
||||
Margin="5"
|
||||
Padding="5"
|
||||
Clicked="DownloadButton_Clicked"
|
||||
IsEnabled="{Binding ElementName=_this, Path=ButtonsEnabled, Mode=OneWay}"></controls:OpaqueButton>
|
||||
<controls:OpaqueButton Text="Upload Build"
|
||||
Foreground="White"
|
||||
Background="DarkGray"
|
||||
Margin="5"
|
||||
Padding="5"
|
||||
Clicked="UploadButton_Clicked"
|
||||
IsEnabled="{Binding ElementName=_this, Path=ButtonsEnabled, Mode=OneWay}"></controls:OpaqueButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Grid Grid.RowSpan="3"
|
||||
Background="#A0202020"
|
||||
Visibility="{Binding ElementName=_this, Path=ShowLoading, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<controls:CircularLoadingWidget MaxWidth="200"
|
||||
MaxHeight="200"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,149 @@
|
||||
using Daybreak.Services.Graph;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Core.Extensions;
|
||||
using System.Windows;
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Controls;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using System.Collections.ObjectModel;
|
||||
using Daybreak.Services.Graph.Models;
|
||||
using System.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Daybreak.Services.BuildTemplates;
|
||||
using System.Linq;
|
||||
using Daybreak.Models;
|
||||
|
||||
namespace Daybreak.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for BuildsSynchronizationView.xaml
|
||||
/// </summary>
|
||||
public partial class BuildsSynchronizationView : UserControl
|
||||
{
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private readonly IGraphClient graphClient;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILogger<BuildsSynchronizationView> logger;
|
||||
|
||||
public ObservableCollection<BuildFile> RemoteBuildEntries { get; } = new();
|
||||
public ObservableCollection<BuildWithTemplateCode> LocalBuildEntries { get; } = new();
|
||||
|
||||
[GenerateDependencyProperty(InitialValue = true)]
|
||||
private bool buttonsEnabled;
|
||||
[GenerateDependencyProperty]
|
||||
private string displayName;
|
||||
[GenerateDependencyProperty]
|
||||
private string lastUploadDate;
|
||||
[GenerateDependencyProperty]
|
||||
private BuildFile selectedRemoteBuild;
|
||||
[GenerateDependencyProperty]
|
||||
private BuildWithTemplateCode selectedLocalBuild;
|
||||
[GenerateDependencyProperty]
|
||||
private bool showLoading;
|
||||
|
||||
public BuildsSynchronizationView(
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
IGraphClient graphClient,
|
||||
IViewManager viewManager,
|
||||
ILogger<BuildsSynchronizationView> logger)
|
||||
{
|
||||
this.buildTemplateManager = buildTemplateManager.ThrowIfNull();
|
||||
this.graphClient = graphClient.ThrowIfNull();
|
||||
this.viewManager = viewManager.ThrowIfNull();
|
||||
this.logger = logger.ThrowIfNull();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private async void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.ButtonsEnabled = false;
|
||||
this.ShowLoading = true;
|
||||
var profile = await this.graphClient.GetUserProfile<BuildsSynchronizationView>();
|
||||
if (profile.TryExtractSuccess(out var user) is false)
|
||||
{
|
||||
this.logger.LogError("Failed to get user info");
|
||||
return;
|
||||
}
|
||||
|
||||
this.DisplayName = user.DisplayName;
|
||||
await this.PopulateBuilds();
|
||||
this.ButtonsEnabled = true;
|
||||
this.ShowLoading = false;
|
||||
}
|
||||
|
||||
private async Task PopulateBuilds()
|
||||
{
|
||||
this.RemoteBuildEntries.ClearAnd().AddRange(await this.graphClient.RetrieveBuildsList().ToListAsync());
|
||||
var localBuilds = await this.buildTemplateManager.GetBuilds().ToListAsync();
|
||||
this.LocalBuildEntries.ClearAnd().AddRange(localBuilds.Select(build => new BuildWithTemplateCode { Build = build, TemplateCode = this.buildTemplateManager.EncodeTemplate(build.Build) }));
|
||||
}
|
||||
|
||||
private void BackButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<BuildsListView>();
|
||||
}
|
||||
|
||||
private async void UploadButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
// TODO: Handle failures to upload
|
||||
if (this.SelectedLocalBuild is not BuildWithTemplateCode buildWithTemplateCode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.ButtonsEnabled = false;
|
||||
this.ShowLoading = true;
|
||||
await this.graphClient.UploadBuild(buildWithTemplateCode.Build.Name);
|
||||
await this.PopulateBuilds();
|
||||
this.ButtonsEnabled = true;
|
||||
this.ShowLoading = false;
|
||||
}
|
||||
|
||||
private async void DownloadButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (this.SelectedRemoteBuild is not BuildFile buildFile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.ButtonsEnabled = false;
|
||||
this.ShowLoading = true;
|
||||
await this.graphClient.DownloadBuild(buildFile.FileName);
|
||||
await this.PopulateBuilds();
|
||||
this.ButtonsEnabled = true;
|
||||
this.ShowLoading = false;
|
||||
}
|
||||
|
||||
private async void DownloadAllButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.ButtonsEnabled = false;
|
||||
this.ShowLoading = true;
|
||||
var result = await this.graphClient.DownloadBuilds().ConfigureAwait(true);
|
||||
result.DoAny(
|
||||
onFailure: (failure) =>
|
||||
{
|
||||
this.logger.LogError(failure, $"Failed to download builds");
|
||||
});
|
||||
|
||||
await this.PopulateBuilds();
|
||||
this.ButtonsEnabled = true;
|
||||
this.ShowLoading = false;
|
||||
}
|
||||
|
||||
private async void UploadAllButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.ButtonsEnabled = false;
|
||||
this.ShowLoading = true;
|
||||
var result = await this.graphClient.UploadBuilds().ConfigureAwait(true);
|
||||
result.DoAny(
|
||||
onFailure: (failure) =>
|
||||
{
|
||||
this.logger.LogError(failure, $"Failed to upload builds");
|
||||
});
|
||||
|
||||
await this.PopulateBuilds();
|
||||
this.ButtonsEnabled = true;
|
||||
this.ShowLoading = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<UserControl x:Class="Daybreak.Views.GraphAuthorizationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Daybreak.Views"
|
||||
xmlns:controls="clr-namespace:Daybreak.Controls"
|
||||
Loaded="UserControl_Loaded"
|
||||
Unloaded="UserControl_Unloaded"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid
|
||||
Background="#A0202020">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
Text="Please login to access OneDrive files"
|
||||
HorizontalAlignment="Center"
|
||||
FontSize="24"
|
||||
Foreground="White"/>
|
||||
<controls:ChromiumBrowserWrapper
|
||||
x:Name="BrowserWrapper"
|
||||
Grid.Row="1"
|
||||
ControlsEnabled="False"
|
||||
CanNavigate="True"
|
||||
CanDownloadBuild="False"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,59 @@
|
||||
using Daybreak.Services.Graph;
|
||||
using Daybreak.Services.Graph.Models;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Core.Extensions;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Daybreak.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for GraphAuthorizationView.xaml
|
||||
/// </summary>
|
||||
public partial class GraphAuthorizationView : UserControl
|
||||
{
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
private readonly IGraphClient graphClient;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILogger<GraphAuthorizationView> logger;
|
||||
|
||||
public GraphAuthorizationView(
|
||||
IGraphClient graphClient,
|
||||
IViewManager viewManager,
|
||||
ILogger<GraphAuthorizationView> logger)
|
||||
{
|
||||
this.graphClient = graphClient.ThrowIfNull();
|
||||
this.viewManager = viewManager.ThrowIfNull();
|
||||
this.logger = logger.ThrowIfNull();
|
||||
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private async void UserControl_Loaded(object _, RoutedEventArgs e)
|
||||
{
|
||||
var authorizationResult = await this.graphClient.PerformAuthorizationFlow(this.BrowserWrapper, this.cancellationTokenSource.Token);
|
||||
if (authorizationResult.TryExtractFailure(out var failure))
|
||||
{
|
||||
this.logger.LogError(failure, "Authorization failed");
|
||||
this.viewManager.ShowView<MainView>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.DataContext is not ViewRedirectContext redirectContext)
|
||||
{
|
||||
this.logger.LogError("Cannot redirect to proper view. No view set in context");
|
||||
this.viewManager.ShowView<MainView>();
|
||||
return;
|
||||
}
|
||||
|
||||
this.viewManager.ShowView(redirectContext.CallingView);
|
||||
}
|
||||
|
||||
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.cancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,6 @@ namespace Daybreak.Views
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly ILiveUpdateableOptions<ApplicationConfiguration> liveOptions;
|
||||
private readonly IScreenManager screenManager;
|
||||
private readonly IBuildTemplateManager buildTemplateManager;
|
||||
private readonly ILogger<ChromiumBrowserWrapper> browserLogger;
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
|
||||
private bool leftBrowserMaximized = false;
|
||||
@@ -60,12 +58,8 @@ namespace Daybreak.Views
|
||||
IApplicationLauncher applicationDetector,
|
||||
IViewManager viewManager,
|
||||
ILiveUpdateableOptions<ApplicationConfiguration> liveOptions,
|
||||
IScreenManager screenManager,
|
||||
IBuildTemplateManager buildTemplateManager,
|
||||
ILogger<ChromiumBrowserWrapper> browserLogger)
|
||||
IScreenManager screenManager)
|
||||
{
|
||||
this.browserLogger = browserLogger;
|
||||
this.buildTemplateManager = buildTemplateManager.ThrowIfNull(nameof(buildTemplateManager));
|
||||
this.screenManager = screenManager.ThrowIfNull(nameof(screenManager));
|
||||
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
|
||||
this.applicationDetector = applicationDetector.ThrowIfNull(nameof(applicationDetector));
|
||||
@@ -77,8 +71,8 @@ namespace Daybreak.Views
|
||||
|
||||
private async void InitializeBrowsers()
|
||||
{
|
||||
await this.LeftWebBrowser.InitializeBrowser(this.liveOptions, this.buildTemplateManager, this.browserLogger);
|
||||
await this.RightWebBrowser.InitializeBrowser(this.liveOptions, this.buildTemplateManager, this.browserLogger);
|
||||
await this.LeftWebBrowser.InitializeDefaultBrowser();
|
||||
await this.RightWebBrowser.InitializeDefaultBrowser();
|
||||
this.NavigateToDefaults();
|
||||
}
|
||||
|
||||
@@ -184,19 +178,19 @@ namespace Daybreak.Views
|
||||
}
|
||||
}
|
||||
|
||||
private void ChromiumBrowserWrapper_BuildDecoded(object sender, Build e)
|
||||
private void ChromiumBrowserWrapper_BuildDecoded(object _, Build e)
|
||||
{
|
||||
this.viewManager.ShowView<BuildTemplateView>(new BuildEntry { Build = e, Name = string.Empty });
|
||||
}
|
||||
|
||||
private void LeftBrowser_FavoriteUriChanged(object sender, string e)
|
||||
private void LeftBrowser_FavoriteUriChanged(object _, string e)
|
||||
{
|
||||
var config = this.liveOptions.Value;
|
||||
config.LeftBrowserDefault = e;
|
||||
this.liveOptions.UpdateOption();
|
||||
}
|
||||
|
||||
private void RightBrowser_FavoriteUriChanged(object sender, string e)
|
||||
private void RightBrowser_FavoriteUriChanged(object _, string e)
|
||||
{
|
||||
var config = this.liveOptions.Value;
|
||||
config.RightBrowserDefault = e;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Daybreak.Views
|
||||
{
|
||||
this.liveOptions = liveOptions.ThrowIfNull();
|
||||
this.viewManager = viewManager.ThrowIfNull();
|
||||
InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void AccountButton_Clicked(object sender, System.EventArgs e)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Daybreak.Views
|
||||
this.applicationUpdater = applicationUpdater;
|
||||
this.logger = logger;
|
||||
this.viewManager = viewManager;
|
||||
this.updateStatus.PropertyChanged += UpdateStatus_PropertyChanged;
|
||||
this.updateStatus.PropertyChanged += this.UpdateStatus_PropertyChanged;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Daybreak.Views
|
||||
}
|
||||
|
||||
this.logger.LogInformation("Starting update procedure");
|
||||
var success = await applicationUpdater.DownloadUpdate(version, updateStatus).ConfigureAwait(true);
|
||||
var success = await this.applicationUpdater.DownloadUpdate(version, this.updateStatus).ConfigureAwait(true);
|
||||
if (success is false)
|
||||
{
|
||||
this.logger.LogError("Update procedure failed");
|
||||
|
||||
@@ -6,6 +6,7 @@ Param(
|
||||
Write-Output "Deleting pdb file"
|
||||
Remove-item .\Publish\Daybreak.pdb
|
||||
Remove-item .\Publish\Daybreak.Installer.pdb
|
||||
Move-Item -Path .\Publish\Daybreak.Installer.exe -Destination .\Publish\Daybreak.Installer.Temp.exe
|
||||
$zipPath = "Publish\daybreakv$version.zip"
|
||||
Write-Output "Compressing binaries to $zipPath"
|
||||
Compress-Archive .\Publish\* $zipPath -Force
|
||||
|
||||
Reference in New Issue
Block a user