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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Event

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

Nokia AMS Event support class for Optical Fiber Network (OFN) data model.

   1:  using Microsoft.EntityFrameworkCore;
   2:  using System;
   3:  using System.Collections.Generic;
   4:  using System.Data;
   5:  using System.IO;
   6:  using System.Linq;
   7:  using System.Reflection;
   8:  using System.Text;
   9:  using System.Web;
  10:  using System.Xml.Linq;
  11:   
  12:  namespace Ia.Ngn.Cl.Model.Data
  13:  {
  14:      ////////////////////////////////////////////////////////////////////////////
  15:   
  16:      /// <summary publish="true">
  17:      /// Nokia AMS Event support class for Optical Fiber Network (OFN) data model.
  18:      /// </summary>
  19:      /// 
  20:      /// <remarks> 
  21:      /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  22:      ///
  23:      /// 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
  24:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  25:      ///
  26:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  27:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  28:      /// 
  29:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  30:      /// 
  31:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  32:      /// </remarks> 
  33:      public class Event
  34:      {
  35:          private static long startEventId;
  36:          private static XDocument xDocument;
  37:          private static readonly object objectLock = new object();
  38:   
  39:          ////////////////////////////////////////////////////////////////////////////
  40:   
  41:          /// <summary>
  42:          ///
  43:          /// </summary>
  44:          public enum Priority
  45:          {
  46:              Urgent = 1, Important, Regular, Unspecified
  47:          }
  48:   
  49:          ////////////////////////////////////////////////////////////////////////////
  50:   
  51:          /// <summary>
  52:          ///
  53:          /// </summary>
  54:          public struct Severity
  55:          {
  56:              /// <summary/>
  57:              public Severity(string id, string name)
  58:              {
  59:                  this.Id = id;
  60:                  this.Name = name;
  61:              }
  62:   
  63:              /// <summary/>
  64:              public string Id { get; set; }
  65:   
  66:              /// <summary/>
  67:              public string Name { get; set; }
  68:          }
  69:   
  70:          ////////////////////////////////////////////////////////////////////////////
  71:   
  72:          /// <summary>
  73:          ///
  74:          /// </summary>
  75:          public struct ServiceEffect
  76:          {
  77:              /// <summary/>
  78:              public ServiceEffect(string id, string name)
  79:              {
  80:                  this.Id = id;
  81:                  this.Name = name;
  82:              }
  83:   
  84:              /// <summary/>
  85:              public string Id { get; set; }
  86:   
  87:              /// <summary/>
  88:              public string Name { get; set; }
  89:          }
  90:   
  91:          ////////////////////////////////////////////////////////////////////////////
  92:   
  93:          /// <summary>
  94:          ///
  95:          /// </summary>
  96:          public struct Alarm
  97:          {
  98:              /// <summary/>
  99:              public string Id { get; set; }
 100:   
 101:              /// <summary/>
 102:              public string Name { get; set; }
 103:   
 104:              /// <summary/>
 105:              public Severity Severity { get; set; }
 106:   
 107:              /// <summary/>
 108:              public ServiceEffect ServiceEffect { get; set; }
 109:   
 110:              /// <summary/>
 111:              public bool SaveMessage { get; set; }
 112:   
 113:              /// <summary/>
 114:              public string Condition { get; set; }
 115:   
 116:              /// <summary/>
 117:              public string Resolution { get; set; }
 118:          }
 119:   
 120:          ////////////////////////////////////////////////////////////////////////////
 121:   
 122:          /// <summary>
 123:          ///
 124:          /// </summary>
 125:          public Event() { }
 126:   
 127:          ////////////////////////////////////////////////////////////////////////////
 128:   
 129:          /// <summary>
 130:          /// This defines a starting point of event id for searching
 131:          /// </summary>
 132:          public static long StartEventId
 133:          {
 134:              get
 135:              {
 136:                  lock (objectLock)
 137:                  {
 138:                      if (startEventId == 0) startEventId = Ia.Ngn.Cl.Model.Data.Event._StartEventId;
 139:   
 140:                      return startEventId;
 141:                  }
 142:              }
 143:          }
 144:   
 145:          ////////////////////////////////////////////////////////////////////////////
 146:   
 147:          /// <summary>
 148:          /// This defines a starting point of event id for searching
 149:          /// </summary>
 150:          private static long _StartEventId
 151:          {
 152:              get
 153:              {
 154:                  if (HttpContext.Current != null && HttpContext.Current.Application["eventStartEventId"] != null)
 155:                  {
 156:                      startEventId = long.Parse(HttpContext.Current.Application["eventStartEventId"].ToString());
 157:                  }
 158:                  else
 159:                  {
 160:                      lock (objectLock)
 161:                      {
 162:                          startEventId = StartIdFromEventTime(DateTime.UtcNow.AddHours(3).AddDays(-30));
 163:   
 164:                          if (HttpContext.Current != null) HttpContext.Current.Application["eventStartEventId"] = startEventId.ToString();
 165:                      }
 166:                  }
 167:   
 168:                  return startEventId;
 169:              }
 170:          }
 171:   
 172:          ////////////////////////////////////////////////////////////////////////////
 173:   
 174:          /// <summary>
 175:          ///
 176:          /// </summary>
 177:          private static long StartIdFromEventTime(DateTime startEventTime)
 178:          {
 179:              long id;
 180:   
 181:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 182:              {
 183:                  id = (from e in db.Events
 184:                        where e.EventTime >= startEventTime
 185:                        select e.Id).Min();
 186:              }
 187:   
 188:              return id;
 189:          }
 190:   
 191:          ////////////////////////////////////////////////////////////////////////////
 192:   
 193:          /// <summary>
 194:          ///
 195:          /// </summary>
 196:          public static List<Ia.Ngn.Cl.Model.Event> ReadList()
 197:          {
 198:              List<Ia.Ngn.Cl.Model.Event> list;
 199:   
 200:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 201:              {
 202:                  list = (from e in db.Events select e).AsNoTracking().ToList();
 203:              }
 204:   
 205:              return list;
 206:          }
 207:   
 208:          ////////////////////////////////////////////////////////////////////////////
 209:   
 210:          /// <summary>
 211:          ///
 212:          /// </summary>
 213:          public static List<Ia.Ngn.Cl.Model.Event> ReadTakeNOrderByIdDescendingListFromNddOntId(string nddOntId, string classId, string severityId, string serviceEffectId, string causeId, int elementsToTake)
 214:          {
 215:              List<Ia.Ngn.Cl.Model.Event> list;
 216:   
 217:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 218:              {
 219:                  if (!string.IsNullOrEmpty(nddOntId))
 220:                  {
 221:                      list = (from e in db.Events
 222:                              where e.Ont != null && nddOntId == e.Ont.Id
 223:                              && (classId == string.Empty || e.Class == classId)
 224:                              && (severityId == string.Empty || e.Severity == severityId)
 225:                              && (serviceEffectId == string.Empty || e.SeverityEffect == serviceEffectId)
 226:                              && (causeId == string.Empty || e.Cause == causeId)
 227:                              orderby e.Id descending
 228:                              select e).Include(u => u.Ont).AsNoTracking().Take(elementsToTake).ToList();
 229:                  }
 230:                  else
 231:                  {
 232:                      list = (from e in db.Events
 233:                              where (classId == string.Empty || e.Class == classId)
 234:                              && (severityId == string.Empty || e.Severity == severityId)
 235:                              && (serviceEffectId == string.Empty || e.SeverityEffect == serviceEffectId)
 236:                              && (causeId == string.Empty || e.Cause == causeId)
 237:                              orderby e.Id descending
 238:                              select e).Include(u => u.Ont).AsNoTracking().Take(elementsToTake).ToList();
 239:                  }
 240:              }
 241:   
 242:              return list;
 243:          }
 244:   
 245:          ////////////////////////////////////////////////////////////////////////////
 246:   
 247:          /// <summary>
 248:          ///
 249:          /// </summary>
 250:          public static List<Ia.Ngn.Cl.Model.Event> ReadTakeNOrderByEventTimeDescendingList(int elementsToTake)
 251:          {
 252:              List<Ia.Ngn.Cl.Model.Event> list;
 253:   
 254:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 255:              {
 256:                  list = (from e in db.Events
 257:                          orderby e.EventTime descending
 258:                          select e).AsNoTracking().Take(elementsToTake).ToList();
 259:              }
 260:   
 261:              return list;
 262:          }
 263:   
 264:          ////////////////////////////////////////////////////////////////////////////
 265:   
 266:          /// <summary>
 267:          ///
 268:          /// </summary>
 269:          public static List<Ia.Ngn.Cl.Model.Event> EventWithMjOrCrSeverityAndClassNotOntRelatedForLast24HoursList()
 270:          {
 271:              DateTime twentyFourHoursAgoDateTime;
 272:              List<Ia.Ngn.Cl.Model.Event> list;
 273:   
 274:              twentyFourHoursAgoDateTime = DateTime.UtcNow.AddHours(3).AddDays(-1);
 275:   
 276:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 277:              {
 278:                  list = (from e in db.Events
 279:                          where (e.Severity == "MJ" || e.Severity == "CR") && e.Class.Substring(0, 3) != "ONT" && e.Created >= twentyFourHoursAgoDateTime
 280:                          orderby e.Created descending
 281:                          select e).AsNoTracking().ToList();
 282:              }
 283:   
 284:              return list;
 285:          }
 286:   
 287:          ////////////////////////////////////////////////////////////////////////////
 288:   
 289:          /// <summary>
 290:          ///
 291:          /// </summary>
 292:          public static List<Ia.Ngn.Cl.Model.Event> EventWithClassOntAndCauseInactAndLastRecordSeverityNotClAndOntAccessNotNullInLast24HoursList()
 293:          {
 294:              DateTime twentyFourHoursAgoDateTime;
 295:              List<Ia.Ngn.Cl.Model.Event> list;
 296:   
 297:              /*
 298:  select e.* 
 299:  from Events e
 300:  inner join 
 301:  (
 302:  select Ont_Id, max(Created) as MaxDate 
 303:  from Events 
 304:  where Class = 'ONT' and Cause = 'INACT' and Created > '2020-01-14'
 305:  group by Ont_Id
 306:  ) e2 on e.Ont_Id = e2.Ont_Id and e.Created = e2.MaxDate
 307:  where e.Severity <> 'CL'
 308:               */
 309:   
 310:              twentyFourHoursAgoDateTime = DateTime.UtcNow.AddHours(3).AddDays(-1);
 311:   
 312:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 313:              {
 314:                  list = (from e in db.Events
 315:                          where e.Class == "ONT" && e.Cause == "INACT" && e.Ont != null && e.Ont.Access != null && e.Created >= twentyFourHoursAgoDateTime
 316:                          group e by e.Ont.Id into eg
 317:                          select eg.OrderByDescending(t => t.Created).FirstOrDefault()).Include(u => u.Ont).ThenInclude(u => u.Access).AsNoTracking().ToList();
 318:   
 319:                  list = (from e in list where e.Severity != "CL" select e).ToList();
 320:              }
 321:   
 322:              return list;
 323:          }
 324:   
 325:          ////////////////////////////////////////////////////////////////////////////
 326:   
 327:          /// <summary>
 328:          /// 
 329:          /// </summary>
 330:          public static List<long> EventIdTakeNOrderByIdDescendingListFromNddOntId(string nddOntId, int take)
 331:          {
 332:              List<long> list;
 333:   
 334:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 335:              {
 336:                  if (!string.IsNullOrEmpty(nddOntId))
 337:                  {
 338:                      //foreach (var v in nddOntList)
 339:                      //{
 340:                      //eventSystemList.Add(v.Pon.PonGroup.Olt.AmsName);
 341:                      //eventAidOntList.Add("ONT-1-1-" + v.Card + "-" + v.Port + "-" + v.Number);
 342:                      //eventAidOntVoipList.Add("ONTVOIP-1-1-" + v.Card + "-" + v.Port + "-1");
 343:   
 344:                      //foreach (var w in ontOntPotsList) eventAidOntPotsList.Add("ONTPOTS-1-1-" + v.Card + "-" + v.Port + "-" + w.Card + "-" + w.Port);
 345:                      //}
 346:   
 347:                      //eventSystemList = eventSystemList.Distinct().ToList();
 348:                      //eventAidOntList = eventAidOntList.Distinct().ToList();
 349:                      //eventAidOntVoipList = eventAidOntVoipList.Distinct().ToList();
 350:   
 351:                      /*
 352:                      eventList = (from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) select e)
 353:                                  .Union(from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) where eventAidOntVoipList.Contains(e.Aid) select e)
 354:                                  .Union(from e in db.Events where eventSystemList.Contains(e.System) where eventAidOntList.Contains(e.Aid) where eventAidOntPotsList.Contains(e.Aid) select e)
 355:                                  .ToList();
 356:                                  */
 357:   
 358:   
 359:                      list = (from e in db.Events
 360:                              where e.Ont != null && nddOntId == e.Ont.Id
 361:                              //orderby e.Created descending
 362:                              orderby e.Id descending
 363:                              select e.Id).Take(take).ToList();
 364:                  }
 365:                  else list = new List<long>();
 366:              }
 367:   
 368:              return list.Distinct().ToList();
 369:          }
 370:   
 371:          ////////////////////////////////////////////////////////////////////////////
 372:   
 373:          /// <summary>
 374:          ///
 375:          /// </summary>
 376:          private static long MaxEventId
 377:          {
 378:              get
 379:              {
 380:                  long maxId;
 381:   
 382:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 383:                  {
 384:                      maxId = db.Events.Max(u => u.Id);
 385:                  }
 386:   
 387:                  return maxId;
 388:              }
 389:          }
 390:   
 391:          ////////////////////////////////////////////////////////////////////////////
 392:          ////////////////////////////////////////////////////////////////////////////
 393:   
 394:          /// <summary>
 395:          ///
 396:          /// </summary>
 397:          public static List<Ia.Ngn.Cl.Model.Event> ReadNewOntList2()
 398:          {
 399:              List<Ia.Ngn.Cl.Model.Event> list;
 400:   
 401:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 402:              {
 403:                  list = (from e in db.Events
 404:                          where e.Cause == "NEWONT"
 405:                          select e).AsNoTracking().ToList();
 406:              }
 407:   
 408:              return list;
 409:          }
 410:   
 411:          ////////////////////////////////////////////////////////////////////////////
 412:   
 413:          /// <summary>
 414:          ///
 415:          /// </summary>
 416:          public static List<Ia.Ngn.Cl.Model.Event> NewOntList
 417:          {
 418:              get
 419:              {
 420:                  //string serial, ontSerial, ontId, accessName;
 421:                  List<Ia.Ngn.Cl.Model.Event> list;
 422:   
 423:                  /*
 424:      use Ia_Ngn
 425:      --select distinct System,Class, Aid, Detail from Events where Id > 18900000 and Cause = 'NEWONT'
 426:      --select *from Events where Id > 18000000 and Cause = 'NEWONT' order by Id
 427:      --select max(id) from Events
 428:      -- 1M events is about 3 weeks
 429:      --select * from Events where Id > (select max(id) - 1000000 from Events) and Cause = 'NEWONT' order by Id
 430:      select distinct System, Aid, Cause, Detail from Events where Id > (select max(id) - 1000000 from Events) and Cause = 'NEWONT'
 431:  
 432:       delete from Events where Id < 45564063
 433:  
 434:                  delete events using SQL before one month from today
 435:       */
 436:   
 437:                  var serialList = new List<string>();
 438:                  var ontIdList = new List<string>();
 439:   
 440:                  //var di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 441:   
 442:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 443:                  {
 444:                      list = (from e in db.Events
 445:                              where e.Cause == "NEWONT" && e.Severity == "MN"
 446:                              orderby e.Id descending
 447:                              select e).Include(u => u.Ont).AsNoTracking().ToList();
 448:                      /*
 449:                      if (list != null && list.Count > 0)
 450:                      {
 451:                          var serialToIdListDictionary = Ia.Ngn.Cl.Model.Data.Nokia.Ont.SerialToIdListDictionary;
 452:  
 453:                          foreach (Ia.Ngn.Cl.Model.Event e in list.OrderByDescending(u => u.Id))
 454:                          {
 455:                              if (!string.IsNullOrEmpty(e.Detail))
 456:                              {
 457:                                  serial = Ia.Cl.Model.Default.Match(e.Detail, "(ALCL.{8})");
 458:  
 459:                                  if (!string.IsNullOrEmpty(serial))
 460:                                  {
 461:                                      if (!serialList.Contains(serial))
 462:                                      {
 463:                                          if (serialToIdListDictionary.ContainsKey(serial))
 464:                                          {
 465:                                              ontId = serialToIdListDictionary[serial];
 466:                                              ontSerial = serial;
 467:  
 468:                                              accessName = di[ontId];
 469:                                          }
 470:                                          else
 471:                                          {
 472:                                              ontId = ontSerial = accessName = string.Empty;
 473:                                          }
 474:  
 475:                                          eventOnt = new Ia.Ngn.Cl.Model.Ui.Event
 476:                                          {
 477:                                              Id = e.Id,
 478:                                              TypeId = e.TypeId,
 479:                                              System = e.System,
 480:                                              Class = e.Class,
 481:                                              Aid = e.Aid,
 482:                                              Cause = e.Cause,
 483:                                              Number = e.Number,
 484:                                              Detail = e.Detail,
 485:                                              Severity = e.Severity,
 486:                                              SeverityEffect = e.SeverityEffect,
 487:                                              EventTime = e.EventTime,
 488:                                              NodeTime = e.NodeTime,
 489:                                              Created = e.Created,
 490:                                              OntId = ontId,
 491:                                              Serial = ontSerial,
 492:                                              AccessName = accessName,
 493:                                          };
 494:  
 495:                                          uiList.Add(eventOnt);
 496:  
 497:                                          serialList.Add(serial);
 498:                                      }
 499:                                      else
 500:                                      {
 501:  
 502:                                      }
 503:                                  }
 504:                              }
 505:                          }
 506:                      }
 507:                      else
 508:                      {
 509:  
 510:                      }
 511:                      */
 512:                  }
 513:   
 514:                  /*
 515:                      string s, sql;
 516:                      StringBuilder sb;
 517:                      Hashtable ht, a_ht;
 518:                      DataTable dt, a_dt;
 519:  
 520:                      sb = new StringBuilder(1000);
 521:                      ht = new Hashtable(1000);
 522:                      a_ht = new Hashtable(1000);
 523:  
 524:                      sql = @"SELECT e.id, '' AS last_event, f.area, f.pon, f.ont, f.olt, f.olt_card, f.olt_port, e.system_id, e.aid, f.ont_serial, e.detail, f.area AS f_area, f.block, f.street, 
 525:                                       f.premises_old, f.premises_new, e.node_time, e.event_time, e.created
 526:              FROM            ia_event AS e LEFT OUTER JOIN
 527:                                       ia_field AS f ON e.detail LIKE '%' + f.ont_serial + '%'
 528:              WHERE        (e.cause = 'NEWONT') AND (e.id =
 529:                                           (SELECT        MAX(id) AS max_id
 530:                                             FROM            ia_event AS e2
 531:                                             WHERE        (cause = 'NEWONT') AND (system_id = e.system_id) AND (aid = e.aid) AND (detail = e.detail))) AND (e.severity <> 'CL')
 532:              ORDER BY e.created DESC";
 533:  
 534:                      dt = null; // main.Data.Select(sql);
 535:  
 536:                      if (dt != null && dt.Rows.Count > 1)
 537:                      {
 538:                          // below: now collect all valid ont_position entries and get the last event for them
 539:                          ///gh3
 540:                          sql = string.Empty;
 541:  
 542:                          foreach (DataRow r in dt.Rows)
 543:                          {
 544:                              if (r["ont"] != null && r["ont"].ToString().Length > 0)
 545:                              {
 546:                                  s = r["system_id"].ToString() + ":" + r["aid"].ToString().Replace("PON", "ONT") + "-" + r["ont"].ToString();
 547:                                  ht[s] = r["id"].ToString();
 548:                                  sb.Append("e.system_id='" + r["system_id"].ToString() + "' AND " + "e.aid='" + r["aid"].ToString().Replace("PON", "ONT") + "-" + r["ont"].ToString() + "' OR ");
 549:                              }
 550:                          }
 551:  
 552:                          sql = sb.ToString();
 553:  
 554:                          if (sql.Length > 0)
 555:                          {
 556:                              sql = sql.Remove(sql.Length - 4, 4);
 557:  
 558:                              a_dt = null; // main.Data.Select(@"SELECT system_id, aid, cause, severity FROM ia_event AS e WHERE (" + sql + @") AND (id = (SELECT MAX(id) AS max_id FROM ia_event AS e2 WHERE (system_id = e.system_id) AND (aid = e.aid)))");
 559:  
 560:                              // below: now loop through table and collect cause + severity
 561:                              foreach (DataRow r in a_dt.Rows)
 562:                              {
 563:                                  s = r["system_id"].ToString() + ":" + r["aid"].ToString();
 564:                                  a_ht[ht[s].ToString()] = r["cause"].ToString() + ":" + r["severity"].ToString();
 565:                              }
 566:  
 567:                              // below: now loop through original table and insert last_event
 568:  
 569:                              foreach (DataRow r in dt.Rows)
 570:                              {
 571:                                  s = r["id"].ToString();
 572:                                  if (a_ht.ContainsKey(s)) r["last_event"] = a_ht[s].ToString();
 573:                              }
 574:  
 575:                              gv.DataSource = dt.DefaultView;
 576:                              gv.DataBind();
 577:                          }
 578:                      }
 579:                  }
 580:                       */
 581:   
 582:                  return list;
 583:              }
 584:          }
 585:   
 586:          ////////////////////////////////////////////////////////////////////////////
 587:   
 588:          /// <summary>
 589:          ///
 590:          /// </summary>
 591:          public static void DeleteAllEventsBeforeDateTime(DateTime dateTime)
 592:          {
 593:              // see comment on ofn/maitenance/log/event/ams.aspx
 594:   
 595:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 596:              {
 597:                  if (dateTime > DateTime.MinValue)
 598:                  {
 599:                      db.Database.ExecuteSqlRaw("delete Events where Created < '" + dateTime.ToString("yyyy-MM-dd") + "'");
 600:   
 601:                      /*
 602:  --select top 100 from events where Created 
 603:  
 604:  delete Events where Created < '2018-11-01'
 605:  
 606:  --delete Events where id < (select (max(id) - min(id))/2 + min(id) from Events) 
 607:  --select max(id), min(id),(max(id) - min(id)),(max(id) - min(id))/2 + min(id) from Events
 608:  */
 609:                  }
 610:              }
 611:          }
 612:   
 613:          ////////////////////////////////////////////////////////////////////////////
 614:   
 615:          /// <summary>
 616:          ///
 617:          /// </summary>
 618:          public static bool DeleteByAccessId(string accessId, out string result)
 619:          {
 620:              bool b;
 621:   
 622:              b = false;
 623:              result = string.Empty;
 624:   
 625:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 626:              {
 627:                  //--delete from Events where Ont_Id = (select id from Onts where Access_Id = '1040101010040004')
 628:   
 629:                  var v = (from e in db.Events
 630:                           join o in db.Onts on e.Ont.Id equals o.Id
 631:                           where o.Access.Id == accessId
 632:                           select e).FirstOrDefault();
 633:   
 634:                  if (v != null)
 635:                  {
 636:                      db.Events.Remove(v);
 637:                      db.SaveChanges();
 638:   
 639:                      b = true;
 640:                  }
 641:                  else b = false;
 642:              }
 643:   
 644:              return b;
 645:          }
 646:   
 647:          ////////////////////////////////////////////////////////////////////////////
 648:   
 649:          /// <summary>
 650:          ///
 651:          /// </summary>
 652:          public static List<Severity> SeverityList
 653:          {
 654:              get
 655:              {
 656:                  List<Severity> severityList;
 657:   
 658:                  severityList = new List<Severity>();
 659:   
 660:                  severityList.Add(new Severity("CR", "Critical"));
 661:                  severityList.Add(new Severity("MJ", "Major"));
 662:                  severityList.Add(new Severity("MN", "Minor"));
 663:                  severityList.Add(new Severity("NR", "Normal/not reported"));
 664:                  severityList.Add(new Severity("NA", "Not alarmed"));
 665:                  severityList.Add(new Severity("ND", "Not yet determained"));
 666:                  severityList.Add(new Severity("WA", "Warning"));
 667:                  severityList.Add(new Severity("CL", "Clear"));
 668:   
 669:                  return severityList;
 670:              }
 671:          }
 672:   
 673:          ////////////////////////////////////////////////////////////////////////////
 674:   
 675:          /// <summary>
 676:          ///
 677:          /// </summary>
 678:          public static List<ServiceEffect> ServiceEffectList
 679:          {
 680:              get
 681:              {
 682:                  List<ServiceEffect> serviceEffectList;
 683:   
 684:                  serviceEffectList = new List<ServiceEffect>();
 685:   
 686:                  serviceEffectList.Add(new ServiceEffect("SA", "Service Affecting"));
 687:                  serviceEffectList.Add(new ServiceEffect("NSA", "Not Service Affecting"));
 688:                  serviceEffectList.Add(new ServiceEffect("NR", "Not Reported"));
 689:   
 690:                  return serviceEffectList;
 691:              }
 692:          }
 693:   
 694:          ////////////////////////////////////////////////////////////////////////////
 695:   
 696:          /// <summary>
 697:          ///
 698:          /// </summary>
 699:          public static List<string> ClassList
 700:          {
 701:              get
 702:              {
 703:                  List<string> list;
 704:   
 705:                  list = new List<string>();
 706:   
 707:                  list.Add("BRGPORT");
 708:                  list.Add("PON");
 709:                  list.Add("EQPT");
 710:                  list.Add("ONTPOTS");
 711:                  list.Add("ONTVOIP");
 712:                  list.Add("ONT");
 713:                  list.Add("ONTENET");
 714:                  list.Add("ONTCARD");
 715:                  list.Add("ONTHSI");
 716:                  list.Add("SECACCESS");
 717:   
 718:                  list.Sort();
 719:   
 720:                  return list;
 721:              }
 722:          }
 723:   
 724:          ////////////////////////////////////////////////////////////////////////////
 725:   
 726:          /// <summary>
 727:          ///
 728:          /// </summary>
 729:          public static List<string> CauseList
 730:          {
 731:              get
 732:              {
 733:                  List<string> list;
 734:   
 735:                  list = new List<string>();
 736:   
 737:                  list.Add("LIMSVCMIS");
 738:                  list.Add("MEM");
 739:                  list.Add("SECUMGTACCESS");
 740:                  list.Add("EQPT");
 741:                  list.Add("SWRESET");
 742:                  list.Add("SECUMGTACCESSTCA");
 743:                  list.Add("BDRESETCF");
 744:                  list.Add("VICONFIGNOTIFYFAIL");
 745:                  list.Add("TXFAIL");
 746:                  list.Add("PONLOS");
 747:                  list.Add("SWVER");
 748:                  list.Add("NEWONT");
 749:                  list.Add("VICONFIGHTTPFAIL");
 750:                  list.Add("LOAM");
 751:                  list.Add("SHUTDOWN");
 752:                  list.Add("BDMISSING");
 753:                  list.Add("BATTMISS");
 754:                  list.Add("LOA");
 755:                  list.Add("ACFAIL");
 756:                  list.Add("RTCPSTREAMLOSS");
 757:                  list.Add("POTSSVCMIS");
 758:                  list.Add("INACT");
 759:                  list.Add("SWDLIP");
 760:                  list.Add("PONMEA");
 761:                  list.Add("OMCICOMM");
 762:                  list.Add("SWVERCTLERR");
 763:                  list.Add("VNTWKERR");
 764:                  list.Add("BDRESET");
 765:                  list.Add("ONTMEA");
 766:                  list.Add("LOS");
 767:                  list.Add("VOIPCNFG");
 768:                  list.Add("SWACTFAIL");
 769:                  list.Add("VGATEWAYCOMM");
 770:                  list.Add("SD");
 771:                  list.Add("BDINIT");
 772:                  list.Add("INTRUDER");
 773:                  list.Add("FANALM");
 774:                  list.Add("DUPADDR");
 775:                  list.Add("SWDLFILE");
 776:                  list.Add("VCLIENTSVCMIS");
 777:                  list.Add("DG");
 778:                  list.Add("SF");
 779:                  list.Add("SUF");
 780:                  list.Add("BATTFAIL");
 781:                  list.Add("HITEMP");
 782:                  list.Add("LANSVCMIS");
 783:                  list.Add("VICONFIGSUBFAIL");
 784:                  list.Add("SWDLFAIL");
 785:                  list.Add("EXCEPTOVLD");
 786:                  list.Add("HSISVCMIS");
 787:                  list.Add("LOKS");
 788:                  list.Add("PONCOMMFAIL");
 789:                  list.Add("HITEMPSHUTOFF");
 790:                  list.Add("LIMMEA");
 791:                  list.Add("RDI");
 792:                  list.Add("ONTDISABLED");
 793:                  list.Add("BATTLOW");
 794:                  list.Add("DOW");
 795:   
 796:                  list.Sort();
 797:   
 798:                  return list;
 799:              }
 800:          }
 801:   
 802:          ////////////////////////////////////////////////////////////////////////////
 803:   
 804:          /// <summary>
 805:          ///
 806:          /// </summary>
 807:          public static List<Alarm> AlarmList
 808:          {
 809:              get
 810:              {
 811:                  Alarm alarm;
 812:                  List<Alarm> alarmList;
 813:   
 814:                  alarmList = new List<Alarm>();
 815:   
 816:                  foreach (XElement xe in XDocument.Element("event").Element("alarm").Elements("aid").Elements("alarmList").Elements("alarm"))
 817:                  {
 818:                      alarm = new Alarm();
 819:   
 820:                      alarm.Id = xe.Attribute("id").Value;
 821:                      alarm.Name = xe.Attribute("name").Value;
 822:                      alarm.Severity = (from s in SeverityList where s.Id == xe.Attribute("severity").Value select s).Single();
 823:                      alarm.ServiceEffect = (from s in ServiceEffectList where s.Id == xe.Attribute("serviceEffect").Value select s).Single();
 824:                      alarm.SaveMessage = bool.Parse(xe.Attribute("saveMessage").Value);
 825:                      alarm.Condition = xe.Element("condition").Value;
 826:                      alarm.Resolution = xe.Element("resolution").Value;
 827:   
 828:                      alarmList.Add(alarm);
 829:                  }
 830:   
 831:                  return alarmList;
 832:              }
 833:          }
 834:   
 835:          ////////////////////////////////////////////////////////////////////////////
 836:   
 837:          /// <summary>
 838:          ///
 839:          /// </summary>
 840:          public static string ToString(Ia.Ngn.Cl.Model.Event _event)
 841:          {
 842:              StringBuilder sb;
 843:   
 844:              sb = new StringBuilder();
 845:   
 846:              sb.AppendLine("Class: " + _event.Class);
 847:              sb.AppendLine("System: " + _event.System);
 848:              sb.AppendLine("Severity: " + _event.Severity);
 849:              sb.AppendLine("SeverityEffect: " + _event.SeverityEffect);
 850:              sb.AppendLine("Aid: " + _event.Aid);
 851:              sb.AppendLine("Cause: " + _event.Cause);
 852:              sb.AppendLine("Number: " + _event.Number);
 853:              sb.AppendLine("Detail: " + _event.Detail);
 854:              sb.AppendLine("EventTime: " + _event.EventTime);
 855:              sb.AppendLine("NodeTime: " + _event.NodeTime);
 856:              sb.AppendLine("Created: " + _event.Created);
 857:   
 858:              return sb.ToString();
 859:          }
 860:   
 861:          ////////////////////////////////////////////////////////////////////////////
 862:   
 863:          /// <summary>
 864:          ///
 865:          /// </summary>
 866:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Event _event)
 867:          {
 868:              StringBuilder sb;
 869:   
 870:              sb = new StringBuilder();
 871:   
 872:              //sb.AppendLine("Class: " + _event.Class);
 873:              sb.AppendLine("System: " + _event.System);
 874:              sb.AppendLine("Severity: " + _event.Severity);
 875:              //sb.AppendLine("SeverityEffect: " + _event.SeverityEffect);
 876:              sb.AppendLine("Aid: " + _event.Aid);
 877:              sb.AppendLine("Cause: " + _event.Cause);
 878:              //sb.AppendLine("Number: " + _event.Number);
 879:              sb.AppendLine("Detail: " + _event.Detail);
 880:              sb.AppendLine("EventTime: " + _event.EventTime);
 881:              //sb.AppendLine("NodeTime: " + _event.NodeTime);
 882:              //sb.AppendLine("Created: " + _event.Created);
 883:   
 884:              return sb.ToString();
 885:          }
 886:   
 887:          ////////////////////////////////////////////////////////////////////////////
 888:   
 889:          /// <summary>
 890:          /// 
 891:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 892:          /// 
 893:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 894:          /// 2. Add "using System.Reflection".
 895:          /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
 896:          /// 
 897:          /// </summary>
 898:   
 899:          private static XDocument XDocument
 900:          {
 901:              get
 902:              {
 903:                  if (xDocument == null)
 904:                  {
 905:                      lock (objectLock)
 906:                      {
 907:                          Assembly _assembly;
 908:                          StreamReader streamReader;
 909:   
 910:                          _assembly = Assembly.GetExecutingAssembly();
 911:                          streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.event.xml"));
 912:   
 913:                          try
 914:                          {
 915:                              if (streamReader.Peek() != -1)
 916:                              {
 917:                                  xDocument = System.Xml.Linq.XDocument.Load(streamReader);
 918:                              }
 919:                          }
 920:                          catch (Exception)
 921:                          {
 922:                          }
 923:                          finally
 924:                          {
 925:                          }
 926:                      }
 927:                  }
 928:   
 929:                  return xDocument;
 930:              }
 931:          }
 932:   
 933:          ////////////////////////////////////////////////////////////////////////////    
 934:          ////////////////////////////////////////////////////////////////////////////    
 935:      }
 936:   
 937:      ////////////////////////////////////////////////////////////////////////////
 938:      ////////////////////////////////////////////////////////////////////////////   
 939:  }