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

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:

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