Skip to content

Commit 9a65d5d

Browse files
author
taku
committed
change json library
1 parent 388b468 commit 9a65d5d

3 files changed

Lines changed: 22 additions & 442 deletions

File tree

DesktopApp/AndroidNotifier/AndroidNotifier/AndroidNotifier.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<Reference Include="System.Net" />
4545
<Reference Include="System.Runtime" />
4646
<Reference Include="System.Runtime.Serialization" />
47+
<Reference Include="System.ServiceModel" />
4748
<Reference Include="System.Windows.Forms" />
4849
<Reference Include="System.Xml" />
4950
<Reference Include="Microsoft.CSharp" />
@@ -70,7 +71,6 @@
7071
<DependentUpon>App.xaml</DependentUpon>
7172
<SubType>Code</SubType>
7273
</Compile>
73-
<Compile Include="DynamicJson.cs" />
7474
<Compile Include="MainWindow.xaml.cs">
7575
<DependentUpon>MainWindow.xaml</DependentUpon>
7676
<SubType>Code</SubType>

DesktopApp/AndroidNotifier/AndroidNotifier/App.xaml.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using Codeplex.Data;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Configuration;
54
using System.Data;
65
using System.IO;
76
using System.Linq;
87
using System.Net;
98
using System.Net.Sockets;
9+
using System.Runtime.Serialization;
10+
using System.Runtime.Serialization.Json;
1011
using System.Text;
1112
using System.Threading.Tasks;
1213
using System.Windows;
@@ -29,15 +30,18 @@ protected override void OnStartup(StartupEventArgs e)
2930

3031
Task.Run(() => {
3132
var data = new StreamReader("./settings.json").ReadToEnd();
32-
var json = DynamicJson.Parse(data);
33-
int port = (int) json.port;
34-
IPEndPoint ep = new IPEndPoint(IPAddress.Any, port);
35-
var client = new UdpClient(port);
36-
while(true)
33+
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SettingData));
34+
using(MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data)))
3735
{
38-
var buff = client.Receive(ref ep);
39-
var text = Encoding.UTF8.GetString(buff);
40-
component.notify(text);
36+
SettingData setting = (SettingData)serializer.ReadObject(ms);
37+
IPEndPoint ep = new IPEndPoint(IPAddress.Any, setting.port);
38+
var client = new UdpClient(setting.port);
39+
while (true)
40+
{
41+
var buff = client.Receive(ref ep);
42+
var text = Encoding.UTF8.GetString(buff);
43+
component.notify(text);
44+
}
4145
}
4246
});
4347
}
@@ -48,4 +52,11 @@ protected override void OnExit(ExitEventArgs e)
4852
component.Dispose();
4953
}
5054
}
55+
56+
[DataContract]
57+
class SettingData
58+
{
59+
[DataMember]
60+
public int port;
61+
}
5162
}

0 commit comments

Comments
 (0)