3
3
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
4
* obtain one at http://mozilla.org/MPL/2.0/
5
5
*
6
- * Copyright (C) 2009-2014 , Peter Johnson (www.delphidabbler.com).
6
+ * Copyright (C) 2009-2016 , Peter Johnson (www.delphidabbler.com).
7
7
*
8
8
* $Rev$
9
9
* $Date$
@@ -67,25 +67,29 @@ TWebProxyInfo = record
67
67
TWebInfo = class (TNoConstructObject)
68
68
strict private
69
69
const
70
- // / <summary>Remote DelphiDabbler web server.</summary>
71
- RemoteHost = ' delphidabbler.com' ;
70
+ // / <summary>Name of server that hosts tested and released web services
71
+ // / that are used by CodeSnip.</summary>
72
+ // / <remarks>There is also a test server that can be used by CodeSnip
73
+ // / where new and updated web services are tested - see
74
+ // / <c>TestServerHost</c> below.</remarks>
75
+ ProductionServerHost = ' delphidabbler.com' ;
72
76
// / <summary>URL of DelphiDabbler website.</summary>
73
- WebsiteURL = ' http://' + RemoteHost ;
77
+ WebsiteURL = ' http://' + ProductionServerHost ;
74
78
// / <summary>Template for URL of Code Snippets news feed.</summary>
75
79
// / <remarks>'%d' placeholder must be replaced by the required number of
76
80
// / days into the past the news feed should cover.</remarks>
77
81
NewsFeedTplt = WebSiteURL + ' /feeds/site-news-feed?id=codesnip&days=%d' ;
78
82
strict private
79
- // / <summary>Returns the name of the host server to be used.</summary>
80
- // / <remarks>This is the remote web server unless the '-localhost# switch
81
- // / was passed on the command line when localhost server is returned.
82
- // / </remarks>
83
+ // / <summary>Returns the name of the server that hosts web services that
84
+ // / are used by CodeSnip.</summary>
85
+ // / <remarks>By default is the production server (as specified by the
86
+ // / <c>ProductionServerHost</c> constant. CodeSnip will instead use a
87
+ // / test server (as returned by the <c>TestServerHost</c> method) if the
88
+ // / name and port of the test server is passed on the command line via the
89
+ // / <c>--test-server</c> command line option.</remarks>
83
90
class function Host : string;
84
91
public
85
92
const
86
- // / <summary>Local web server.</summary>
87
- // / <remarks>Used for test purposes.</remarks>
88
- LocalHost = ' localhost:8080' ;
89
93
// / <summary>URL of home page on DelphiDabbler website.</summary>
90
94
DelphiDabblerHomeURL = WebsiteURL + ' /' ;
91
95
// / <summary>URL of home page of the CodeSnip project.</summary>
@@ -101,6 +105,24 @@ TWebInfo = class(TNoConstructObject)
101
105
// / <summary>URL of CodeSnip's FAQ web page.</summary>
102
106
FAQsURL = WebsiteURL + ' /url/codesnip-faq' ;
103
107
public
108
+ // / <summary>Returns the name of the server that hosts web services used by
109
+ // / CodeSnip when under testing. This server receives updated web services
110
+ // / before they are released to the production server.</summary>
111
+ // / <remarks>
112
+ // / <para>The name of this server must be passed on the command line via
113
+ // / the <c>--test-server</c> option. If this option is not specified then
114
+ // / <c>TestServerHost</c> returns the empty string.</para>
115
+ // / <para>The format of the command line switch is
116
+ // / <c>--test-server=server-name</c> or
117
+ // / <c>--test-server=server-name:port</c> where <c>server-name</c> is the
118
+ // / name of the test server and <c>port</c> is the port number it is
119
+ // / operating on, for example <c>--test-server=localhost:8080</c> or
120
+ // / <c>--test-server=test.delphidabbler.com</c>. The
121
+ // / port number and its preceding ':' character can be omitted if the
122
+ // / server is on port 80.</para>
123
+ // / <para>The server must be using the <c>http://</c> protocol.</para>
124
+ // / </remarks>
125
+ class function TestServerHost : string;
104
126
// / <summary>Builds the URL of the CodeSnip news feed.</summary>
105
127
// / <param name="Age">Word [in] Maximum age, in days, of news items to be
106
128
// / included in the feed.</param>
@@ -114,17 +136,18 @@ TWebInfo = class(TNoConstructObject)
114
136
// / <summary>Gets information about any required web proxy.</summary>
115
137
// / <remarks>The web proxy information is read from settings.</remarks>
116
138
class function WebProxyInfo : TWebProxyInfo;
117
- // / <summary>Checks if the program is using the web server on localhost.
118
- // / </summary>
119
- // / <returns>Boolean. True if localhost is being used, False if the remote,
120
- // / production, server is being used. </returns>
139
+ // / <summary>Checks if the program is using a test web server.</summary>
140
+ // / <returns><c>Boolean</c>. <c>True</c> if a test web server is being
141
+ // / used, <c>False</c> if the production web server is being used.
142
+ // / </returns>
121
143
// / <remarks>
122
- // / <para>True is returned iff the '-localhost' switch was passed on the
123
- // / command line.</para>
124
- // / <para>Localhost should only be used by developers with access to a
125
- // / suitable test server running as 'locahost'.</para>
144
+ // / <para><c>True</c> is returned iff a valid <c>--test-server</c> command
145
+ // / line option was supplied on the command line.</para>
146
+ // / <para><c>--test-server</c> should only be specified by developers with
147
+ // / access to a suitable test server.</para>
148
+
126
149
// / </remarks>
127
- class function UsingLocalHost : Boolean;
150
+ class function UsingTestServer : Boolean;
128
151
end ;
129
152
130
153
@@ -142,20 +165,43 @@ implementation
142
165
143
166
class function TWebInfo.Host : string;
144
167
begin
145
- if UsingLocalHost then
146
- Result := LocalHost
168
+ if UsingTestServer then
169
+ Result := TestServerHost
147
170
else
148
- Result := RemoteHost ;
171
+ Result := ProductionServerHost ;
149
172
end ;
150
173
151
174
class function TWebInfo.NewsFeedURL (const Age: Word): string;
152
175
begin
153
176
Result := Format(NewsFeedTplt, [Age]);
154
177
end ;
155
178
156
- class function TWebInfo.UsingLocalHost : Boolean;
179
+ class function TWebInfo.TestServerHost : string;
180
+ const
181
+ TestServerSwitch = ' --test-server' ;
182
+ Separator = ' =' ;
183
+ var
184
+ Idx: Integer;
185
+ ParamName: string;
186
+ ParamValue: string;
187
+ begin
188
+ for Idx := 1 to ParamCount do
189
+ begin
190
+ if not StrContainsStr(Separator, ParamStr(Idx)) then
191
+ Continue;
192
+ StrSplit(ParamStr(Idx), Separator, ParamName, ParamValue);
193
+ if not StrSameStr(TestServerSwitch, ParamName) then
194
+ Continue;
195
+ if ParamValue = EmptyStr then
196
+ Continue;
197
+ Exit(ParamValue);
198
+ end ;
199
+ Result := EmptyStr;
200
+ end ;
201
+
202
+ class function TWebInfo.UsingTestServer : Boolean;
157
203
begin
158
- Result := FindCmdLineSwitch( ' localhost ' , True) ;
204
+ Result := TestServerHost <> EmptyStr ;
159
205
end ;
160
206
161
207
class function TWebInfo.WebProxyInfo : TWebProxyInfo;
0 commit comments