Skip to content

Commit

Permalink
v1.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anoyetta committed Apr 28, 2021
1 parent 7e4d376 commit 6686813
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 22 deletions.
33 changes: 22 additions & 11 deletions source/CeVIOAIProxy/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions source/CeVIOAIProxy/CeVIOAIProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ApplicationIcon>share.ico</ApplicationIcon>
<LangVersion>preview</LangVersion>
<SignAssembly>false</SignAssembly>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
36 changes: 35 additions & 1 deletion source/CeVIOAIProxy/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
});
}
}
}
16 changes: 16 additions & 0 deletions source/CeVIOAIProxy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 1 addition & 10 deletions source/CeVIOAIProxy/Servers/CAPTcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -47,7 +39,6 @@ public void Close()
if (this.listener != null)
{
this.isClosing = true;
this.listener.Server.Close();
this.listener.Stop();
this.listener = null;
}
Expand Down
16 changes: 16 additions & 0 deletions source/CeVIOAIProxy/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</assembly>

0 comments on commit 6686813

Please sign in to comment.