1: using System;
2: using System.Collections.Generic;
3: using System.Data;
4: using System.IO;
5: using System.Linq;
6: using System.Reflection;
7: using System.Xml.Linq;
8:
9: namespace Ia.Ngn.Cl.Model.Data
10: {
11: ////////////////////////////////////////////////////////////////////////////
12:
13: /// <summary publish="true">
14: /// Transaction support class for Optical Fiber Network (OFN) data model.
15: /// </summary>
16: ///
17: /// <remarks>
18: /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
19: ///
20: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
21: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
22: ///
23: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
25: ///
26: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
27: ///
28: /// Copyright notice: This notice may not be removed or altered from any source distribution.
29: /// </remarks>
30: public class Transaction
31: {
32: private static XDocument xDocument;
33: private static List<System> systemList;
34: private static List<Process> processList;
35: private static List<Function> functionList;
36:
37: private static readonly object objectLock = new object();
38:
39: ////////////////////////////////////////////////////////////////////////////
40:
41: /// <summary>
42: ///
43: /// </summary>
44: public struct Direction
45: {
46: public int Id { get; set; }
47: public string Name { get; set; }
48: public string ArabicName { get; set; }
49: }
50:
51: ////////////////////////////////////////////////////////////////////////////
52:
53: /// <summary>
54: ///
55: /// </summary>
56: public class System
57: {
58: public int Id { get; set; }
59: public string Name { get; set; }
60: public virtual ICollection<Process> Processes
61: {
62: get
63: {
64: return (from p in ProcessList where p.System.Id == this.Id select p).ToList();
65: }
66: }
67: }
68:
69: ////////////////////////////////////////////////////////////////////////////
70:
71: /// <summary>
72: ///
73: /// </summary>
74: public class Process
75: {
76: public int Id { get; set; }
77: public string Name { get; set; }
78: public virtual System System { get; set; }
79: public virtual ICollection<Function> Functions
80: {
81: get
82: {
83: return (from f in FunctionList where f.Process.Id == this.Id select f).ToList();
84: }
85: }
86:
87: public static int ProcessId(int systemId, int id)
88: {
89: return systemId * 100 + id;
90: }
91: }
92:
93: ////////////////////////////////////////////////////////////////////////////
94:
95: /// <summary>
96: ///
97: /// </summary>
98: public class Function
99: {
100: public int Id { get; set; }
101: public string Name { get; set; }
102: public string Parameter { get; set; }
103: public virtual Process Process { get; set; }
104:
105: public static int FunctionId(int processId, int id)
106: {
107: return processId * 100 + id;
108: }
109: }
110:
111: ////////////////////////////////////////////////////////////////////////////
112:
113: /// <summary>
114: ///
115: /// </summary>
116: public Transaction() { }
117:
118: //////////////////////////////////////////////////////////////////////////////
119:
120: ///// <summary>
121: /////
122: ///// </summary>
123: public static List<System> SystemList
124: {
125: get
126: {
127: if (systemList == null || systemList.Count == 0)
128: {
129: lock (objectLock)
130: {
131: systemList = Ia.Ngn.Cl.Model.Data.Transaction._SystemList;
132: }
133: }
134:
135: return systemList;
136: }
137: }
138:
139: //////////////////////////////////////////////////////////////////////////////
140:
141: ///// <summary>
142: /////
143: ///// </summary>
144: private static List<System> _SystemList
145: {
146: get
147: {
148: System system;
149:
150: systemList = new List<System>();
151:
152: foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system"))
153: {
154: system = new System();
155:
156: system.Id = int.Parse(xe.Attribute("id").Value);
157: system.Name = xe.Attribute("name").Value;
158:
159: systemList.Add(system);
160: }
161:
162: return systemList;
163: }
164: }
165:
166: //////////////////////////////////////////////////////////////////////////////
167:
168: ///// <summary>
169: /////
170: ///// </summary>
171: public static List<Process> ProcessList
172: {
173: get
174: {
175: if (processList == null || processList.Count == 0)
176: {
177: lock (objectLock)
178: {
179: processList = Ia.Ngn.Cl.Model.Data.Transaction._ProcessList;
180: }
181: }
182:
183: return processList;
184: }
185: }
186:
187: //////////////////////////////////////////////////////////////////////////////
188:
189: ///// <summary>
190: /////
191: ///// </summary>
192: private static List<Process> _ProcessList
193: {
194: get
195: {
196: int systemId, id;
197: Process process;
198:
199: processList = new List<Process>();
200:
201: foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system").Elements("processList").Elements("process"))
202: {
203: process = new Process();
204:
205: systemId = int.Parse(xe.Parent.Parent.Attribute("id").Value);
206: id = int.Parse(xe.Attribute("id").Value);
207:
208: process.System = (from s in SystemList where s.Id == systemId select s).Single();
209: process.Id = Process.ProcessId(systemId, id);
210: process.Name = xe.Attribute("name").Value;
211:
212: processList.Add(process);
213: }
214:
215: return processList;
216: }
217: }
218:
219: //////////////////////////////////////////////////////////////////////////////
220:
221: ///// <summary>
222: /////
223: ///// </summary>
224: public static List<Function> FunctionList
225: {
226: get
227: {
228: if (functionList == null || functionList.Count == 0)
229: {
230: lock (objectLock)
231: {
232: functionList = Ia.Ngn.Cl.Model.Data.Transaction._FunctionList;
233: }
234: }
235:
236: return functionList;
237: }
238: }
239:
240: //////////////////////////////////////////////////////////////////////////////
241:
242: ///// <summary>
243: /////
244: ///// </summary>
245: private static List<Function> _FunctionList
246: {
247: get
248: {
249: int systemId, processId, id;
250: Function function;
251:
252: functionList = new List<Function>();
253:
254: foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system").Elements("processList").Elements("process").Elements("functionList").Elements("function"))
255: {
256: function = new Function();
257:
258: systemId = int.Parse(xe.Parent.Parent.Parent.Parent.Attribute("id").Value);
259: id = int.Parse(xe.Parent.Parent.Attribute("id").Value);
260: processId = Process.ProcessId(systemId, id);
261: id = int.Parse(xe.Attribute("id").Value);
262:
263: function.Process = (from p in ProcessList where p.Id == processId select p).Single();
264: function.Id = Function.FunctionId(processId, id);
265: function.Name = xe.Attribute("name").Value;
266:
267: functionList.Add(function);
268: }
269:
270: return functionList;
271: }
272: }
273:
274: ////////////////////////////////////////////////////////////////////////////
275:
276: /// <summary>
277: ///
278: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
279: ///
280: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
281: /// 2. Add "using System.Reflection".
282: /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
283: ///
284: /// </summary>
285:
286: private static XDocument XDocument
287: {
288: get
289: {
290: if (xDocument == null)
291: {
292: lock (objectLock)
293: {
294: Assembly _assembly;
295: StreamReader streamReader;
296:
297: _assembly = Assembly.GetExecutingAssembly();
298: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.transaction.xml"));
299:
300: try
301: {
302: if (streamReader.Peek() != -1)
303: {
304: xDocument = global::System.Xml.Linq.XDocument.Load(streamReader);
305: }
306: }
307: catch (Exception)
308: {
309: }
310: finally
311: {
312: }
313: }
314: }
315:
316: return xDocument;
317: }
318: }
319:
320: ////////////////////////////////////////////////////////////////////////////
321: ////////////////////////////////////////////////////////////////////////////
322: }
323:
324: /*
325: /// <summary/>
326: public enum State
327: {
328: Initiated = 1, NoConnection = 2, NotSent = 3, Sent = 4, Closed = 5, Unspecified = 6
329: }
330:
331: /// <summary/>
332: public enum Priority
333: {
334: Urgent = 1, Important = 2, Regular = 3, Unspecified = 4
335: }
336:
337: /// <summary/>
338: public enum Recipient
339: {
340: AluMgc = 1, AluAms = 2, AluIms = 3 //Ftp, Hsi, HuIms, Si???, Tnmd, etc
341: }
342: */
343:
344: ////////////////////////////////////////////////////////////////////////////
345: ////////////////////////////////////////////////////////////////////////////
346: }