)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Event (Ia.Ftn.Cl.Models.Data)

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

Nokia AMS Event support class for Fixed Telecommunications Network (FTN) data model.

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