Skip to content

Commit

Permalink
Merge pull request #108 from ingen084/add-workflow
Browse files Browse the repository at this point in the history
ワークフロー機能の作成
  • Loading branch information
ingen084 committed Apr 25, 2024
2 parents 9b9f13d + 5f3b832 commit 54b7f9e
Show file tree
Hide file tree
Showing 51 changed files with 1,571 additions and 21 deletions.
5 changes: 4 additions & 1 deletion KyoshinEewViewer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
common.props = common.props
CREATE-THEME-MANUAL.md = CREATE-THEME-MANUAL.md
old_update_history.md = old_update_history.md
README.md = README.md
workflow-guide.md = workflow-guide.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KyoshinEewViewer.Core", "src\KyoshinEewViewer.Core\KyoshinEewViewer.Core.csproj", "{9FB22DFA-509C-4F1E-A5DC-70EE3437AA4B}"
Expand Down Expand Up @@ -62,7 +65,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KyoshinEewViewer.Browser",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KyoshinEewViewer.Benchmark", "src\KyoshinEewViewer.Benchmark\KyoshinEewViewer.Benchmark.csproj", "{A497161D-4ECD-4125-B70B-0FFD05832E4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaDirectRenderTest", "src\Sandboxes\SkiaDirectRenderTest\SkiaDirectRenderTest.csproj", "{F2782C78-C8BC-4CF5-9385-A29A5D360EE4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaDirectRenderTest", "src\Sandboxes\SkiaDirectRenderTest\SkiaDirectRenderTest.csproj", "{F2782C78-C8BC-4CF5-9385-A29A5D360EE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 3 additions & 3 deletions common.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<PublishReadyToRun>true</PublishReadyToRun>

<PublishTrimmed>true</PublishTrimmed>
<PublishTrimmed>false</PublishTrimmed>
<TrimMode>partial</TrimMode>
<StripSymbols>false</StripSymbols>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
Expand All @@ -46,12 +46,12 @@
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
<PackageReference Include="FluentAvaloniaUI" Version="2.0.5" />

<PackageReference Include="Splat.DependencyInjection.SourceGenerator" Version="1.2.3" PrivateAssets="all" />

<PackageReference Condition="$(RuntimeIdentifier.StartsWith('linux'))" Include="Mono.Posix.NETStandard" Version="1.0.0" />

<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NReco.Logging.File" Version="1.2.0" />

<PackageReference Include="KyoshinMonitorLib" Version="0.4.6-alpha3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace KyoshinEewViewer.Core;

