NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper Class Reference

OR/M mapper for table timeServer. More...

Inheritance diagram for Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper:
Collaboration diagram for Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper:

Protected Member Functions

override TimeServer FetchExternal (int id)
 Fetch time server from external source. More...
 
override void Insert (TimeServer item)
 
override void ReadContent ()
 
override void Update (TimeServer item)
 
- Protected Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >
 SqlDatabaseMapper (LogBase log)
 
void AddItem (T item)
 
void Close ()
 
IDbDataParameter CreateParameter (string name, object value)
 
abstract void Insert (T item)
 
void Open ()
 
string PrepareInsertSql (string sql)
 
virtual string PrepareSql (string sql)
 
void RemoveItem (T item)
 
abstract void Update (T item)
 

Protected Attributes

override string CreateSql
 
override string TableName => "timeServer"
 
override bool UseCache => true
 
- Protected Attributes inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >
IEnumerable< T > Content
 
readonly object MapperLocker
 
IDataReader Reader
 

Package Functions

 TimeServerDatabaseMapper (LogBase log)
 

Private Attributes

const string InsertSql
 
const string SelectSql
 

Additional Inherited Members

- Public Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >
void CheckTable ()
 
override IEnumerator< T > GetEnumerator ()
 Read all data from table in a sequential manner. More...
 
void Save (T item)
 
- Properties inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >
IDbCommand Command [get, private set]
 
abstract string CreateSql [get]
 
abstract string TableName [get]
 
this[int id] [get]
 
abstract bool UseCache [get]
 

Detailed Description

OR/M mapper for table timeServer.

Definition at line 36 of file TimeServerDatabaseMapper.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.TimeServerDatabaseMapper ( LogBase  log)
inlinepackage

Definition at line 38 of file TimeServerDatabaseMapper.cs.

39  : base(log)
40  {
41  }

Member Function Documentation

override TimeServer Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.FetchExternal ( int  id)
inlineprotectedvirtual

Fetch time server from external source.

Returns
The external.
Parameters
idThe time server identifier used on support.ntp.org.

Reimplemented from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >.

Definition at line 102 of file TimeServerDatabaseMapper.cs.

References Ntp.Analyzer.Data.Import.TimeServerWebAdapter.Create(), and e.

103  {
104  var adapter = TimeServerWebAdapter.Create(Log);
105 
106  if (adapter == null)
107  return null;
108 
109  TimeServer server;
110 
111  try
112  {
113  server = adapter.Import(id);
114  Insert(server);
115  AddItem(server);
116  }
117  catch (Exception e)
118  {
119  Log.TimeServerFetchError(e);
120  return null;
121  }
122 
123  return server;
124  }
var e
Definition: bootstrap.min.js:6
static TimeServerWebAdapter Create(LogBase log)

Here is the call graph for this function:

override void Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.Insert ( TimeServer  item)
inlineprotected

Definition at line 127 of file TimeServerDatabaseMapper.cs.

References Ntp.Analyzer.Objects.TimeServer.AccessDetails, Ntp.Analyzer.Objects.TimeServer.AccessPolicy, Ntp.Analyzer.Objects.TimeServer.Address, Ntp.Analyzer.Objects.TimeServer.AutoKey, Ntp.Analyzer.Objects.TimeServer.Contact, Ntp.Analyzer.Objects.TimeServer.Country, Ntp.Analyzer.Objects.TimeServer.DisplayLocation, e, Ntp.Analyzer.Objects.TimeServer.Geo, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.TimeServer.IsPoolMember, Ntp.Analyzer.Objects.TimeServer.Location, Ntp.Analyzer.Objects.TimeServer.Name, Ntp.Analyzer.Objects.TimeServer.Organization, Ntp.Analyzer.Objects.TimeServer.ProviderPage, Ntp.Analyzer.Objects.TimeServer.ProviderUrl, Ntp.Analyzer.Objects.TimeServer.Server, Ntp.Analyzer.Objects.TimeServer.ServiceArea, Ntp.Analyzer.Objects.PersistentObject.SetId(), Ntp.Analyzer.Objects.TimeServer.ShouldNotify, Ntp.Analyzer.Objects.TimeServer.ShouldUseDns, Ntp.Analyzer.Objects.TimeServer.Stratum, Ntp.Analyzer.Objects.TimeServer.SymKey, Ntp.Analyzer.Objects.TimeServer.SymUrl, Ntp.Analyzer.Objects.TimeServer.Updated, and Ntp.Analyzer.Objects.TimeServer.V6Address.

