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

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

    1: using Microsoft.AspNetCore.Identity;
    2: using Microsoft.AspNetCore.Mvc.Rendering;
    3: using System.Text;
    4: using System.Text.RegularExpressions;
    5:  
    6: namespace Ia.Ftn.Wa.Models.Administration
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     ///
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2025 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 static class Sdc
   28:     {
   29:         private struct PonNameReceiveTransmitValue { public string Name; public long Value; public long ReceiveValue; public long TransmitValue; }
   30:  
   31:         /// <summary/>
   32:         public readonly static int PastDays = 7;
   33:  
   34:         private class Pon
   35:         {
   36:             public string Value { get; set; }
   37:             public string Text { get; set; }
   38:         };
   39:  
   40:         private class Olt
   41:         {
   42:             public int Value { get; set; }
   43:             public string Text { get; set; }
   44:         };
   45:  
   46:  
   47:         ////////////////////////////////////////////////////////////////////////////
   48:  
   49:         /// <summary>
   50:         ///
   51:         /// </summary>
   52:         public static Ia.Ftn.Wa.Models.Administration.SdcViewModel ViewModel()
   53:         {
   54:             var sdcViewModel = new Ia.Ftn.Wa.Models.Administration.SdcViewModel();
   55:  
   56:             OltSelectList(ref sdcViewModel);
   57:  
   58:             return sdcViewModel;
   59:         }
   60:  
   61:         ////////////////////////////////////////////////////////////////////////////
   62:  
   63:         /// <summary>
   64:         ///
   65:         /// </summary>
   66:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
   67:         {
   68:             OltSelectList(ref sdcViewModel);
   69:         }
   70:  
   71:         ////////////////////////////////////////////////////////////////////////////
   72:  
   73:         /// <summary>
   74:         ///
   75:         /// </summary>
   76:         public static Ia.Ftn.Wa.Models.Administration.SdcViewModel SdcPonBandwidthUtilizationViewModel()
   77:         {
   78:             var sdcViewModel = new Ia.Ftn.Wa.Models.Administration.SdcViewModel();
   79:  
   80:             PonBandwidthChartDataBind(ref sdcViewModel);
   81:  
   82:             return sdcViewModel;
   83:         }
   84:  
   85:         ////////////////////////////////////////////////////////////////////////////
   86:  
   87:         /// <summary>
   88:         ///
   89:         /// </summary>
   90:         private static void OltSelectList(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
   91:         {
   92:             List<Olt> list2;
   93:  
   94:             list2 = new List<Olt>();
   95:  
   96:             var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
   97:                         where o.Odf != null && o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
   98:                         select o).ToList();
   99:  
  100:             foreach (var o in list) list2.Add(new Olt() { Text = o.Symbol + " (" + o.AmsName + ")", Value = o.Id });
  101:  
  102:  
  103:             list2 = list2.OrderBy(u => u.Text).ToList();
  104:  
  105:             if (!string.IsNullOrEmpty(sdcViewModel.OltSelectedValue))
  106:             {
  107:                 sdcViewModel.OltSelectList = new SelectList(list2, "Value", "Text", sdcViewModel.OltSelectedValue);
  108:             }
  109:             else
  110:             {
  111:                 sdcViewModel.OltSelectList = new SelectList(list2, "Value", "Text", list[0].Id.ToString());
  112:                 sdcViewModel.OltSelectedValue = list2[0].Value.ToString();
  113:             }
  114:  
  115:             OltSelectList_SelectedIndexChanged(ref sdcViewModel);
  116:         }
  117:  
  118:         ////////////////////////////////////////////////////////////////////////////
  119:  
  120:         /// <summary>
  121:         ///
  122:         /// </summary>
  123:         private static void OltSelectList_SelectedIndexChanged(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
  124:         {
  125:             int oltId;
  126:  
  127:             if (sdcViewModel.OltSelectList.Count() > 0 && !string.IsNullOrEmpty(sdcViewModel.OltSelectedValue))
  128:             {
  129:                 oltId = int.Parse(sdcViewModel.OltSelectedValue);
  130:  
  131:                 PonSelectList_Data(ref sdcViewModel, oltId);
  132:  
  133:                 DisplayStatisticButton_Click(ref sdcViewModel);
  134:             }
  135:             else
  136:             {
  137:             }
  138:         }
  139:  
  140:         ////////////////////////////////////////////////////////////////////////////
  141:  
  142:         /// <summary>
  143:         ///
  144:         /// </summary>
  145:         private static void PonSelectList_Data(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel, int oltId)
  146:         {
  147:             List<Pon> list2;
  148:  
  149:             list2 = new List<Pon>();
  150:  
  151:             var list = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
  152:                         where p.PonGroup.Olt.Id == oltId
  153:                         select p).ToList();
  154:  
  155:             foreach (var p in list) list2.Add(new Pon() { Text = p.Name, Value = p.Id });
  156:  
  157:             if (!string.IsNullOrEmpty(sdcViewModel.PonSelectedValue))
  158:             {
  159:                 sdcViewModel.PonSelectList = new SelectList(list2, "Value", "Text", sdcViewModel.OltSelectedValue);
  160:             }
  161:             else
  162:             {
  163:                 sdcViewModel.PonSelectList = new SelectList(list2, "Value", "Text", list[0].Id.ToString());
  164:                 sdcViewModel.PonSelectedValue = list2[0].Value.ToString();
  165:             }
  166:  
  167:             PonSelectList_SelectedIndexChanged(ref sdcViewModel);
  168:         }
  169:  
  170:         ////////////////////////////////////////////////////////////////////////////
  171:  
  172:         /// <summary>
  173:         ///
  174:         /// </summary>
  175:         private static void PonSelectList_SelectedIndexChanged(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
  176:         {
  177:             DisplayStatisticButton_Click(ref sdcViewModel);
  178:         }
  179:  
  180:         ////////////////////////////////////////////////////////////////////////////
  181:         ////////////////////////////////////////////////////////////////////////////
  182:  
  183:         /// <summary>
  184:         ///
  185:         /// </summary>
  186:         private static void DisplayStatisticButton_Click(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
  187:         {
  188:             int oltId;
  189:             string ponId;
  190:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon;
  191:  
  192:             var result = new Ia.Cl.Models.Result();
  193:  
  194:             sdcViewModel.Result = new Ia.Cl.Models.Result();
  195:  
  196:             if (sdcViewModel.OltSelectList.Count() > 0 && !string.IsNullOrEmpty(sdcViewModel.OltSelectedValue))
  197:             {
  198:                 oltId = int.Parse(sdcViewModel.OltSelectedValue);
  199:  
  200:                 if (sdcViewModel.PonSelectList.Count() > 0 && !string.IsNullOrEmpty(sdcViewModel.PonSelectedValue))
  201:                 {
  202:                     ponId = sdcViewModel.PonSelectedValue;
  203:  
  204:                     pon = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
  205:                            where p.Id == ponId
  206:                            select p).SingleOrDefault();
  207:  
  208:                     if (pon != null)
  209:                     {
  210:                         result = DisplaySelectedPonStatistics(ref sdcViewModel, pon);
  211:  
  212:                         if (result.IsSuccessful) sdcViewModel.Result.AddSuccess("Display PON Statistics: " + result.Message);
  213:                         else sdcViewModel.Result.AddError("Display PON Statistics: " + result.Message);
  214:                     }
  215:                     else
  216:                     {
  217:                         sdcViewModel.Result.AddError("PON is null.");
  218:                     }
  219:                 }
  220:                 else
  221:                 {
  222:                     sdcViewModel.Result.AddError("PON is undefined.");
  223:                 }
  224:             }
  225:             else
  226:             {
  227:                 sdcViewModel.Result.AddError("OLT is undefined.");
  228:             }
  229:         }
  230:  
  231:         ////////////////////////////////////////////////////////////////////////////
  232:  
  233:         /// <summary>
  234:         ///
  235:         /// </summary>
  236:         private static Ia.Cl.Models.Result DisplaySelectedPonStatistics(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon)
  237:         {
  238:             var result = new Ia.Cl.Models.Result();
  239:  
  240:             var receiveTransactionTimestampValueList = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.ReadTransactionTimestampHourlyValueListOfPon(Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction.Receive, pon);
  241:             var transmitTransactionTimestampValueList = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.ReadTransactionTimestampHourlyValueListOfPon(Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction.Transmit, pon);
  242:  
  243:             // 12 to account for five minute readings
  244:             sdcViewModel.CountText = "Total number of readings: Receive: " + receiveTransactionTimestampValueList.Count * 12 + ", Transmit: " + transmitTransactionTimestampValueList.Count * 12;
  245:  
  246:             ChartDataBind(ref sdcViewModel, receiveTransactionTimestampValueList, transmitTransactionTimestampValueList);
  247:  
  248:             return result;
  249:         }
  250:  
  251:         ////////////////////////////////////////////////////////////////////////////
  252:  
  253:         /// <summary>
  254:         ///
  255:         /// </summary>
  256:         private static void ChartDataBind(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> receiveTimestampValueList, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> transmitTimestampValueList)
  257:         {
  258:             sdcViewModel.Chart = new Ia.Cl.Models.Ui.Chart();
  259:  
  260:             sdcViewModel.Chart.Id = "chart";
  261:  
  262:             sdcViewModel.Chart.Labels = (from t in receiveTimestampValueList select t.Timestamp.ToString("yyyy-MM-dd HH:mm")).ToList();
  263:  
  264:             sdcViewModel.Chart.Label1 = "Timestamp vs Received Data Rate (Mb/s)";
  265:             sdcViewModel.Chart.Data1 = (from t in receiveTimestampValueList select (int)(t.Value)).ToList();
  266:  
  267:             sdcViewModel.Chart.Label2 = "Timestamp vs Transmitted Data Rate (Mb/s)";
  268:             sdcViewModel.Chart.Data2 = (from t in transmitTimestampValueList select (int)(t.Value)).ToList();
  269:  
  270:             sdcViewModel.Chart.Type = "stackedBar";
  271:             sdcViewModel.Chart.Width = 1200;
  272:             sdcViewModel.Chart.Height = 300;
  273:  
  274:             sdcViewModel.Chart.DataBind();
  275:         }
  276:  
  277:         ////////////////////////////////////////////////////////////////////////////
  278:         ////////////////////////////////////////////////////////////////////////////
  279:  
  280:  
  281:  
  282:  
  283:  
  284:  
  285:  
  286:  
  287:  
  288:  
  289:  
  290:         ////////////////////////////////////////////////////////////////////////////
  291:         ////////////////////////////////////////////////////////////////////////////
  292:  
  293:         /// <summary>
  294:         ///
  295:         /// </summary>
  296:         private static void PonBandwidthChartDataBind(ref Ia.Ftn.Wa.Models.Administration.SdcViewModel sdcViewModel)
  297:         {
  298:             var dateTime = DateTime.UtcNow.AddHours(3).AddDays(-PastDays);
  299:  
  300:             var ponNameToTransactionTimestampValueListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueHourlyListDictionary();
  301:  
  302:             var list0 = (from p in ponNameToTransactionTimestampValueListDictionary
  303:                          where p.Value.Any(u => u.Timestamp >= dateTime)
  304:                          select p).ToList();
  305:  
  306:             var list1 = new List<PonNameReceiveTransmitValue>();
  307:  
  308:             foreach (var kvp in list0)
  309:             {
  310:                 list1.Add(new PonNameReceiveTransmitValue()
  311:                 {
  312:                     Name = kvp.Key,
  313:                     Value = kvp.Value.Sum(u => u.Value),
  314:                     ReceiveValue = kvp.Value.Where(u => u.Transaction == Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction.Receive).Sum(u => u.Value),
  315:                     TransmitValue = kvp.Value.Where(u => u.Transaction == Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction.Transmit).Sum(u => u.Value),
  316:                 });
  317:             }
  318:  
  319:             var list2 = (from l in list1 select l).OrderByDescending(u => u.Value).Take(70).ToList();
  320:  
  321:  
  322:             sdcViewModel.Chart = new Ia.Cl.Models.Ui.Chart();
  323:  
  324:             sdcViewModel.Chart.Id = "char";
  325:  
  326:             sdcViewModel.Chart.Labels = (from l in list2 select l.Name).ToList();
  327:  
  328:             sdcViewModel.Chart.Label1 = "PON vs Received Data Rate (Mb/s)";
  329:             sdcViewModel.Chart.Data1 = (from l in list2 select (int)(Ia.Ftn.Cl.Models.Business.Nokia.Sdc.ConvertHourlyByteCountToMegaBitsPerSecond(l.ReceiveValue))).ToList();
  330:  
  331:             sdcViewModel.Chart.Label2 = "PON vs Transmitted Data Rate (Mb/s)";
  332:             sdcViewModel.Chart.Data2 = (from l in list2 select (int)(Ia.Ftn.Cl.Models.Business.Nokia.Sdc.ConvertHourlyByteCountToMegaBitsPerSecond(l.TransmitValue))).ToList();
  333:  
  334:             sdcViewModel.Chart.Type = "stackedBar";
  335:             sdcViewModel.Chart.Width = 1200;
  336:             sdcViewModel.Chart.Height = 300;
  337:  
  338:             sdcViewModel.Chart.DataBind();
  339:         }
  340:  
  341:         ////////////////////////////////////////////////////////////////////////////
  342:         ////////////////////////////////////////////////////////////////////////////
  343:     }
  344:  
  345:     ////////////////////////////////////////////////////////////////////////////
  346:     ////////////////////////////////////////////////////////////////////////////
  347: }