From 66868132410a5a8004a2773f32af06660fa14129 Mon Sep 17 00:00:00 2001 From: anoyetta Date: Wed, 28 Apr 2021 21:02:00 +0900 Subject: [PATCH] v1.0.0.0 --- source/CeVIOAIProxy/App.xaml.cs | 33 ++++++++++++------- source/CeVIOAIProxy/CeVIOAIProxy.csproj | 1 + source/CeVIOAIProxy/MainViewModel.cs | 36 ++++++++++++++++++++- source/CeVIOAIProxy/MainWindow.xaml.cs | 16 +++++++++ source/CeVIOAIProxy/Servers/CAPTcpServer.cs | 11 +------ source/CeVIOAIProxy/app.manifest | 16 +++++++++ 6 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 source/CeVIOAIProxy/app.manifest diff --git a/source/CeVIOAIProxy/App.xaml.cs b/source/CeVIOAIProxy/App.xaml.cs index 0db6d4a..9aa5a58 100644 --- a/source/CeVIOAIProxy/App.xaml.cs +++ b/source/CeVIOAIProxy/App.xaml.cs @@ -24,19 +24,18 @@ public App() this.Startup += this.App_Startup; this.Exit += this.App_Exit; + this.DispatcherUnhandledException += this.App_DispatcherUnhandledException; + AppDomain.CurrentDomain.UnhandledException += this.CurrentDomain_UnhandledException; } - private async void App_Startup(object sender, StartupEventArgs e) + private void App_Startup(object sender, StartupEventArgs e) { var c = Config.Instance; c.SetStartup(c.IsStartupWithWindows); - await Task.Run(() => - { - this.server = new CAPTcpServer(); - this.server.Open(c.TcpServerPort); - }); + this.server = new CAPTcpServer(); + this.server.Open(c.TcpServerPort); } private void App_Exit(object sender, ExitEventArgs e) @@ -49,32 +48,44 @@ private void App_Exit(object sender, ExitEventArgs e) GC.SuppressFinalize(this); } - private async void CloseServer() + private void CloseServer() { if (this.server != null) { this.server.Close(); this.server.Dispose(); - await Task.Delay(TimeSpan.FromMilliseconds(100)); this.server = null; } } - private async void App_DispatcherUnhandledException( + private void App_DispatcherUnhandledException( object sender, DispatcherUnhandledExceptionEventArgs e) + { + this.DumpUnhandledException(e.Exception); + } + + private void CurrentDomain_UnhandledException( + object sender, + UnhandledExceptionEventArgs e) + { + this.DumpUnhandledException(e.ExceptionObject as Exception); + } + + private async void DumpUnhandledException( + Exception ex) { await Task.Run(() => { File.WriteAllText( @".\CeVIOAIProxy.error.log", - e.Exception.ToString(), + $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}\n{ex}", new UTF8Encoding(false)); }); MessageBox.Show( "予期しない例外を検知しました。アプリケーションを終了します。\n\n" + - e.Exception, + ex, "Fatal", MessageBoxButton.OK, MessageBoxImage.Error); diff --git a/source/CeVIOAIProxy/CeVIOAIProxy.csproj b/source/CeVIOAIProxy/CeVIOAIProxy.csproj index 6f84a85..c42699c 100644 --- a/source/CeVIOAIProxy/CeVIOAIProxy.csproj +++ b/source/CeVIOAIProxy/CeVIOAIProxy.csproj @@ -7,6 +7,7 @@ share.ico preview false + app.manifest diff --git a/source/CeVIOAIProxy/MainViewModel.cs b/source/CeVIOAIProxy/MainViewModel.cs index c12fba0..c56be58 100644 --- a/source/CeVIOAIProxy/MainViewModel.cs +++ b/source/CeVIOAIProxy/MainViewModel.cs @@ -1,5 +1,8 @@ using System.Collections.ObjectModel; +using System.IO; using System.Linq; +using System.Net.Sockets; +using System.Text; using System.Threading.Tasks; using CeVIO.Talk.RemoteService2; using Prism.Commands; @@ -84,7 +87,38 @@ private void SetCurrentComponents() private async void ExecuteTestCommand() { - await CeVIO.SpeakAsync("本日は晴天なり。"); + await CeVIO.SpeakAsync("CeVIOへの接続は正常です。"); + + await Task.Run(() => + { + using (var tcp = new TcpClient("127.0.0.1", this.Config.TcpServerPort)) + using (var ns = tcp.GetStream()) + using (var bw = new BinaryWriter(ns)) + { + var sMessage = "TCPからの接続は正常です。"; + + byte bCode = 0; + short iVoice = 1; + short iVolume = -1; + short iSpeed = -1; + short iTone = -1; + short iCommand = 0x0001; + + var bMessage = Encoding.UTF8.GetBytes(sMessage); + var iLength = bMessage.Length; + + bw.Write(iCommand); // コマンド( 0:メッセージ読み上げ) + bw.Write(iSpeed); // 速度 (-1:棒読みちゃん画面上の設定) + bw.Write(iTone); // 音程 (-1:棒読みちゃん画面上の設定) + bw.Write(iVolume); // 音量 (-1:棒読みちゃん画面上の設定) + bw.Write(iVoice); // 声質 ( 0:棒読みちゃん画面上の設定、1:女性1、2:女性2、3:男性1、4:男性2、5:中性、6:ロボット、7:機械1、8:機械2、10001~:SAPI5) + bw.Write(bCode); // 文字列のbyte配列の文字コード(0:UTF-8, 1:Unicode, 2:Shift-JIS) + bw.Write(iLength); // 文字列のbyte配列の長さ + bw.Write(bMessage); // 文字列のbyte配列 + + bw.Flush(); + } + }); } } } diff --git a/source/CeVIOAIProxy/MainWindow.xaml.cs b/source/CeVIOAIProxy/MainWindow.xaml.cs index e9befc9..cc7dee3 100644 --- a/source/CeVIOAIProxy/MainWindow.xaml.cs +++ b/source/CeVIOAIProxy/MainWindow.xaml.cs @@ -16,6 +16,22 @@ public MainWindow() this.InitializeComponent(); + if (Config.Instance.IsMinimizeStartup) + { + this.ShowInTaskbar = false; + this.WindowState = WindowState.Minimized; + + this.Loaded += (_, _) => + { + this.ToHide(); + this.ShowInTaskbar = true; + }; + } + else + { + this.Loaded += (_, _) => this.Activate(); + } + this.StateChanged += this.MainWindow_StateChanged; } diff --git a/source/CeVIOAIProxy/Servers/CAPTcpServer.cs b/source/CeVIOAIProxy/Servers/CAPTcpServer.cs index 1d4d50b..6af13b3 100644 --- a/source/CeVIOAIProxy/Servers/CAPTcpServer.cs +++ b/source/CeVIOAIProxy/Servers/CAPTcpServer.cs @@ -29,15 +29,7 @@ public void Open( { this.isClosing = false; - this.listener = new TcpListener(IPAddress.Any, port); - - /* - this.listener.Server.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.ReuseAddress, - true); - */ - + this.listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port); this.listener.Start(); this.listener.BeginAcceptTcpClient(AcceptTcpClientCallback, null); } @@ -47,7 +39,6 @@ public void Close() if (this.listener != null) { this.isClosing = true; - this.listener.Server.Close(); this.listener.Stop(); this.listener = null; } diff --git a/source/CeVIOAIProxy/app.manifest b/source/CeVIOAIProxy/app.manifest new file mode 100644 index 0000000..ffb888b --- /dev/null +++ b/source/CeVIOAIProxy/app.manifest @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + +