شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Transaction

Public general use code classes and xml files that we've compiled and used over the years:

Transaction support class for Next Generation Network (NGN) data model.

   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 Next Generation Network (NGN) 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 partial 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:                  lock (objectLock)
 128:                  {
 129:                      if (systemList == null || systemList.Count == 0) systemList = Ia.Ngn.Cl.Model.Data.Transaction._SystemList;
 130:   
 131:                      return systemList;
 132:                  }
 133:              }
 134:          }
 135:   
 136:          //////////////////////////////////////////////////////////////////////////////
 137:   
 138:          ///// <summary>
 139:          /////
 140:          ///// </summary>
 141:          private static List<System> _SystemList
 142:          {
 143:              get
 144:              {
 145:                  System system;
 146:   
 147:                  systemList = new List<System>();
 148:   
 149:                  foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system"))
 150:                  {
 151:                      system = new System();
 152:   
 153:                      system.Id = int.Parse(xe.Attribute("id").Value);
 154:                      system.Name = xe.Attribute("name").Value;
 155:   
 156:                      systemList.Add(system);
 157:                  }
 158:   
 159:                  return systemList;
 160:              }
 161:          }
 162:   
 163:          //////////////////////////////////////////////////////////////////////////////
 164:   
 165:          ///// <summary>
 166:          /////
 167:          ///// </summary>
 168:          public static List<Process> ProcessList
 169:          {
 170:              get
 171:              {
 172:                  lock (objectLock)
 173:                  {
 174:                      if (processList == null || processList.Count == 0) processList = Ia.Ngn.Cl.Model.Data.Transaction._ProcessList;
 175:   
 176:                      return processList;
 177:                  }
 178:              }
 179:          }
 180:   
 181:          //////////////////////////////////////////////////////////////////////////////
 182:   
 183:          ///// <summary>
 184:          /////
 185:          ///// </summary>
 186:          private static List<Process> _ProcessList
 187:          {
 188:              get
 189:              {
 190:                  int systemId, id;
 191:                  Process process;
 192:   
 193:                  processList = new List<Process>();
 194:   
 195:                  foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system").Elements("processList").Elements("process"))
 196:                  {
 197:                      process = new Process();
 198:   
 199:                      systemId = int.Parse(xe.Parent.Parent.Attribute("id").Value);
 200:                      id = int.Parse(xe.Attribute("id").Value);
 201:   
 202:                      process.System = (from s in SystemList where s.Id == systemId select s).Single();
 203:                      process.Id = Process.ProcessId(systemId, id);
 204:                      process.Name = xe.Attribute("name").Value;
 205:   
 206:                      processList.Add(process);
 207:                  }
 208:   
 209:                  return processList;
 210:              }
 211:          }
 212:   
 213:          //////////////////////////////////////////////////////////////////////////////
 214:   
 215:          ///// <summary>
 216:          /////
 217:          ///// </summary>
 218:          public static List<Function> FunctionList
 219:          {
 220:              get
 221:              {
 222:                  lock (objectLock)
 223:                  {
 224:                      if (functionList == null || functionList.Count == 0) functionList = Ia.Ngn.Cl.Model.Data.Transaction._FunctionList;
 225:   
 226:                      return functionList;
 227:                  }
 228:              }
 229:          }
 230:   
 231:          //////////////////////////////////////////////////////////////////////////////
 232:   
 233:          ///// <summary>
 234:          /////
 235:          ///// </summary>
 236:          private static List<Function> _FunctionList
 237:          {
 238:              get
 239:              {
 240:                  int systemId, processId, id;
 241:                  Function function;
 242:   
 243:                  functionList = new List<Function>();
 244:   
 245:                  foreach (XElement xe in XDocument.Element("transaction").Elements("systemList").Elements("system").Elements("processList").Elements("process").Elements("functionList").Elements("function"))
 246:                  {
 247:                      function = new Function();
 248:   
 249:                      systemId = int.Parse(xe.Parent.Parent.Parent.Parent.Attribute("id").Value);
 250:                      id = int.Parse(xe.Parent.Parent.Attribute("id").Value);
 251:                      processId = Process.ProcessId(systemId, id);
 252:                      id = int.Parse(xe.Attribute("id").Value);
 253:   
 254:                      function.Process = (from p in ProcessList where p.Id == processId select p).Single();
 255:                      function.Id = Function.FunctionId(processId, id);
 256:                      function.Name = xe.Attribute("name").Value;
 257:   
 258:                      functionList.Add(function);
 259:                  }
 260:   
 261:                  return functionList;
 262:              }
 263:          }
 264:   
 265:          ////////////////////////////////////////////////////////////////////////////
 266:   
 267:          /// <summary>
 268:          /// 
 269:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 270:          /// 
 271:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 272:          /// 2. Add "using System.Reflection".
 273:          /// 3. See sample below.
 274:          /// 
 275:          /// </summary>
 276:   
 277:          private static XDocument XDocument
 278:          {
 279:              get
 280:              {
 281:                  if (xDocument == null)
 282:                  {
 283:                      Assembly _assembly;
 284:                      StreamReader streamReader;
 285:   
 286:                      _assembly = Assembly.GetExecutingAssembly();
 287:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.transaction.xml"));
 288:   
 289:                      try
 290:                      {
 291:                          if (streamReader.Peek() != -1)
 292:                          {
 293:                              xDocument = global::System.Xml.Linq.XDocument.Load(streamReader);
 294:                          }
 295:                      }
 296:                      catch (Exception)
 297:                      {
 298:                      }
 299:                      finally
 300:                      {
 301:                      }
 302:                  }
 303:   
 304:                  return xDocument;
 305:              }
 306:          }
 307:   
 308:          ////////////////////////////////////////////////////////////////////////////
 309:          ////////////////////////////////////////////////////////////////////////////    
 310:      }
 311:   
 312:      /*
 313:      /// <summary/>
 314:      public enum State
 315:      {
 316:          Initiated = 1, NoConnection = 2, NotSent = 3, Sent = 4, Closed = 5, Unspecified = 6
 317:      }
 318:  
 319:      /// <summary/>
 320:      public enum Priority
 321:      {
 322:          Urgent = 1, Important = 2, Regular = 3, Unspecified = 4
 323:      }
 324:  
 325:      /// <summary/>
 326:      public enum Recipient
 327:      {
 328:          AluMgc = 1, AluAms = 2, AluIms = 3 //Ftp, Hsi, HuIms, Si???, Tnmd, etc
 329:      }
 330:       */
 331:   
 332:      ////////////////////////////////////////////////////////////////////////////
 333:      ////////////////////////////////////////////////////////////////////////////   
 334:  }