128  {
129  string countryCode = item.Country?.PadRight(7).Substring(0, 7).TrimEnd();
130  string hostName = item.Name?.PadRight(50).Substring(0, 50).TrimEnd();
131  string ip = item.Address?.ToString().PadRight(15).Substring(0, 15).TrimEnd();
132  string ip6 = item.V6Address?.PadRight(30).Substring(0, 30).TrimEnd();
133  string location = item.Location?.PadRight(100).Substring(0, 100).TrimEnd();
134  string displayLocation = item.DisplayLocation?.PadRight(60).Substring(0, 60).TrimEnd();
135  string organization = item.Organization?.PadRight(50).Substring(0, 50).TrimEnd();
136  string coordinates = item.Geo?.PadRight(50).Substring(0, 50).TrimEnd();
137  string synchronization = item.Server?.PadRight(255).Substring(0, 255).TrimEnd();
138  string serviceArea = item.ServiceArea?.PadRight(100).Substring(0, 100).TrimEnd();
139  string accessPolicy = item.AccessPolicy?.PadRight(255).Substring(0, 255).TrimEnd();
140  string accessDetails = item.AccessDetails?.PadRight(512).Substring(0, 512).TrimEnd();
141  string autoKeyUrl = item.AutoKey?.PadRight(255).Substring(0, 255).TrimEnd();
142  string symmetricKeyType = item.SymKey?.PadRight(100).Substring(0, 100).TrimEnd();
143  string symmetricKeyUrl = item.SymUrl?.PadRight(100).Substring(0, 100).TrimEnd();
144  string serverContact = item.Contact?.PadRight(255).Substring(0, 255).TrimEnd();
145  string providerPage = item.ProviderPage?.PadRight(100).Substring(0, 100).TrimEnd();
146  string providerUrl = item.ProviderUrl?.PadRight(255).Substring(0, 255).TrimEnd();
147 
148  lock (MapperLocker)
149  {
150  try
151  {
152  Open();
153  Command.CommandText = PrepareInsertSql(InsertSql);
154  Command.Parameters.Add(CreateParameter("@id", item.Id));
155  Command.Parameters.Add(CreateParameter("@stratum", item.Stratum));
156  Command.Parameters.Add(CreateParameter("@countryCode", countryCode));
157  Command.Parameters.Add(CreateParameter("@hostName", hostName));
158  Command.Parameters.Add(CreateParameter("@ip", ip));
159  Command.Parameters.Add(CreateParameter("@ip6", ip6));
160  Command.Parameters.Add(CreateParameter("@useDns", item.ShouldUseDns));
161  Command.Parameters.Add(CreateParameter("@poolMember", item.IsPoolMember));
162  Command.Parameters.Add(CreateParameter("@location", location));
163  Command.Parameters.Add(CreateParameter("@displayLocation", displayLocation));
164  Command.Parameters.Add(CreateParameter("@organization", organization));
165  Command.Parameters.Add(CreateParameter("@coordinates", coordinates));
166  Command.Parameters.Add(CreateParameter("@synchronization", synchronization));
167  Command.Parameters.Add(CreateParameter("@serviceArea", serviceArea));
168  Command.Parameters.Add(CreateParameter("@accessPolicy", accessPolicy));
169  Command.Parameters.Add(CreateParameter("@accessDetails", accessDetails));
170  Command.Parameters.Add(CreateParameter("@notification", item.ShouldNotify));
171  Command.Parameters.Add(CreateParameter("@autoKeyUrl", autoKeyUrl));
172  Command.Parameters.Add(CreateParameter("@symmetricKeyType", symmetricKeyType));
173  Command.Parameters.Add(CreateParameter("@symmetricKeyURL", symmetricKeyUrl));
174  Command.Parameters.Add(CreateParameter("@serverContact", serverContact));
175  Command.Parameters.Add(CreateParameter("@providerPage", providerPage));
176  Command.Parameters.Add(CreateParameter("@providerUrl", providerUrl));
177  Command.Parameters.Add(CreateParameter("@updated", item.Updated));
178  Command.Prepare();
179  Log.SqlExecute(Command.CommandText, Command.Parameters);
180  Command.ExecuteNonQuery();
181  item.SetId(item.Id);
182  }
183  catch (Exception e)
184  {
185  Log.InsertError(TableName, e);
186  }
187  finally
188  {
189  Close();
190  }
191  }
192  }
abstract string ProviderPage
Definition: TimeServer.cs:78
abstract string Organization
Definition: TimeServer.cs:56
abstract string AccessDetails
Definition: TimeServer.cs:66
void SetId(int id)
Sets the identifier after the object have been stored in persistent storage.
var e
Definition: bootstrap.min.js:6
abstract string AccessPolicy
Definition: TimeServer.cs:64
IDbDataParameter CreateParameter(string name, object value)
abstract IPAddress Address
Definition: TimeServer.cs:44
abstract DateTime Updated
Definition: TimeServer.cs:82
abstract string DisplayLocation
Definition: TimeServer.cs:54

