1: using System;
2: using System.Collections.Generic;
3: using System.IO;
4: using System.Reflection;
5: using System.Xml.Linq;
6:
7: namespace Ia.Ngn.Cl.Model.Data
8: {
9: ////////////////////////////////////////////////////////////////////////////
10:
11: /// <summary publish="true">
12: /// POTS legacy support class for Next Generation Network (NGN) data model.
13: /// </summary>
14: ///
15: /// <remarks>
16: /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
17: ///
18: /// 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
19: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
20: ///
21: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23: ///
24: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
25: ///
26: /// Copyright notice: This notice may not be removed or altered from any source distribution.
27: /// </remarks>
28: public partial class Pots
29: {
30: private static XDocument xDocument;
31: private static List<Category> categoryList;
32:
33: private static readonly object objectLock = new object();
34:
35: ////////////////////////////////////////////////////////////////////////////
36:
37: /// <summary>
38: ///
39: /// </summary>
40: public Pots() { }
41:
42: ////////////////////////////////////////////////////////////////////////////
43: ////////////////////////////////////////////////////////////////////////////
44:
45: public class Category
46: {
47: public Category() { }
48:
49: public int Id { get; set; }
50: public string Name { get; set; }
51: public string ArabicName { get; set; }
52: /*
53: public virtual ICollection<Area> Areas
54: {
55: get
56: {
57: return (from q in AreaList where q.Category.Id == this.Id select q).ToList();
58: }
59: }
60: */
61: }
62:
63: ////////////////////////////////////////////////////////////////////////////
64:
65: /// <summary>
66: ///
67: /// </summary>
68: public static List<Ia.Ngn.Cl.Model.Data.Pots.Category> CategoryList
69: {
70: get
71: {
72: lock (objectLock)
73: {
74: if (categoryList == null || categoryList.Count == 0) categoryList = Ia.Ngn.Cl.Model.Data.Pots._CategoryList;
75:
76: return categoryList;
77: }
78: }
79: }
80:
81: ////////////////////////////////////////////////////////////////////////////
82:
83: /// <summary>
84: ///
85: /// </summary>
86: private static List<Ia.Ngn.Cl.Model.Data.Pots.Category> _CategoryList
87: {
88: get
89: {
90: int id;
91: Category category;
92:
93: categoryList = new List<Category>();
94:
95: foreach (XElement x in XDocument.Element("report").Elements("category"))
96: {
97: category = new Category();
98:
99: id = int.Parse(x.Attribute("id").Value);
100:
101: category.Id = id;
102: category.Name = x.Attribute("name").Value;
103: category.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
104:
105: categoryList.Add(category);
106: }
107:
108: return categoryList;
109: }
110: }
111:
112: ////////////////////////////////////////////////////////////////////////////
113: ////////////////////////////////////////////////////////////////////////////
114:
115: /// <summary>
116: ///
117: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
118: ///
119: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
120: /// 2. Add "using System.Reflection".
121: /// 3. See sample below.
122: ///
123: /// </summary>
124:
125: public static XDocument XDocument
126: {
127: get
128: {
129: Assembly _assembly;
130: StreamReader streamReader;
131:
132: if (xDocument == null)
133: {
134: _assembly = Assembly.GetExecutingAssembly();
135: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.pots.xml"));
136:
137: try
138: {
139: if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
140: }
141: catch (Exception)
142: {
143: }
144: finally
145: {
146: }
147: }
148:
149: return xDocument;
150: }
151: }
152:
153: ////////////////////////////////////////////////////////////////////////////
154: ////////////////////////////////////////////////////////////////////////////
155: }
156:
157: ////////////////////////////////////////////////////////////////////////////
158: ////////////////////////////////////////////////////////////////////////////
159: }