forked from bLightZP/marsGameServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.Forms.Main.pas
149 lines (126 loc) · 3.83 KB
/
Server.Forms.Main.pas
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
(*
Copyright 2016, MARS-Curiosity - REST Library
Home: https://github.com/andrea-magni/MARS
*)
unit Server.Forms.Main;
{$I MARS.inc}
interface
uses Classes, SysUtils, Forms, ActnList, ComCtrls, StdCtrls, Controls, ExtCtrls
, System.Actions
, MARS.http.Server.Indy
;
type
TMainForm = class(TForm)
MainActionList: TActionList;
StartServerAction: TAction;
StopServerAction: TAction;
TopPanel: TPanel;
Label1: TLabel;
StartButton: TButton;
StopButton: TButton;
PortNumberEdit: TEdit;
MainTreeView: TTreeView;
procedure StartServerActionExecute(Sender: TObject);
procedure StartServerActionUpdate(Sender: TObject);
procedure StopServerActionExecute(Sender: TObject);
procedure StopServerActionUpdate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PortNumberEditChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
FServer: TMARShttpServerIndy;
protected
procedure RenderEngines(const ATreeView: TTreeView);
public
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses
StrUtils, Web.HttpApp
, MARS.Core.URL, MARS.Core.Engine, MARS.Core.Application, MARS.Core.Registry
, MARS.Core.Registry.Utils
, Server.Ignition
;
procedure TMainForm.RenderEngines(const ATreeView: TTreeView);
begin
ATreeview.Items.BeginUpdate;
try
ATreeview.Items.Clear;
TMARSEngineRegistry.Instance.EnumerateEngines(
procedure (AName: string; AEngine: TMARSEngine)
var
LEngineItem: TTreeNode;
begin
LEngineItem := ATreeview.Items.AddChild(nil
, AName + ' [ :' + AEngine.Port.ToString + AEngine.BasePath + ']'
);
AEngine.EnumerateApplications(
procedure (AName: string; AApplication: TMARSApplication)
var
LApplicationItem: TTreeNode;
begin
LApplicationItem := ATreeview.Items.AddChild(LEngineItem
, AApplication.Name + ' [' + AApplication.BasePath + ']'
);
AApplication.EnumerateResources(
procedure (AName: string; AInfo: TMARSConstructorInfo)
begin
ATreeview.Items.AddChild(
LApplicationItem
, AInfo.TypeTClass.ClassName + ' [' + AName + ']'
);
end
);
end
);
end
);
if ATreeView.Items.Count > 0 then
ATreeView.Items[0].Expand(True);
finally
ATreeView.Items.EndUpdate;
end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
StopServerAction.Execute;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
//PortNumberEdit.Text := IntToStr(TServerEngine.Default.Port);
PortNumberEdit.Text := '8081';
RenderEngines(MainTreeView);
StartServerAction.Execute;
end;
procedure TMainForm.PortNumberEditChange(Sender: TObject);
begin
TServerEngine.Default.Port := StrToInt(PortNumberEdit.Text);
end;
procedure TMainForm.StartServerActionExecute(Sender: TObject);
begin
// http server implementation
FServer := TMARShttpServerIndy.Create(TServerEngine.Default);
try
FServer.DefaultPort := TServerEngine.Default.Port;
FServer.Active := True;
except
FServer.Free;
raise;
end;
end;
procedure TMainForm.StartServerActionUpdate(Sender: TObject);
begin
StartServerAction.Enabled := (FServer = nil) or (FServer.Active = False);
end;
procedure TMainForm.StopServerActionExecute(Sender: TObject);
begin
FServer.Active := False;
FreeAndNil(FServer);
end;
procedure TMainForm.StopServerActionUpdate(Sender: TObject);
begin
StopServerAction.Enabled := Assigned(FServer) and (FServer.Active = True);
end;
end.