PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/Source/Libraries/TimeSeriesFramework/UI/DataModels/SignalType.cs

#
C# | 322 lines | 205 code | 39 blank | 78 comment | 32 complexity | e6b4ce822cd13c3239cdcd344f084411 MD5 | raw file
Possible License(s): EPL-1.0
  1. //******************************************************************************************************
  2. // SignalType.cs - Gbtc
  3. //
  4. // Copyright © 2010, Grid Protection Alliance. All Rights Reserved.
  5. //
  6. // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
  7. // the NOTICE file distributed with this work for additional information regarding copyright ownership.
  8. // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
  9. // not use this file except in compliance with the License. You may obtain a copy of the License at:
  10. //
  11. // http://www.opensource.org/licenses/eclipse-1.0.php
  12. //
  13. // Unless agreed to in writing, the subject software distributed under the License is distributed on an
  14. // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
  15. // License for the specific language governing permissions and limitations.
  16. //
  17. // Code Modification History:
  18. // ----------------------------------------------------------------------------------------------------
  19. // 05/06/2011 - Mehulbhai P Thakkar
  20. // Generated original version of source code.
  21. // 05/13/2011 - Mehulbhai P Thakkar
  22. // Added regular expression validator for Acronym.
  23. // 09/15/2011 - Mehulbhai P Thakkar
  24. // Hard coded signal types for PMU, Voltage Phasor and Current Phasor.
  25. //
  26. //******************************************************************************************************
  27. using System.Collections.Generic;
  28. using System.Collections.ObjectModel;
  29. using System.ComponentModel.DataAnnotations;
  30. using System.Data;
  31. using TVA;
  32. using TVA.Data;
  33. namespace TimeSeriesFramework.UI.DataModels
  34. {
  35. /// <summary>
  36. /// Represents a record of <see cref="SignalType"/> information as defined in the database.
  37. /// </summary>
  38. public class SignalType : DataModelBase
  39. {
  40. #region [ Members ]
  41. // Fields
  42. private int m_id;
  43. private string m_name;
  44. private string m_acronym;
  45. private string m_suffix;
  46. private string m_abbreviation;
  47. private string m_source;
  48. private string m_engineeringUnits;
  49. #endregion
  50. #region [ Properties ]
  51. /// <summary>
  52. /// Gets or sets <see cref="SignalType"/> ID.
  53. /// </summary>
  54. // Field is populated by database via auto-increment and has no screen interaction, so no validation attributes are applied
  55. public int ID
  56. {
  57. get
  58. {
  59. return m_id;
  60. }
  61. set
  62. {
  63. m_id = value;
  64. }
  65. }
  66. /// <summary>
  67. /// Gets or sets <see cref="SignalType"/> Acronym.
  68. /// </summary>
  69. [Required(ErrorMessage = "SignalType acronym is a required field, please provide value.")]
  70. [StringLength(4, ErrorMessage = "SignalType Acronym cannot exceed 4 characters.")]
  71. [RegularExpression("^[A-Z0-9-'!'_'@#\\$]+$", ErrorMessage = "Only upper case letters, numbers, '!', '-', '@', '#', '_' and '$' are allowed.")]
  72. public string Acronym
  73. {
  74. get
  75. {
  76. return m_acronym;
  77. }
  78. set
  79. {
  80. m_acronym = value;
  81. OnPropertyChanged("Acronym");
  82. }
  83. }
  84. /// <summary>
  85. /// Gets or sets <see cref="SignalType"/> Name.
  86. /// </summary>
  87. [Required(ErrorMessage = "SignalType name is a required field, please provide value.")]
  88. [StringLength(200, ErrorMessage = "SignalType Name cannot exceed 200 characters.")]
  89. public string Name
  90. {
  91. get
  92. {
  93. return m_name;
  94. }
  95. set
  96. {
  97. m_name = value;
  98. OnPropertyChanged("Name");
  99. }
  100. }
  101. /// <summary>
  102. /// Gets or sets <see cref="SignalType"/> Suffix.
  103. /// </summary>
  104. [Required(ErrorMessage = "SignalType suffix is required field, please provide value.")]
  105. [StringLength(2, ErrorMessage = "SignalType Suffix cannot exceed 2 characters.")]
  106. public string Suffix
  107. {
  108. get
  109. {
  110. return m_suffix;
  111. }
  112. set
  113. {
  114. m_suffix = value;
  115. OnPropertyChanged("Suffix");
  116. }
  117. }
  118. /// <summary>
  119. /// Gets or sets <see cref="SignalType"/> Abbreviation.
  120. /// </summary>
  121. [Required(ErrorMessage = "SignalType Abbreviation is required field, please provide value.")]
  122. [StringLength(2, ErrorMessage = "SignalType abbreviation cannot exceed 2 characeters.")]
  123. public string Abbreviation
  124. {
  125. get
  126. {
  127. return m_abbreviation;
  128. }
  129. set
  130. {
  131. m_abbreviation = value;
  132. OnPropertyChanged("Abbreviation");
  133. }
  134. }
  135. /// <summary>
  136. /// Gets or sets <see cref="SignalType"/> Source.
  137. /// </summary>
  138. [Required(ErrorMessage = "SignalType Source is required field, please provide value.")]
  139. [StringLength(10, ErrorMessage = "SignalType source cannot exceed 10 characters.")]
  140. public string Source
  141. {
  142. get
  143. {
  144. return m_source;
  145. }
  146. set
  147. {
  148. m_source = value;
  149. OnPropertyChanged("Source");
  150. }
  151. }
  152. /// <summary>
  153. /// Gets or sets <see cref="SignalType"/> EngineeringUnits.
  154. /// </summary>
  155. [StringLength(10, ErrorMessage = "SignalType engineering units cannot exceed 10 characters.")]
  156. public string EngineeringUnits
  157. {
  158. get
  159. {
  160. return m_engineeringUnits;
  161. }
  162. set
  163. {
  164. m_engineeringUnits = value;
  165. OnPropertyChanged("EngineeringUnits");
  166. }
  167. }
  168. #endregion
  169. #region [ Static ]
  170. // Static Methods
  171. /// <summary>
  172. /// Loads <see cref="SignalType"/> information as an <see cref="ObservableCollection{T}"/> style list.
  173. /// </summary>
  174. /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
  175. /// <param name="source">Type if source to filter data.</param>
  176. /// <param name="phasorType">Type of phasor type to filter data.</param>
  177. /// <returns>Collection of <see cref="SignalType"/>.</returns>
  178. public static ObservableCollection<SignalType> Load(AdoDataConnection database, string source = "", string phasorType = "")
  179. {
  180. bool createdConnection = false;
  181. try
  182. {
  183. createdConnection = CreateConnection(ref database);
  184. ObservableCollection<SignalType> signalTypeList = new ObservableCollection<SignalType>();
  185. string query = "SELECT ID, Acronym, Name, Suffix, Abbreviation, Source, EngineeringUnits FROM SignalType ORDER BY Name";
  186. if (!string.IsNullOrEmpty(source) && source.ToUpper() == "PMU")
  187. {
  188. query = "SELECT ID, Acronym, Name, Suffix, Abbreviation, Source, EngineeringUnits FROM SignalType Where Source = 'PMU' AND SUFFIX IN ('FQ','DF','SF','AV','DV','CV') ORDER BY Name";
  189. }
  190. else if (!string.IsNullOrEmpty(source) && source.ToUpper() == "PHASOR" && !string.IsNullOrEmpty(phasorType))
  191. {
  192. if (phasorType.ToUpper() == "V")
  193. query = "SELECT ID, Acronym, Name, Suffix, Abbreviation, Source, EngineeringUnits FROM SignalType Where Source = 'Phasor' " +
  194. "AND Acronym IN ('VPHM', 'VPHA') ORDER BY Name";
  195. else if (phasorType.ToUpper() == "I")
  196. query = "SELECT ID, Acronym, Name, Suffix, Abbreviation, Source, EngineeringUnits FROM SignalType Where Source = 'Phasor' " +
  197. "AND Acronym IN ('IPHM', 'IPHA') ORDER BY Name";
  198. }
  199. DataTable signalTypeTable = database.Connection.RetrieveData(database.AdapterType, query);
  200. foreach (DataRow row in signalTypeTable.Rows)
  201. {
  202. signalTypeList.Add(new SignalType()
  203. {
  204. ID = row.ConvertField<int>("ID"),
  205. Acronym = row.Field<string>("Acronym"),
  206. Name = row.Field<string>("Name"),
  207. Suffix = row.Field<string>("Suffix"),
  208. Abbreviation = row.Field<string>("Abbreviation"),
  209. Source = row.Field<string>("Source"),
  210. EngineeringUnits = row["EngineeringUnits"].ToNonNullString()
  211. });
  212. }
  213. return signalTypeList;
  214. }
  215. finally
  216. {
  217. if (createdConnection && database != null)
  218. database.Dispose();
  219. }
  220. }
  221. /// <summary>
  222. /// Gets a <see cref="Dictionary{T1,T2}"/> style list of <see cref="SignalType"/> information.
  223. /// </summary>
  224. /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
  225. /// <param name="isOptional">Indicates if selection on UI is optional for this collection.</param>
  226. public static Dictionary<int, string> GetLookupList(AdoDataConnection database, bool isOptional = false)
  227. {
  228. bool createdConnection = false;
  229. try
  230. {
  231. createdConnection = CreateConnection(ref database);
  232. Dictionary<int, string> signalTypeList = new Dictionary<int, string>();
  233. DataTable signalTypeTable;
  234. if (isOptional)
  235. signalTypeList.Add(0, "Select SignalType");
  236. signalTypeTable = database.Connection.RetrieveData(database.AdapterType, "SELECT ID, Name FROM SignalType ORDER BY Name");
  237. foreach (DataRow row in signalTypeTable.Rows)
  238. signalTypeList[row.ConvertField<int>("ID")] = row.Field<string>("Name");
  239. return signalTypeList;
  240. }
  241. finally
  242. {
  243. if (createdConnection && database != null)
  244. database.Dispose();
  245. }
  246. }
  247. /// <summary>
  248. /// Method to return signal types for PMU device.
  249. /// </summary>
  250. /// <returns>Returns <see cref="ObservableCollection{T}"/> type collection of signal types.</returns>
  251. public static ObservableCollection<SignalType> GetPmuSignalTypes()
  252. {
  253. if (s_pmuSignalTypes == null || s_pmuSignalTypes.Count == 0)
  254. s_pmuSignalTypes = Load(null, "PMU");
  255. return s_pmuSignalTypes;
  256. }
  257. /// <summary>
  258. /// Method to return signal types for voltage phasor.
  259. /// </summary>
  260. /// <returns>Returns <see cref="ObservableCollection{T}"/> type collection of signal types.</returns>
  261. public static ObservableCollection<SignalType> GetVoltagePhasorSignalTypes()
  262. {
  263. if (s_voltagePhasorSignalTypes == null || s_voltagePhasorSignalTypes.Count == 0)
  264. s_voltagePhasorSignalTypes = Load(null, "Phasor", "V");
  265. return s_voltagePhasorSignalTypes;
  266. }
  267. /// <summary>
  268. /// Method to return signal types for current phasor.
  269. /// </summary>
  270. /// <returns>Returns <see cref="ObservableCollection{T}"/> type collection of signal types.</returns>
  271. public static ObservableCollection<SignalType> GetCurrentPhasorSignalTypes()
  272. {
  273. if (s_currentPhasorSignalTypes == null || s_currentPhasorSignalTypes.Count == 0)
  274. s_currentPhasorSignalTypes = Load(null, "Phasor", "I");
  275. return s_currentPhasorSignalTypes;
  276. }
  277. // Static Fields
  278. private static ObservableCollection<SignalType> s_pmuSignalTypes;
  279. private static ObservableCollection<SignalType> s_voltagePhasorSignalTypes;
  280. private static ObservableCollection<SignalType> s_currentPhasorSignalTypes;
  281. #endregion
  282. }
  283. }