[JsonSourceGenerationOptions(WriteIndented = false, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
[JsonSerializable(typeof(KyoshinEewViewerConfiguration))]
[JsonSerializable(typeof(GitHubRelease[]))]
[JsonSerializable(typeof(UpdaterStore))]
Expand Down
1 change: 1 addition & 0 deletions src/KyoshinEewViewer.Desktop/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<core:KyoshinEewViewerWindowTheme />
<core:KyoshinEewViewerIntensityTheme />
<sty:FluentAvaloniaTheme UseSystemFontOnWindows="False" PreferUserAccentColor="True" />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
</Application.Styles>

<NativeMenu.Menu>
Expand Down
12 changes: 12 additions & 0 deletions src/KyoshinEewViewer.Desktop/Views/SettingWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@
<pages:SoundPage />
</Panel>
</TabItem>
<!--ワークフロー-->
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe289;" Classes="icon" />
<TextBlock Text="ワークフロー" />
</StackPanel>
</TabItem.Header>
<Panel Background="{DynamicResource MainBackgroundColor}">
<pages:WorkflowPage />
</Panel>
</TabItem>
<!-- 強震モニタ -->
<TabItem>
<TabItem.Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Sentry" Version="3.41.3" />
<PackageReference Include="Sentry" Version="4.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/KyoshinEewViewer.Updater/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private async void DoUpdate()
SentrySdk.ConfigureScope(s =>
{
s.Release = Core.Utils.Version;
s.User = new User {
s.User = new SentryUser {
IpAddress = "{{auto}}",
};
});
Expand Down
93 changes: 88 additions & 5 deletions src/KyoshinEewViewer/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using KyoshinEewViewer.Core;
using KyoshinEewViewer.Core.Models;
using KyoshinEewViewer.Services.Workflows;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
Expand All @@ -12,17 +13,37 @@ namespace KyoshinEewViewer;
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "<Pending>")]
public static class ConfigurationLoader
{
private static JsonSerializerOptions SerializeOption { get; } = new()
private static JsonSerializerOptions ConfigSerializeOption { get; } = new()
{
TypeInfoResolver = KyoshinEewViewerSerializerContext.Default,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};

private static JsonSerializerOptions WorkflowSerializeOption { get; } = new()
{
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true,
IgnoreReadOnlyFields = true,
IgnoreReadOnlyProperties = true,
TypeInfoResolver = KyoshinEewViewerSerializerContext.Default,
};

public static KyoshinEewViewerConfiguration Load()
{
if (!LoadPrivate(out var config, RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) && !LoadPrivate(out config, true) || config == null)
KyoshinEewViewerConfiguration? config;
try
{
if (!LoadPrivate(out config, RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) && !LoadPrivate(out config, true) || config == null)
config = new KyoshinEewViewerConfiguration();
}
catch (UnauthorizedAccessException)
{
if (!LoadPrivate(out config, true) || config == null)
config = new KyoshinEewViewerConfiguration();
}
catch
{
config = new KyoshinEewViewerConfiguration();
}

if (System.Reflection.Assembly.GetExecutingAssembly().GetName()?.Version?.Minor != 0)
config.Update.UseUnstableBuild = true;
Expand All @@ -37,7 +58,7 @@ private static bool LoadPrivate(out KyoshinEewViewerConfiguration? config, bool
if (!File.Exists(fileName))
return false;

var v = JsonSerializer.Deserialize<KyoshinEewViewerConfiguration>(File.ReadAllText(fileName), SerializeOption);
var v = JsonSerializer.Deserialize<KyoshinEewViewerConfiguration>(File.ReadAllText(fileName), ConfigSerializeOption);
if (v == null)
return false;

Expand All @@ -64,6 +85,68 @@ private static void SavePrivate(KyoshinEewViewerConfiguration config, bool useHo

var fileName = useHomeDirectory ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".kevi", "config.json") : "config.json";
config.SavedVersion = System.Reflection.Assembly.GetEntryAssembly()?.GetName()?.Version;
File.WriteAllText(fileName, JsonSerializer.Serialize(config, SerializeOption));
File.WriteAllText(fileName, JsonSerializer.Serialize(config, ConfigSerializeOption));
}

public static Workflow[] LoadWorkflows()
{
Workflow[]? config;
try
{
if (!LoadWorkflowsPrivate(out config, RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) && !LoadWorkflowsPrivate(out config, true) || config == null)
config = Array.Empty<Workflow>();
}
catch (UnauthorizedAccessException)
{
if (!LoadWorkflowsPrivate(out config, true) || config == null)
config = Array.Empty<Workflow>();
}
catch
{
config = Array.Empty<Workflow>();
}

return config;
}

private static bool LoadWorkflowsPrivate(out Workflow[]? config, bool useHomeDirectory)
{
config = null;
var fileName = useHomeDirectory ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".kevi", "workflows.json") : "workflows.json";
if (!File.Exists(fileName))
return false;

var v = JsonSerializer.Deserialize<Workflow[]>(File.ReadAllText(fileName), WorkflowSerializeOption);
if (v == null)
return false;

config = v;
return true;
}

public static void SaveWorkflows(Workflow[] config)
{
try
{
SaveWorkflowsPrivate(config, RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
}
catch (UnauthorizedAccessException)
{
SaveWorkflowsPrivate(config, true);
}
catch(Exception ex)

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish-macos (x64)

The variable 'ex' is declared but never used

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish (windows, x64)

The variable 'ex' is declared but never used

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish-macos (arm64)

The variable 'ex' is declared but never used

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish (windows, arm64)

The variable 'ex' is declared but never used

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish (ubuntu, x64)

The variable 'ex' is declared but never used

Check warning on line 137 in src/KyoshinEewViewer/ConfigurationLoader.cs

View workflow job for this annotation

GitHub Actions / publish (ubuntu, arm64)

The variable 'ex' is declared but never used
{
;
}
}


private static void SaveWorkflowsPrivate(Workflow[] config, bool useHomeDirectory)
{
if (useHomeDirectory && !Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".kevi")))
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".kevi"));

var fileName = useHomeDirectory ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".kevi", "workflows.json") : "workflows.json";
File.WriteAllText(fileName, JsonSerializer.Serialize(config, WorkflowSerializeOption));
}
}
15 changes: 13 additions & 2 deletions src/KyoshinEewViewer/KyoshinEewViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="Sentry.Extensions.Logging" Version="4.4.0" />
<PackageReference Include="Splat.Microsoft.Extensions.Logging" Version="14.8.12" />

