-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHome.cs
114 lines (102 loc) · 3.66 KB
/
Home.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using IoT.Server.Host.Properties;
using IoT.Server.Interfaces;
using Microsoft.Extensions.Hosting;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using Orleans.Serialization;
using System;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IoT.Server.Host
{
public partial class Home : Form
{
private Guid Id { get; set; } = Guid.NewGuid();
private bool Running { get; set; } = false;
private ISiloHost Host { get; set; }
public Home()
{
InitializeComponent();
Text = $"{Text} [{Id}]";
}
private async void OnStartStop(object sender, EventArgs e)
{
if (Running)
{
btnStartStop.Enabled = false;
await StopServer();
Running = false;
btnStartStop.Text = "START";
btnStartStop.Enabled = true;
}
else
{
btnStartStop.Enabled = false;
await StartServer();
Running = true;
btnStartStop.Text = "STOP";
btnStartStop.Enabled = true;
}
}
private async Task StartServer()
{
if (Host == null)
{
var builder = new SiloHostBuilder()
.UseAdoNetClustering(config => config.Configure(options =>
{
options.ConnectionString = Settings.Default.Database;
options.Invariant = "System.Data.SqlClient";
}))
.Configure<ClusterOptions>(config =>
{
config.ClusterId = "development";
config.ServiceId = "calculator";
})
.Configure<SerializationProviderOptions>(config =>
{
config.SerializationProviders.Clear();
config.SerializationProviders.Add(typeof(BondSerializer));
config.FallbackSerializationProvider = typeof(BinaryFormatterSerializer);
})
.Configure<EndpointOptions>(config =>
{
config.AdvertisedIPAddress = IPAddress.Loopback;
config.GatewayPort = (int)nPort.Value;
config.SiloPort = (int)nPort.Value + 10000;
})
.AddAdoNetGrainStorage("SQLServer", config => config.Configure(options =>
{
options.ConnectionString = Settings.Default.Database;
options.Invariant = "System.Data.SqlClient";
options.UseJsonFormat = true;
}))
//.AddRedisGrainStorage("Redis", config => config.Configure(options =>
//{
// options.ConnectionString = "127.0.0.1:6379";
// options.UseJson = true;
// options.DatabaseNumber = 1;
//}))
.ConfigureApplicationParts(parts =>
{
parts.AddApplicationPart(typeof(IStatistics).Assembly).WithReferences();
parts.AddApplicationPart(typeof(Statistics).Assembly).WithReferences();
});
//.ConfigureLogging(logging => logging.AddConsole());
Host = builder.Build();
await Host.StartAsync();
}
}
private async Task StopServer()
{
if (Host != null)
{
await Host.StopAsync();
await Host.DisposeAsync();
Host = null;
}
}
}
}