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

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

Heartbeat information support class for the Fixed Telecommunications Network business model

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Threading.Tasks;
    5:  
    6: namespace Ia.Ftn.Cl.Model.Business
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     /// Heartbeat information support class for the Fixed Telecommunications Network business model
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public class Heartbeat
   28:     {
   29:         private static Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary = new Dictionary<string, DateTime>();
   30:  
   31:         private static readonly object objectLock = new object();
   32:  
   33:         ////////////////////////////////////////////////////////////////////////////
   34:  
   35:         /// <summary>
   36:         ///
   37:         /// </summary>
   38:         public static Dictionary<string, DateTime> AssemblyNameToCreatedDateTimeDictionary
   39:         {
   40:             get { return assemblyNameToCreatedDateTimeDictionary; }
   41:  
   42:             set { assemblyNameToCreatedDateTimeDictionary = value; }
   43:         }
   44:  
   45:         ////////////////////////////////////////////////////////////////////////////
   46:  
   47:         /// <summary>
   48:         ///
   49:         /// </summary>
   50:         public Heartbeat() { }
   51:  
   52:         ////////////////////////////////////////////////////////////////////////////
   53:  
   54:         /// <summary>
   55:         /// 
   56:         /// </summary>
   57:         public static void Create(Ia.Ftn.Cl.Model.Business.Msmq.Application application)
   58:         {
   59:             if (!string.IsNullOrEmpty(application.Assembly))
   60:             {
   61:                 assemblyNameToCreatedDateTimeDictionary[application.Assembly] = DateTime.UtcNow.AddHours(3);
   62:             }
   63:             else
   64:             {
   65:             }
   66:         }
   67:  
   68:         ////////////////////////////////////////////////////////////////////////////
   69:  
   70:         /// <summary>
   71:         ///
   72:         /// </summary>
   73:         public static List<string> MissingAssemblyNameList(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary)
   74:         {
   75:             bool assemblyWasSeen;
   76:  
   77:             var list = new List<string>();
   78:  
   79:             var assemblyNameList = (from h in assemblyNameToCreatedDateTimeDictionary
   80:                                     select h.Key).ToList();
   81:  
   82:             var text = string.Empty;
   83:             string applicationName, assemblyName;
   84:  
   85:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
   86:             {
   87:                 assemblyName = keyValuePair.Key;
   88:                 applicationName = keyValuePair.Value;
   89:  
   90:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
   91:  
   92:                 if (assemblyName == "ia.ftn.netm.ca" || assemblyName == "ia.ftn.citrixguistarter.ca")
   93:                 {
   94:                     // skip
   95:                     //text += applicationName + " (" + assembly + @") Active?: [<span style=""color:Orange"">Unknown</span>]<br/>";
   96:                 }
   97:                 else if (assemblyName == "ia.ftn.mdaa.ca")
   98:                 {
   99:                     // skip
  100:                 }
  101:                 else
  102:                 {
  103:                     assemblyWasSeen = assemblyNameList.Contains(assemblyName);
  104:  
  105:                     if (!assemblyWasSeen) list.Add(assemblyName);
  106:                 }
  107:             }
  108:  
  109:             return list;
  110:         }
  111:  
  112:         ////////////////////////////////////////////////////////////////////////////
  113:  
  114:         /// <summary>
  115:         ///
  116:         /// </summary>
  117:         public static List<string> WithinLastNMinuteAssemblyNameList(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary, int withinLastNMinute)
  118:         {
  119:             bool assemblyIsActive;
  120:  
  121:             var list = new List<string>();
  122:  
  123:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  124:  
  125:             var assemblyNameWithinLastNMinuteList = (from h in assemblyNameToCreatedDateTimeDictionary
  126:                                                      where h.Value >= dateTime
  127:                                                      select h.Key).ToList();
  128:  
  129:             var text = string.Empty;
  130:             string applicationName, assemblyName;
  131:  
  132:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  133:             {
  134:                 assemblyName = keyValuePair.Key;
  135:                 applicationName = keyValuePair.Value;
  136:  
  137:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  138:  
  139:                 if (assemblyName == "ia.ftn.netm.ca" || assemblyName == "ia.ftn.citrixguistarter.ca")
  140:                 {
  141:                     //text += applicationName + " (" + assemblyName + ") Active?: Unknown\r\n\r\n";
  142:                 }
  143:                 else
  144:                 {
  145:                     assemblyIsActive = assemblyNameWithinLastNMinuteList.Contains(assemblyName);
  146:  
  147:                     if (assemblyIsActive) list.Add(assemblyName);
  148:                 }
  149:             }
  150:  
  151:             return list;
  152:         }
  153:  
  154:         ////////////////////////////////////////////////////////////////////////////
  155:  
  156:         /// <summary>
  157:         ///
  158:         /// </summary>
  159:         public static string WithinLastNMinuteTextTable(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary, int withinLastNMinute)
  160:         {
  161:             // see below
  162:  
  163:             bool assemblyIsActive;
  164:  
  165:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  166:  
  167:             var assemblyNameWithinLastNMinuteList = (from h in assemblyNameToCreatedDateTimeDictionary
  168:                                                      where h.Value >= dateTime
  169:                                                      select h.Key).ToList();
  170:  
  171:             var text = string.Empty;
  172:             string applicationName, assembly;
  173:  
  174:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  175:             {
  176:                 assembly = keyValuePair.Key;
  177:                 applicationName = keyValuePair.Value;
  178:  
  179:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  180:  
  181:                 if (assembly == "ia.ftn.netm.ca" || assembly == "ia.ftn.citrixguistarter.ca")
  182:                 {
  183:                     text += applicationName + " (" + assembly + ") Active?: Unknown\r\n\r\n";
  184:                 }
  185:                 else
  186:                 {
  187:                     assemblyIsActive = assemblyNameWithinLastNMinuteList.Contains(assembly);
  188:  
  189:                     text += applicationName + " (" + assembly + ") Active?: " + Ia.Cl.Models.Default.YesNoText(assemblyIsActive) + "\r\n\r\n";
  190:                 }
  191:             }
  192:  
  193:             return text.Trim();
  194:         }
  195:  
  196:         ////////////////////////////////////////////////////////////////////////////
  197:  
  198:         /// <summary>
  199:         ///
  200:         /// </summary>
  201:         public static string WithinLastNMinuteHtmlTable(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary, int withinLastNMinute)
  202:         {
  203:             // see above
  204:  
  205:             bool assemblyIsActive;
  206:  
  207:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  208:  
  209:             var assemblyNameWithinLastNMinuteList = (from h in assemblyNameToCreatedDateTimeDictionary
  210:                                                      where h.Value >= dateTime
  211:                                                      select h.Key).ToList();
  212:  
  213:             var text = string.Empty;
  214:             string applicationName, assembly;
  215:  
  216:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  217:             {
  218:                 assembly = keyValuePair.Key;
  219:                 applicationName = keyValuePair.Value;
  220:  
  221:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  222:  
  223:                 if (assembly == "ia.ftn.netm.ca" || assembly == "ia.ftn.citrixguistarter.ca")
  224:                 {
  225:                     text += applicationName + " (" + assembly + @") Active?: [<span style=""color:Orange"">Unknown</span>]<br/>";
  226:                 }
  227:                 else
  228:                 {
  229:                     assemblyIsActive = assemblyNameWithinLastNMinuteList.Contains(assembly);
  230:  
  231:                     text += applicationName + " (" + assembly + ") Active?: [" + Ia.Cl.Models.Default.YesNo(assemblyIsActive) + "]<br/>";
  232:                 }
  233:             }
  234:  
  235:             return text.Trim();
  236:         }
  237:  
  238:         ////////////////////////////////////////////////////////////////////////////
  239:  
  240:         /// <summary>
  241:         ///
  242:         /// </summary>
  243:         public static string MissingOrInactiveWithinLastNMinuteApplicationNameListText(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary, int withinLastNMinute)
  244:         {
  245:             // see above
  246:  
  247:             var missingAssemblyNameList = MissingAssemblyNameList(assemblyNameToCreatedDateTimeDictionary);
  248:  
  249:             var heartbeatsWithinLastNMinuteAssemblyNameList = WithinLastNMinuteAssemblyNameList(assemblyNameToCreatedDateTimeDictionary, withinLastNMinute);
  250:  
  251:             bool missingOrInactiveAssemblyName;
  252:  
  253:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  254:  
  255:             var assemblyNameNotWithinLastNMinuteList = (from h in assemblyNameToCreatedDateTimeDictionary
  256:                                                         where h.Value < dateTime
  257:                                                         select h.Key).ToList();
  258:  
  259:             var missingOrInactiveAssemblyNameList = missingAssemblyNameList.Union(assemblyNameNotWithinLastNMinuteList).ToList();
  260:  
  261:             var text = string.Empty;
  262:             string applicationName, assembly;
  263:  
  264:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  265:             {
  266:                 assembly = keyValuePair.Key;
  267:                 applicationName = keyValuePair.Value;
  268:  
  269:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  270:  
  271:                 if (assembly == "ia.ftn.netm.ca" || assembly == "ia.ftn.citrixguistarter.ca")
  272:                 {
  273:                     // skip
  274:                     //text += applicationName + " (" + assembly + @") Active?: [<span style=""color:Orange"">Unknown</span>]<br/>";
  275:                 }
  276:                 else if (assembly == "ia.ftn.mdaa.ca")
  277:                 {
  278:                     // skip
  279:                 }
  280:                 else
  281:                 {
  282:                     missingOrInactiveAssemblyName = missingOrInactiveAssemblyNameList.Contains(assembly);
  283:  
  284:                     if (missingOrInactiveAssemblyName)
  285:                     {
  286:                         text += applicationName + " (" + assembly + ") ";// Active?: [" + Ia.Cl.Models.Default.YesNo(assemblyIsActive) + "]<br/>";
  287:                     }
  288:                 }
  289:             }
  290:  
  291:             return text.Trim();
  292:         }
  293:  
  294:         ////////////////////////////////////////////////////////////////////////////
  295:  
  296:         /// <summary>
  297:         ///
  298:         /// </summary>
  299:         public static bool AxeAndEwsdAreActive(Dictionary<string, DateTime> assemblyNameToCreatedDateTimeDictionary, int withinLastNMinute)
  300:         {
  301:             bool areActive;
  302:  
  303:             var axe = "ia.ftn.axe.ca";
  304:             var ewsd = "ia.ftn.netmanager.ca";
  305:  
  306:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  307:  
  308:             var list0 = (from h in assemblyNameToCreatedDateTimeDictionary
  309:                          where h.Value >= dateTime
  310:                          select h.Key).ToList();
  311:  
  312:             areActive = list0.Contains(axe) && list0.Contains(ewsd);
  313:  
  314:             return areActive;
  315:         }
  316:  
  317:         ////////////////////////////////////////////////////////////////////////////
  318:         ////////////////////////////////////////////////////////////////////////////
  319:  
  320:  
  321:  
  322:  
  323:         ////////////////////////////////////////////////////////////////////////////
  324:         ////////////////////////////////////////////////////////////////////////////
  325:  
  326:         /// <summary>
  327:         ///
  328:         /// </summary>
  329:         public static async Task<List<Ia.Cl.Models.Heartbeat>> HearbeatsAsync()
  330:         {
  331:             var heartbeats = await Ia.Cl.Models.Http.GetAsync<List<Ia.Cl.Models.Heartbeat>>("https://api.ia.com.kw", "api/heartbeats");
  332:  
  333:             return heartbeats;
  334:         }
  335:  
  336:         ////////////////////////////////////////////////////////////////////////////
  337:  
  338:         /// <summary>
  339:         ///
  340:         /// </summary>
  341:         public static async Task<string> HearbeatsWithinLastNMinutesTextAsync(int withinLastNMinute)
  342:         {
  343:             // see below
  344:  
  345:             bool assemblyIsActive;
  346:  
  347:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  348:  
  349:             var heartbeats = await Ia.Ftn.Cl.Model.Business.Heartbeat.HearbeatsAsync();
  350:  
  351:             var list = (from h in heartbeats where h.Created > dateTime select h.Name).Distinct().ToList();
  352:  
  353:             var text = string.Empty;
  354:             string applicationName, assembly;
  355:  
  356:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  357:             {
  358:                 assembly = keyValuePair.Key;
  359:                 applicationName = keyValuePair.Value;
  360:  
  361:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  362:  
  363:                 if (assembly == "ia.ftn.netm.ca" || assembly == "ia.ftn.citrixguistarter.ca")
  364:                 {
  365:                     text += applicationName + " (" + assembly + ") Active?: Unknown\r\n\r\n";
  366:                 }
  367:                 else
  368:                 {
  369:                     assemblyIsActive = list.Contains(assembly);
  370:  
  371:                     text += applicationName + " (" + assembly + ") Active?: " + Ia.Cl.Models.Default.YesNoText(assemblyIsActive) + "\r\n\r\n";
  372:                 }
  373:             }
  374:  
  375:             return text.Trim();
  376:         }
  377:  
  378:         ////////////////////////////////////////////////////////////////////////////
  379:  
  380:         /// <summary>
  381:         ///
  382:         /// </summary>
  383:         public static async Task<string> HearbeatsWithinLastNMinuteHtmlAsync(int withinLastNMinute)
  384:         {
  385:             // see above
  386:  
  387:             bool assemblyIsActive;
  388:  
  389:             var heartbeats = await Ia.Ftn.Cl.Model.Business.Heartbeat.HearbeatsAsync();
  390:  
  391:             var dateTime = DateTime.UtcNow.AddHours(3).AddMinutes(-withinLastNMinute);
  392:  
  393:             var list = (from h in heartbeats where h.Created > dateTime select h.Name).Distinct().ToList();
  394:  
  395:             var text = string.Empty;
  396:             string applicationName, assembly;
  397:  
  398:             foreach (KeyValuePair<string, string> keyValuePair in Ia.Ftn.Cl.Model.Business.Default.ApplicationAssemblyNameToApplicationName)
  399:             {
  400:                 assembly = keyValuePair.Key;
  401:                 applicationName = keyValuePair.Value;
  402:  
  403:                 applicationName = applicationName.Replace("Fixed Telecommunications Network's Operations Support System ", "");
  404:  
  405:                 if (assembly == "ia.ftn.netm.ca" || assembly == "ia.ftn.citrixguistarter.ca")
  406:                 {
  407:                     text += applicationName + " (" + assembly + @") Active?: [<span style=""color:Orange"">Unknown</span>]<br/>";
  408:                 }
  409:                 else
  410:                 {
  411:                     assemblyIsActive = list.Contains(assembly);
  412:  
  413:                     text += applicationName + " (" + assembly + ") Active?: [" + Ia.Cl.Models.Default.YesNo(assemblyIsActive) + "]<br/>";
  414:                 }
  415:             }
  416:  
  417:             return text.Trim();
  418:         }
  419:  
  420:         ////////////////////////////////////////////////////////////////////////////
  421:         ////////////////////////////////////////////////////////////////////////////   
  422:     }
  423:  
  424:     ////////////////////////////////////////////////////////////////////////////
  425:     ////////////////////////////////////////////////////////////////////////////   
  426: }