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

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

Administration support class for Fixed Telecommunications Network (FTN) data model.

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