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$
@@ -35,12 +35,13 @@ TWebServiceInfo = record
35
35
// / <summary>MIME type of media used by web service.</summary>
36
36
MediaType: string;
37
37
// / <summary>Constructs a record with given field values.</summary>
38
- // / <param name="AScriptURLTplt">string [in] Template for web service's
39
- // / URI.</param>
40
- // / <param name="AUserAgent">string [in] User agent to use when accessing
41
- // / web service.</param>
42
- // / <param name="AMediaType">string [in] Optional. Media type used by web
43
- // / service.</param>
38
+ // / <param name="AScriptURLTplt"><c>string</c> [in] Template for web
39
+ // / service's URI. Must contain a single '%s' placeholder for web host.
40
+ // / </param>
41
+ // / <param name="AUserAgent"><c>string</c> [in] User agent to use when
42
+ // / accessing web service.</param>
43
+ // / <param name="AMediaType"><c>string</c> [in] Optional. Media type used
44
+ // / by web service.</param>
44
45
constructor Create(const AScriptURLTplt, AUserAgent: string;
45
46
const AMediaType: string = ' text/*' );
46
47
end ;
@@ -67,25 +68,31 @@ TWebProxyInfo = record
67
68
TWebInfo = class (TNoConstructObject)
68
69
strict private
69
70
const
70
- // / <summary>Remote DelphiDabbler web server.</summary>
71
- RemoteHost = ' delphidabbler.com' ;
71
+ // / <summary>Name of server that hosts tested and released web services
72
+ // / that are used by CodeSnip.</summary>
73
+ // / <remarks>There is also a test server that can be used by CodeSnip
74
+ // / where new and updated web services are tested - see
75
+ // / <c>TestServerHost</c> below.</remarks>
76
+ ProductionServerHost = ' delphidabbler.com' ;
72
77
// / <summary>URL of DelphiDabbler website.</summary>
73
- WebsiteURL = ' http://' + RemoteHost ;
78
+ WebsiteURL = ' http://' + ProductionServerHost ;
74
79
// / <summary>Template for URL of Code Snippets news feed.</summary>
75
80
// / <remarks>'%d' placeholder must be replaced by the required number of
76
- // / days into the past the news feed should cover.</remarks>
81
+ // / days into the past the news feed should cover. Passing <c>0</c> as
82
+ // / the number of days results in all news items being returned.
83
+ // / </remarks>
77
84
NewsFeedTplt = WebSiteURL + ' /feeds/site-news-feed?id=codesnip&days=%d' ;
78
85
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>
86
+ // / <summary>Returns the name of the server that hosts web services that
87
+ // / are used by CodeSnip.</summary>
88
+ // / <remarks>By default is the production server (as specified by the
89
+ // / <c>ProductionServerHost</c> constant). CodeSnip will instead use a
90
+ // / test server (as returned by the <c>TestServerHost</c> method) if the
91
+ // / name and port of the test server is passed on the command line via the
92
+ // / <c>--test-server</c> command line option.</remarks>
83
93
class function Host : string;
84
94
public
85
95
const
86
- // / <summary>Local web server.</summary>
87
- // / <remarks>Used for test purposes.</remarks>
88
- LocalHost = ' localhost:8080' ;
89
96
// / <summary>URL of home page on DelphiDabbler website.</summary>
90
97
DelphiDabblerHomeURL = WebsiteURL + ' /' ;
91
98
// / <summary>URL of home page of the CodeSnip project.</summary>
@@ -94,37 +101,59 @@ TWebInfo = class(TNoConstructObject)
94
101
DatabaseURL = WebsiteURL + ' /url/csdb' ;
95
102
// / <summary>URL used to make donations towards the CodeSnip project.
96
103
// / </summary>
97
- // / <summary >This URL redirects to the correct page on PayPal.</summary >
104
+ // / <remarks >This URL redirects to the correct page on PayPal.</remarks >
98
105
DonateURL = WebsiteURL + ' /url/donate-cs' ;
99
106
// / <summary>URL used to view and report CodeSnip bugs.</summary>
107
+ // / <remarks>This URL will redirect to the actual bug tracker which may
108
+ // / be on an external site such as SourceForge or GitHub.</remarks>
100
109
BugTrackerURL = WebsiteURL + ' /url/codesnip-bugs' ;
101
110
// / <summary>URL of CodeSnip's FAQ web page.</summary>
111
+ // / <remarks>This URL will redirect to the FAQ location which may be on
112
+ // / an external site such as GitHub or SourceForge.</remarks>
102
113
FAQsURL = WebsiteURL + ' /url/codesnip-faq' ;
103
114
public
115
+ // / <summary>Returns the name of the server that hosts web services used by
116
+ // / CodeSnip when under testing. This server receives updated web services
117
+ // / before they are released to the production server.</summary>
118
+ // / <remarks>
119
+ // / <para>The name of this server must be passed on the command line via
120
+ // / the <c>--test-server</c> option. If this option is not specified then
121
+ // / <c>TestServerHost</c> returns the empty string.</para>
122
+ // / <para>The format of the command line switch is
123
+ // / <c>--test-server=server-name</c> or
124
+ // / <c>--test-server=server-name:port</c> where <c>server-name</c> is the
125
+ // / name of the test server and <c>port</c> is the port number it is
126
+ // / operating on, for example <c>--test-server=localhost:8080</c> or
127
+ // / <c>--test-server=test.delphidabbler.com</c>. The
128
+ // / port number and its preceding ':' character can be omitted if the
129
+ // / server is on port 80.</para>
130
+ // / <para>The server must be using the <c>http://</c> protocol.</para>
131
+ // / </remarks>
132
+ class function TestServerHost : string;
104
133
// / <summary>Builds the URL of the CodeSnip news feed.</summary>
105
- // / <param name="Age">Word [in] Maximum age, in days, of news items to be
106
- // / included in the feed.</param>
107
- // / <returns>string. Required URL.</returns>
134
+ // / <param name="Age"><c> Word</c> [in] Maximum age, in days, of news items
135
+ // / to be included in the feed.</param>
136
+ // / <returns><c> string</c> . Required URL.</returns>
108
137
class function NewsFeedURL (const Age: Word): string;
109
138
// / <summary>Builds the URL of a web service.</summary>
110
- // / <param name="URLTplt">string. [in] Template of URL of web service
111
- // / script. Must contain a '%s' placeholder for host name.</param>
112
- // / <returns>string. Required URL.</returns>
139
+ // / <param name="URLTplt"><c> string</c> . [in] Template of URL of web
140
+ // / service script. Must contain a '%s' placeholder for host name.</param>
141
+ // / <returns><c> string</c> . Required URL.</returns>
113
142
class function WebServiceURL (const URLTplt: string): string;
114
143
// / <summary>Gets information about any required web proxy.</summary>
115
144
// / <remarks>The web proxy information is read from settings.</remarks>
116
145
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>
146
+ // / <summary>Checks if the program is using a test web server.</summary>
147
+ // / <returns><c>Boolean</c>. <c>True</c> if a test web server is being
148
+ // / used, <c>False</c> if the production web server is being used.
149
+ // / </returns>
121
150
// / <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>
151
+ // / <para><c> True</c> is returned iff a valid <c>--test-server</c> command
152
+ // / line option was supplied .</para>
153
+ // / <para><c>--test-server</c> should only be specified by developers with
154
+ // / access to a suitable test server .</para>
126
155
// / </remarks>
127
- class function UsingLocalHost : Boolean;
156
+ class function UsingTestServer : Boolean;
128
157
end ;
129
158
130
159
@@ -142,20 +171,43 @@ implementation
142
171
143
172
class function TWebInfo.Host : string;
144
173
begin
145
- if UsingLocalHost then
146
- Result := LocalHost
174
+ if UsingTestServer then
175
+ Result := TestServerHost
147
176
else
148
- Result := RemoteHost ;
177
+ Result := ProductionServerHost ;
149
178
end ;
150
179
151
180
class function TWebInfo.NewsFeedURL (const Age: Word): string;
152
181
begin
153
182
Result := Format(NewsFeedTplt, [Age]);
154
183
end ;
155
184
156
- class function TWebInfo.UsingLocalHost : Boolean;
185
+ class function TWebInfo.TestServerHost : string;
186
+ const
187
+ TestServerSwitch = ' --test-server' ;
188
+ Separator = ' =' ;
189
+ var
190
+ Idx: Integer;
191
+ ParamName: string;
192
+ ParamValue: string;
193
+ begin
194
+ for Idx := 1 to ParamCount do
195
+ begin
196
+ if not StrContainsStr(Separator, ParamStr(Idx)) then
197
+ Continue;
198
+ StrSplit(ParamStr(Idx), Separator, ParamName, ParamValue);
199
+ if not StrSameStr(TestServerSwitch, ParamName) then
200
+ Continue;
201
+ if ParamValue = EmptyStr then
202
+ Continue;
203
+ Exit(ParamValue);
204
+ end ;
205
+ Result := EmptyStr;
206
+ end ;
207
+
208
+ class function TWebInfo.UsingTestServer : Boolean;
157
209
begin
158
- Result := FindCmdLineSwitch( ' localhost ' , True) ;
210
+ Result := TestServerHost <> EmptyStr ;
159
211
end ;
160
212
161
213
class function TWebInfo.WebProxyInfo : TWebProxyInfo;
0 commit comments