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

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

Default mdaa network information support class for the Fixed Telecommunications Network business model

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.IO;
    5: using System.Linq;
    6: using System.Text;
    7: using System.Text.Json;
    8: using System.Text.RegularExpressions;
    9: using System.Threading;
   10: using System.Threading.Tasks;
   11:  
   12: namespace Ia.Ftn.Cl.Models.Business.Mdaa
   13: {
   14:     ////////////////////////////////////////////////////////////////////////////
   15:  
   16:     /// <summary publish="true">
   17:     /// Default mdaa network information support class for the Fixed Telecommunications Network business model
   18:     /// </summary>
   19:     /// 
   20:     /// <remarks> 
   21:     /// Copyright © 2021-2022 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 Default
   34:     {
   35:         private static readonly string archive = @"\\Jabriya\Users\Public\Documents\Archive\Mdaa\";
   36:  
   37:         private static Ia.Ftn.Mdaa.Cl.Models.Business.DatabaseInformation databaseInformation = new Ia.Ftn.Mdaa.Cl.Models.Business.DatabaseInformation();
   38:  
   39:         private static Ia.Cl.Models.Db.Oracle oracle;
   40:  
   41:         private static readonly object objectLock = new object();
   42:  
   43:         public const bool ApplicationIsDisconnectedFromMinistryNetworkForDebugging = true;
   44:  
   45:         ////////////////////////////////////////////////////////////////////////////
   46:  
   47:         /// <summary>
   48:         ///
   49:         /// </summary>
   50:         public Default() { }
   51:  
   52:         ////////////////////////////////////////////////////////////////////////////
   53:  
   54:         /// <summary>
   55:         ///
   56:         /// </summary>
   57:         public static Ia.Cl.Models.Result InitializeOracleConnection()
   58:         {
   59:             var result = new Ia.Cl.Models.Result();
   60:  
   61:             if (!ApplicationIsDisconnectedFromMinistryNetworkForDebugging)
   62:             {
   63:                 //var oracleConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"].ToString();
   64:                 var oracleConnectionString = "DATA SOURCE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.139)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.36)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MOCDB))) IBM1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.139)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MOCDB) (INSTANCE_NAME=MOCDB1))) IBM2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.36)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MOCDB) (INSTANCE_NAME=MOCDB2)));PERSIST SECURITY INFO=True;USER ID=NGNUSER;PASSWORD=NGN;ENLIST=True";
   65:  
   66:                 try
   67:                 {
   68:                     oracle = new Ia.Cl.Models.Db.Oracle(oracleConnectionString);
   69:  
   70:                     oracle.Sql(Ia.Ftn.Cl.Models.Business.Mdaa.MinistryDatabase.AlterSessionOfCustomerDepartmentOracleDatabase);
   71:  
   72:                     result.AddSuccess("Initialize Oracle Connection: Success");
   73:                 }
   74:                 catch (Exception ex)
   75:                 {
   76:                     result.AddError("Initialize Oracle Connection: Error: Exception: " + ex.Message);
   77:                 }
   78:             }
   79:  
   80:             return result;
   81:         }
   82:  
   83:         ////////////////////////////////////////////////////////////////////////////
   84:  
   85:         /// <summary>
   86:         ///
   87:         /// </summary>
   88:         public static Ia.Cl.Models.Result Collect()
   89:         {
   90:             var result = new Ia.Cl.Models.Result();
   91:  
   92:             databaseInformation.Read();
   93:  
   94:             var tableList = databaseInformation.TableInformationList;
   95:  
   96:             var i = 0;
   97:             foreach (var table in tableList)
   98:             {
   99:                 var tableInformation = CollectTableInformationFromMocdbOracleDatabase(table.Name, table.Schema);
  100:  
  101:                 databaseInformation.Update(tableInformation);
  102:  
  103:                 result.AddSuccess("Collect: table name: " + table.Name + ", number: " + i++);
  104:  
  105:                 Thread.Sleep(2000);
  106:  
  107:                 //if (i == 4) break;
  108:             }
  109:  
  110:             return result;
  111:         }
  112:  
  113:         ////////////////////////////////////////////////////////////////////////////
  114:  
  115:         /// <summary>
  116:         ///
  117:         /// </summary>
  118:         public static Ia.Cl.Models.Result Analisys()
  119:         {
  120:             var result = new Ia.Cl.Models.Result();
  121:  
  122:             var stringBuilder = new StringBuilder();
  123:  
  124:             string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\analysis.html";
  125:  
  126:             databaseInformation.Read();
  127:  
  128:             stringBuilder.AppendLine(@"<html><head><style>
  129:   span {color:red;}
  130: </style></head><body><pre>");
  131:  
  132:             stringBuilder.AppendLine("Number of tables: " + databaseInformation.TableInformationList.Count);
  133:  
  134:             var i = 1000;
  135:             var c = (from ti in databaseInformation.TableInformationList where ti.Count > i select ti).Count();
  136:  
  137:             stringBuilder.AppendLine("Number of tables with over " + i + " records: " + c);
  138:  
  139:             stringBuilder.AppendLine("<hr/>");
  140:  
  141:             var distinctSchemaList = (from ti in databaseInformation.TableInformationList
  142:                                       where ti.Count > 0
  143:                                       select ti.Schema).Distinct();
  144:  
  145:             stringBuilder.AppendLine("Distinct Schema: " + string.Join(", ", distinctSchemaList));
  146:  
  147:             stringBuilder.AppendLine("<hr/>");
  148:  
  149:             stringBuilder.AppendLine("<dl>");
  150:  
  151:             foreach (var schema in distinctSchemaList)
  152:             {
  153:                 var tableList = (from ti in databaseInformation.TableInformationList
  154:                                  where ti.Schema == schema && ti.Count > 0
  155:                                  select ti).ToList();
  156:  
  157:                 //stringBuilder.AppendLine("Schema: " + schema); // tables: " + string.Join(", ", tableList.));
  158:                 //stringBuilder.AppendLine();
  159:  
  160:                 foreach (var table in tableList)
  161:                 {
  162:                     stringBuilder.AppendLine("<dt>Table: " + table.Name + ", Schema: " + table.Schema + ", Record count: <span>" + table.Count + "</span></dt>");
  163:  
  164:                     // "Desc": "COLUMN_NAME\tDATATYPE_LENGTH\t\r\nFEEDER_ID\tNUMBER(22)\t\r\nFEEDER_NAME\tVARCHAR2(300)\t\r\nMDF_PAIR\tNUMBER(22)\t\r\nREMARKS\tVARCHAR2(500)\t\r\nFEEDER_BOX_ID\tNUMBER(22)\t\r\nE_DATE\tDATE(7)\t\r\nE_USER\tVARCHAR2(30)\t\r\nL_DATE\tDATE(7)\t\r\nL_USER\tVARCHAR2(30)\t\r\n",
  165:                     //      "TopRecordText": "\r\n"
  166:  
  167:                     stringBuilder.AppendLine("<dd>");
  168:                     var desc = table.Desc;
  169:  
  170:                     stringBuilder.AppendLine("Database fields: ");
  171:                     stringBuilder.AppendLine(table.Desc);
  172:                     stringBuilder.AppendLine();
  173:                     stringBuilder.AppendLine("TopRecordText: ");
  174:                     stringBuilder.AppendLine(table.TopRecordText);
  175:                     stringBuilder.AppendLine("</dd>");
  176:  
  177:                     stringBuilder.AppendLine("<hr/>");
  178:                 }
  179:  
  180:                 stringBuilder.AppendLine("<hr/>");
  181:             }
  182:  
  183:             stringBuilder.AppendLine("</dl>");
  184:  
  185:             stringBuilder.AppendLine("</pre></body></html>");
  186:  
  187:             File.WriteAllText(filePath, stringBuilder.ToString());
  188:  
  189:             return result;
  190:         }
  191:  
  192:         ////////////////////////////////////////////////////////////////////////////
  193:  
  194:         /// <summary>
  195:         ///
  196:         /// </summary>
  197:         private static Ia.Ftn.Mdaa.Cl.Models.Business.TableInformation CollectTableInformationFromMocdbOracleDatabase(string tableName, string tableSchema)
  198:         {
  199:             int count;
  200:  
  201:             var countSql = "select count(*) from " + tableName;
  202:             var sql = "select * from " + tableName + " where rownum <= 10";
  203:  
  204:             var tableInformation = new Ia.Ftn.Mdaa.Cl.Models.Business.TableInformation();
  205:  
  206:             try
  207:             {
  208:                 var countString = oracle.Scalar(countSql);
  209:                 var descDt = oracle.Desc(tableName, tableSchema);
  210:                 var dt = oracle.Select(sql);
  211:  
  212:                 if (int.TryParse(countString, out count)) { }
  213:                 else count = 0;
  214:  
  215:                 tableInformation.Schema = tableSchema;
  216:                 tableInformation.Name = tableName;
  217:                 tableInformation.Count = count;
  218:                 tableInformation.Desc = Ia.Cl.Models.Default.GenerateTabSeparatedTextFromDataTable(descDt);
  219:                 tableInformation.TopRecordText = Ia.Cl.Models.Default.GenerateTabSeparatedTextFromDataTable(dt);
  220:             }
  221:             catch (Exception ex)
  222:             {
  223:  
  224:             }
  225:  
  226:             return tableInformation;
  227:         }
  228:  
  229:         ////////////////////////////////////////////////////////////////////////////
  230:  
  231:         /// <summary>
  232:         ///
  233:         /// </summary>
  234:         public static Ia.Cl.Models.Result ManageProperly(ref int properlySelectedHundredsSubdomainListIndex)
  235:         {
  236:             List<string> addedServiceList, removedServiceList;
  237:  
  238:             var result = new Ia.Cl.Models.Result();
  239:  
  240:             var hundredsSubdomain = Ia.Ftn.Cl.Models.Business.Mdaa.MinistryDatabase.ProperlySelectedHundredsSubdomainListItem(ref properlySelectedHundredsSubdomainListIndex, out int itemIndex, out int listCount);
  241:  
  242:             var dataTable = ReadHundredsSubdomainBalanceListItemDataTable(hundredsSubdomain);
  243:  
  244:             var serviceStateThatCrossedThresholdList = UpdateServiceStateThatCrossedThresholdList(hundredsSubdomain, dataTable, out addedServiceList, out removedServiceList);
  245:  
  246:             var s = string.Empty;
  247:  
  248:             if (hundredsSubdomain.PstnId != 0) s += "Legacy: " + hundredsSubdomain.Pstn.Name + ": ";
  249:             if (hundredsSubdomain.RouterId != 0) s += "Ims: " + hundredsSubdomain.Router.Name + ": ";
  250:  
  251:             var r = s
  252:                 + hundredsSubdomain.FirstServiceNumber + "-" + hundredsSubdomain.LastServiceNumber + " "
  253:                 + "(" + itemIndex + "/" + listCount + "): "
  254:                 + "list (total): " + serviceStateThatCrossedThresholdList.Count + " (" + Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateThatCrossedThresholdList.Count + "), "
  255:                 + "added (total): " + addedServiceList.Count + " (" + Ia.Ftn.Cl.Models.Data.MinistryDatabase.AddedServiceList.Count + "), "
  256:                 + "removed (total): " + removedServiceList.Count + " (" + Ia.Ftn.Cl.Models.Data.MinistryDatabase.RemovedServiceList.Count + ")";
  257:  
  258:             result.AddSuccess(r);
  259:  
  260:             return result;
  261:         }
  262:  
  263:         ////////////////////////////////////////////////////////////////////////////
  264:  
  265:         /// <summary>
  266:         ///
  267:         /// </summary>4
  268:         public static Ia.Cl.Models.Result ManageTransaction()
  269:         {
  270:             var result = new Ia.Cl.Models.Result();
  271:  
  272:             var serviceTransactionList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceTransactionList;
  273:  
  274:             var latestTransactionId = serviceTransactionList.Count > 0 ? serviceTransactionList.Max(u => u.TransactionId) : 0;
  275:  
  276:             var dataTable = ReadPaymentTransactionOfThePreviousNDaysServiceDataTable(latestTransactionId, 2);
  277:  
  278:             serviceTransactionList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceSerialTransactionIdDateTimeListFromTransactionListDataTable(dataTable);
  279:  
  280:             Ia.Ftn.Cl.Models.Data.MinistryDatabase.Update(serviceTransactionList, out List<string> addedServiceTransactionList);
  281:  
  282:             var r =
  283:                 "list (total): " + serviceTransactionList.Count + " (" + Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceTransactionList.Count + "), "
  284:                 + "added: " + addedServiceTransactionList.Count;
  285:  
  286:             result.AddSuccess(r);
  287:  
  288:             return result;
  289:         }
  290:  
  291:         ////////////////////////////////////////////////////////////////////////////
  292:  
  293:         /// <summary>
  294:         ///
  295:         /// </summary>
  296:         public static Ia.Cl.Models.Result ManageAnalyzeTransaction()
  297:         {
  298:             List<string> addedServiceList, removedServiceList;
  299:  
  300:             var result = new Ia.Cl.Models.Result();
  301:  
  302:             var examinedServiceTransactionIdList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ExaminedServiceTransactionIdList;
  303:  
  304:             var serviceTransactionList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceTransactionList; // note that ServiceTransactionList is not sorted here, it will be sorted just below
  305:  
  306:             var serviceTransaction = (from st in serviceTransactionList
  307:                                       where !examinedServiceTransactionIdList.Contains(st.TransactionId)
  308:                                       select st).OrderBy(u => u.TransactionId).LastOrDefault();
  309:  
  310:             var r = string.Empty;
  311:  
  312:             if (!string.IsNullOrEmpty(serviceTransaction.Service))
  313:             {
  314:                 r = "reading: " + serviceTransaction.Service;
  315:  
  316:                 var dataTable = ReadASingleServiceNumberBalanceDataTable(int.Parse(serviceTransaction.Service));
  317:  
  318:                 if (dataTable != null)
  319:                 {
  320:                     var hundredsSubdomain = new Ia.Ftn.Cl.Models.Business.Service.HundredsSubdomain(serviceTransaction.Service);
  321:  
  322:                     if (hundredsSubdomain.Subdomain != 0)
  323:                     {
  324:                         var serviceStateThatCrossedThresholdList = UpdateServiceStateThatCrossedThresholdList(hundredsSubdomain, dataTable, out addedServiceList, out removedServiceList);
  325:  
  326:                         Ia.Ftn.Cl.Models.Data.MinistryDatabase.ExaminedServiceTransactionIdList.Add(serviceTransaction.TransactionId);
  327:                     }
  328:                     else
  329:                     {
  330:                         Ia.Ftn.Cl.Models.Data.MinistryDatabase.ExaminedServiceTransactionIdList.Add(serviceTransaction.TransactionId);
  331:                     }
  332:                 }
  333:                 else
  334:                 {
  335:                 }
  336:             }
  337:             else r = "reading: no pending services to read";
  338:  
  339:             result.AddSuccess(r);
  340:  
  341:             return result;
  342:         }
  343:  
  344:         ////////////////////////////////////////////////////////////////////////////
  345:  
  346:         /// <summary>
  347:         ///
  348:         /// </summary>
  349:         public static Ia.Cl.Models.Result ManageMessageQueue()
  350:         {
  351:             var result = new Ia.Cl.Models.Result();
  352:  
  353:             var queueCount = Ia.Ftn.Cl.Models.Data.MessageQueue.MdaaApplication.Count;
  354:  
  355:             if (queueCount > 0)
  356:             {
  357:                 var message = Ia.Ftn.Cl.Models.Data.MessageQueue.MdaaApplication.Dequeue;
  358:  
  359:                 if (message != null)
  360:                 {
  361:                     if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ReadService)
  362:                     {
  363:  
  364:                         result.AddSuccess(message.Service);
  365:                     }
  366:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.Synchronize)
  367:                     {
  368:                         //var r = ManageSynchronization();
  369:  
  370:                         //result.AddResult(r);
  371:                     }
  372:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ActiveApplicationRunningPermissionState)
  373:                     {
  374:                         Ia.Ftn.Cl.Models.Business.Default.PermitActiveApplicationsToRun = message.State;
  375:  
  376:                         result.AddSuccess("PermitActiveApplicationsToRun: " + message.State);
  377:                     }
  378:                     else
  379:                     {
  380:                         throw new ArgumentOutOfRangeException("MessageQueue process " + message.Process.ToString() + " is undefined");
  381:                     }
  382:                 }
  383:                 else
  384:                 {
  385:                 }
  386:             }
  387:             else
  388:             {
  389:             }
  390:  
  391:             return result;
  392:         }
  393:  
  394:         ////////////////////////////////////////////////////////////////////////////
  395:  
  396:         /// <summary>
  397:         ///
  398:         /// </summary>
  399:         private static List<Ia.Ftn.Cl.Models.Business.Mdaa.MinistryDatabase.ServiceState> UpdateServiceStateThatCrossedThresholdList(Ia.Ftn.Cl.Models.Business.Service.HundredsSubdomain hundredsSubdomain, DataTable dataTable, out List<string> addedServiceList, out List<string> removedServiceList)
  400:         {
  401:             var serviceStateList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateListFromHundredsSubdomainListDataTable(hundredsSubdomain, dataTable);
  402:  
  403:             var serviceStateWithLatestSerialList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.FilterServiceStateListByServicesWithLatestSerial(serviceStateList);
  404:  
  405:             var serviceStateThatCrossedThresholdList = Ia.Ftn.Cl.Models.Data.MinistryDatabase.FilterServiceStateListByServicesThatCrossedAdministrativeDisconnectionBalanceThresholdList(serviceStateWithLatestSerialList);
  406:  
  407:             Ia.Ftn.Cl.Models.Data.MinistryDatabase.Update(hundredsSubdomain, serviceStateThatCrossedThresholdList, out addedServiceList, out removedServiceList);
  408:  
  409:             return serviceStateThatCrossedThresholdList;
  410:         }
  411:  
  412:         ////////////////////////////////////////////////////////////////////////////
  413:  
  414:         /// <summary>
  415:         ///
  416:         /// </summary>
  417:         public static Ia.Cl.Models.Result ManageSynchronization()
  418:         {
  419:             var result = new Ia.Cl.Models.Result();
  420:  
  421:             var addedList = new List<string>();
  422:             var removedList = new List<string>();
  423:  
  424:             foreach (var service in Ia.Ftn.Cl.Models.Data.MinistryDatabase.AddedServiceList)
  425:             {
  426:                 var task = Ia.Cl.Models.Http.PostAsync("http://ftn", "api/v2/service-request-administrative-issues/" + service);
  427:                 task.Wait();
  428:                 var v = task.Result;
  429:  
  430:                 if (v.Contains(@"""IsSuccessful"":true")) addedList.Add(service);
  431:             }
  432:  
  433:             foreach (var service in Ia.Ftn.Cl.Models.Data.MinistryDatabase.RemovedServiceList)
  434:             {
  435:                 var task = Ia.Cl.Models.Http.DeleteAsync("http://ftn", "api/v2/service-request-administrative-issues/" + service);
  436:                 task.Wait();
  437:                 var v = task.Result;
  438:  
  439:                 if (v.Contains(@"""IsSuccessful"":true")) removedList.Add(service);
  440:             }
  441:  
  442:             foreach (var v in addedList)
  443:             {
  444:                 Ia.Ftn.Cl.Models.Data.MinistryDatabase.AddedServiceList.Remove(v);
  445:             }
  446:  
  447:             foreach (var v in removedList)
  448:             {
  449:                 Ia.Ftn.Cl.Models.Data.MinistryDatabase.RemovedServiceList.Remove(v);
  450:             }
  451:  
  452:             var r = " added service list: [" + string.Join(" ", addedList) + "], removed service list: [" + string.Join(" ", removedList) + "] ";
  453:  
  454:             result.AddSuccess(r);
  455:  
  456:             return result;
  457:         }
  458:  
  459:         ////////////////////////////////////////////////////////////////////////////
  460:  
  461:         /// <summary>
  462:         ///
  463:         /// </summary>
  464:         public static Ia.Cl.Models.Result Information()
  465:         {
  466:             var result = new Ia.Cl.Models.Result();
  467:  
  468:             var r = "ExaminedServiceTransactionIdList count: " + Ia.Ftn.Cl.Models.Data.MinistryDatabase.ExaminedServiceTransactionIdList.Count + "\r\n"
  469:         + "AddedServiceList count: " + Ia.Ftn.Cl.Models.Data.MinistryDatabase.AddedServiceList.Count + "\r\n"
  470:         + "RemovedServiceList count: " + Ia.Ftn.Cl.Models.Data.MinistryDatabase.RemovedServiceList.Count + "\r\n"
  471:         + "ServiceStateThatCrossedThresholdList count: " + Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateThatCrossedThresholdList.Count + "\r\n"
  472:         + "ServiceStateThatCrossedThresholdList: " + string.Join(", ", Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateThatCrossedThresholdList.Select(u => u.Service)) + "\r\n"
  473:         + "ServiceTransactionList count: " + Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceTransactionList.Count + "\r\n";
  474:  
  475:             result.AddSuccess(r);
  476:  
  477:             return result;
  478:         }
  479:  
  480:         ////////////////////////////////////////////////////////////////////////////
  481:  
  482:         /// <summary>
  483:         ///
  484:         /// </summary>
  485:         public static DataTable ReadHundredsSubdomainBalanceListItemDataTable(Ia.Ftn.Cl.Models.Business.Service.HundredsSubdomain hundredsSubdomain)
  486:         {
  487:             DataTable dateTable = null;
  488:  
  489:             var sql = Ia.Ftn.Cl.Models.Data.MinistryDatabase.OracleSqlCommandToReadBalanceForRangeOfAHundredsSubdomain(hundredsSubdomain);
  490:  
  491:             if (oracle != null)
  492:             {
  493:                 try
  494:                 {
  495:                     dateTable = oracle.Select(sql);
  496:                 }
  497:                 catch (Exception)
  498:                 {
  499:                     InitializeOracleConnection();
  500:  
  501:                     dateTable = oracle.Select(sql);
  502:                 }
  503:             }
  504:  
  505:             if (dateTable != null) dateTable.TableName = sql;
  506:  
  507:             return dateTable;
  508:         }
  509:  
  510:         ////////////////////////////////////////////////////////////////////////////
  511:  
  512:         /// <summary>
  513:         ///
  514:         /// </summary>
  515:         public static DataTable ReadASingleServiceNumberBalanceDataTable(int serviceNumber)
  516:         {
  517:             DataTable dateTable = null;
  518:  
  519:             var sql = Ia.Ftn.Cl.Models.Data.MinistryDatabase.OracleSqlCommandToReadBalanceOfASingleServiceNumber(serviceNumber);
  520:  
  521:             if (oracle != null)
  522:             {
  523:                 try
  524:                 {
  525:                     dateTable = oracle.Select(sql);
  526:                 }
  527:                 catch (Exception)
  528:                 {
  529:                     InitializeOracleConnection();
  530:  
  531:                     dateTable = oracle.Select(sql);
  532:                 }
  533:             }
  534:  
  535:             if (dateTable != null) dateTable.TableName = sql;
  536:  
  537:             return dateTable;
  538:         }
  539:  
  540:         ////////////////////////////////////////////////////////////////////////////
  541:  
  542:         /// <summary>
  543:         ///
  544:         /// </summary>
  545:         public static void SaveServiceStateThatCrossedThresholdListToFile()
  546:         {
  547:             var list = Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateThatCrossedThresholdList;
  548:  
  549:             var jsonSerializerOptions = new JsonSerializerOptions
  550:             {
  551:                 WriteIndented = true
  552:             };
  553:  
  554:             var text = JsonSerializer.Serialize(list, jsonSerializerOptions);
  555:  
  556:             SaveContentInADateTimeNamedFileInArchive(text);
  557:         }
  558:  
  559:         ////////////////////////////////////////////////////////////////////////////
  560:  
  561:         /// <summary>
  562:         ///
  563:         /// </summary>
  564:         public static void ReadServiceStateThatCrossedThresholdListFromFile()
  565:         {
  566:             if (!ApplicationIsDisconnectedFromMinistryNetworkForDebugging)
  567:             {
  568:                 var text = ReadContentOfLatestFileInArchive();
  569:  
  570:                 if (!string.IsNullOrEmpty(text))
  571:                 {
  572:                     var list = JsonSerializer.Deserialize<List<Ia.Ftn.Cl.Models.Business.Mdaa.MinistryDatabase.ServiceState>>(text);
  573:  
  574:                     Ia.Ftn.Cl.Models.Data.MinistryDatabase.ServiceStateThatCrossedThresholdList = list.ToList();
  575:                 }
  576:             }
  577:         }
  578:  
  579:         ////////////////////////////////////////////////////////////////////////////
  580:  
  581:         /// <summary>
  582:         ///
  583:         /// </summary>
  584:         private static void SaveContentInADateTimeNamedFileInArchive(string content)
  585:         {
  586:             var now = DateTime.UtcNow.AddHours(3);
  587:  
  588:             var archiveDirectory = archive + now.ToString("yyyy-MM-dd") + @"\";
  589:             var archiveFileName = archiveDirectory + now.ToString("HH-mm-ss-fff") + @".txt";
  590:  
  591:             lock (objectLock)
  592:             {
  593:                 Directory.CreateDirectory(archiveDirectory);
  594:  
  595:                 File.WriteAllText(archiveFileName, content);
  596:             }
  597:         }
  598:  
  599:         ////////////////////////////////////////////////////////////////////////////
  600:  
  601:         /// <summary>
  602:         ///
  603:         /// </summary>
  604:         private static string ReadContentOfLatestFileInArchive()
  605:         {
  606:             string content;
  607:  
  608:             var now = DateTime.UtcNow.AddHours(3);
  609:  
  610:             var archiveDirectory = archive + now.ToString("yyyy-MM-dd") + @"\";
  611:  
  612:             lock (objectLock)
  613:             {
  614:                 var directoryInfo = Directory.CreateDirectory(archiveDirectory);
  615:  
  616:                 var file = (from f in directoryInfo.GetFiles()
  617:                             orderby f.LastWriteTime descending
  618:                             select f).FirstOrDefault();
  619:  
  620:                 if (file != null) content = File.ReadAllText(file.FullName);
  621:                 else content = string.Empty;
  622:             }
  623:  
  624:             return content;
  625:         }
  626:  
  627:         ////////////////////////////////////////////////////////////////////////////
  628:  
  629:         /// <summary>
  630:         ///
  631:         /// </summary>
  632:         private static DataTable ReadPaymentTransactionOfThePreviousNDaysServiceDataTable(long latestTransactionId, int previousNDays)
  633:         {
  634:             DataTable dateTable = null;
  635:  
  636:             var sql = Ia.Ftn.Cl.Models.Data.MinistryDatabase.OracleSqlCommandToReturnPaymentTransactionOfThePreviousNDays(latestTransactionId, previousNDays);
  637:  
  638:             if (oracle != null)
  639:             {
  640:                 try
  641:                 {
  642:                     dateTable = oracle.Select(sql);
  643:                 }
  644:                 catch (Exception)
  645:                 {
  646:                     InitializeOracleConnection();
  647:  
  648:                     dateTable = oracle.Select(sql);
  649:                 }
  650:             }
  651:  
  652:             if (dateTable != null) dateTable.TableName = sql;
  653:  
  654:             return dateTable;
  655:         }
  656:  
  657:         ////////////////////////////////////////////////////////////////////////////
  658:         ////////////////////////////////////////////////////////////////////////////   
  659:     }
  660:  
  661:     ////////////////////////////////////////////////////////////////////////////
  662:     ////////////////////////////////////////////////////////////////////////////   
  663: }