Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » LogicalCircuit

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

Logical-Circuit Entity Framework class for Next Generation Network (NGN) entity model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.ComponentModel.DataAnnotations;
   6:  using System.ComponentModel.DataAnnotations.Schema;
   7:  using System.Xml.Linq;
   8:   
   9:  namespace Ia.Ngn.Cl.Model
  10:  {
  11:      ////////////////////////////////////////////////////////////////////////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Logical-Circuit Entity Framework class for Next Generation Network (NGN) entity model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2006-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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 LogicalCircuit
  31:      {
  32:          /// <summary/>
  33:          public LogicalCircuit() { }
  34:   
  35:          /// <summary/>
  36:          [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
  37:          public int Id { get; set; }
  38:   
  39:          /// <summary/>
  40:          public int GatewayIndex { get; set; } // GWY_INDEX
  41:   
  42:          /// <summary/>
  43:          public int TerminationIdIndex { get; set; } // TERMID_INDEX
  44:   
  45:          /// <summary/>
  46:          public string GatewayName { get; set; } // GWY_NAME
  47:   
  48:          /// <summary/>
  49:          public string TerminationString { get; set; } // TERM_STRING
  50:   
  51:          /// <summary/>
  52:          public int Lceid { get; set; } // LCEID
  53:   
  54:          /// <summary/>
  55:          public string LceidName { get; set; } // LCEID Name
  56:   
  57:          /// <summary/>
  58:          public int Tn { get; set; } // TN
  59:   
  60:          /// <summary/>
  61:          public DateTime Created { get; set; }
  62:   
  63:          /// <summary/>
  64:          public DateTime Updated { get; set; }
  65:   
  66:          /*
  67:          ////////////////////////////////////////////////////////////////////////////
  68:  
  69:          /// <summary>
  70:          ///
  71:          /// </summary>
  72:          public static int LogicalCircuitId(string lceid, int lan)
  73:          {
  74:              // below: logic below is based on LCEID data in service.xml
  75:              int id;
  76:  
  77:              id = global::Ia.Cl.Model.Default.HexToDec(lceid);
  78:              id = (id - 48000) / 16 * 100000;
  79:              id += lan;
  80:  
  81:              return id;
  82:          }
  83:  
  84:          ////////////////////////////////////////////////////////////////////////////
  85:  
  86:          /// <summary>
  87:          ///
  88:          /// </summary>
  89:          public static int LogicalCircuitId(int lceid, int lan)
  90:          {
  91:              // below: logic below is based on LCEID data in service.xml
  92:              int id;
  93:  
  94:              id = (lceid - 48000) / 16 * 100000;
  95:              id += lan;
  96:  
  97:              return id;
  98:          }
  99:  
 100:          ////////////////////////////////////////////////////////////////////////////
 101:  
 102:          /// <summary>
 103:          ///
 104:          /// </summary>
 105:          public static bool Create(LogicalCircuit newLogicalCircuit, out string result)
 106:          {
 107:              bool b;
 108:  
 109:              b = false;
 110:              result = "";
 111:  
 112:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 113:              {
 114:                  newLogicalCircuit.Created = newLogicalCircuit.Updated = DateTime.UtcNow.AddHours(3);
 115:  
 116:                  db.LogicalCircuits.Add(newLogicalCircuit);
 117:                  db.SaveChanges();
 118:  
 119:                  b = true;
 120:              }
 121:  
 122:              return b;
 123:          }
 124:  
 125:          ////////////////////////////////////////////////////////////////////////////
 126:  
 127:          /// <summary>
 128:          ///
 129:          /// </summary>
 130:          public static LogicalCircuit Read(int id)
 131:          {
 132:              LogicalCircuit logicalCircuit;
 133:  
 134:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 135:              {
 136:                  logicalCircuit = (from q in db.LogicalCircuits where q.Id == id select q).SingleOrDefault();
 137:              }
 138:  
 139:              return logicalCircuit;
 140:          }
 141:  
 142:          ////////////////////////////////////////////////////////////////////////////
 143:  
 144:          /// <summary>
 145:          /// Read all logical circuits
 146:          /// </summary>
 147:          public static List<LogicalCircuit> ReadList()
 148:          {
 149:              List<LogicalCircuit> logicalCircuitList;
 150:  
 151:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 152:              {
 153:                  logicalCircuitList = (from q in db.LogicalCircuits orderby q.Id select q).ToList();
 154:              }
 155:  
 156:              return logicalCircuitList;
 157:          }
 158:  
 159:          ////////////////////////////////////////////////////////////////////////////
 160:  
 161:          /// <summary>
 162:          /// Read all logical circuits for a certain LCEID
 163:          /// </summary>
 164:          public static List<LogicalCircuit> ReadList(string lceidName)
 165:          {
 166:              int logicalCircuitNumber;
 167:              List<LogicalCircuit> logicalCircuitList;
 168:  
 169:              // lceid = Ia.Ngn.Cl.Model.Data.Service.LceidInDecFromLceidName(lceidName);
 170:              logicalCircuitNumber = (from q in Ia.Ngn.Cl.Model.Data.Service.LceidList where q.Name == lceidName select q.LogicalCircuitNumber).SingleOrDefault();
 171:  
 172:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 173:              {
 174:                  logicalCircuitList = (from q in db.LogicalCircuits where q.Lceid == logicalCircuitNumber select q).ToList();
 175:              }
 176:  
 177:              return logicalCircuitList;
 178:          }
 179:  
 180:          ////////////////////////////////////////////////////////////////////////////
 181:  
 182:          /// <summary>
 183:          /// Read all logical circuits within lan range given the lceid number
 184:          /// </summary>
 185:          public static List<LogicalCircuit> ReadList(int lceid, int startTn, int endTn)
 186:          {
 187:              List<LogicalCircuit> logicalCircuitList;
 188:  
 189:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 190:              {
 191:                  logicalCircuitList = (from q in db.LogicalCircuits where q.Lceid == lceid && q.Tn >= startTn && q.Tn <= endTn select q).ToList();
 192:              }
 193:  
 194:              return logicalCircuitList;
 195:          }
 196:  
 197:          ////////////////////////////////////////////////////////////////////////////
 198:  
 199:          /// <summary>
 200:          ///
 201:          /// </summary>
 202:          public bool Update(LogicalCircuit updatedLogicalCircuit)
 203:          {
 204:              // below: this will not update Id, Created
 205:              bool updated;
 206:  
 207:              updated = false;
 208:  
 209:              if (this.GatewayIndex != updatedLogicalCircuit.GatewayIndex) { this.GatewayIndex = updatedLogicalCircuit.GatewayIndex; updated = true; }
 210:              if (this.GatewayName != updatedLogicalCircuit.GatewayName) { this.GatewayName = updatedLogicalCircuit.GatewayName; updated = true; }
 211:              if (this.Lceid != updatedLogicalCircuit.Lceid) { this.Lceid = updatedLogicalCircuit.Lceid; updated = true; }
 212:              if (this.LceidName != updatedLogicalCircuit.LceidName) { this.LceidName = updatedLogicalCircuit.LceidName; updated = true; }
 213:              if (this.TerminationIdIndex != updatedLogicalCircuit.TerminationIdIndex) { this.TerminationIdIndex = updatedLogicalCircuit.TerminationIdIndex; updated = true; }
 214:              if (this.TerminationString != updatedLogicalCircuit.TerminationString) { this.TerminationString = updatedLogicalCircuit.TerminationString; updated = true; }
 215:              if (this.Tn != updatedLogicalCircuit.Tn) { this.Tn = updatedLogicalCircuit.Tn; updated = true; }
 216:  
 217:              if (updated) this.Updated = /*this.Inspected =* / DateTime.UtcNow.AddHours(3);
 218:              //else this.Inspected = DateTime.UtcNow.AddHours(3);
 219:  
 220:              return updated;
 221:          }
 222:  
 223:          //////////////////////////////////////////////////////////////////////////////
 224:  
 225:          ///// <summary>
 226:          /////
 227:          ///// </summary>
 228:          //public static bool CreateOrUpdate(LogicalCircuit updatedLogicalCircuit, out string result)
 229:          //{
 230:          //    bool b;
 231:  
 232:          //    b = false;
 233:          //    result = "";
 234:  
 235:          //    using (var db = new Ia.Ngn.Cl.Model.Ngn())
 236:          //    {
 237:          //        if (Read(updatedLogicalCircuit.Id) != null) b = Update(updatedLogicalCircuit, out result);
 238:          //        else b = Create(updatedLogicalCircuit, out result);
 239:          //    }
 240:  
 241:          //    return b;
 242:          //}
 243:  
 244:          ////////////////////////////////////////////////////////////////////////////
 245:  
 246:          /// <summary>
 247:          ///
 248:          /// </summary>
 249:          public static bool Delete(int id, out string result)
 250:          {
 251:              bool b;
 252:  
 253:              b = false;
 254:              result = "";
 255:  
 256:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 257:              {
 258:                  var x = (from q in db.LogicalCircuits where q.Id == id select q).FirstOrDefault();
 259:  
 260:                  db.LogicalCircuits.Remove(x);
 261:                  db.SaveChanges();
 262:  
 263:                  b = true;
 264:              }
 265:  
 266:              return b;
 267:          }
 268:           */ 
 269:   
 270:          ////////////////////////////////////////////////////////////////////////////
 271:          ////////////////////////////////////////////////////////////////////////////
 272:      }
 273:   
 274:      ////////////////////////////////////////////////////////////////////////////
 275:      ////////////////////////////////////////////////////////////////////////////
 276:  }