شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Administration

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

Administration support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Web;
   3:  using System.Xml;
   4:  using System.Xml.Linq;
   5:  using System.IO;
   6:  using System.Configuration;
   7:  using System.Text;
   8:  using System.Text.RegularExpressions;
   9:  using System.Data;
  10:  using System.Data.SqlClient;
  11:  using System.Web.UI;
  12:  using System.Web.UI.WebControls;
  13:  using System.Collections;
  14:  using System.Collections.Generic;
  15:  using System.Linq;
  16:  using System.Reflection;
  17:  using System.Web.Security;
  18:  using System.ComponentModel.DataAnnotations.Schema;
  19:   
  20:  namespace Ia.Ngn.Cl.Model.Data
  21:  {
  22:      ////////////////////////////////////////////////////////////////////////////
  23:   
  24:      /// <summary publish="true">
  25:      /// Administration support class for Next Generation Network (NGN) data model.
  26:      /// </summary>
  27:      /// 
  28:      /// <remarks> 
  29:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  30:      ///
  31:      /// 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
  32:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  33:      ///
  34:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  35:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  36:      /// 
  37:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  38:      /// 
  39:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  40:      /// </remarks> 
  41:      public class Administration
  42:      {
  43:          private static XDocument xDocument;
  44:          private static List<Framework> frameworkList;
  45:          private static List<Category> categoryList;
  46:          private static List<StaffFramework> staffFrameworkList;
  47:          private static List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact> staffContactList;
  48:          private static List<Authority> authorityList;
  49:          private static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea> statisticList;
  50:          private static object objectLock = new object();
  51:   
  52:          /// <summary/>
  53:          public static int ServiceSuspensionFlagCounter = 0;
  54:   
  55:          ////////////////////////////////////////////////////////////////////////////
  56:   
  57:          /// <summary>
  58:          ///
  59:          /// </summary>
  60:          public Administration() { }
  61:   
  62:          ////////////////////////////////////////////////////////////////////////////
  63:   
  64:          /// <summary>
  65:          ///
  66:          /// </summary>
  67:          public class Framework
  68:          {
  69:              public Framework() { }
  70:   
  71:              /// <summary/>
  72:              public int Id { get; set; }
  73:              /// <summary/>
  74:              public int Level { get; set; }
  75:              /// <summary/>
  76:              public Guid Guid { get; set; }
  77:              /// <summary/>
  78:              public string Type { get; set; }
  79:              /// <summary/>
  80:              public string Name { get; set; }
  81:              /// <summary/>
  82:              public string ArabicName { get; set; }
  83:              /// <summary/>
  84:              public string ColoredArabicName { get; set; }
  85:              /// <summary/>
  86:              public Framework Parent { get; set; }
  87:              /// <summary/>
  88:              public List<Framework> Ancestors { get; set; }
  89:              /// <summary/>
  90:              public List<Framework> Siblings { get; set; }
  91:              /// <summary/>
  92:              public List<Framework> Children { get; set; }
  93:              /// <summary/>
  94:              public List<Framework> Descendants { get; set; }
  95:              /// <summary/>
  96:              public List<Authority> Authorities { get; set; }
  97:   
  98:              /// <summary/>
  99:              public Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site Site { get; set; }
 100:   
 101:              /// <summary/>
 102:              //public Ia.Cl.Model.Identity.User Role { get; set; }
 103:   
 104:              /// <summary/>
 105:              public static bool operator ==(Framework fa, Framework fb)
 106:              {
 107:                  bool b;
 108:   
 109:                  // if both are null, or both are same instance, return true.
 110:                  if (System.Object.ReferenceEquals(fa, fb)) b = true;
 111:                  // if one is null, but not both, return false.
 112:                  else if (((object)fa == null) || ((object)fb == null)) b = false;
 113:                  // true if the fields match:
 114:                  else b = fa.Id == fb.Id;
 115:   
 116:                  return b;
 117:              }
 118:   
 119:              /// <summary/>
 120:              public static bool operator !=(Framework fa, Framework fb)
 121:              {
 122:                  return !(fa == fb);
 123:              }
 124:   
 125:              /// <summary/>
 126:              public string FullyQualifiedArabicName
 127:              {
 128:                  get
 129:                  {
 130:                      string s;
 131:   
 132:                      s = string.Empty;
 133:   
 134:                      foreach(var f in this.Ancestors) s += f.ArabicName + " | ";
 135:   
 136:                      s = s + this.ArabicName;
 137:   
 138:                      return s;
 139:                  }
 140:              }
 141:   
 142:              ////////////////////////////////////////////////////////////////////////////
 143:   
 144:              /// <summary>
 145:              ///
 146:              /// </summary>
 147:              public override bool Equals(object value)
 148:              {
 149:                  return value != null && Equals(value as Framework);
 150:              }
 151:   
 152:              /// <summary/>
 153:              public int FrameworkId(int parentId, int frameworkId)
 154:              {
 155:                  return parentId * 10 + frameworkId;
 156:              }
 157:   
 158:              /// <summary/>
 159:              public static int ParentId(long frameworkId)
 160:              {
 161:                  int i;
 162:                  string s;
 163:   
 164:                  s = frameworkId.ToString();
 165:   
 166:                  if (s.Length > 2)
 167:                  {
 168:                      s = s.Substring(0, s.Length - 2);
 169:   
 170:                      i = (int.TryParse(s, out i)) ? i : 0;
 171:                  }
 172:                  else i = 0;
 173:   
 174:                  return i;
 175:              }
 176:          }
 177:   
 178:          ////////////////////////////////////////////////////////////////////////////
 179:   
 180:          /// <summary>
 181:          ///
 182:          /// </summary>
 183:          public class Category
 184:          {
 185:              /// <summary/>
 186:              public Category() { }
 187:              /// <summary/>
 188:              public string Name { get; set; }
 189:              /// <summary/>
 190:              public string Description { get; set; }
 191:              /// <summary/>
 192:              public string Regex { get; set; }
 193:              /// <summary/>
 194:              public string Color { get; set; }
 195:          }
 196:   
 197:          ////////////////////////////////////////////////////////////////////////////
 198:   
 199:          /// <summary>
 200:          ///
 201:          /// </summary>
 202:          public class StaffFramework
 203:          {
 204:              private bool isStaff;
 205:   
 206:              /// <summary/>
 207:              public StaffFramework() { }
 208:              /// <summary/>
 209:              public Guid Guid { get; set; }
 210:              /// <summary/>
 211:              public long FrameworkId { get; set; }
 212:              /// <summary/>
 213:              public string Name { get; set; }
 214:              /// <summary/>
 215:              public bool IsStaff
 216:              {
 217:                  get { return isStaff; }
 218:                  set { isStaff = true; }
 219:              }
 220:              /// <summary/>
 221:              public bool IsFramework
 222:              {
 223:                  get { return !isStaff; }
 224:                  set { isStaff = false; }
 225:              }
 226:          }
 227:   
 228:          ////////////////////////////////////////////////////////////////////////////
 229:   
 230:          /// <summary>
 231:          ///
 232:          /// </summary>
 233:          public class Authority
 234:          {
 235:              public Authority() { }
 236:   
 237:              /// <summary/>
 238:              public int Id { get; set; }
 239:              /// <summary/>
 240:              public string Name { get; set; }
 241:              /// <summary/>
 242:              public string ArabicName { get; set; }
 243:              /// <summary/>
 244:              public string AllowedFrameworkArabicName { get; set; }
 245:              /// <summary/>
 246:              public bool HeadOnly { get; set; }
 247:              /// <summary/>
 248:              public string Medium { get; set; }
 249:              /// <summary/>
 250:              public string System { get; set; }
 251:              /// <summary/>
 252:              public string Process { get; set; }
 253:              /// <summary/>
 254:              public string Function { get; set; }
 255:              /// <summary/>
 256:              public string ParameterRegex { get; set; }
 257:              /// <summary/>
 258:              public string ResponseRegex { get; set; }
 259:              /// <summary/>
 260:              public string Help { get; set; }
 261:   
 262:              /// <summary/>
 263:              public int AuthorityId(int parentId, int authorityId)
 264:              {
 265:                  return parentId * 10 + authorityId;
 266:              }
 267:   
 268:              /// <summary/>
 269:              public int ParentId(long authorityId)
 270:              {
 271:                  int i;
 272:                  string s;
 273:   
 274:                  s = authorityId.ToString();
 275:   
 276:                  if (s.Length > 2)
 277:                  {
 278:                      s = s.Substring(0, s.Length - 2);
 279:   
 280:                      i = (int.TryParse(s, out i)) ? i : 0;
 281:                  }
 282:                  else i = 0;
 283:   
 284:                  return i;
 285:              }
 286:          }
 287:   
 288:          ////////////////////////////////////////////////////////////////////////////
 289:   
 290:          /// <summary>
 291:          ///
 292:          /// </summary>
 293:          public static List<Ia.Ngn.Cl.Model.Data.Administration.Framework> FrameworkList
 294:          {
 295:              get
 296:              {
 297:                  if (frameworkList == null || frameworkList.Count == 0)
 298:                  {
 299:                      if (HttpContext.Current != null && HttpContext.Current.Application["frameworkList"] != null)
 300:                      {
 301:                          frameworkList = (List<Ia.Ngn.Cl.Model.Data.Administration.Framework>)HttpContext.Current.Application["frameworkList"];
 302:                      }
 303:                      else
 304:                      {
 305:                          frameworkList = Ia.Ngn.Cl.Model.Data.Administration._FrameworkList;
 306:   
 307:                          if (HttpContext.Current != null) HttpContext.Current.Application["frameworkList"] = frameworkList;
 308:                      }
 309:                  }
 310:   
 311:                  return frameworkList.ToList();
 312:              }
 313:          }
 314:   
 315:          ////////////////////////////////////////////////////////////////////////////
 316:   
 317:          /// <summary>
 318:          ///
 319:          /// </summary>
 320:          public static List<Ia.Ngn.Cl.Model.Data.Administration.Framework> _FrameworkList
 321:          {
 322:              get
 323:              {
 324:                  //if (frameworkList == null || frameworkList.Count == 0)
 325:                  //{
 326:                  int id, parentId;
 327:                  string arabicName, coloredArabicName, siteName;
 328:                  List<string> lightBackgroundColorList;
 329:                  Framework framework;
 330:   
 331:                  frameworkList = new List<Framework>(Ia.Ngn.Cl.Model.Business.Administration.InitialFrameworkListLength); // needed to prevent errors
 332:   
 333:                  lock (objectLock)
 334:                  {
 335:                      lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList;
 336:                  }
 337:   
 338:                  lock (objectLock)
 339:                  {
 340:                      foreach (XElement xe in XDocument.Element("administration").Element("frameworkList").Descendants("framework"))
 341:                      {
 342:                          id = int.Parse(XmlBasedTwoDigitPerId(xe));
 343:                          parentId = Framework.ParentId(id);
 344:                          arabicName = xe.Attribute("arabicName").Value;
 345:                          coloredArabicName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + arabicName + "</span>";
 346:   
 347:                          framework = new Framework();
 348:   
 349:                          framework.Id = id;
 350:                          framework.Level = xe.Ancestors().Count();
 351:                          framework.Guid = Guid.Parse(xe.Attribute("guid").Value);
 352:                          framework.Type = xe.Attribute("type").Value;
 353:                          framework.Name = xe.Attribute("name").Value;
 354:                          framework.ArabicName = arabicName;
 355:                          framework.ColoredArabicName = coloredArabicName;
 356:   
 357:                          if (xe.Parent.Attribute("siteName") != null && !string.IsNullOrEmpty(xe.Parent.Attribute("siteName").Value))
 358:                          {
 359:                              siteName = xe.Parent.Attribute("siteName").Value;
 360:                              framework.Site = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Name == siteName select s).SingleOrDefault();
 361:                          }
 362:                          else framework.Site = null;
 363:   
 364:                          frameworkList.Add(framework);
 365:                      }
 366:                  }
 367:   
 368:                  // Parents, authorities and children
 369:                  foreach (Framework f in frameworkList)
 370:                  {
 371:                      parentId = Framework.ParentId(f.Id);
 372:   
 373:                      /*
 374:  [InvalidOperationException: Sequence contains more than one element]
 375:  System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +348
 376:  Ia.Ngn.Cl.Model.Data.Administration.get__FrameworkList() in C:\Users\Jasem\Documents\Visual Studio 2017\Projects\Next Generation Network\cl\model\data\administration.cs:343                                 
 377:  */
 378:                      f.Parent = (from _f in frameworkList where _f.Id == parentId select _f).SingleOrDefault();
 379:   
 380:                      //HttpContext.Current.Response.Write("[" + f.ArabicName + "]" + "[" + ex.Message + "]" + "[count: " + frameworkList.Count + "]");
 381:   
 382:                      //f.Authorities = (from a in AuthorityList where a.AllowedFrameworkArabicName == f.ArabicName select a).ToList();
 383:   
 384:                      f.Children = new List<Ia.Ngn.Cl.Model.Data.Administration.Framework>();
 385:   
 386:                      if (f.Parent != null) f.Parent.Children.Add(f);
 387:                  }
 388:   
 389:                  // below: Siblings
 390:                  foreach (Framework f in frameworkList.ToList())
 391:                  {
 392:                      f.Siblings = new List<Ia.Ngn.Cl.Model.Data.Administration.Framework>();
 393:   
 394:                      f.Siblings = (from _f in frameworkList where _f.Parent == f.Parent && _f.Id != f.Id select _f).ToList();
 395:                  }
 396:   
 397:                  // below: Descendants
 398:                  foreach (Framework f in frameworkList.ToList())
 399:                  {
 400:                      f.Descendants = new List<Ia.Ngn.Cl.Model.Data.Administration.Framework>();
 401:   
 402:                      f.Descendants = (from _f in frameworkList
 403:                                       where _f.Id != f.Id && _f.Id > f.Id &&
 404:                                           (_f.Parent != null && (_f.Parent == f
 405:                                           || _f.Parent.Parent != null && (_f.Parent.Parent == f
 406:                                           || _f.Parent.Parent.Parent != null && (_f.Parent.Parent.Parent == f
 407:                                           || _f.Parent.Parent.Parent.Parent != null && _f.Parent.Parent.Parent.Parent == f)))
 408:                                           )
 409:                                       select _f).ToList();
 410:                  }
 411:   
 412:                  // below: Ancestors
 413:                  foreach (Framework f in frameworkList.ToList())
 414:                  {
 415:                      f.Ancestors = new List<Ia.Ngn.Cl.Model.Data.Administration.Framework>();
 416:   
 417:                      f.Ancestors = (from _f in frameworkList
 418:                                     where _f.Id != f.Id && _f.Id < f.Id &&
 419:                                         (f.Parent != null && (f.Parent == _f
 420:                                         || f.Parent.Parent != null && (f.Parent.Parent == _f
 421:                                         || f.Parent.Parent.Parent != null && (f.Parent.Parent.Parent == _f
 422:                                         || f.Parent.Parent.Parent.Parent != null && f.Parent.Parent.Parent.Parent == _f)))
 423:                                         )
 424:                                     select _f).ToList();
 425:                  }
 426:                  //}
 427:   
 428:                  //list = (from q in list select q).OrderByDescending(c => c.IsHead).ThenBy(c => c.AdministrativeFrameworkId);
 429:   
 430:                  //frameworkList = (from q in frameworkList select q).OrderBy(c => c.Id); //.ThenBy(c => c.ParentId);
 431:   
 432:                  return frameworkList.ToList();
 433:              }
 434:          }
 435:   
 436:          ////////////////////////////////////////////////////////////////////////////
 437:   
 438:          /// <summary>
 439:          ///
 440:          /// </summary>
 441:          private static string XmlBasedOneDigitPerId(XElement xeIn)
 442:          {
 443:              return XmlBasedId(xeIn, 1);
 444:          }
 445:   
 446:          ////////////////////////////////////////////////////////////////////////////
 447:   
 448:          /// <summary>
 449:          ///
 450:          /// </summary>
 451:          private static string XmlBasedTwoDigitPerId(XElement xeIn)
 452:          {
 453:              return XmlBasedId(xeIn, 2);
 454:          }
 455:   
 456:          ////////////////////////////////////////////////////////////////////////////
 457:   
 458:          /// <summary>
 459:          ///
 460:          /// </summary>
 461:          private static string XmlBasedId(XElement xe, int digit)
 462:          {
 463:              string id;
 464:   
 465:              id = "";
 466:   
 467:              while (xe.HasAttributes && xe.Attribute("id") != null)
 468:              {
 469:                  id = xe.Attribute("id").Value.PadLeft(digit, '0') + id;
 470:                  xe = xe.Parent;
 471:              }
 472:   
 473:              return id;
 474:          }
 475:   
 476:          ////////////////////////////////////////////////////////////////////////////
 477:   
 478:          /// <summary>
 479:          ///
 480:          /// </summary>
 481:          public static List<Ia.Ngn.Cl.Model.Data.Administration.Category> CategoryList
 482:          {
 483:              get
 484:              {
 485:                  if (categoryList == null || categoryList.Count == 0)
 486:                  {
 487:                      Category category;
 488:   
 489:                      categoryList = new List<Category>();
 490:   
 491:                      foreach (XElement xe in XDocument.Element("administration").Elements("category"))
 492:                      {
 493:                          category = new Category()
 494:                          {
 495:                              Name = xe.Attribute("name").Value,
 496:                              Regex = xe.Attribute("regex").Value,
 497:                              Description = (xe.Attribute("description") != null) ? xe.Attribute("description").Value : string.Empty,
 498:                              Color = (xe.Attribute("color") != null) ? xe.Attribute("color").Value : string.Empty
 499:                          };
 500:   
 501:                          categoryList.Add(category);
 502:                      }
 503:                  }
 504:   
 505:                  return categoryList.ToList();
 506:              }
 507:          }
 508:   
 509:          ////////////////////////////////////////////////////////////////////////////
 510:   
 511:          /// <summary>
 512:          ///
 513:          /// </summary>
 514:          public static List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact> StaffContactList
 515:          {
 516:              get
 517:              {
 518:                  if (staffContactList == null || staffContactList.Count == 0)
 519:                  {
 520:                      if (HttpContext.Current != null && HttpContext.Current.Application["staffContactList"] != null)
 521:                      {
 522:                          staffContactList = (List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact>)HttpContext.Current.Application["staffContactList"];
 523:                      }
 524:                      else
 525:                      {
 526:                          staffContactList = null;
 527:                          staffContactList = Ia.Ngn.Cl.Model.Data.Administration._StaffContactList;
 528:   
 529:                          if (HttpContext.Current != null) HttpContext.Current.Application["staffContactList"] = staffContactList;
 530:                      }
 531:                  }
 532:   
 533:                  return staffContactList;
 534:              }
 535:          }
 536:   
 537:          ////////////////////////////////////////////////////////////////////////////
 538:   
 539:          /// <summary>
 540:          ///
 541:          /// </summary>
 542:          private static List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact> _StaffContactList
 543:          {
 544:              get
 545:              {
 546:                  Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact;
 547:                  List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact> staffContactList;
 548:   
 549:                  staffContactList = new List<Ia.Ngn.Cl.Model.Business.Administration.StaffContact>();
 550:   
 551:                  foreach (Ia.Ngn.Cl.Model.Staff staff in Ia.Ngn.Cl.Model.Data.Staff.List)
 552:                  {
 553:                      if (staff.User != null && staff.User.Email != null)
 554:                      {
 555:                          staffContact = new Ia.Ngn.Cl.Model.Business.Administration.StaffContact() { Staff = staff };
 556:   
 557:                          staffContactList.Add(staffContact);
 558:                      }
 559:                  }
 560:   
 561:                  foreach (Ia.Ngn.Cl.Model.Contact contact in Ia.Ngn.Cl.Model.Data.Contact.List)
 562:                  {
 563:                      if (contact.Email != null)
 564:                      {
 565:                          staffContact = new Ia.Ngn.Cl.Model.Business.Administration.StaffContact() { Contact = contact };
 566:   
 567:                          staffContactList.Add(staffContact);
 568:                      }
 569:                  }
 570:   
 571:                  return staffContactList.ToList();
 572:              }
 573:          }
 574:   
 575:          ////////////////////////////////////////////////////////////////////////////
 576:   
 577:          /// <summary>
 578:          ///
 579:          /// </summary>
 580:          public static List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> StaffFrameworkList
 581:          {
 582:              get
 583:              {
 584:                  if (staffFrameworkList == null || staffFrameworkList.Count == 0)
 585:                  {
 586:                      List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> staffList, frameworkList;
 587:   
 588:                      staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 589:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 590:                                   {
 591:                                       Guid = s.UserId,
 592:                                       FrameworkId = s.Framework.Id,
 593:                                       IsStaff = true,
 594:                                       Name = s.FirstAndMiddleName
 595:                                   }
 596:                      ).ToList();
 597:   
 598:                      frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 599:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 600:                                       {
 601:                                           Guid = f.Guid,
 602:                                           FrameworkId = f.Id,
 603:                                           IsFramework = true,
 604:                                           Name = f.FullyQualifiedArabicName //.ArabicName
 605:                                       }
 606:                      ).ToList();
 607:   
 608:                      staffFrameworkList = staffList.Union(frameworkList).ToList();
 609:                  }
 610:   
 611:                  return staffFrameworkList.ToList();
 612:              }
 613:          }
 614:   
 615:          ////////////////////////////////////////////////////////////////////////////
 616:   
 617:          /// <summary>
 618:          ///
 619:          /// </summary>
 620:          public static List<Ia.Ngn.Cl.Model.Data.Administration.Authority> AuthorityList
 621:          {
 622:              get
 623:              {
 624:                  if (authorityList == null || authorityList.Count == 0)
 625:                  {
 626:                      if (HttpContext.Current != null && HttpContext.Current.Application["authorityList"] != null)
 627:                      {
 628:                          authorityList = (List<Ia.Ngn.Cl.Model.Data.Administration.Authority>)HttpContext.Current.Application["authorityList"];
 629:                      }
 630:                      else
 631:                      {
 632:                          authorityList = null;
 633:                          authorityList = Ia.Ngn.Cl.Model.Data.Administration._AuthorityList;
 634:   
 635:                          if (HttpContext.Current != null) HttpContext.Current.Application["authorityList"] = authorityList;
 636:                      }
 637:                  }
 638:   
 639:                  return authorityList.ToList();
 640:              }
 641:          }
 642:   
 643:          ////////////////////////////////////////////////////////////////////////////
 644:   
 645:          /// <summary>
 646:          ///
 647:          /// </summary>
 648:          private static List<Ia.Ngn.Cl.Model.Data.Administration.Authority> _AuthorityList
 649:          {
 650:              get
 651:              {
 652:                  if (authorityList == null || authorityList.Count == 0)
 653:                  {
 654:                      Authority authority;
 655:   
 656:                      authorityList = new List<Authority>();
 657:   
 658:                      lock (authorityList)
 659:                      {
 660:                          foreach (XElement xe in XDocument.Element("administration").Element("authorization").Element("authorityList").Descendants("authority"))
 661:                          {
 662:                              authority = new Authority()
 663:                              {
 664:                                  Id = int.Parse(XmlBasedTwoDigitPerId(xe)),
 665:                                  Name = xe.Attribute("name").Value,
 666:                                  ArabicName = xe.Attribute("arabicName").Value,
 667:                                  AllowedFrameworkArabicName = xe.Attribute("allowedFrameworkArabicName").Value,
 668:                                  HeadOnly = (xe.Attribute("allowedHeadOnly").Value == "true") ? true : false,
 669:                                  Medium = xe.Attribute("medium").Value,
 670:                                  System = xe.Attribute("system").Value,
 671:                                  Process = xe.Attribute("process").Value,
 672:                                  Function = xe.Attribute("function").Value,
 673:   
 674:                                  ParameterRegex = xe.Element("parameterRegex").Value,
 675:                                  ResponseRegex = xe.Element("responseRegex").Value,
 676:   
 677:                                  Help = xe.Element("help").Value
 678:                              };
 679:   
 680:                              authorityList.Add(authority);
 681:                          }
 682:                      }
 683:                  }
 684:   
 685:                  return authorityList.ToList();
 686:              }
 687:          }
 688:   
 689:          ////////////////////////////////////////////////////////////////////////////
 690:          ////////////////////////////////////////////////////////////////////////////
 691:   
 692:          /// <summary>
 693:          ///
 694:          /// </summary>
 695:          public static int ServiceRequestServicesWithNullAccessCount()
 696:          {
 697:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 698:              {
 699:                  return (from srs in db.ServiceRequestServices where srs.Access == null select srs.Id).Count();
 700:              }
 701:          }
 702:   
 703:          ////////////////////////////////////////////////////////////////////////////
 704:   
 705:          /// <summary>
 706:          ///
 707:          /// </summary>
 708:          public static int ServicesWithNullAccessCount()
 709:          {
 710:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 711:              {
 712:                  return (from s in db.Service2s where s.Access == null select s.Id).Count();
 713:              }
 714:          }
 715:   
 716:          ////////////////////////////////////////////////////////////////////////////
 717:   
 718:          /// <summary>
 719:          ///
 720:          /// </summary>
 721:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea> ServiceAccessStatisticWithinKuwaitNgnAreaCachedDaily
 722:          {
 723:              get
 724:              {
 725:                  if (statisticList == null || statisticList.Count == 0)
 726:                  {
 727:                      if (HttpContext.Current != null && HttpContext.Current.Application["statisticList" + DateTime.Now.Day] != null)
 728:                      {
 729:                          statisticList = (List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea>)HttpContext.Current.Application["statisticList" + DateTime.Now.Day];
 730:                      }
 731:                      else
 732:                      {
 733:                          statisticList = null;
 734:                          statisticList = Ia.Ngn.Cl.Model.Data.Administration.ServiceAccessStatisticWithinKuwaitNgnArea;
 735:   
 736:                          if (HttpContext.Current != null) HttpContext.Current.Application["statisticList" + DateTime.Now.Day] = statisticList;
 737:                      }
 738:                  }
 739:   
 740:                  return statisticList;
 741:              }
 742:          }
 743:   
 744:          ////////////////////////////////////////////////////////////////////////////
 745:   
 746:          /// <summary>
 747:          ///
 748:          /// </summary>
 749:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea> ServiceAccessStatisticWithinKuwaitNgnArea
 750:          {
 751:              get
 752:              {
 753:                  if (statisticList == null || statisticList.Count == 0)
 754:                  {
 755:                      int c;
 756:                      Dictionary<string, int> accessIdToKuwaitNgnAreaIdDictionary, accessIdToOdfIdDictionary, accessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary;
 757:                      Dictionary<string, string> serviceToAccessIdDictionary, srsServiceToAccessIdDictionary, sServiceToAccessIdDictionary, ontIdToAccessIdDictionary;
 758:                      Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea kuwaitAreaStatistic;
 759:                      Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt;
 760:                      List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> nddOntList;
 761:                      List<Ia.Ngn.Cl.Model.Ont> ontList;
 762:                      List<Ia.Ngn.Cl.Model.Access> accessList;
 763:                      List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea> kuwaitNgnAreaList;
 764:   
 765:                      statisticList = new List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea>();
 766:                      statisticList.Clear();
 767:   
 768:                      //kuwaitNgnAreaList = new List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea>(); // I need to clear it because I add an item in it below
 769:                      kuwaitNgnAreaList = Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList;
 770:   
 771:                      nddOntList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList;
 772:                      ontIdToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Nokia.Ont.IdToAccessIdDictionary;
 773:   
 774:                      ontList = Ia.Ngn.Cl.Model.Data.Nokia.Ont.ListIncludeAccess();
 775:                      accessList = Ia.Ngn.Cl.Model.Data.Access.List();
 776:                      accessIdToOdfIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToOltIdDictionary;
 777:   
 778:                      serviceToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceToAccessIdDictionary;
 779:                      accessIdToKuwaitNgnAreaIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaIdDictionary;
 780:   
 781:                      srsServiceToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceToAccessIdDictionary;
 782:                      sServiceToAccessIdDictionary = Ia.Ngn.Cl.Model.Data.Service2.ServiceIdToAccessIdDictionary;
 783:   
 784:                      accessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary = Ia.Ngn.Cl.Model.Data.Access.AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary;
 785:   
 786:                      //ontIdToOltIdDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIdToOltIdDictionary;
 787:   
 788:                      // - ONT capacity, usage, # of services in an ONT, type of ONT
 789:                      // - Graphics
 790:                      /*
 791:                      update statistics
 792:          Vendor,
 793:          number perfix,
 794:          4 in ONT,
 795:          0 in ONT,
 796:          Acces: ONT used by subscribers
 797:          */
 798:   
 799:                      foreach (var kna in kuwaitNgnAreaList)
 800:                      {
 801:                          kuwaitAreaStatistic = new Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea();
 802:   
 803:                          kuwaitAreaStatistic.Name = kna.NameArabicName;
 804:   
 805:                          kuwaitAreaStatistic.Symbol = kna.Symbol;
 806:   
 807:                          kuwaitAreaStatistic.ServiceRequestService = 0;
 808:   
 809:                          kuwaitAreaStatistic.Service = 0;
 810:   
 811:                          foreach (KeyValuePair<string, string> kvp in sServiceToAccessIdDictionary)
 812:                          {
 813:                              if (accessIdToKuwaitNgnAreaIdDictionary.ContainsKey(kvp.Value))
 814:                              {
 815:                                  if (accessIdToKuwaitNgnAreaIdDictionary[kvp.Value] == kna.Id) kuwaitAreaStatistic.Service++;
 816:                              }
 817:                          }
 818:   
 819:                          kuwaitAreaStatistic.ServiceRequestServiceService = kuwaitAreaStatistic.ServiceRequestService + " (" + kuwaitAreaStatistic.Service + ")";
 820:   
 821:                          //statistic.SiteAccessCapacity = kna.Site.Routers.SelectMany(x => x.Odfs.SelectMany(y => y.Olts)).Count() * 1024;
 822:                          //statistic.SiteAccessCapacity = f.Sum(u => kna.Site.Routers.Any(x => x.Odfs.Any(y => y.Olts.Any(z => z.Id == u.Value)))) * 1024;
 823:                          //kuwaitAreaStatistic.AccessProvisioned = accessIdToKuwaitNgnAreaIdDictionary.Count(u => u.Value == kna.Id);
 824:                          //kuwaitAreaStatistic.AccessUtilized = 0;
 825:   
 826:                          kuwaitAreaStatistic.NokiaOnt = 0;
 827:                          kuwaitAreaStatistic.HuaweiOnt = 0;
 828:   
 829:                          foreach (var o in ontList)
 830:                          {
 831:                              if (o.Access != null)
 832:                              {
 833:                                  if (accessIdToKuwaitNgnAreaIdDictionary.ContainsKey(o.Access.Id))
 834:                                  {
 835:                                      if (accessIdToKuwaitNgnAreaIdDictionary[o.Access.Id] == kna.Id)
 836:                                      {
 837:                                          // <vendor id="1" name="Nokia" shortName="No" ... />
 838:                                          if (o.VendorId == 1) kuwaitAreaStatistic.NokiaOnt++;
 839:   
 840:                                          // <vendor id="2" name="Huawei" shortName="Hu" ... />
 841:                                          else if (o.VendorId == 2) kuwaitAreaStatistic.HuaweiOnt++;
 842:                                      }
 843:                                  }
 844:                              }
 845:                              else
 846:                              {
 847:                              }
 848:                          }
 849:   
 850:                          c = kuwaitAreaStatistic.NokiaOnt + kuwaitAreaStatistic.HuaweiOnt;
 851:                          kuwaitAreaStatistic.OntTotalNokiaHuawei = c + " (" + kuwaitAreaStatistic.NokiaOnt + "/" + kuwaitAreaStatistic.HuaweiOnt + ")";
 852:   
 853:                          kuwaitAreaStatistic.NokiaAccess = 0;
 854:                          kuwaitAreaStatistic.HuaweiAccess = 0;
 855:   
 856:                          foreach (var a in accessList)
 857:                          {
 858:                              if (accessIdToKuwaitNgnAreaIdDictionary[a.Id] == kna.Id)
 859:                              {
 860:                                  olt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList where o.Id == accessIdToOdfIdDictionary[a.Id] select o).SingleOrDefault();
 861:   
 862:                                  if (olt != null)
 863:                                  {
 864:                                      // <vendor id="1" name="Nokia" shortName="No" ... />
 865:                                      if (olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia) kuwaitAreaStatistic.NokiaAccess++;
 866:   
 867:                                      // <vendor id="2" name="Huawei" shortName="Hu" ... />
 868:                                      else if (olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei) kuwaitAreaStatistic.HuaweiAccess++;
 869:                                  }
 870:                                  else
 871:                                  {
 872:   
 873:                                  }
 874:                              }
 875:                          }
 876:   
 877:                          c = kuwaitAreaStatistic.NokiaAccess + kuwaitAreaStatistic.HuaweiAccess;
 878:                          kuwaitAreaStatistic.AccessTotalNokiaHuawei = c + " (" + kuwaitAreaStatistic.NokiaAccess + "/" + kuwaitAreaStatistic.HuaweiAccess + ")";
 879:   
 880:   
 881:                          kuwaitAreaStatistic.AccessReadyForService = 0;
 882:   
 883:                          foreach (var a in accessList)
 884:                          {
 885:                              if (accessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary.ContainsKey(a.Id))
 886:                              {
 887:                                  if (accessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary[a.Id] == kna.Id)
 888:                                  {
 889:                                      kuwaitAreaStatistic.AccessReadyForService++;
 890:                                  }
 891:                              }
 892:                          }
 893:   
 894:                          statisticList.Add(kuwaitAreaStatistic);
 895:                      }
 896:   
 897:                      statisticList.Add(new Ia.Ngn.Cl.Model.Business.Administration.Statistic.KuwaitArea("Unknown", "غير معرف"));
 898:                  }
 899:   
 900:                  return statisticList;
 901:              }
 902:          }
 903:   
 904:          ////////////////////////////////////////////////////////////////////////////
 905:   
 906:          /// <summary>
 907:          ///
 908:          /// </summary>
 909:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site> SiteStatistic()
 910:          {
 911:              int siteId;
 912:              Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site siteStatistic;
 913:              List<Ia.Ngn.Cl.Model.Access> mainAccessList;//, accessList;
 914:              List<Ia.Ngn.Cl.Model.Ont> mainOntList;//, ontList;
 915:              List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site> siteStatisticList;
 916:   
 917:              siteStatisticList = new List<Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site>();
 918:   
 919:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 920:              {
 921:                  mainAccessList = (from a in db.Accesses select a).ToList();
 922:                  mainOntList = (from o in db.Onts select o).ToList();
 923:   
 924:                  // site
 925:                  foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList)
 926:                  {
 927:                      siteStatistic = new Ia.Ngn.Cl.Model.Business.Administration.Statistic.Site();
 928:   
 929:                      siteId = site.Id;
 930:                      siteStatistic.Id = site.Id.ToString();
 931:                      siteStatistic.Name = site.NameArabicName;
 932:   
 933:                      foreach (Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea in site.KuwaitNgnAreas) siteStatistic.KuwaitAreaNameListString += kuwaitNgnArea.ArabicName + ", ";
 934:                      if (siteStatistic.KuwaitAreaNameListString != null && siteStatistic.KuwaitAreaNameListString.Length > 0) siteStatistic.KuwaitAreaNameListString = siteStatistic.KuwaitAreaNameListString.Trim(',', ' ');
 935:   
 936:                      foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Router router in site.Routers) siteStatistic.DomainListString += router.DomainListString + ",";
 937:                      if (siteStatistic.DomainListString != null && siteStatistic.DomainListString.Length > 0) siteStatistic.DomainListString = siteStatistic.DomainListString.Trim(',', ' ');
 938:   
 939:                      foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList)
 940:                      {
 941:                          if (olt.Odf.Router.Site.Id == siteId)
 942:                          {
 943:                              if (string.IsNullOrEmpty(siteStatistic.SymbolListString) || !siteStatistic.SymbolListString.Contains(olt.Symbol)) siteStatistic.SymbolListString += olt.Symbol + ", ";
 944:                          }
 945:                      }
 946:   
 947:                      if (siteStatistic.SymbolListString != null && siteStatistic.SymbolListString.Length > 0) siteStatistic.SymbolListString = siteStatistic.SymbolListString.Trim(',', ' ');
 948:   
 949:                      siteStatistic.AccessCapacity = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList where o.Odf.Router.Site.Id == siteId select o).Count() * 1024;
 950:   
 951:                      //accessList = (from a in mainAccessList where site.Routers.SelectMany(u => u.Odfs.Contains(a.Odf)) select a).ToList();
 952:                      //ontList = (from o in mainOntList where o.Access != null && o.Access.Odf == odf.Id.ToString() select o).ToList();
 953:   
 954:                      /*
 955:                      foreach (Ia.Ngn.Cl.Model.Access access in accessList)
 956:                      {
 957:                      }
 958:                       */
 959:   
 960:                      /*
 961:                      kuwaitAreaStatistic.NddOntNokiaAccessCount = 0;
 962:                      kuwaitAreaStatistic.NddOntHuaweiAccessCount = 0;
 963:  
 964:                      foreach (var o in nddOntList)
 965:                      {
 966:                          if(o.Pon.PonGroup.Olt.Odf.Router.Site)
 967:                          // <vendor id="1" name="Nokia" shortName="No" ... />
 968:                          if (o.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia) kuwaitAreaStatistic.NddOntNokiaAccessCount++;
 969:  
 970:                          // <vendor id="2" name="Huawei" shortName="Hu" ... />
 971:                          else if (o.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei) kuwaitAreaStatistic.NddOntHuaweiAccessCount++;
 972:                      }
 973:  
 974:                      kuwaitAreaStatistic.AccessCount = kuwaitAreaStatistic.NddOntNokiaAccessCount + kuwaitAreaStatistic.NddOntHuaweiAccessCount;
 975:                       */
 976:   
 977:                      siteStatisticList.Add(siteStatistic);
 978:                  }
 979:              }
 980:   
 981:              return siteStatisticList;
 982:          }
 983:   
 984:          /*
 985:          ////////////////////////////////////////////////////////////////////////////
 986:  
 987:          /// <summary>
 988:          ///
 989:          /// </summary>
 990:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> OdfStatistic()
 991:          {
 992:              Ia.Ngn.Cl.Model.Business.Administration.Statistic statistic;
 993:              List<Ia.Ngn.Cl.Model.Access> mainAccessList, accessList;
 994:              List<Ia.Ngn.Cl.Model.Ont> mainOntList, ontList;
 995:              List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> statisticList;
 996:  
 997:              statisticList = new List<Ia.Ngn.Cl.Model.Business.Administration.Statistic>();
 998:  
 999:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1000:              {
1001:                  mainAccessList = (from a in db.Accesses select a).ToList();
1002:                  mainOntList = (from o in db.Onts select o).ToList();
1003:  
1004:                  foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Odf odf in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OdfList)
1005:                  {
1006:                      statistic = new Ia.Ngn.Cl.Model.Business.Administration.Statistic();
1007:  
1008:                      statistic.Id = odf.Id.ToString();
1009:                      statistic.Name = odf.Name;
1010:                      statistic.Site = odf.Router.Site.NameArabicName;
1011:                      statistic.Symbol = odf.Name;
1012:  
1013:                      accessList = (from a in mainAccessList where a.Odf == odf.Id.ToString() select a).ToList();
1014:                      ontList = (from o in mainOntList where o.Access != null && o.Access.Odf == odf.Id.ToString() select o).ToList();
1015:  
1016:                      foreach (Ia.Ngn.Cl.Model.Access access in accessList)
1017:                      {
1018:                      }
1019:  
1020:                      statistic.AccessCapacity = 1024;
1021:                      statistic.AccessInstalledContractor = accessList.Count();
1022:                      statistic.AccessInstalledContractorWithSerial = (from o in ontList where o.Serial != null select o).Count();
1023:  
1024:                      statisticList.Add(statistic);
1025:                  }
1026:  
1027:                  /*
1028:                  accessStatisticList = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList
1029:                       group a by a.Id into grp
1030:                       orderby grp.Key
1031:                       select new Ia.Ngn.Cl.Model.Business.Administration.Statistic()
1032:                       {
1033:                           Id = grp.Key.ToString(),
1034:                           Name = grp.SingleOrDefault().NameArabicName,
1035:                           --InstalledContractor = (from a in db.Accesses where a.AreaId == grp.Key select a.Id).Count().ToString(),
1036:                           InstalledContractorWithSerial = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != null select a.Id).Count().ToString(),
1037:                           Provisioned = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId != 0 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1038:                           ReadyForService = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1039:                           DefinedInCustomerDepartment = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id join sro in db.ServiceRequestOnts on a.Id equals sro.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1040:                           Utilized = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id 
1041:                                         join sro in db.ServiceRequestOnts on a.Id equals sro.Access.Id 
1042:                                         join srs in db.ServiceRequestServices on a.Id equals srs.Access.Id
1043:                                         where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString()
1044:                       }).ToList();
1045:                   */
1046:   
1047:          /*
1048:          if (dt != null)
1049:          {
1050:              // below: the totals rows
1051:  
1052:              dr = dt.NewRow();
1053:              dr["capacity"] = dt.Compute("SUM (capacity)", "").ToString();
1054:              dr["installed_contractor"] = dt.Compute("SUM (installed_contractor)", "").ToString();
1055:              dr["installed_contractor_with_serial"] = dt.Compute("SUM (installed_contractor_with_serial)", "").ToString();
1056:              dr["provisioned"] = dt.Compute("SUM (provisioned)", "").ToString();
1057:              dr["ont_ready_for_service"] = dt.Compute("SUM (ont_ready_for_service)", "").ToString();
1058:              dr["ont_defined_cs"] = dt.Compute("SUM (ont_defined_cs)", "").ToString();
1059:              dt.Rows.Add(dr);
1060:          }
1061:           * /
1062:      }
1063:  
1064:      return statisticList;
1065:  }
1066:  */
1067:   
1068:          /*
1069:          ////////////////////////////////////////////////////////////////////////////
1070:  
1071:          /// <summary>
1072:          ///
1073:          /// </summary>
1074:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> OltStatistic()
1075:          {
1076:              Ia.Ngn.Cl.Model.Business.Administration.Statistic statistic;
1077:              List<Ia.Ngn.Cl.Model.Access> mainAccessList, accessList;
1078:              List<Ia.Ngn.Cl.Model.Ont> mainOntList, ontList;
1079:              List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> statisticList;
1080:  
1081:              statisticList = new List<Ia.Ngn.Cl.Model.Business.Administration.Statistic>();
1082:  
1083:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1084:              {
1085:                  /*
1086:                  var v =
1087:                      (from a in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList
1088:                       group a by a.Id into grp
1089:                       orderby grp.Key
1090:                       select new
1091:                       {
1092:                           Id = grp.Key,
1093:                           Name = grp.SingleOrDefault().NameArabicName,
1094:                           Capacity = grp.Sum(w => w.Routers.SelectMany(x => x.Odfs.SelectMany(y => y.Olts)).Count()) * 1024,
1095:                       })
1096:                      .ToList();
1097:                   * /
1098:  
1099:                  mainAccessList = (from a in db.Accesses select a).ToList();
1100:                  mainOntList = (from o in db.Onts select o).ToList();
1101:  
1102:                  foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList)
1103:                  {
1104:                      statistic = new Ia.Ngn.Cl.Model.Business.Administration.Statistic();
1105:  
1106:                      statistic.Id = olt.Id.ToString();
1107:                      statistic.Name = olt.Name;
1108:                      statistic.Site = olt.Odf.Router.Site.NameArabicName;
1109:                      statistic.Symbol = olt.Symbol;
1110:  
1111:                      accessList = (from a in mainAccessList where a.Olt == olt.Id select a).ToList();
1112:                      ontList = (from o in mainOntList where o.Access != null && o.Access.Olt == olt.Id select o).ToList();
1113:  
1114:                      foreach (Ia.Ngn.Cl.Model.Access access in accessList)
1115:                      {
1116:                      }
1117:  
1118:                      statistic.AccessCapacity = 1024;
1119:                      statistic.AccessInstalledContractor = accessList.Count();
1120:                      statistic.AccessInstalledContractorWithSerial = (from o in ontList where o.Serial != null select o).Count();
1121:  
1122:                      statisticList.Add(statistic);
1123:                  }
1124:  
1125:                  /*
1126:                  accessStatisticList = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList
1127:                       group a by a.Id into grp
1128:                       orderby grp.Key
1129:                       select new Ia.Ngn.Cl.Model.Business.Administration.Statistic()
1130:                       {
1131:                           Id = grp.Key.ToString(),
1132:                           Name = grp.SingleOrDefault().NameArabicName,
1133:                           --InstalledContractor = (from a in db.Accesses where a.AreaId == grp.Key select a.Id).Count().ToString(),
1134:                           InstalledContractorWithSerial = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != null select a.Id).Count().ToString(),
1135:                           Provisioned = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId != 0 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1136:                           ReadyForService = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1137:                           DefinedInCustomerDepartment = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id join sro in db.ServiceRequestOnts on a.Id equals sro.Access.Id where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString(),
1138:                           Utilized = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id 
1139:                                         join sro in db.ServiceRequestOnts on a.Id equals sro.Access.Id 
1140:                                         join srs in db.ServiceRequestServices on a.Id equals srs.Access.Id
1141:                                         where a.AreaId == grp.Key && o.Serial != "ALCL00000000" && o.StateId == 1 && o.ActiveSoftware == o.PlannedSoftware select a.Id).Count().ToString()
1142:                       }).ToList();
1143:                   */
1144:   
1145:          /*
1146:          if (dt != null)
1147:          {
1148:              // below: the totals rows
1149:  
1150:              dr = dt.NewRow();
1151:              dr["capacity"] = dt.Compute("SUM (capacity)", "").ToString();
1152:              dr["installed_contractor"] = dt.Compute("SUM (installed_contractor)", "").ToString();
1153:              dr["installed_contractor_with_serial"] = dt.Compute("SUM (installed_contractor_with_serial)", "").ToString();
1154:              dr["provisioned"] = dt.Compute("SUM (provisioned)", "").ToString();
1155:              dr["ont_ready_for_service"] = dt.Compute("SUM (ont_ready_for_service)", "").ToString();
1156:              dr["ont_defined_cs"] = dt.Compute("SUM (ont_defined_cs)", "").ToString();
1157:              dt.Rows.Add(dr);
1158:          }
1159:           * /
1160:      }
1161:  
1162:      return statisticList;
1163:  }
1164:  */
1165:   
1166:          /*
1167:          ////////////////////////////////////////////////////////////////////////////
1168:  
1169:          /// <summary>
1170:          ///
1171:          /// </summary>
1172:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> PhoneStatistic(string timePeriod)
1173:          {
1174:              List<Ia.Ngn.Cl.Model.Business.Administration.Statistic> phoneStatisticList;
1175:              
1176:              /*
1177:              string s, where;
1178:              DateTime from, to;
1179:              DataTable dt;
1180:  
1181:              if (timePeriod != null)
1182:              {
1183:                  from = DateTime.Parse(timePeriod);
1184:                  to = DateTime.Parse(timePeriod);
1185:                  to = to.AddMonths(1);
1186:  
1187:                  where = " AND (sr.request_time >= '" + sqlserver.SmallDateTime(from) + "' AND sr.request_time < '" + sqlserver.SmallDateTime(to) + "') ";
1188:              }
1189:              else where = "";
1190:               * /
1191:              
1192:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1193:              {
1194:                  phoneStatisticList = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList
1195:                       group a by a.Id into grp
1196:                       orderby grp.Key
1197:                       select new Ia.Ngn.Cl.Model.Business.Administration.Statistic()
1198:                       {
1199:                           Id = grp.Key.ToString(),
1200:                           Name = grp.SingleOrDefault().NameArabicName,
1201:                           //ServiceRequests = (from sr in db.ServiceRequests where sr.AreaId == grp.Key && sr.ServiceRequestService != null select sr.Id).Count().ToString(),
1202:                           ServiceRequestServices = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key select srs.Id).Count(),
1203:                           Services = (from s in db.Service2s where s.Access != null && s.Access.AreaId == grp.Key select s.Id).Count(),
1204:                           InternationalCalling = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.InternationalCalling == true select srs.Id).Count(),
1205:                           InternationalCallingUserControlled = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.InternationalCallingUserControlled == true select srs.Id).Count(),
1206:                           CallWaiting = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallWaiting == true select srs.Id).Count(),
1207:  
1208:                           AlarmCall = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.AlarmCall == true select srs.Id).Count(),
1209:  
1210:                           CallBarring = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallBarring == true select srs.Id).Count(),
1211:                           CallerId = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallerId == true select srs.Id).Count(),
1212:                           CallForwarding = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallForwarding == true select srs.Id).Count(),
1213:                           ConferenceCall = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.ConferenceCall == true select srs.Id).Count(),
1214:                           ServiceSuspension = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.ServiceSuspension == true select srs.Id).Count()
1215:                       }).ToList();
1216:  
1217:                  /*
1218:                  if (dt != null)
1219:                  {
1220:                      // below: the totals rows
1221:                      dr = dt.NewRow();
1222:  
1223:                      dr["SRS_AccessIdNotNull"] = dt.Compute("SUM (SRS_AccessIdNotNull)", "").ToString();
1224:                      dr["IMS_AccessIdNotNull"] = dt.Compute("SUM (IMS_AccessIdNotNull)", "").ToString();
1225:                      dr["SRS_AccordingToAreaIdFromDomain"] = dt.Compute("SUM (SRS_AccordingToAreaIdFromDomain)", "").ToString();
1226:  
1227:                      dr["InternationalCalling"] = dt.Compute("SUM (InternationalCalling)", "").ToString();
1228:                      dr["InternationalCallingUserControlled"] = dt.Compute("SUM (InternationalCallingUserControlled)", "").ToString();
1229:                      dr["CallWaiting"] = dt.Compute("SUM (CallWaiting)", "").ToString();
1230:                      dr["AlarmCall"] = dt.Compute("SUM (AlarmCall)", "").ToString();
1231:                      dr["CallBarring"] = dt.Compute("SUM (CallBarring)", "").ToString();
1232:                      dr["CallerId"] = dt.Compute("SUM (CallerId)", "").ToString();
1233:                      dr["CallForwarding"] = dt.Compute("SUM (CallForwarding)", "").ToString();
1234:                      dr["ConferenceCall"] = dt.Compute("SUM (ConferenceCall)", "").ToString();
1235:                      dr["ServiceSuspension"] = dt.Compute("SUM (ServiceSuspension)", "").ToString();
1236:  
1237:                      dt.Rows.Add(dr);
1238:                  }
1239:                   * /
1240:              }
1241:  
1242:              return phoneStatisticList;
1243:          }
1244:          */
1245:   
1246:          ////////////////////////////////////////////////////////////////////////////
1247:   
1248:          /// <summary>
1249:          ///
1250:          /// </summary>
1251:          public static List<Ia.Ngn.Cl.Model.Ui.Performance> StaffAndFrameworkPerformanceReport(int daysAgo)
1252:          {
1253:              DateTime startDateTime;
1254:              List<Ia.Ngn.Cl.Model.Ui.Performance> performanceList;
1255:   
1256:              // after 2015-06-01 user report closer inserts a last historic report
1257:              // I should designate last report as CLOSED and add it to resolution list to be accessed by HEAD only.
1258:   
1259:              // if daysAgo is 0 will make it 9999 days to cover all times
1260:              startDateTime = DateTime.UtcNow.AddDays(daysAgo == 0 ? -9999 : -daysAgo);
1261:   
1262:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1263:              {
1264:                  performanceList =
1265:                      (
1266:                      from staff in (from s in db.Staff group s.UserId by s.UserId into g select new { UserId = g.Key, Count = g.Count() })
1267:   
1268:                      join resolved in (from r in db.ReportHistories where r.Resolution == 1020 && r.Created > startDateTime group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1269:                      on staff.UserId equals resolved.UserId into resolved_gj
1270:                      from re in resolved_gj.DefaultIfEmpty()
1271:   
1272:                      join attempted in (from r in db.ReportHistories where r.Resolution != 1020 && r.Created > startDateTime group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1273:                      on staff.UserId equals attempted.UserId into attempted_gj
1274:                      from at in attempted_gj.DefaultIfEmpty()
1275:   
1276:                      join inserted in
1277:                          (from r in db.Reports where r.Created > startDateTime group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1278:                      on staff.UserId equals inserted.UserId into inserted_gj
1279:                      from ins in inserted_gj.DefaultIfEmpty()
1280:   
1281:                      join open in
1282:                          (from r in db.Reports where r.Created > startDateTime group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1283:                      on staff.UserId equals open.UserId into open_gj
1284:                      from opn in open_gj.DefaultIfEmpty()
1285:   
1286:                          // below: the 20, 10, 1 give weight to the field
1287:                      orderby re.Count descending, at.Count descending, ins.Count descending
1288:   
1289:                      select new Ia.Ngn.Cl.Model.Ui.Performance
1290:                      {
1291:                          UserId = staff.UserId,
1292:                          Resolved = (re == null ? 0 : re.Count),
1293:                          Attempted = (at == null ? 0 : at.Count),
1294:                          Inserted = (ins == null ? 0 : ins.Count),
1295:                          Open = (ins == null ? 0 : opn.Count),
1296:                          AverageReportsPerDay = 0
1297:                      }).ToList();
1298:   
1299:                  /*
1300:      select users.UserId, resolved.count,attempted.count,inserted.count from
1301:      (
1302:      (select count(*) as count, UserId from Users group by UserId) as users
1303:      left outer join
1304:      (select count(*) as count, rh.UserId from ReportHistories as rh where rh.Resolution = 1020 group by rh.UserId) as resolved
1305:      on users.UserId = resolved.UserId
1306:      left outer join
1307:      (select count(*) as count, rh.UserId from ReportHistories as rh where rh.Resolution <> 1020 group by rh.UserId) as attempted
1308:      on users.UserId = attempted.UserId
1309:      left outer join
1310:      (select count(*) as count, UserId from Reports group by UserId) as inserted
1311:      on users.UserId = inserted.UserId
1312:      )
1313:      order by resolved.count*20+attempted.count*10+inserted.count desc
1314:              */
1315:              }
1316:   
1317:              return performanceList;
1318:          }
1319:   
1320:          ////////////////////////////////////////////////////////////////////////////
1321:   
1322:          /// <summary>
1323:          ///
1324:          /// </summary>
1325:          public static List<Ia.Ngn.Cl.Model.Ui.Performance> StatisticsOfResolvedAndAttemptedAndInsertedStaffReport2(Guid userId)
1326:          {
1327:              List<Ia.Ngn.Cl.Model.Ui.Performance> performanceList;
1328:   
1329:              // after 2015-06-01 user report closer inserts a last historic report
1330:              // I should designate last report as CLOSED and add it to resolution list to be accessed by HEAD only.
1331:   
1332:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1333:              {
1334:                  performanceList =
1335:                      (
1336:                      from staff in
1337:                          (from s in db.Staff group s.UserId by s.UserId into g select new { UserId = g.Key, Count = g.Count() })
1338:                      join resolved in
1339:                          (from r in db.ReportHistories where r.Resolution == 1020 group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1340:                      on staff.UserId equals resolved.UserId into resolved_gj
1341:                      from re in resolved_gj.DefaultIfEmpty()
1342:   
1343:                      join attempted in
1344:                          (from r in db.ReportHistories where r.Resolution != 1020 group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1345:                      on staff.UserId equals attempted.UserId into attempted_gj
1346:                      from at in attempted_gj.DefaultIfEmpty()
1347:   
1348:                      join inserted in
1349:                          (from r in db.Reports group r.UserId by r.UserId into g select new { UserId = g.Key, Count = g.Count() })
1350:                      on staff.UserId equals inserted.UserId into inserted_gj
1351:                      from ins in inserted_gj.DefaultIfEmpty()
1352:                          // below: the 20, 10, 1 give weight to the field
1353:                      orderby re.Count descending, at.Count descending, ins.Count descending
1354:                      select new Ia.Ngn.Cl.Model.Ui.Performance
1355:                      {
1356:                          UserId = staff.UserId,
1357:                          Resolved = (re == null ? 0 : re.Count),
1358:                          Attempted = (at == null ? 0 : at.Count),
1359:                          Inserted = (ins == null ? 0 : ins.Count),
1360:                          AverageReportsPerDay = 0
1361:                      }).ToList();
1362:   
1363:                  /*
1364:      select users.UserId, resolved.count,attempted.count,inserted.count from
1365:      (
1366:      (select count(*) as count, UserId from Users group by UserId) as users
1367:      left outer join
1368:      (select count(*) as count, rh.UserId from ReportHistories as rh where rh.Resolution = 1020 group by rh.UserId) as resolved
1369:      on users.UserId = resolved.UserId
1370:      left outer join
1371:      (select count(*) as count, rh.UserId from ReportHistories as rh where rh.Resolution <> 1020 group by rh.UserId) as attempted
1372:      on users.UserId = attempted.UserId
1373:      left outer join
1374:      (select count(*) as count, UserId from Reports group by UserId) as inserted
1375:      on users.UserId = inserted.UserId
1376:      )
1377:      order by resolved.count*20+attempted.count*10+inserted.count desc
1378:              */
1379:              }
1380:   
1381:              return performanceList.ToList();
1382:          }
1383:   
1384:          ////////////////////////////////////////////////////////////////////////////
1385:   
1386:          /// <summary>
1387:          ///
1388:          /// </summary>
1389:          public DataTable CountOfActiveNumbersInArea()
1390:          {
1391:              return CountOfActiveNumbersInAreaByTimePeriod(null);
1392:          }
1393:   
1394:          ////////////////////////////////////////////////////////////////////////////
1395:   
1396:          /// <summary>
1397:          ///
1398:          /// </summary>
1399:          public static DataTable CountOfActiveNumbersInAreaByTimePeriod(string timePeriod)
1400:          {
1401:              string s, where;
1402:              DateTime from, to;
1403:              DataTable dt;
1404:   
1405:              if (timePeriod != null)
1406:              {
1407:                  from = DateTime.Parse(timePeriod);
1408:                  to = DateTime.Parse(timePeriod);
1409:                  to = to.AddMonths(1);
1410:   
1411:                  where = null; // " AND (sr.request_time >= '" + sqlserver.SmallDateTime(from) + "' AND sr.request_time < '" + sqlserver.SmallDateTime(to) + "') ";
1412:              }
1413:              else where = "";
1414:   
1415:              s = @"SELECT COUNT(1) AS count, f.area
1416:  FROM         ia_system AS s INNER JOIN
1417:                        ia_protocol AS p ON s.lceid = p.lceid AND s.lan = p.lan INNER JOIN
1418:                        ia_standard AS st ON st.ip = p.ip INNER JOIN
1419:                        ia_field AS f ON f.id = st.id LEFT OUTER JOIN
1420:                        ia_service_request_service AS srs ON srs.dn = s.dn LEFT OUTER JOIN
1421:                        ia_service_request AS sr ON sr.id = srs.ia_service_request_id
1422:  WHERE f.area != 0 " + where + @" GROUP BY f.area ";
1423:   
1424:              dt = null; // sqlserver.Select(s);
1425:   
1426:              return dt;
1427:          }
1428:   
1429:          ////////////////////////////////////////////////////////////////////////////    
1430:   
1431:          /// <summary>
1432:          ///
1433:          /// </summary>
1434:          public static Dictionary<string, int> DateTimesWithAvailableData()
1435:          {
1436:              Dictionary<string, int> dic;
1437:   
1438:   
1439:              dic = new Dictionary<string, int>(100);
1440:   
1441:   
1442:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1443:              {
1444:                  //dic = (from q in db.ServiceRequests orderby q.RequestDateTime select q.RequestDateTime).Distinct().ToDictionary(r => r.CustomerName, r => r.Id);
1445:   
1446:                  // dictionary = (from q in ReportXDocument.Elements("report").Elements("category") select new { Id = int.Parse(q.Attribute("id").Value), Name = q.Attribute("name").Value }).ToDictionary(r => r.Id, r => r.Name);
1447:   
1448:              }
1449:   
1450:              /*
1451:  SELECT DISTINCT CONVERT(varchar(7), RequestDateTime, 102) AS date, COUNT(1) AS count
1452:  FROM [Ia_Ngn].[dbo].[ServiceRequests]
1453:  GROUP BY CONVERT(varchar(7), RequestDateTime, 102)
1454:  ORDER BY date
1455:               */
1456:   
1457:              return dic;
1458:          }
1459:   
1460:          ////////////////////////////////////////////////////////////////////////////
1461:          ////////////////////////////////////////////////////////////////////////////
1462:   
1463:          /// <summary>
1464:          /// 
1465:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
1466:          /// 
1467:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
1468:          /// 2. Add "using System.Reflection".
1469:          /// 3. See sample below.
1470:          /// 
1471:          /// </summary>
1472:   
1473:          private static XDocument XDocument
1474:          {
1475:              get
1476:              {
1477:                  Assembly _assembly;
1478:                  StreamReader streamReader;
1479:   
1480:                  if (xDocument == null)
1481:                  {
1482:                      _assembly = Assembly.GetExecutingAssembly();
1483:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.administration.xml"));
1484:   
1485:                      try
1486:                      {
1487:                          if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
1488:                      }
1489:                      catch (Exception)
1490:                      {
1491:                      }
1492:                      finally
1493:                      {
1494:                      }
1495:                  }
1496:   
1497:                  return xDocument;
1498:              }
1499:          }
1500:   
1501:          ////////////////////////////////////////////////////////////////////////////
1502:          ////////////////////////////////////////////////////////////////////////////    
1503:      }
1504:   
1505:      ////////////////////////////////////////////////////////////////////////////
1506:      ////////////////////////////////////////////////////////////////////////////   
1507:  }