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

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

Fixed Telecommunications Network's Operations Support System Management Intranet (FTN OSS) support class for Nokia's Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore.Internal;
    2: using SimpleImpersonation;
    3: using System;
    4: using System.Collections.Generic;
    5: using System.Configuration;
    6: using System.IO;
    7: using System.Linq;
    8: using System.Text;
    9: using System.Text.Json;
   10: using static Ia.Cl.Models.Db.Temp;
   11: using static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument;
   12: using static Ia.Ftn.Cl.Models.Business.Nokia.Sdc;
   13: using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
   14:  
   15: namespace Ia.Ftn.Cl.Models.Data.Nokia
   16: {
   17:     ////////////////////////////////////////////////////////////////////////////
   18:  
   19:     /// <summary publish="true">
   20:     /// Fixed Telecommunications Network's Operations Support System Management Intranet (FTN OSS) support class for Nokia's Fixed Telecommunications Network (FTN) data model.
   21:     /// </summary>
   22:     /// 
   23:     /// <remarks> 
   24:     /// Copyright © 2018-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   25:     ///
   26:     /// 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
   27:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   28:     ///
   29:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   30:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   31:     /// 
   32:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   33:     /// 
   34:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   35:     /// </remarks> 
   36:     public class Sdc
   37:     {
   38:         private static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> ponNameToTransactionTimestampValueListDictionary, ponNameToTransactionTimestampValueHourlyListDictionary;
   39:  
   40:         private static readonly object objectLock = new object();
   41:  
   42:         //public static readonly string SdcArchiveFilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SdcPonNameToTimestampValueListDictionary " + DateTime.UtcNow.AddHours(3).ToString("yyyy-MM") + ".json";
   43:         public static readonly string SdcArchiveFilePath = @"\\" + ArchiveServerHostIp + @"\Users\Public\Documents\Archive\SdcPonNameToTransactionTimestampValueListDictionary ";
   44:  
   45:         /// <summary/>
   46:         public static string ArchiveServerHostIp { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ArchiveServerHostIp"); } }
   47:  
   48:         /// <summary/>
   49:         public static string ArchiveServerDomain { get { return "dummydomain"; } }
   50:  
   51:         /// <summary/>
   52:         public static string ArchiveServerUserName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ArchiveServerUserName"); } }
   53:  
   54:         /// <summary/>
   55:         public static string ArchiveServerPassword { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ArchiveServerPassword"); } }
   56:  
   57:         ////////////////////////////////////////////////////////////////////////////
   58:  
   59:         /// <summary>
   60:         ///
   61:         /// </summary>
   62:         public Sdc() { }
   63:  
   64:         ////////////////////////////////////////////////////////////////////////////
   65:  
   66:         /// <summary>
   67:         ///
   68:         /// </summary>
   69:         public static List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> ReadTransactionTimestampHourlyValueListOfPon(Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction transaction, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon)
   70:         {
   71:             var transactionTimestampValueList0 = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.TransactionTimestampValueHourlyListByPonName(pon.Name);
   72:  
   73:             var transactionTimestampValueList = Ia.Ftn.Cl.Models.Business.Nokia.Sdc.AdjustTransactionTimestampHourlyValueList(transaction, transactionTimestampValueList0);
   74:  
   75:             return transactionTimestampValueList;
   76:         }
   77:  
   78:         ////////////////////////////////////////////////////////////////////////////
   79:  
   80:         /// <summary>
   81:         ///
   82:         /// </summary>
   83:         public static List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> TransactionTimestampValueListByPonName(string ponName)
   84:         {
   85:             List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> list;
   86:  
   87:             var d = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueListDictionary();
   88:  
   89:             if (d.ContainsKey(ponName)) list = d[ponName];
   90:             else list = new List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
   91:  
   92:             return list;
   93:         }
   94:  
   95:         ////////////////////////////////////////////////////////////////////////////
   96:  
   97:         /// <summary>
   98:         ///
   99:         /// </summary>
  100:         public static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> PonNameToTransactionTimestampValueListDictionary()
  101:         {
  102:             return Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueListDictionary(false);
  103:         }
  104:  
  105:         ////////////////////////////////////////////////////////////////////////////
  106:  
  107:         /// <summary>
  108:         ///
  109:         /// </summary>
  110:         public static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> PonNameToTransactionTimestampValueListDictionary(bool resetContent)
  111:         {
  112:             if (ponNameToTransactionTimestampValueListDictionary == null || ponNameToTransactionTimestampValueListDictionary.Count == 0 || resetContent)
  113:             {
  114:                 lock (objectLock)
  115:                 {
  116:                     ponNameToTransactionTimestampValueListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc._PonNameToTransactionTimestampValueListDictionaryFromArchiveServer();
  117:                 }
  118:             }
  119:  
  120:             return ponNameToTransactionTimestampValueListDictionary;
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:  
  125:         /// <summary>
  126:         ///
  127:         /// </summary>
  128:         private static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> _PonNameToTransactionTimestampValueListDictionaryFromArchiveServer()
  129:         {
  130:             try
  131:             {
  132:                 var userCredentials = new UserCredentials(Ia.Ftn.Cl.Models.Data.Nokia.Sdc.ArchiveServerDomain,
  133:                     Ia.Ftn.Cl.Models.Data.Nokia.Sdc.ArchiveServerUserName,
  134:                     Ia.Ftn.Cl.Models.Data.Nokia.Sdc.ArchiveServerPassword);
  135:  
  136:                 Impersonation.RunAsUser(userCredentials, LogonType.NewCredentials, () =>
  137:                 {
  138:                     var zipBytes = File.ReadAllBytes(SdcArchiveFilePath + DateTime.UtcNow.AddHours(3).ToString("yyyy-MM") + ".zip.bytes");
  139:  
  140:                     string json = Ia.Cl.Models.Zip.UnzipString(zipBytes);
  141:  
  142:                     ponNameToTransactionTimestampValueListDictionary = JsonSerializer.Deserialize<Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>>>(json);
  143:                 });
  144:             }
  145:             catch (Exception e)
  146:             {
  147:             }
  148:  
  149:             // default value
  150:             if (ponNameToTransactionTimestampValueListDictionary == null)
  151:             {
  152:                 ponNameToTransactionTimestampValueListDictionary = new Dictionary<string, List<Business.Nokia.Sdc.TransactionTimestampValue>>();
  153:             }
  154:  
  155:             return ponNameToTransactionTimestampValueListDictionary;
  156:         }
  157:  
  158:         ////////////////////////////////////////////////////////////////////////////
  159:  
  160:         /// <summary>
  161:         ///
  162:         /// </summary>
  163:         public static void SaveTransactionTimestampValueListOfPon(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon, Ia.Ftn.Cl.Models.Business.Nokia.Sdc.Transaction transaction, DateTime timestampDateTime, List<long> valueList)
  164:         {
  165:             var ponNameToTransactionTimestampValueListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueListDictionary();
  166:  
  167:             // debug
  168:             /*
  169:             if (ponNameToTimestampValueListDictionary == null || ponNameToTimestampValueListDictionary.Count == 0)
  170:             {
  171:                 ponNameToTimestampValueListDictionary = new Dictionary<string, List<Business.Nokia.Sdc.TimestampValue>>();
  172:             }
  173:             */
  174:  
  175:             if (ponNameToTransactionTimestampValueListDictionary.ContainsKey(pon.Name))
  176:             {
  177:                 if (ponNameToTransactionTimestampValueListDictionary[pon.Name] == null)
  178:                 {
  179:                     ponNameToTransactionTimestampValueListDictionary[pon.Name] = new List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
  180:                 }
  181:             }
  182:             else ponNameToTransactionTimestampValueListDictionary[pon.Name] = new List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
  183:  
  184:             var transactiontimestampValueList = ponNameToTransactionTimestampValueListDictionary[pon.Name];
  185:  
  186:             int i = 1;
  187:  
  188:             foreach (var v in valueList)
  189:             {
  190:                 if (!transactiontimestampValueList.Any(u => u.Transaction == transaction && u.Timestamp.DayOfYear == timestampDateTime.DayOfYear && u.Timestamp.Hour == timestampDateTime.Hour && u.Value == v))
  191:                 {
  192:                     var transactionTimestampValue = new TransactionTimestampValue(transaction, timestampDateTime.AddMinutes(-i * 5), v);
  193:  
  194:                     ponNameToTransactionTimestampValueListDictionary[pon.Name].Add(transactionTimestampValue);
  195:                 }
  196:                 else
  197:                 {
  198:                 }
  199:  
  200:                 i++;
  201:             }
  202:         }
  203:  
  204:         ////////////////////////////////////////////////////////////////////////////
  205:  
  206:         /// <summary>
  207:         ///
  208:         /// </summary>
  209:         public static void WritePonNameToTransactionTimestampValueHourlyListDictionaryToJsonFile()
  210:         {
  211:             var now = DateTime.UtcNow.AddHours(3);
  212:  
  213:             var startOfThisMonth = new DateTime(now.Year, now.Month, 1, 0, 0, 0);
  214:  
  215:             var filteredPonNameToTransactionTimestampValueHourlyListDictionary = new Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>>();
  216:  
  217:             var ponNameToTransactionTimestampValueHourlyListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueHourlyListDictionary(true);
  218:             //var ponNameToTransactionTimestampValueListDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Sdc.PonNameToTransactionTimestampValueListDictionary();
  219:  
  220:             if (ponNameToTransactionTimestampValueHourlyListDictionary != null)
  221:             {
  222:                 foreach (var ponName in ponNameToTransactionTimestampValueHourlyListDictionary.Keys)
  223:                 {
  224:                     var transactionTimestampValueList = ponNameToTransactionTimestampValueHourlyListDictionary[ponName];
  225:  
  226:                     foreach (var transactionTimestampValue in transactionTimestampValueList)
  227:                     {
  228:                         if (transactionTimestampValue.Timestamp >= startOfThisMonth)
  229:                         {
  230:                             if (!filteredPonNameToTransactionTimestampValueHourlyListDictionary.ContainsKey(ponName))
  231:                             {
  232:                                 filteredPonNameToTransactionTimestampValueHourlyListDictionary[ponName] = new List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
  233:                             }
  234:  
  235:                             filteredPonNameToTransactionTimestampValueHourlyListDictionary[ponName].Add(transactionTimestampValue);
  236:                         }
  237:                     }
  238:                 }
  239:  
  240:                 var json = JsonSerializer.Serialize(filteredPonNameToTransactionTimestampValueHourlyListDictionary);
  241:  
  242:                 byte[] zipBytes = Ia.Cl.Models.Zip.ZipString(json);
  243:  
  244:                 File.WriteAllBytes(SdcArchiveFilePath + DateTime.UtcNow.AddHours(3).ToString("yyyy-MM") + ".zip.bytes", zipBytes);
  245:             }
  246:             else
  247:             {
  248:             }
  249:         }
  250:  
  251:         ////////////////////////////////////////////////////////////////////////////
  252:  
  253:         /// <summary>
  254:         ///
  255:         /// </summary>
  256:         public static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> PonNameToTransactionTimestampValueHourlyListDictionary()
  257:         {
  258:             return Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueHourlyListDictionary(false);
  259:         }
  260:  
  261:         ////////////////////////////////////////////////////////////////////////////
  262:  
  263:         /// <summary>
  264:         ///
  265:         /// </summary>
  266:         public static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> PonNameToTransactionTimestampValueHourlyListDictionary(bool recalculateContent)
  267:         {
  268:             if (ponNameToTransactionTimestampValueHourlyListDictionary == null || ponNameToTransactionTimestampValueHourlyListDictionary.Count == 0 || recalculateContent)
  269:             {
  270:                 lock (objectLock)
  271:                 {
  272:                     ponNameToTransactionTimestampValueHourlyListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc._PonNameToTransactionTimestampValueHourlyListDictionary();
  273:                 }
  274:             }
  275:  
  276:             return ponNameToTransactionTimestampValueHourlyListDictionary;
  277:         }
  278:  
  279:         ////////////////////////////////////////////////////////////////////////////
  280:  
  281:         /// <summary>
  282:         ///
  283:         /// </summary>
  284:         private static Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>> _PonNameToTransactionTimestampValueHourlyListDictionary()
  285:         {
  286:             string key;
  287:             DateTime dateTime;
  288:  
  289:             var ponNameToTransactionTimestampValueListDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.PonNameToTransactionTimestampValueListDictionary();
  290:  
  291:             var dictionary = new Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>>();
  292:  
  293:             foreach (var ponName in ponNameToTransactionTimestampValueListDictionary.Keys)
  294:             {
  295:                 var transactionTimestampToTransactionTimestampValueDictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
  296:  
  297:                 var list = ponNameToTransactionTimestampValueListDictionary[ponName];
  298:  
  299:                 foreach (var l in list)
  300:                 {
  301:                     dateTime = new DateTime(l.Timestamp.Year, l.Timestamp.Month, l.Timestamp.Day, l.Timestamp.Hour, 0, 0);
  302:  
  303:                     key = l.Transaction + ":" + dateTime;
  304:  
  305:                     if (!transactionTimestampToTransactionTimestampValueDictionary.ContainsKey(key)) transactionTimestampToTransactionTimestampValueDictionary[key] = new Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue(l.Transaction, dateTime, 0);
  306:  
  307:                     if (transactionTimestampToTransactionTimestampValueDictionary.ContainsKey(key)) transactionTimestampToTransactionTimestampValueDictionary[key].Value += l.Value;
  308:                     else
  309:                     {
  310:                         transactionTimestampToTransactionTimestampValueDictionary[key] = new Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue(l.Transaction, dateTime, l.Value);
  311:                     }
  312:                 }
  313:  
  314:                 dictionary[ponName] = transactionTimestampToTransactionTimestampValueDictionary.Values.OrderBy(u => u.Timestamp).ToList();
  315:             }
  316:  
  317:             return dictionary;
  318:         }
  319:  
  320:         ////////////////////////////////////////////////////////////////////////////
  321:  
  322:         /// <summary>
  323:         ///
  324:         /// </summary>
  325:         public static List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue> TransactionTimestampValueHourlyListByPonName(string ponName)
  326:         {
  327:             string key;
  328:             DateTime dateTime;
  329:  
  330:             var transactionTimestampValueList = Ia.Ftn.Cl.Models.Data.Nokia.Sdc.TransactionTimestampValueListByPonName(ponName);
  331:  
  332:             var dictionary = new Dictionary<string, List<Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>>();
  333:  
  334:             var transactionTimestampToTransactionTimestampValueDictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue>();
  335:  
  336:             foreach (var l in transactionTimestampValueList)
  337:             {
  338:                 dateTime = new DateTime(l.Timestamp.Year, l.Timestamp.Month, l.Timestamp.Day, l.Timestamp.Hour, 0, 0);
  339:  
  340:                 key = l.Transaction + ":" + dateTime;
  341:  
  342:                 if (!transactionTimestampToTransactionTimestampValueDictionary.ContainsKey(key)) transactionTimestampToTransactionTimestampValueDictionary[key] = new Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue(l.Transaction, dateTime, 0);
  343:  
  344:                 if (transactionTimestampToTransactionTimestampValueDictionary.ContainsKey(key)) transactionTimestampToTransactionTimestampValueDictionary[key].Value += l.Value;
  345:                 else
  346:                 {
  347:                     transactionTimestampToTransactionTimestampValueDictionary[key] = new Ia.Ftn.Cl.Models.Business.Nokia.Sdc.TransactionTimestampValue(l.Transaction, dateTime, l.Value);
  348:                 }
  349:             }
  350:  
  351:             var list = transactionTimestampToTransactionTimestampValueDictionary.Values.OrderBy(u => u.Timestamp).ToList();
  352:  
  353:             return list;
  354:         }
  355:  
  356:         ////////////////////////////////////////////////////////////////////////////
  357:         ////////////////////////////////////////////////////////////////////////////
  358:     }
  359:  
  360:     ////////////////////////////////////////////////////////////////////////////
  361:     ////////////////////////////////////////////////////////////////////////////   
  362: }