<PackageReference Include="Avalonia.Xaml.Behaviors" Version="$(AvaloniaVersion)" />
<PackageReference Include="Sentry.Extensions.Logging" Version="3.41.3" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Splat.Microsoft.Extensions.Logging" Version="14.8.12" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.0.6" />

<PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />

<PackageReference Include="Scriban" Version="5.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -61,6 +66,12 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Services\Workflows\BuiltinActions\PlaySoundActionControl.axaml.cs">
<DependentUpon>PlaySoundActionControl.axaml</DependentUpon>
</Compile>
<Compile Update="Views\SettingPages\WorkflowPage.axaml.cs">
<DependentUpon>WorkflowPage.axaml</DependentUpon>
</Compile>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
2 changes: 1 addition & 1 deletion src/KyoshinEewViewer/LoggingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Setup(KyoshinEewViewerConfiguration config)
o.MinimumEventLevel = LogLevel.Error;
o.ConfigureScope(s =>
{
s.User = new User {
s.User = new SentryUser {
IpAddress = "{{auto}}",
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
using KyoshinEewViewer.CustomControl;
using KyoshinEewViewer.Events;
using KyoshinEewViewer.Map;
using KyoshinEewViewer.Map.Layers;
using KyoshinEewViewer.Series.KyoshinMonitor.Events;
using KyoshinEewViewer.Series.KyoshinMonitor.Models;
using KyoshinEewViewer.Series.KyoshinMonitor.Services;
using KyoshinEewViewer.Series.KyoshinMonitor.Services.Eew;
using KyoshinEewViewer.Series.KyoshinMonitor.Workflow;
using KyoshinEewViewer.Services;
using KyoshinMonitorLib;
using KyoshinMonitorLib.ApiResult.WebApi;
using ReactiveUI;
using SkiaSharp;
using Splat;
Expand Down Expand Up @@ -59,6 +58,7 @@ public class KyoshinMonitorSeries : SeriesBase
SoundPlayerService soundPlayer,
EventHookService eventHook,
TimerService timerService,
WorkflowService workflowService,
ILogManager logManager) : base(MetaData)
{
SplatRegistrations.RegisterLazySingleton<KyoshinMonitorSeries>();
Expand Down Expand Up @@ -162,6 +162,7 @@ public class KyoshinMonitorSeries : SeriesBase
{ "SHAKE_DETECT_MAX_INTENSITY", evt.Points.Max(p => p.LatestIntensity)?.ToString("0.0") ?? "null" },
{ "SHAKE_DETECT_REGIONS", string.Join(',', evt.Points.Select(p => p.Region.Length > 3 ? p.Region[..3] : p.Region).Distinct()) },
}).ConfigureAwait(false);
workflowService.PublishEvent(new ShakeDetectedEvent(e.time, evt));
switch (evt.Level)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<ItemsControl ItemsSource="{Binding Eews}" Width="300" Margin="5" HorizontalAlignment="Left">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="models:IEew">
<controlSeries:EewPanel Margin="0,0,0,5" ShowAccuracy="{ReflectionBinding $parent[UserControl].DataContext.ShowEewAccuracy}" />
<controlSeries:EewPanel Margin="0,0,0,5" ShowAccuracy="{Binding $parent[UserControl].((local:KyoshinMonitorSeries)DataContext).ShowEewAccuracy}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KyoshinMonitorWatchService
AutomaticDecompression = DecompressionMethods.All
})
{ Timeout = TimeSpan.FromSeconds(2) };

private ILogger Logger { get; }
private TimerService TimerService { get; }
private KyoshinEewViewerConfiguration Config { get; }
Expand Down Expand Up @@ -83,11 +84,11 @@ public void Start()

foreach (var point in Points)
// 60キロ以内の近い順の最大15観測点を関連付ける
// 生活振動が多い神奈川・東京は17観測点とする
// 生活振動が多い神奈川・東京は20観測点とする
point.NearPoints = Points
.Where(p => point != p && point.Location.Distance(p.Location) < 60)
.OrderBy(p => point.Location.Distance(p.Location))
.Take(point.Region is "神奈川県" or "東京都" ? 17 : 15)
.Take(point.Region is "神奈川県" or "東京都" ? 20 : 15)
.ToArray();

TimerService.StartMainTimer();
Expand Down
Loading

0 comments on commit 54b7f9e

Please sign in to comment.