Here is the call graph for this function:

override void Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.ReadContent ( )
inlineprotectedvirtual

Implements Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< TimeServer >.

Definition at line 195 of file TimeServerDatabaseMapper.cs.

References e.

196  {
197  try
198  {
199  Open();
200  Command.CommandText = PrepareSql(SelectSql);
201  Log.SqlExecute(Command.CommandText);
202  Reader = Command.ExecuteReader();
203 
204  while (Reader.Read())
205  {
206  int id = Convert.ToInt32(Reader["id"]);
207  int stratum = Convert.ToInt32(Reader["stratum"]);
208  string countryCode = Reader["countryCode"].ToString();
209  string hostName = Reader["hostName"].ToString();
210  string ip4 = Reader["ip"] != DBNull.Value ? Reader["ip"].ToString() : null;
211  string ip6 = Reader["ip6"] != DBNull.Value ? Reader["ip6"].ToString() : null;
212  bool? useDns = Reader["dns"] != DBNull.Value ? Convert.ToBoolean(Reader["dns"]) : (bool?) null;
213  bool? poolMember = Reader["pool"] != DBNull.Value ? Convert.ToBoolean(Reader["pool"]) : (bool?) null;
214  string location = Reader["location"].ToString();
215  string displayLocation = Reader["displayLocation"].ToString();
216  string organization = Reader["organization"] != DBNull.Value
217  ? Reader["organization"].ToString()
218  : null;
219  string coordinates = Reader["coordinates"] != DBNull.Value
220  ? Reader["organization"].ToString()
221  : null;
222  string synchronization = Reader["synchronization"].ToString();
223  string serviceArea = Reader["serviceArea"].ToString();
224  string accessPolicy = Reader["accessPolicy"].ToString();
225  string accessDetails = Reader["accessDetails"] != DBNull.Value
226  ? Reader["accessDetails"].ToString()
227  : null;
228  bool? notification = Reader["noti"] != DBNull.Value
229  ? Convert.ToBoolean(Reader["noti"])
230  : (bool?) null;
231  string autoKeyUrl = Reader["autoKeyUrl"] != DBNull.Value ? Reader["autoKeyUrl"].ToString() : null;
232  string symmetricKeyType = Reader["symmetricKeyType"] != DBNull.Value
233  ? Reader["symmetricKeyType"].ToString()
234  : null;
235  string symmetricKeyUrl = Reader["symmetricKeyURL"] != DBNull.Value
236  ? Reader["symmetricKeyURL"].ToString()
237  : null;
238  string serverContact = Reader["serverContact"] != DBNull.Value
239  ? Reader["serverContact"].ToString()
240  : null;
241  string providerPage = Reader["providerPage"] != DBNull.Value
242  ? Reader["providerPage"].ToString()
243  : null;
244  string providerUrl = Reader["providerUrl"] != DBNull.Value
245  ? Reader["providerUrl"].ToString()
246  : null;
247  DateTime updated = Convert.ToDateTime(Reader["updated"]);
248 
249  IPAddress address = null;
250  if (ip4 != null)
251  IPAddress.TryParse(ip4, out address);
252 
253  var server = new CalgaryTimeServer(
254  id, stratum, countryCode, hostName, address, ip6, useDns, poolMember, location,
255  displayLocation, organization, coordinates, synchronization, serviceArea, accessDetails,
256  accessPolicy, notification, autoKeyUrl, symmetricKeyType, symmetricKeyUrl, serverContact,
257  providerPage, providerUrl, updated);
258 
259  AddItem(server);
260  }
261  }
262  catch (Exception e)
263  {
264  Log.ReadError(TableName, e);
265  }
266  finally
267  {
268  Close();
269  }
270  }
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.Update ( TimeServer  item)
inlineprotected

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE timeServer ( " +
" id INT NOT NULL PRIMARY KEY, " +
" stratum INT NOT NULL, " +
" countryCode CHAR(7) NOT NULL, " +
" hostName VARCHAR(50) NOT NULL, " +
" ip VARCHAR(15) NULL, " +
" ip6 VARCHAR(30) NULL, " +
" useDns BIT(1) NULL, " +
" poolMember BIT(1) NULL, " +
" location VARCHAR(100) NULL, " +
" displayLocation VARCHAR(60) NOT NULL, " +
" organization VARCHAR(50) NULL, " +
" coordinates VARCHAR(50) NULL, " +
" synchronization VARCHAR(255) NULL, " +
" serviceArea VARCHAR(100) NULL, " +
" accessPolicy VARCHAR(255) NULL, " +
" accessDetails VARCHAR(512) NULL, " +
" notification BIT(1) NULL, " +
" autoKeyUrl VARCHAR(255) NULL, " +
" symmetricKeyType VARCHAR(100) NULL, " +
" symmetricKeyURL VARCHAR(100) NULL, " +
" serverContact VARCHAR(255) NULL, " +
" updated TIMESTAMP NOT NULL, " +
" providerPage VARCHAR(100) NULL, " +
" providerUrl VARCHAR(255) NULL " +
"){1};"

Definition at line 70 of file TimeServerDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO timeServer( id, stratum, countryCode, hostName, ip, ip6, " +
"useDns, poolMember, location, displayLocation, organization, " +
"coordinates, synchronization, serviceArea, accessPolicy, " +
"accessDetails, notification, autoKeyUrl, symmetricKeyType, " +
"symmetricKeyURL, serverContact, providerPage, providerUrl, " +
"updated ) " +
"VALUES ( @id, @stratum, @countryCode, @hostName, @ip, @ip6, " +
"@useDns, @poolMember, @location, @displayLocation, @organization, " +
"@coordinates, @synchronization, @serviceArea, @accessPolicy, " +
"@accessDetails, @notification, @autoKeyUrl, @symmetricKeyType, " +
"@symmetricKeyURL, @serverContact, @providerPage, @providerUrl, " +
"@updated );"

Definition at line 52 of file TimeServerDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT id, stratum, countryCode, hostName, ip, ip6, " +
"useDns+0 as dns, poolMember+0 as pool, location, displayLocation, organization, " +
"coordinates, synchronization, serviceArea, accessPolicy, " +
"accessDetails, notification+0 as noti, autoKeyUrl, symmetricKeyType, " +
"symmetricKeyURL, serverContact, providerPage, providerUrl, " +
"updated " +
"FROM timeServer;"

Definition at line 43 of file TimeServerDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.TableName => "timeServer"
protected

Definition at line 68 of file TimeServerDatabaseMapper.cs.

override bool Ntp.Analyzer.Data.Sql.TimeServerDatabaseMapper.UseCache => true
protected

Definition at line 66 of file TimeServerDatabaseMapper.cs.


The documentation for this class was generated from the following file: