1: using System;
2: using System.Collections.Generic;
3: using System.Data;
4: using System.Linq;
5: using System.Text;
6:
7: namespace Ia.Ngn.Cl.Model.Ui
8: {
9: ////////////////////////////////////////////////////////////////////////////
10:
11: /// <summary publish="true">
12: /// Administration support class for Next Generation Network (NGN) ui model.
13: /// </summary>
14: ///
15: /// <remarks>
16: /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
17: ///
18: /// 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
19: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
20: ///
21: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23: ///
24: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
25: ///
26: /// Copyright notice: This notice may not be removed or altered from any source distribution.
27: /// </remarks>
28: public class Administration
29: {
30: ////////////////////////////////////////////////////////////////////////////
31:
32: /// <summary>
33: ///
34: /// </summary>
35: public Administration() { }
36:
37: /////////////////////////////////////////////////////////////////////////////////
38:
39: /// <summary>
40: ///
41: /// </summary>
42: public static void EmailDailyOfnStatusReport(string name, string email, out Ia.Cl.Model.Result result)
43: {
44: //bool b;
45: string content, subject;
46: DateTime now;
47:
48: now = DateTime.UtcNow.AddHours(3);
49:
50: // subject can't have \r\n
51: subject = "Daily Optical Fiber Network (OFN) Status Report (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
52:
53: content = "Daily Optical Fiber Network (OFN) Status Report: " + now.ToString("yyyy-MM-dd HH:mm") + "\r\n"
54: + "Status: undefined.\r\n"
55: + @"For help send ""help"" in an email." + "\r\n";
56:
57: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
58: }
59:
60: /////////////////////////////////////////////////////////////////////////////////
61:
62: /// <summary>
63: ///
64: /// </summary>
65: public static void EmailListWithOntListProvisionedAndReadyButDoNotExistInCustomerDepartmentDatabase(string name, string email, out Ia.Cl.Model.Result result)
66: {
67: //bool b;
68: string content, subject;
69: DataTable accessDataTable;
70: DateTime now;
71:
72: now = DateTime.UtcNow.AddHours(3);
73:
74: subject = "Table of latest 100 ONTs that are provisioned and ready within NGN access network but do not exist in the Customer Department's database (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
75:
76: accessDataTable = Ia.Ngn.Cl.Model.Ui.Access.ReadListWithOntListProvisionedAndReadyButDoNotExistInCustomerDepartmentDatabaseDataTable(100);
77:
78: content = "Table of latest 100 ONTs that are provisioned and ready within NGN access network but do not exist in the Customer Department's database (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
79:
80: content += "\r\n";
81: content += "\r\n";
82:
83: content += Ia.Cl.Model.Default.GenerateTabSeparatedTextFromDataTable(accessDataTable);
84:
85: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
86: }
87:
88: /////////////////////////////////////////////////////////////////////////////////
89:
90: /// <summary>
91: ///
92: /// </summary>
93: public static void EmailStatistic(string name, string email, out Ia.Cl.Model.Result result)
94: {
95: //bool b;
96: string subject;
97: StringBuilder stringBuilder;
98: DateTime now;
99: List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site> siteList;
100: List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea> serviceList;
101:
102: now = DateTime.UtcNow.AddHours(3);
103: stringBuilder = new StringBuilder();
104:
105: subject = "Statistics of Site, Access, and Service usage within the Optical Fiber Network (OFN) (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
106:
107: siteList = Ia.Ngn.Cl.Model.Data.Administration.SiteStatistic();
108: serviceList = Ia.Ngn.Cl.Model.Data.Administration.ServiceAccessStatisticWithinKuwaitNgnArea();
109:
110: stringBuilder.AppendLine("Statistics of Site, Access, and Service usage within the Optical Fiber Network (OFN) (" + now.ToString("yyyy-MM-dd HH:mm") + ")");
111:
112: stringBuilder.AppendLine();
113: stringBuilder.AppendLine();
114:
115: foreach (var s in siteList)
116: {
117: stringBuilder.AppendLine();
118: stringBuilder.AppendLine(s.ToSimpleTextString());
119: }
120:
121: stringBuilder.AppendLine();
122: stringBuilder.AppendLine();
123:
124: foreach (var s in serviceList)
125: {
126: stringBuilder.AppendLine();
127: stringBuilder.AppendLine(s.ToSimpleTextString());
128: }
129:
130: stringBuilder.AppendLine();
131: stringBuilder.AppendLine();
132:
133: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, stringBuilder.ToString(), out result);
134: }
135:
136: /////////////////////////////////////////////////////////////////////////////////
137:
138: /// <summary>
139: ///
140: /// </summary>
141: public static void EmailListOfNumberOfAgcfGatewayRecordInGroupOfMgcIp(string name, string email, out Ia.Cl.Model.Result result)
142: {
143: string content, subject;
144: Dictionary<string, int> dictionary;
145: DateTime now;
146:
147: now = DateTime.UtcNow.AddHours(3);
148:
149: subject = "List of the number of AGCF gateway records in groups of MGC IP (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
150:
151: dictionary = Ia.Ngn.Cl.Model.Business.Nokia.Ims.NumberOfAgcfGatewayRecordInGroupOfMgcIpDictionary.OrderBy(u => u.Key).ToDictionary(u => u.Key, u => u.Value);
152:
153: content = "List of the number of AGCF gateway records in groups of MGC IP (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
154:
155: content += "\r\n";
156: content += "\r\n";
157:
158: content += Ia.Cl.Model.Default.GenerateTabSeparatedTextFromDictionary(dictionary);
159:
160: content += "\r\n";
161: content += "Total number of AGCF gateway records: " + dictionary.Sum(u => u.Value) + ". ";
162:
163: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
164: }
165:
166: /////////////////////////////////////////////////////////////////////////////////
167:
168: /// <summary>
169: ///
170: /// </summary>
171: public static void EmailWeeklyOfnNokiaReport(string name, string email, out Ia.Cl.Model.Result result)
172: {
173: string content, subject;
174: DateTime now;
175: List<string> list;
176: SortedDictionary<string, int> sortedDictionary;
177:
178: now = DateTime.UtcNow.AddHours(3);
179:
180: // subject can't have \r\n
181: subject = "Weekly Optical Fiber Network (OFN) Nokia Report (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
182:
183: content = "Weekly Optical Fiber Network (OFN) Nokia Report: " + now.ToString("yyyy-MM-dd HH:mm") + "\r\n"
184: + "Status: Normal\r\n"
185: + @"Please contact Jasem for any specific data that you may need on a weekly bases." + "\r\n";
186:
187: content += "\r\n";
188: content += "\r\n";
189:
190:
191: content += "List of the number of AGCF gateway records in groups of MGC IP: ";
192:
193: content += "\r\n";
194: content += "\r\n";
195:
196: sortedDictionary = new SortedDictionary<string, int>(Ia.Ngn.Cl.Model.Business.Nokia.Ims.NumberOfAgcfGatewayRecordInGroupOfMgcIpDictionary);
197:
198: content += Ia.Cl.Model.Default.GenerateTabSeparatedTextFromDictionary(sortedDictionary);
199:
200: content += "\r\n";
201: content += "\r\n";
202:
203:
204: content += "List of the number of AGCF gateway records in IMS pairs of MGC IP: ";
205:
206: content += "\r\n";
207: content += "\r\n";
208:
209: foreach (Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsBasicService imsBasicService in Ia.Ngn.Cl.Model.Business.Nokia.Ims.ImsBasicServiceList)
210: {
211: content += imsBasicService.MgcIp + ", " + imsBasicService.MgcSecondaryIp + "\t" + (sortedDictionary[imsBasicService.MgcIp] + sortedDictionary[imsBasicService.MgcSecondaryIp]);
212: content += "\r\n";
213: }
214:
215: content += "\r\n";
216: content += "\r\n";
217:
218:
219: content += "Number of Nokia subscribers per FSDB: ";
220:
221: content += "\r\n";
222: content += "\r\n";
223:
224: list = Ia.Ngn.Cl.Model.Business.Nokia.Ims.NumberOfNokiaSubsribersPerFsdb();
225:
226: content += string.Join("\r\n", list.ToArray());
227: content += "\r\n";
228:
229: content += "\r\n";
230: content += "\r\n";
231:
232:
233: content += "Service and access name list where subscriber's AlternateOtasRealm group number is not equal to subparties AssocOtasRealm group number: ";
234:
235: content += "\r\n";
236: content += "\r\n";
237:
238: list.Clear();
239:
240: foreach (var w in Ia.Ngn.Cl.Model.Data.Nokia.Ims.ServiceWhereSubscriberAlternateOtasRealmGroupNumberDoesNotEqualSubPartyAssocOtasRealmGroupNumberList())
241: {
242: if (w.Access != null)
243: {
244: list.Add(w.Service + ": " + w.Access.Name);
245: }
246: else list.Add(w.Service + ": ");
247: }
248:
249: if (list.Count > 0)
250: {
251: content += string.Join("\r\n", list.ToArray());
252: }
253: else content += "None";
254:
255: content += "\r\n";
256:
257: content += "\r\n";
258: content += "\r\n";
259:
260:
261: content += "AGCF gateway records within NDD ONT list with wrong secondary IP: ";
262:
263: content += "\r\n";
264: content += "\r\n";
265:
266: list.Clear();
267:
268: var agcfGatewayRecordsWithinNddOntListWithWrongSecondaryIpList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AgcfGatewayRecordsWithinNddOntListWithWrongSecondaryIpList();
269:
270: foreach (var w in agcfGatewayRecordsWithinNddOntListWithWrongSecondaryIpList)
271: {
272: list.Add(w.GwId.ToString());
273: }
274:
275: content += string.Join(", ", list.ToArray());
276:
277: content += "\r\n";
278: content += "\r\n";
279: content += "\r\n";
280:
281:
282: content += "SubParties' PrimaryPUIDCPEProfileNumber count distribution: ";
283:
284: content += "\r\n";
285: content += "\r\n";
286:
287: list.Clear();
288:
289: foreach (KeyValuePair<int, int> w in Ia.Ngn.Cl.Model.Data.Nokia.SubParty.PrimaryPuidCpeProfileNumberCountDistributionDictionary)
290: {
291: list.Add(w.Key + "\t" + w.Value);
292: }
293:
294: content += string.Join("\r\n", list.ToArray());
295:
296: content += "\r\n";
297: content += "\r\n";
298:
299:
300: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
301: }
302:
303: /////////////////////////////////////////////////////////////////////////////////
304:
305: /// <summary>
306: ///
307: /// </summary>
308: public static void EmailWeeklyOfnHuaweiReport(string name, string email, out Ia.Cl.Model.Result result)
309: {
310: string content, subject;
311: DateTime now;
312:
313: now = DateTime.UtcNow.AddHours(3);
314:
315: // subject can't have \r\n
316: subject = "Weekly Optical Fiber Network (OFN) Huawei Report (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
317:
318: content = "Weekly Optical Fiber Network (OFN) Huawei Report: " + now.ToString("yyyy-MM-dd HH:mm") + "\r\n"
319: + "Status:.\r\n"
320: + @"Please contact Jasem for any specific data that you may need on a weekly bases." + "\r\n";
321:
322: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
323: }
324:
325: /////////////////////////////////////////////////////////////////////////////////
326:
327: /// <summary>
328: ///
329: /// </summary>
330: public static void EmailListOfPstnToGponMigratedAndProvisionedServiceInAllowedToBeMigratedOlt(string name, string email, out Ia.Cl.Model.Result result)
331: {
332: string content, subject;
333: StringBuilder stringBuilder;
334: DateTime now;
335:
336: now = DateTime.UtcNow.AddHours(3);
337:
338: subject = "List of PSTN to GPON Migrated and Newly Provisioned Services in Allowed to be Migrated OLTs (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
339:
340: content = "List of PSTN to GPON Migrated and Newly Provisioned Services in Allowed to be Migrated OLTs (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
341:
342: content += "\r\n";
343: content += "\r\n";
344:
345: var dictionary = Ia.Ngn.Cl.Model.Data.Service.GponServiceToOntRouterVendorInAllowedToBeMigratedOltDictionary;
346:
347: stringBuilder = new StringBuilder(dictionary.Count * 64);
348:
349: if (dictionary.Count > 0)
350: {
351: stringBuilder.AppendLine("List count: " + dictionary.Count);
352: stringBuilder.AppendLine(" ");
353:
354: /*
355: foreach (KeyValuePair<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> kvp in dictionary)
356: {
357: stringBuilder.Append(kvp.Key + ", ");
358: }
359: */
360:
361: stringBuilder.Append(string.Join(", ", dictionary.Keys));
362: }
363: else
364: {
365: }
366:
367: content += stringBuilder.ToString().Trim();
368:
369: content += "\r\n";
370: content += "\r\n";
371:
372: Ia.Ngn.Cl.Model.Ui.Mail.SendPlainMail(name, email, subject, content, out result);
373: }
374:
375: ////////////////////////////////////////////////////////////////////////////
376: ////////////////////////////////////////////////////////////////////////////
377:
378: /// <summary>
379: ///
380: /// </summary>
381: public static string FrameworkStructureDataTable()
382: {
383: string htmlTable;
384: List<Ia.Ngn.Cl.Model.Business.Administration.Framework> frameworkList;
385:
386: frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.Type == "ministry" || f.Type == "supplier" select f).ToList();
387:
388: htmlTable = @"<div id=""framework-structure"">";
389:
390: foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in frameworkList)
391: {
392: htmlTable += FrameworkStructureDataTableIteration(framework);
393: }
394:
395: htmlTable += "</div>";
396:
397: return htmlTable;
398: }
399:
400: ////////////////////////////////////////////////////////////////////////////
401:
402: /// <summary>
403: ///
404: /// </summary>
405: private static string FrameworkStructureDataTableIteration(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
406: {
407: string htmlTable;
408: Ia.Ngn.Cl.Model.Staff headStaff;
409: List<Ia.Ngn.Cl.Model.Staff> staffList;
410:
411: htmlTable = null;
412:
413: if (framework != null)
414: {
415: headStaff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.Framework != null && s.Framework.Id == framework.Id && s.IsHead select s).SingleOrDefault();
416:
417: htmlTable = "<table>";
418:
419: if (framework.Children != null && framework.Children.Count > 0)
420: {
421: htmlTable += "<tr>";
422:
423: htmlTable += @"<td class=""" + framework.Type + @""" colspan=""" + framework.Children.Count + @""">" + framework.ArabicName;
424: if (headStaff != null) htmlTable += @"<span class=""head"">" + headStaff.FirstAndMiddleName + "</span>";
425: htmlTable += @"</td>";
426:
427: htmlTable += "</tr>";
428:
429: htmlTable += "<tr>";
430:
431: foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework f in framework.Children)
432: {
433: htmlTable += @"<td class=""" + f.Type + @""">" + FrameworkStructureDataTableIteration(f) + "</td>";
434: }
435:
436: htmlTable += "</tr>";
437: }
438: else
439: {
440: staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.Framework != null && s.Framework.Id == framework.Id && !s.IsHead select s).ToList();
441:
442: htmlTable += "<tr>";
443:
444: htmlTable += @"<td class=""" + framework.Type + @""">" + framework.ArabicName;
445: if (headStaff != null) htmlTable += @"<span class=""head"">" + headStaff.FirstAndMiddleName + "</span>";
446:
447: foreach (Ia.Ngn.Cl.Model.Staff staff in staffList)
448: {
449: htmlTable += @"<span class=""staff"">" + staff.FirstAndMiddleName + "</span>";
450: }
451:
452: htmlTable += @"</td>";
453:
454: htmlTable += "</tr>";
455: }
456:
457: htmlTable += "</table>";
458: }
459:
460: return htmlTable;
461: }
462:
463: /////////////////////////////////////////////////////////////////////////////////
464: /////////////////////////////////////////////////////////////////////////////////
465:
466: /// <summary>
467: ///
468: /// </summary>
469: public static void StatisticsListForTelegramBotApi(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string opcode, out string subject, out string content)
470: {
471: string inputType, horizontalRule;
472: StringBuilder stringBuilder;
473: DateTime now;
474:
475: inputType = string.Empty;
476: horizontalRule = " ";
477:
478: now = DateTime.UtcNow.AddHours(3);
479:
480: // subject can't have \r\n
481: subject = string.Empty; // "Optical Fiber Network (OFN) TNMD list: ";
482:
483: if (Ia.Ngn.Cl.Model.Business.Authority.FrameworkCanReadStatistics(framework))
484: {
485: opcode = opcode.ToLower();
486:
487: StatisticListForTelegramBotApiAndMailSimpleText(opcode, inputType, horizontalRule, out stringBuilder);
488:
489: stringBuilder.AppendLine(horizontalRule);
490: stringBuilder.AppendLine(Ia.Ngn.Cl.Model.Data.Help.Text(Ia.Ngn.Cl.Model.Data.Help.TelegramString.NeedHelpSendCommandSlashHelp));
491: stringBuilder.AppendLine(horizontalRule);
492: stringBuilder.AppendLine();
493:
494: content = stringBuilder.ToString();
495: }
496: else
497: {
498: content = "\r\n";
499: content += "You are not authorized to modify this value. ";
500: content += "\r\n";
501: }
502: }
503:
504: ////////////////////////////////////////////////////////////////////////////
505:
506: /// <summary>
507: ///
508: /// </summary>
509: public static void StatisticListForTelegramBotApiAndMailSimpleText(string opcode, string inputType, string horizontalRule, out StringBuilder contentStringBuilder)
510: {
511: StringBuilder stringBuilder;
512: DateTime now;
513: List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea> statisticList;
514:
515: stringBuilder = new StringBuilder();
516: now = DateTime.UtcNow.AddHours(3);
517:
518: //stringBuilder.AppendLine("Optical Fiber Network (OFN) Find Result: " + now.ToString("yyyy-MM-dd HH:mm"));
519:
520: //stringBuilder.AppendLine(@"Opcode: """ + opcode + @""".");
521: //responseContent += @"Operand: """ + operand + @"""." + "\r\n";
522: //stringBuilder.AppendLine();
523:
524: if (opcode.Contains("statistics"))
525: {
526: statisticList = Ia.Ngn.Cl.Model.Data.Administration.ServiceAccessStatisticWithinKuwaitNgnAreaCachedDaily;
527:
528: if (statisticList != null && statisticList.Count > 0)
529: {
530: stringBuilder.AppendLine(horizontalRule);
531: stringBuilder.AppendLine("Statistics:");
532: stringBuilder.AppendLine();
533: foreach (var s in statisticList) stringBuilder.AppendLine(s.ToSimpleTextString());
534: stringBuilder.AppendLine(horizontalRule);
535: stringBuilder.AppendLine();
536: }
537: else
538: {
539: stringBuilder.AppendLine(horizontalRule);
540: stringBuilder.AppendLine();
541: }
542: }
543: else
544: {
545: stringBuilder.AppendLine(horizontalRule);
546: stringBuilder.AppendLine("Error: opcode: [" + opcode + "] is unrecognized. ");
547: stringBuilder.AppendLine(horizontalRule);
548: stringBuilder.AppendLine();
549: }
550:
551: contentStringBuilder = stringBuilder.Replace(Environment.NewLine + horizontalRule, horizontalRule);
552: }
553:
554: ////////////////////////////////////////////////////////////////////////////
555: ////////////////////////////////////////////////////////////////////////////
556: }
557:
558: ////////////////////////////////////////////////////////////////////////////
559: ////////////////////////////////////////////////////////////////////////////
560: }