Ejemplo n.º 1
0
 /// <summary>
 ///     Registers the Patient component service classes. Operation in the DI container
 /// </summary>
 /// <param name="services">Specifies the contract for a collection of service descriptors</param>
 /// <returns></returns>
 public static IServiceCollection Register(this IServiceCollection services)
 {
     ApplicationService.Register(services);
     DomainService.Register(services);
     InfrastructureService.Register(services);
     return(services);
 }
Ejemplo n.º 2
0
    void BindInfrastructure()
    {
        Infrastructure        infra        = new Infrastructure();
        InfrastructureService infraService = new InfrastructureService();

        infra = infraService.GetInfrastructureByReport(ReportId);
        if (infra != null)
        {
            if (infra.ProduceAreaNo > 0)
            {
                ltProduceArea.Text = infra.ProduceAreaNo.ToString();
            }
            if (infra.OfficeAreaNo > 0)
            {
                ltOfficeArea.Text = infra.OfficeAreaNo.ToString();
            }
            if (infra.ProduceEmployeeNo > 0)
            {
                ltProduceEmployeeNo.Text = infra.ProduceEmployeeNo.ToString();
            }
            if (infra.OfficeEmployeeNo > 0)
            {
                ltOfficeEmployeeNo.Text = infra.OfficeEmployeeNo.ToString();
            }
        }
    }
Ejemplo n.º 3
0
    public ulong GetNewID(InfrastructureBuilding building) //So far, only parks, police stations and schools require IDs and are limited in number.
    {
        InfrastructureService type = building.InfrastructureType();
        ulong newID = 0;

        switch (type)
        {
        case InfrastructureService.parks:
            newID = parkIDHandler.AssignNewBuilding(building.gameObject.GetComponent <Park_1>());
            break;

        case InfrastructureService.safety:
            newID = policeIDHandler.AssignNewBuilding(building.gameObject.GetComponent <PoliceStation_1>());
            break;

        case InfrastructureService.education:
            newID = schoolIDHandler.AssignNewBuilding(building.gameObject.GetComponent <School_1>());
            break;

        default:
            break;
        }

        return(newID);
    }
Ejemplo n.º 4
0
    public void UnetInfrastructureLayerCoverageByID(ulong id, InfrastructureService type) //TODO test this
    {
        //Make a reference to the layer we will modify based on service type
        GridLayer <ulong> targetLayer;

        switch (type)
        {
        case InfrastructureService.parks:
            targetLayer = parksLayer;
            break;

        case InfrastructureService.safety:
            targetLayer = policeLayer;
            break;

        case InfrastructureService.education:
            targetLayer = schoolsLayer;
            break;

        default:
            print("WARNING! Attempting to unset infralayer coverage for non supporting type: " + type);
            return;
        }

        //Loop over entire grid and unset the id bit (op is fast, should be able to get away with it with minimal performance impact)
        for (uint i = 0; i < noOfCells.x; i++)
        {
            for (uint j = 0; j < noOfCells.y; j++)
            {
                targetLayer.GetCellRef(j, i) = targetLayer.GetCellValue(j, i) & (~id);
            }
        }
    }
Ejemplo n.º 5
0
    public InfrastructureBuilding GetInfrastructureBuilding(InfrastructureService type, ulong id) //Used for buildings with unique IDs only.
    {
        switch (type)
        {
        // case InfrastructureService.water:
        //     break;
        // case InfrastructureService.power:
        //     break;
        // case InfrastructureService.health:
        //     break;
        case InfrastructureService.education:
            return(schoolIDHandler.Building(id));

        // case InfrastructureService.gas:
        //     break;
        case InfrastructureService.safety:
            return(policeIDHandler.Building(id));

        case InfrastructureService.parks:
            return(parkIDHandler.Building(id));

        default:
            return(null);
        }
    }
Ejemplo n.º 6
0
    void AddInfrastructureBuilding(InfrastructureBuilding building, InfrastructureService type)
    {
        switch (type)
        {
        case InfrastructureService.water:
            waterProductionBuildings.Add(building);
            break;

        case InfrastructureService.power:
            powerProductionBuildings.Add(building);
            break;

        case InfrastructureService.health:
            break;

        case InfrastructureService.education:
            break;

        case InfrastructureService.gas:
            break;

        case InfrastructureService.safety:
            break;

        case InfrastructureService.parks:
            break;

        default:
            break;
        }
    }
        /// <summary>
        /// <see cref="SifService{UI, DB}.Create(UI, string, string)"/>
        /// </summary>
        public override Guid Create(environmentType item, string zoneId = null, string contextId = null)
        {
            EnvironmentRegister environmentRegister =
                (new EnvironmentRegisterService()).RetrieveByUniqueIdentifiers
                    (item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId);

            if (environmentRegister == null)
            {
                string errorMessage = string.Format("Environment with application key of {0}, solution ID of {1}, instance ID of {2} and user token of {3} does NOT exist.",
                                                    item.applicationInfo.applicationKey, (item.solutionId == null ? "[null]" : item.solutionId), (item.instanceId == null ? "[null]" : item.instanceId), (item.userToken == null ? "[null]" : item.userToken));
                throw new AlreadyExistsException(errorMessage);
            }

            string sessionToken = AuthenticationUtils.GenerateSessionToken(item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId);

            environmentType environmentType = RetrieveBySessionToken(sessionToken);

            if (environmentType != null)
            {
                string errorMessage = string.Format("A session token already exists for environment with application key of {0}, solution ID of {1}, instance ID of {2} and user token of {3}.",
                                                    item.applicationInfo.applicationKey, (item.solutionId == null ? "[null]" : item.solutionId), (item.instanceId == null ? "[null]" : item.instanceId), (item.userToken == null ? "[null]" : item.userToken));
                throw new AlreadyExistsException(errorMessage);
            }

            IDictionary <InfrastructureServiceNames, InfrastructureService> infrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices);
            IDictionary <string, ProvisionedZone> provisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones);
            Environment repoItem = MapperFactory.CreateInstance <environmentType, Environment>(item);

            if (environmentRegister.DefaultZone != null)
            {
                repoItem.DefaultZone = CopyDefaultZone(environmentRegister.DefaultZone);
            }

            if (infrastructureServices.Count > 0)
            {
                repoItem.InfrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices);
            }

            if (provisionedZones.Count > 0)
            {
                repoItem.ProvisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones);
            }

            repoItem.SessionToken = sessionToken;
            Guid environmentId = repository.Save(repoItem);

            if (repoItem.InfrastructureServices.Count > 0)
            {
                InfrastructureService infrastructureService = repoItem.InfrastructureServices[InfrastructureServiceNames.environment];

                if (infrastructureService != null)
                {
                    infrastructureService.Value = infrastructureService.Value + "/" + environmentId;
                    repository.Save(repoItem);
                }
            }

            return(environmentId);
        }
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _InfrastructureService = new InfrastructureService(LanguageRequest, User);
     _TVItemLinkService     = new TVItemLinkService(LanguageRequest, User);
     _MapInfoPointService   = new MapInfoPointService(LanguageRequest, User);
     _AddressService        = new AddressService(LanguageRequest, User);
 }
Ejemplo n.º 9
0
        private void SetupTest(ContactModel contactModelToDo, CultureInfo culture, string actionStr)
        {
            LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

            if (contactModelToDo == null)
            {
                user = null;
            }
            else
            {
                user = new GenericPrincipal(new GenericIdentity(contactModelToDo.LoginEmail, "Forms"), null);
            }
            routeData = new RouteData();
            routeData.Values.Add("culture", culture);
            routeData.Values.Add("controller", "Infrastructure");
            routeData.Values.Add("action", actionStr);

            stubHttpContext            = new StubHttpContextBase();
            stubHttpRequestBase        = new StubHttpRequestBase();
            stubHttpContext.RequestGet = () => stubHttpRequestBase;
            requestContext             = new RequestContext(stubHttpContext, routeData);
            controller     = new InfrastructureController();
            controller.Url = new UrlHelper(requestContext);
            controller.ControllerContext = new ControllerContext(stubHttpContext, routeData, controller);
            stubHttpContext.UserGet      = () => user;
            randomService         = new RandomService(languageEnum, user);
            tvItemService         = new TVItemService(languageEnum, user);
            infrastructureService = new InfrastructureService(languageEnum, user);
            tvItemLinkService     = new TVItemLinkService(languageEnum, user);
            mapInfoPointService   = new MapInfoPointService(languageEnum, user);

            controller.SetRequestContext(requestContext);

            Assert.IsNotNull(controller);
            Assert.AreEqual(2, controller.CultureListAllowable.Count);
            Assert.AreEqual("en-CA", controller.CultureListAllowable[0]);
            Assert.AreEqual("fr-CA", controller.CultureListAllowable[1]);
            Assert.IsNotNull(controller._ContactService);
            Assert.IsNotNull(controller._RequestContext);
            Assert.IsNotNull(controller._InfrastructureService);
            Assert.IsNotNull(controller._TVItemService);
            Assert.IsNotNull(controller.urlModel);
            Assert.IsNotNull(culture.Name, controller._RequestContext.RouteData.Values["culture"].ToString());
            Assert.IsNotNull("Infrastructure", controller._RequestContext.RouteData.Values["controller"].ToString());
            Assert.IsNotNull(actionStr, controller._RequestContext.RouteData.Values["action"].ToString());
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.LanguageRequest);
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.ViewBag.Language);
            Assert.AreEqual(culture.Name, controller.CultureRequest);
            Assert.AreEqual(culture.Name, controller.ViewBag.Culture);
            if (contactModelToDo != null)
            {
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.IsAdmin);
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.ViewBag.IsAdmin);
            }
            Assert.AreEqual(true, controller.Debug);
            Assert.AreEqual(true, controller.ViewBag.Debug);
        }
Ejemplo n.º 10
0
    bool IsInfrastructureSet(InfrastructureService service, InfrastructureService cellServices)
    {
        if ((cellServices & service) == service) //TODO check this.
        {
            return(true);
        }

        return(false);
    }
        public void Infrastructure_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(infrastructureController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType);

                    Infrastructure infrastructureLast = new Infrastructure();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        InfrastructureService infrastructureService = new InfrastructureService(query, db, ContactID);
                        infrastructureLast = (from c in db.Infrastructures select c).FirstOrDefault();
                    }

                    // ok with Infrastructure info
                    IHttpActionResult jsonRet = infrastructureController.GetInfrastructureWithID(infrastructureLast.InfrastructureID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <Infrastructure> Ret = jsonRet as OkNegotiatedContentResult <Infrastructure>;
                    Infrastructure infrastructureRet = Ret.Content;
                    Assert.AreEqual(infrastructureLast.InfrastructureID, infrastructureRet.InfrastructureID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = infrastructureController.Put(infrastructureRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <Infrastructure> infrastructureRet2 = jsonRet2 as OkNegotiatedContentResult <Infrastructure>;
                    Assert.IsNotNull(infrastructureRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because InfrastructureID of 0 does not exist
                    infrastructureRet.InfrastructureID = 0;
                    IHttpActionResult jsonRet3 = infrastructureController.Put(infrastructureRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <Infrastructure> infrastructureRet3 = jsonRet3 as OkNegotiatedContentResult <Infrastructure>;
                    Assert.IsNull(infrastructureRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
 public IHttpActionResult GetInfrastructureList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
 {
     using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
     {
         InfrastructureService infrastructureService = new InfrastructureService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Ejemplo n.º 13
0
 public KMZService(LanguageEnum LanguageRequest, IPrincipal User)
     : base(LanguageRequest, User)
 {
     _TVItemService         = new TVItemService(LanguageRequest, User);
     _TVItemLinkService     = new TVItemLinkService(LanguageRequest, User);
     _PolSourceSiteService  = new PolSourceSiteService(LanguageRequest, User);
     _InfrastructureService = new InfrastructureService(LanguageRequest, User);
     _MapInfoService        = new MapInfoService(LanguageRequest, User);
     _LogService            = new LogService(LanguageRequest, User);
 }
Ejemplo n.º 14
0
 public AcademicsController(InfrastructureService infraService, StudentService studentService, InquiryService inquiryService, InstitutionService institutionService,
                            FeeService feeService, StudentProgramService studentprogramService)
 {
     this._infraService          = infraService;
     this._studentService        = studentService;
     this._inquiryService        = inquiryService;
     this._institutionService    = institutionService;
     this._feeService            = feeService;
     this._studentprogramService = studentprogramService;
 }
Ejemplo n.º 15
0
    void GetCellInfrastructureStates(ref Cell cell)
    {
        InfrastructureService cellServices = infrastructureLayer.GetCellValue(cell.cellID[0], cell.cellID[1]);

        cell.isEducated = IsInfrastructureSet(InfrastructureService.education, cellServices);
        cell.isHealthed = IsInfrastructureSet(InfrastructureService.health, cellServices);
        cell.isPowered  = IsInfrastructureSet(InfrastructureService.power, cellServices);
        cell.isWatered  = IsInfrastructureSet(InfrastructureService.water, cellServices);

        cell.servicingParks   = parksLayer.GetCellValue(cell.cellID[0], cell.cellID[1]);
        cell.servicingSchools = schoolsLayer.GetCellValue(cell.cellID[0], cell.cellID[1]);
        cell.servicingPolice  = policeLayer.GetCellValue(cell.cellID[0], cell.cellID[1]);
    }
Ejemplo n.º 16
0
        public IHttpActionResult GetInfrastructureWithID([FromUri] int InfrastructureID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                InfrastructureService infrastructureService = new InfrastructureService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                infrastructureService.Query = infrastructureService.FillQuery(typeof(Infrastructure), lang, 0, 1, "", "", extra);

                if (infrastructureService.Query.Extra == "A")
                {
                    InfrastructureExtraA infrastructureExtraA = new InfrastructureExtraA();
                    infrastructureExtraA = infrastructureService.GetInfrastructureExtraAWithInfrastructureID(InfrastructureID);

                    if (infrastructureExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(infrastructureExtraA));
                }
                else if (infrastructureService.Query.Extra == "B")
                {
                    InfrastructureExtraB infrastructureExtraB = new InfrastructureExtraB();
                    infrastructureExtraB = infrastructureService.GetInfrastructureExtraBWithInfrastructureID(InfrastructureID);

                    if (infrastructureExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(infrastructureExtraB));
                }
                else
                {
                    Infrastructure infrastructure = new Infrastructure();
                    infrastructure = infrastructureService.GetInfrastructureWithInfrastructureID(InfrastructureID);

                    if (infrastructure == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(infrastructure));
                }
            }
        }
Ejemplo n.º 17
0
        private IDictionary <InfrastructureServiceNames, InfrastructureService> CopyInfrastructureServices(IDictionary <InfrastructureServiceNames, InfrastructureService> sourceInfrastructureServices)
        {
            IDictionary <InfrastructureServiceNames, InfrastructureService> destinationInfrastructureServices = new Dictionary <InfrastructureServiceNames, InfrastructureService>();

            if (sourceInfrastructureServices != null && sourceInfrastructureServices.Count > 0)
            {
                foreach (InfrastructureService sourceInfrastructureService in sourceInfrastructureServices.Values)
                {
                    InfrastructureService destinationInfrastructureService = new InfrastructureService {
                        Name = sourceInfrastructureService.Name, Value = sourceInfrastructureService.Value
                    };
                    destinationInfrastructureServices.Add(destinationInfrastructureService.Name, destinationInfrastructureService);
                }
            }

            return(destinationInfrastructureServices);
        }
        public void Infrastructure_Controller_GetInfrastructureWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    InfrastructureController infrastructureController = new InfrastructureController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(infrastructureController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureController.DatabaseType);

                    Infrastructure infrastructureFirst = new Infrastructure();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        InfrastructureService infrastructureService = new InfrastructureService(new Query(), db, ContactID);
                        infrastructureFirst = (from c in db.Infrastructures select c).FirstOrDefault();
                    }

                    // ok with Infrastructure info
                    IHttpActionResult jsonRet = infrastructureController.GetInfrastructureWithID(infrastructureFirst.InfrastructureID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <Infrastructure> Ret = jsonRet as OkNegotiatedContentResult <Infrastructure>;
                    Infrastructure infrastructureRet = Ret.Content;
                    Assert.AreEqual(infrastructureFirst.InfrastructureID, infrastructureRet.InfrastructureID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = infrastructureController.GetInfrastructureWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <Infrastructure> infrastructureRet2 = jsonRet2 as OkNegotiatedContentResult <Infrastructure>;
                    Assert.IsNull(infrastructureRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Ejemplo n.º 19
0
        public IHttpActionResult Delete([FromBody] Infrastructure infrastructure, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                InfrastructureService infrastructureService = new InfrastructureService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!infrastructureService.Delete(infrastructure))
                {
                    return(BadRequest(String.Join("|||", infrastructure.ValidationResults)));
                }
                else
                {
                    infrastructure.ValidationResults = null;
                    return(Ok(infrastructure));
                }
            }
        }
        /// <summary>
        /// Create a copy of a dictionary of InfrastructureService objects.
        /// </summary>
        /// <param name="sourceInfrastructureServices">Dictionary of InfrastructureService objects to copy.</param>
        /// <returns>New copy of the dictionary of InfrastructureService objects.</returns>
        private IDictionary <InfrastructureServiceNames, InfrastructureService> CopyInfrastructureServices(IDictionary <InfrastructureServiceNames, InfrastructureService> sourceInfrastructureServices)
        {
            IDictionary <InfrastructureServiceNames, InfrastructureService> destinationInfrastructureServices = null;

            if (sourceInfrastructureServices != null)
            {
                destinationInfrastructureServices = new Dictionary <InfrastructureServiceNames, InfrastructureService>();

                foreach (InfrastructureServiceNames key in sourceInfrastructureServices.Keys)
                {
                    InfrastructureService sourceInfrastructureService;
                    sourceInfrastructureServices.TryGetValue(key, out sourceInfrastructureService);
                    InfrastructureService destinationInfrastructureService = new InfrastructureService {
                        Name = sourceInfrastructureService.Name, Value = sourceInfrastructureService.Value
                    };
                    destinationInfrastructureServices.Add(key, destinationInfrastructureService);
                }
            }

            return(destinationInfrastructureServices);
        }
Ejemplo n.º 21
0
    //TODO fix the functions bellow. While for most of the radius it works correctly, it fails at the poles (@ymin and ymax), only painting a single cell each.
    public void SetInfrastructureState(InfrastructureService service, uint cellID_x, uint cellID_y, uint radius)
    {
        //Equation of circle: (x-a)^2 + (y-b)^2 = r^2
        //a = cellID_x, b = cellID_y, r = radius

        uint minY = (uint)Mathf.RoundToInt(Mathf.Clamp((long)cellID_y - (long)radius, 0, noOfCells.y - 1));
        uint maxY = (uint)Mathf.RoundToInt(Mathf.Clamp((long)cellID_y + (long)radius, 0, noOfCells.y - 1));

        for (uint i = minY; i <= maxY; i++)
        {
            long sqrtVal = Mathf.RoundToInt(Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow((long)i - (long)cellID_y, 2))); //cache this calculation, since its result will be used twice.

            uint minX = (uint)Mathf.FloorToInt(Mathf.Clamp((long)cellID_x - sqrtVal, 0, noOfCells.x - 1));
            uint maxX = (uint)Mathf.CeilToInt(Mathf.Clamp((long)cellID_x + sqrtVal, 0, noOfCells.x - 1));

            for (uint j = minX; j <= maxX; j++)
            {
                infrastructureLayer.GetCellRef(j, i) = infrastructureLayer.GetCellValue(j, i) | service;
            }
        }
    }
        /// <summary>
        /// Create a copy of a dictionary of InfrastructureService objects.
        /// </summary>
        /// <param name="sourceServices">Dictionary of InfrastructureService objects to copy.</param>
        /// <returns>New copy of the dictionary of InfrastructureService objects if not null; null otherwise.</returns>
        private static IDictionary <InfrastructureServiceNames, InfrastructureService> CopyInfrastructureServices(
            IDictionary <InfrastructureServiceNames, InfrastructureService> sourceServices)
        {
            if (sourceServices == null)
            {
                return(null);
            }

            var destinationServices = new Dictionary <InfrastructureServiceNames, InfrastructureService>();

            foreach (InfrastructureServiceNames key in sourceServices.Keys)
            {
                if (sourceServices.TryGetValue(key, out InfrastructureService sourceService))
                {
                    var destinationService =
                        new InfrastructureService {
                        Name = sourceService.Name, Value = sourceService.Value
                    };
                    destinationServices.Add(key, destinationService);
                }
            }

            return(destinationServices);
        }
Ejemplo n.º 23
0
 public SettingsController(InfrastructureService infraService, InstitutionService institutionService, SystemService systemService)
 {
     this._infraService       = infraService;
     this._institutionService = institutionService;
     this._systemService      = systemService;
 }
Ejemplo n.º 24
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        #region get data
        WordExtend ex   = new WordExtend();
        string     temp = "TempReport/TemMauBaoCao" + drpmaubaocao.SelectedValue + ".doc";
        ex.OpenFile(Server.MapPath(ResolveUrl("~") + temp));
        Enterprise        or    = new Enterprise();
        EnterpriseService orser = new EnterpriseService();
        or = orser.FindByKey(Convert.ToInt32(memVal.OrgId));

        DataTable dtinfo = new DataTable();
        ex.WriteToMergeField("BC_MaDN", "");
        if (memVal.OrgId > 0)
        {
            dtinfo = new ReportFuelService().GetInfoReportFuel(ReportId);
        }

        if (or != null)
        {
            ex.WriteToMergeField("BC_Title", or.Title);
            ex.WriteToMergeField("BC_TenCoSo", or.Title);
            ex.WriteToMergeField("BC_TenCoSo1", or.Title);
            ex.WriteToMergeField("BC_TenCoSo2", or.Title);
        }
        else
        {
            ex.WriteToMergeField("BC_TenCoSo", "");
        }
        if (dtinfo.Rows[0]["Year"] != DBNull.Value)
        {
            string NextYear = (Convert.ToInt32(dtinfo.Rows[0]["Year"]) + 1).ToString();
            ex.WriteToMergeField("BC_NextYear", NextYear);
            ex.WriteToMergeField("BC_NextYear1", NextYear);
            ex.WriteToMergeField("BC_NextYear2", NextYear);
            ex.WriteToMergeField("BC_Year", dtinfo.Rows[0]["Year"].ToString());
            ex.WriteToMergeField("BC_Year1", dtinfo.Rows[0]["Year"].ToString());
        }
        if (dtinfo.Rows[0]["Responsible"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_ChiuTrachNhiem", dtinfo.Rows[0]["Responsible"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_ChiuTrachNhiem", "");
        }

        if (dtinfo.Rows[0]["ReportDate"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_NgayLap", Convert.ToDateTime(dtinfo.Rows[0]["ReportDate"]).ToString("dd/MM/yyyy"));
            ex.WriteToMergeField("BC_NgayBC", Convert.ToDateTime(dtinfo.Rows[0]["ReportDate"]).ToString("dd/MM/yyyy"));
        }
        if (dtinfo.Rows[0]["ReceivedDate"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_NgayNhan", Convert.ToDateTime(dtinfo.Rows[0]["ReceivedDate"]).ToString("dd/MM/yyyy"));
        }
        else
        {
            ex.WriteToMergeField("BC_NgayNhan", "");
        }
        if (dtinfo.Rows[0]["ConfirmedDate"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_NgayXacNhan", Convert.ToDateTime(dtinfo.Rows[0]["ConfirmedDate"]).ToString("dd/MM/yyyy"));
        }
        else
        {
            ex.WriteToMergeField("BC_NgayXacNhan", "");
        }
        if (dtinfo.Rows[0]["SubAreaName"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_PhanNganh", dtinfo.Rows[0]["SubAreaName"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_PhanNganh", "");
        }

        if (dtinfo.Rows[0]["TaxCode"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_TaxCode", dtinfo.Rows[0]["TaxCode"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_TaxCode", "");
        }

        ex.WriteToMergeField("BC_Owner", ltOwner.Text);

        if (or.Address != null)
        {
            ex.WriteToMergeField("BC_DiaChi", or.Address);
        }
        if (dtinfo.Rows[0]["DistrictName"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_Huyen", dtinfo.Rows[0]["DistrictName"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_Huyen", "");
        }
        if (dtinfo.Rows[0]["ProvinceName"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_Tinh", dtinfo.Rows[0]["ProvinceName"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_Tinh", "");
        }
        if (dtinfo.Rows[0]["ReporterName"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_NguoiBC", dtinfo.Rows[0]["ReporterName"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_NguoiBC", "");
        }

        if (dtinfo.Rows[0]["Fax"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_Fax", dtinfo.Rows[0]["Fax"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_Fax", "");
        }
        if (dtinfo.Rows[0]["Email"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_Email", dtinfo.Rows[0]["Email"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_Email", "");
        }

        if (dtinfo.Rows[0]["Phone"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_DienThoai", dtinfo.Rows[0]["Phone"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_DienThoai", "");
        }
        if (dtinfo.Rows[0]["ParentName"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_TenCtyMe", dtinfo.Rows[0]["ParentName"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_TenCtyMe", "");
        }

        if (dtinfo.Rows[0]["AddressParent"] != null)
        {
            ex.WriteToMergeField("BC_DiaChiP", dtinfo.Rows[0]["AddressParent"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_DiaChiP", "");
        }

        if (dtinfo.Rows[0]["DistrictNameP"] != null)
        {
            ex.WriteToMergeField("BC_HuyenP", dtinfo.Rows[0]["DistrictNameP"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_HuyenP", "");
        }

        if (dtinfo.Rows[0]["ProvinceNameP"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_TinhP", dtinfo.Rows[0]["ProvinceNameP"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_TinhP", "");
        }

        if (dtinfo.Rows[0]["PhoneParent"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_DienThoaiP", dtinfo.Rows[0]["PhoneParent"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_DienThoaiP", "");
        }

        if (dtinfo.Rows[0]["FaxParent"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_FaxP", dtinfo.Rows[0]["FaxParent"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_FaxP", "");
        }
        if (dtinfo.Rows[0]["EmailParent"] != DBNull.Value)
        {
            ex.WriteToMergeField("BC_EmailP", dtinfo.Rows[0]["EmailParent"].ToString());
        }
        else
        {
            ex.WriteToMergeField("BC_EmailP", "");
        }

        if (or.ActiveYear > 0)
        {
            ex.WriteToMergeField("ActiveYear", or.ActiveYear.ToString());
        }
        else
        {
            ex.WriteToMergeField("ActiveYear", "");
        }

        Infrastructure        infra        = new Infrastructure();
        InfrastructureService infraService = new InfrastructureService();

        infra = infraService.GetInfrastructureByReport(ReportId);
        if (infra != null)
        {
            if (infra.ProduceAreaNo > 0)
            {
                ex.WriteToMergeField("ProduceAreaNo", infra.ProduceAreaNo.ToString());
            }
            else
            {
                ex.WriteToMergeField("ProduceAreaNo", "");
            }
            if (infra.OfficeAreaNo > 0)
            {
                ex.WriteToMergeField("OfficeAreaNo", infra.OfficeAreaNo.ToString());
            }
            else
            {
                ex.WriteToMergeField("OfficeAreaNo", "");
            }
            if (infra.ProduceEmployeeNo > 0)
            {
                ex.WriteToMergeField("ProduceEmployeeNo", infra.ProduceEmployeeNo.ToString());
            }
            else
            {
                ex.WriteToMergeField("ProduceEmployeeNo", "");
            }
            if (infra.OfficeEmployeeNo > 0)
            {
                ex.WriteToMergeField("OfficeEmployeeNo", infra.OfficeEmployeeNo.ToString());
            }
            else
            {
                ex.WriteToMergeField("OfficeEmployeeNo", "");
            }
        }
        else
        {
            ex.WriteToMergeField("ProduceAreaNo", "");
            ex.WriteToMergeField("OfficeAreaNo", "");
            ex.WriteToMergeField("ProduceEmployeeNo", "");
            ex.WriteToMergeField("OfficeEmployeeNo", "");
        }


        UsingElectrict        usingElectrict        = new UsingElectrict();
        UsingElectrictService usingElectrictService = new UsingElectrictService();

        usingElectrict = usingElectrictService.GetUsingElectrictByReport(ReportId, false);
        if (usingElectrict != null)
        {
            //Su dung dien 2
            if (usingElectrict.Quantity > 0)
            {
                ex.WriteToMergeField("QuantityResult2", usingElectrict.Quantity.ToString());
            }
            else
            {
                ex.WriteToMergeField("QuantityResult2", "");
            }
            if (usingElectrict.InstalledCapacity > 0)
            {
                ex.WriteToMergeField("InstalledCapacityResult2", usingElectrict.InstalledCapacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("InstalledCapacityResult2", "");
            }
            if (usingElectrict.Capacity > 0)
            {
                ex.WriteToMergeField("CapacityResult2", usingElectrict.Capacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("CapacityResult2", "");
            }
            if (usingElectrict.BuyCost > 0)
            {
                ex.WriteToMergeField("BuyCostResult2", usingElectrict.BuyCost.ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyCostResult2", "");
            }
            if (usingElectrict.BuyCost > 0 && usingElectrict.Capacity > 0)
            {
                ex.WriteToMergeField("BuyPriceResult2", Math.Round((usingElectrict.BuyCost / (usingElectrict.Capacity * 1000)), 0).ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyPriceResult2", "");
            }
            if (usingElectrict.ProduceQty > 0)
            {
                ex.WriteToMergeField("ProduceQtyResult2", usingElectrict.ProduceQty.ToString());
            }
            else
            {
                ex.WriteToMergeField("ProduceQtyResult2", "");
            }
            if (usingElectrict.Technology != null)
            {
                ex.WriteToMergeField("TechnologyResult2", usingElectrict.Technology.ToString());
            }
            else
            {
                ex.WriteToMergeField("TechnologyResult2", "");
            }
            if (usingElectrict.FuelId > 0)
            {
                Fuel fuel = new Fuel();

                fuel = new FuelService().FindByKey(usingElectrict.FuelId);
                if (fuel != null)
                {
                    ex.WriteToMergeField("FuelNameResult2", fuel.FuelName);
                    ex.WriteToMergeField("FuelNameResult", fuel.FuelName);
                }
                else
                {
                    ex.WriteToMergeField("FuelNameResult2", "");
                    ex.WriteToMergeField("FuelNameResult", "");
                }
            }
            else
            {
                ex.WriteToMergeField("FuelNameResult2", "");
                ex.WriteToMergeField("FuelNameResult", "");
            }
            if (usingElectrict.PriceProduce > 0)
            {
                ex.WriteToMergeField("PriceProduceResult2", usingElectrict.PriceProduce.ToString());
            }
            else
            {
                ex.WriteToMergeField("PriceProduceResult2", "");
            }


            //Su dung dien 1
            if (usingElectrict.Quantity > 0)
            {
                ex.WriteToMergeField("QuantityResult", usingElectrict.Quantity.ToString());
            }
            else
            {
                ex.WriteToMergeField("QuantityResult", "");
            }
            if (usingElectrict.InstalledCapacity > 0)
            {
                ex.WriteToMergeField("InstalledCapacityResult", usingElectrict.InstalledCapacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("InstalledCapacityResult", "");
            }
            if (usingElectrict.Capacity > 0)
            {
                ex.WriteToMergeField("CapacityResult", usingElectrict.Capacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("CapacityResult", "");
            }
            if (usingElectrict.BuyCost > 0)
            {
                ex.WriteToMergeField("BuyCostResult", usingElectrict.BuyCost.ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyCostResult", "");
            }
            if (usingElectrict.BuyCost > 0 && usingElectrict.Capacity > 0)
            {
                ex.WriteToMergeField("BuyPriceResult", Math.Round((usingElectrict.BuyCost / (usingElectrict.Capacity * 1000)), 0).ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyPriceResult", "");
            }
            if (usingElectrict.ProduceQty > 0)
            {
                ex.WriteToMergeField("ProduceQtyResult", usingElectrict.ProduceQty.ToString());
            }
            else
            {
                ex.WriteToMergeField("ProduceQtyResult", "");
            }
            if (usingElectrict.Technology != null)
            {
                ex.WriteToMergeField("TechnologyResult", usingElectrict.Technology.ToString());
            }
            else
            {
                ex.WriteToMergeField("TechnologyResult", "");
            }
            if (usingElectrict.FuelId > 0)
            {
                ex.WriteToMergeField("FuelNameResult", usingElectrict.FuelId.ToString());
            }
            else
            {
                ex.WriteToMergeField("FuelNameResult", "");
            }
        }
        else
        {
            ex.WriteToMergeField("QuantityResult2", "");
            ex.WriteToMergeField("InstalledCapacityResult2", "");
            ex.WriteToMergeField("CapacityResult2", "");
            ex.WriteToMergeField("BuyCostResult2", "");
            ex.WriteToMergeField("ProduceQtyResult2", "");
            ex.WriteToMergeField("TechnologyResult2", "");
            ex.WriteToMergeField("FuelNameResult2", "");
            ex.WriteToMergeField("PriceProduceResult2", "");


            ex.WriteToMergeField("QuantityResult", "");
            ex.WriteToMergeField("InstalledCapacityResult", "");
            ex.WriteToMergeField("CapacityResult", "");
            ex.WriteToMergeField("BuyCostResult", "");
            ex.WriteToMergeField("ProduceQtyResult", "");
            ex.WriteToMergeField("TechnologyResult", "");
            ex.WriteToMergeField("FuelNameResult", "");
        }


        usingElectrict = new UsingElectrict();

        usingElectrict = usingElectrictService.GetUsingElectrictByReport(ReportId, true);
        if (usingElectrict != null)
        {
            //Su dung dien 2
            if (usingElectrict.Quantity > 0)
            {
                ex.WriteToMergeField("QuantityPlan", usingElectrict.Quantity.ToString());
            }
            else
            {
                ex.WriteToMergeField("QuantityPlan", "");
            }
            if (usingElectrict.InstalledCapacity > 0)
            {
                ex.WriteToMergeField("InstalledCapacityPlan", usingElectrict.InstalledCapacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("InstalledCapacityPlan", "");
            }
            if (usingElectrict.Capacity > 0)
            {
                ex.WriteToMergeField("CapacityPlan", usingElectrict.Capacity.ToString());
            }
            else
            {
                ex.WriteToMergeField("CapacityPlan", "");
            }
            if (usingElectrict.BuyCost > 0)
            {
                ex.WriteToMergeField("BuyCostPlan", usingElectrict.BuyCost.ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyCostPlan", "");
            }

            if (usingElectrict.BuyCost > 0)
            {
                ex.WriteToMergeField("BuyPricePlan", usingElectrict.BuyCost.ToString());
            }
            else
            {
                ex.WriteToMergeField("BuyPricePlan", "");
            }

            if (usingElectrict.ProduceQty > 0)
            {
                ex.WriteToMergeField("ProduceQtyPlan", usingElectrict.ProduceQty.ToString());
            }
            else
            {
                ex.WriteToMergeField("ProduceQtyPlan", "");
            }
            if (usingElectrict.Technology != null)
            {
                ex.WriteToMergeField("TechnologyPlan", usingElectrict.Technology.ToString());
            }
            else
            {
                ex.WriteToMergeField("TechnologyPlan", "");
            }
            if (usingElectrict.FuelId > 0)
            {
                Fuel fuel = new Fuel();

                fuel = new FuelService().FindByKey(usingElectrict.FuelId);
                if (fuel != null)
                {
                    ex.WriteToMergeField("FuelNamePlan", fuel.FuelName);
                }
                else
                {
                    ex.WriteToMergeField("FuelNamePlan", "");
                }
            }
            else
            {
                ex.WriteToMergeField("FuelNamePlan", "");
            }
            if (usingElectrict.PriceProduce > 0)
            {
                ex.WriteToMergeField("PriceProducePlan", usingElectrict.PriceProduce.ToString());
            }
            else
            {
                ex.WriteToMergeField("PriceProducePlan", "");
            }
        }
        else
        {
            ex.WriteToMergeField("QuantityPlan", "");
            ex.WriteToMergeField("InstalledCapacityPlan", "");
            ex.WriteToMergeField("CapacityPlan", "");
            ex.WriteToMergeField("BuyCostPlan", "");
            ex.WriteToMergeField("ProduceQtyPlan", "");
            ex.WriteToMergeField("TechnologyPlan", "");
            ex.WriteToMergeField("FuelNamePlan", "");
            ex.WriteToMergeField("PriceProducePlan", "");
        }

        DataTable dthientai = new DataTable();
        DataTable dtdukien  = new DataTable();

        DataSet dshientai = new DataSet("tbl1");

        DataTable dt = new DataTable();

        dt = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, false);

        dt.Columns.Add("dvnhietnang", typeof(string));
        dt.Columns.Add("dvnhieulieu", typeof(string));
        dthientai = dt.Clone();
        foreach (DataRow item in dt.Rows)
        {
            DataRow workRow = null;
            workRow = dthientai.NewRow();
            workRow = item;
            if (workRow["MeasurementName"].ToString().Contains("Mét khối"))
            {
                workRow["dvnhietnang"] = "kJ/m3";
            }
            else
            {
                workRow["dvnhietnang"] = "kJ/kg";
            }
            if (workRow["MeasurementName"].ToString().Contains("tấn") || workRow["MeasurementName"].ToString().Contains("Klg"))
            {
                workRow["dvnhieulieu"] = "kJ/tấn";
            }
            else
            {
                workRow["dvnhieulieu"] = "đ/m3";
            }
            workRow.AcceptChanges();
            dthientai.AcceptChanges();
            dthientai.ImportRow(workRow);
        }
        dt = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, true);
        dt.Columns.Add("dvnhietnang", typeof(string));
        dt.Columns.Add("dvnhieulieu", typeof(string));
        dtdukien = dt.Clone();
        foreach (DataRow item in dt.Rows)
        {
            DataRow workRow = null;
            workRow = dtdukien.NewRow();
            workRow = item;
            if (workRow["MeasurementName"].ToString().Contains("Mét khối"))
            {
                workRow["dvnhietnang"] = "kJ/m3";
            }
            else
            {
                workRow["dvnhietnang"] = "kJ/kg";
            }
            if (workRow["MeasurementName"].ToString().Contains("tấn") || workRow["MeasurementName"].ToString().Contains("Klg"))
            {
                workRow["dvnhieulieu"] = "kJ/tấn";
            }
            else
            {
                workRow["dvnhieulieu"] = "đ/m3";
            }
            workRow.AcceptChanges();
            dtdukien.ImportRow(workRow);
            dtdukien.AcceptChanges();
        }
        ProductCapacityService productCapacityService = new ProductCapacityService();
        DataTable tblProductResult = new DataTable();
        tblProductResult = productCapacityService.GetDataCapacity(ReportId, false);
        dshientai.Merge(tblProductResult);
        dshientai.Tables[0].TableName = "tbl1";

        dshientai.Merge(dthientai);

        dshientai.Tables[1].TableName = "tbl2";
        //ex.WriteDataSetToMergeField(dshientai);

        DataTable tblProductPlan = new DataTable();
        tblProductPlan = productCapacityService.GetDataCapacity(ReportId, true);
        dshientai.Merge(tblProductPlan);
        dshientai.Tables[2].TableName = "tbl3";

        dshientai.Merge(dtdukien);
        dshientai.Tables[3].TableName = "tbl4";
        //ex.WriteDataSetToMergeField(dshientai);


        DataSet         dsData           = new DataSet();
        PlanTBService   plangpservice    = new PlanTBService();
        PlanTKNLService plangTKNLservice = new PlanTKNLService();
        DataTable       tblGPTKNLPlan    = new DataTable();
        tblGPTKNLPlan = plangTKNLservice.GetPlanTKNLEnerprise(Convert.ToInt32(memVal.OrgId), ReportId, false, true);
        dshientai.Merge(tblGPTKNLPlan);
        dshientai.Tables[4].TableName = "tbl5";

        DataTable tblTBPlan = new DataTable();
        tblTBPlan = plangpservice.GetPlanTBEnterprise(memVal.OrgId, ReportId, false, true);
        dshientai.Merge(tblTBPlan);
        dshientai.Tables[5].TableName = "tbl6";

        dshientai.Merge(tblProductPlan.Copy());
        dshientai.Tables[6].TableName = "tbl7";

        dshientai.Merge(dthientai.Copy());
        dshientai.Tables[7].TableName = "tbl8";

        DataTable tblGPTKNLResult = new DataTable();
        tblGPTKNLResult = plangTKNLservice.GetPlanTKNLEnerprise(Convert.ToInt32(memVal.OrgId), ReportId, false, false);
        dshientai.Merge(tblGPTKNLResult);
        dshientai.Tables[8].TableName = "tbl9";
        DataTable tblTBResult = new DataTable();
        tblTBResult = plangpservice.GetPlanTBEnterprise(memVal.OrgId, ReportId, false, false);
        dshientai.Merge(tblTBResult);
        dshientai.Tables[9].TableName = "tbl10";

        dshientai.Tables.Add(tblTBResult.Copy());
        dshientai.Tables[10].TableName = "tbl11";

        ex.WriteDataSetToMergeField(dshientai);
        // dsg.Tables.Add(dst);
        //var dt2 = ExcelExportHelper.CreateGroupInDT(dt, "DepName", "STT");
        #endregion
        ex.Save(Server.MapPath(ResolveUrl("~") + "TempReport/" + memVal.UserName + ".Bao-cao-hang-nam-" + dtinfo.Rows[0]["Year"] + ".doc"));
        HttpContext.Current.Response.Redirect(string.Format("~/Download.aspx?fp={0}&fn={1}",
                                                            System.IO.Path.GetFileName(Server.MapPath(ResolveUrl("~") + "TempReport/" + memVal.UserName + ".Bao-cao-hang-nam-" + dtinfo.Rows[0]["Year"] + ".doc")),
                                                            ""
                                                            ));
    }
        /// <summary>
        /// <see cref="SifService{UI, DB}.Create(UI, string, string)"/>
        /// </summary>
        public override Guid Create(environmentType item, string zoneId = null, string contextId = null)
        {
            var environmentRegisterService          = new EnvironmentRegisterService();
            EnvironmentRegister environmentRegister = environmentRegisterService.RetrieveByUniqueIdentifiers(
                item.applicationInfo.applicationKey,
                item.instanceId,
                item.userToken,
                item.solutionId);

            if (environmentRegister == null)
            {
                var errorMessage =
                    $"Environment with [applicationKey:{item.applicationInfo.applicationKey}|solutionId:{item.solutionId ?? "<null>"}|instanceId:{item.instanceId ?? "<null>"}|userToken:{item.userToken ?? "<null>"}] does NOT exist.";
                throw new AlreadyExistsException(errorMessage);
            }

            string sessionToken = AuthenticationUtils.GenerateSessionToken(
                item.applicationInfo.applicationKey,
                item.instanceId,
                item.userToken,
                item.solutionId);

            environmentType environmentType = RetrieveBySessionToken(sessionToken);

            if (environmentType != null)
            {
                var errorMessage =
                    $"A session token already exists for environment with [applicationKey:{item.applicationInfo.applicationKey}|solutionId:{item.solutionId ?? "<null>"}|instanceId:{item.instanceId ?? "<null>"}|userToken:{item.userToken ?? "<null>"}].";
                throw new AlreadyExistsException(errorMessage);
            }

            IDictionary <InfrastructureServiceNames, InfrastructureService> infrastructureServices =
                CopyInfrastructureServices(environmentRegister.InfrastructureServices);
            IDictionary <string, ProvisionedZone> provisionedZones =
                CopyProvisionedZones(environmentRegister.ProvisionedZones);
            Environment repoItem = MapperFactory.CreateInstance <environmentType, Environment>(item);

            if (environmentRegister.DefaultZone != null)
            {
                repoItem.DefaultZone = CopyDefaultZone(environmentRegister.DefaultZone);
            }

            if (infrastructureServices.Count > 0)
            {
                repoItem.InfrastructureServices =
                    CopyInfrastructureServices(environmentRegister.InfrastructureServices);
            }

            if (provisionedZones.Count > 0)
            {
                repoItem.ProvisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones);
            }

            repoItem.SessionToken = sessionToken;
            Guid environmentId = repository.Save(repoItem);

            if (repoItem.InfrastructureServices != null && repoItem.InfrastructureServices.Count > 0)
            {
                InfrastructureService infrastructureService =
                    repoItem.InfrastructureServices[InfrastructureServiceNames.environment];

                if (infrastructureService != null)
                {
                    infrastructureService.Value = infrastructureService.Value + "/" + environmentId;
                    repository.Save(repoItem);
                }
            }

            return(environmentId);
        }
Ejemplo n.º 26
0
    public List <ulong> GetInfrastructureIDsCoveringCell(uint cellID_x, uint cellID_y, InfrastructureService type)
    {
        List <ulong> result   = new List <ulong>();
        ulong        bitChain = 0;

        switch (type)
        {
        case InfrastructureService.parks:
            bitChain = parksLayer.GetCellValue(cellID_x, cellID_y);
            break;

        case InfrastructureService.safety:
            bitChain = policeLayer.GetCellValue(cellID_x, cellID_y);
            break;

        case InfrastructureService.education:
            bitChain = schoolsLayer.GetCellValue(cellID_x, cellID_y);
            break;
        }

        for (uint i = 0; i < 64; i++)
        {
            ulong testedID = BuildingIDHandler <int> .ULongPow(2, i);

            if ((bitChain & testedID) == testedID)
            {
                result.Add(testedID);
            }
        }

        return(result);
    }
Ejemplo n.º 27
0
        public void Generate(FileInfo fi)
        {
            TVItemService         tvItemService         = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MapInfoService        mapInfoService        = new MapInfoService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            InfrastructureService infrastructureService = new InfrastructureService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            if (_TaskRunnerBaseService._BWObj.appTaskModel.Language == "fr")
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
            }
            else
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");
            }

            TVFileService tvFileService  = new TVFileService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            string        ServerFilePath = tvFileService.GetServerFilePath(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            DirectoryInfo di = new DirectoryInfo(ServerFilePath);

            if (!di.Exists)
            {
                di.Create();
            }

            if (fi.Exists)
            {
                fi.Delete();
            }

            StringBuilder sbKMZ        = new StringBuilder();
            StringBuilder sbKMZWWTP    = new StringBuilder();
            StringBuilder sbKMZLS      = new StringBuilder();
            StringBuilder sbKMZOutfall = new StringBuilder();
            StringBuilder sbKMZOther   = new StringBuilder();

            sbKMZ.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            sbKMZ.AppendLine(@"<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">");
            sbKMZ.AppendLine(@"<Document>");
            sbKMZ.AppendLine(@"	<name>" + _TaskRunnerBaseService.generateDocParams.FileName + "</name>");

            sbKMZ.AppendLine(@"    <StyleMap id=""msn_ylw-pushpin"">");
            sbKMZ.AppendLine(@"		<Pair>");
            sbKMZ.AppendLine(@"			<key>normal</key>");
            sbKMZ.AppendLine(@"			<styleUrl>#sn_ylw-pushpin</styleUrl>");
            sbKMZ.AppendLine(@"		</Pair>");
            sbKMZ.AppendLine(@"		<Pair>");
            sbKMZ.AppendLine(@"			<key>highlight</key>");
            sbKMZ.AppendLine(@"			<styleUrl>#sh_ylw-pushpin</styleUrl>");
            sbKMZ.AppendLine(@"		</Pair>");
            sbKMZ.AppendLine(@"	</StyleMap>");
            sbKMZ.AppendLine(@"	<Style id=""sh_ylw-pushpin"">");
            sbKMZ.AppendLine(@"		<IconStyle>");
            sbKMZ.AppendLine(@"			<scale>1.2</scale>");
            sbKMZ.AppendLine(@"		</IconStyle>");
            sbKMZ.AppendLine(@"		<LineStyle>");
            sbKMZ.AppendLine(@"			<color>ff00ff00</color>");
            sbKMZ.AppendLine(@"			<width>1.5</width>");
            sbKMZ.AppendLine(@"		</LineStyle>");
            sbKMZ.AppendLine(@"		<PolyStyle>");
            sbKMZ.AppendLine(@"			<color>0000ff00</color>");
            sbKMZ.AppendLine(@"		</PolyStyle>");
            sbKMZ.AppendLine(@"	</Style>");
            sbKMZ.AppendLine(@"	<Style id=""sn_ylw-pushpin"">");
            sbKMZ.AppendLine(@"		<LineStyle>");
            sbKMZ.AppendLine(@"			<color>ff00ff00</color>");
            sbKMZ.AppendLine(@"			<width>1.5</width>");
            sbKMZ.AppendLine(@"		</LineStyle>");
            sbKMZ.AppendLine(@"		<PolyStyle>");
            sbKMZ.AppendLine(@"			<color>0000ff00</color>");
            sbKMZ.AppendLine(@"		</PolyStyle>");
            sbKMZ.AppendLine(@"	</Style>");

            TVItemModel tvItemModelMunicipality = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);
            List <MapInfoPointModel> mapInfoPointModelMuniList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Municipality, MapInfoDrawTypeEnum.Point);

            sbKMZ.AppendLine(@"	<Folder>");
            sbKMZ.AppendLine(@"	<name>Municipality</name>");

            // Doing Point
            sbKMZ.AppendLine(@"	<Placemark>");
            sbKMZ.AppendLine(@"	<name>" + tvItemModelMunicipality.TVText + "</name>");
            sbKMZ.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
            //sbKMZ.AppendLine(@"	<description>");
            //sbKMZ.AppendLine(@"<![CDATA[");
            //sbKMZ.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelRoot) + @""">" + tvItemModelRoot.TVText + "</a>");
            //sbKMZ.AppendLine(@"]]>");
            //sbKMZ.AppendLine(@"	</description>");
            sbKMZ.AppendLine(@"	<Point>");
            sbKMZ.AppendLine(@"		<coordinates>"+ mapInfoPointModelMuniList[0].Lng + "," + mapInfoPointModelMuniList[0].Lat + ",0</coordinates>");
            sbKMZ.AppendLine(@"	</Point>");
            sbKMZ.AppendLine(@"	</Placemark>");

            // Doing Infrastructures
            sbKMZ.AppendLine(@" <Folder>");
            sbKMZ.AppendLine(@"	<name>Infrastructures</name>");

            sbKMZWWTP.AppendLine(@" <Folder>");
            sbKMZWWTP.AppendLine(@"	<name>Waste Water Treatment Plants</name>");
            sbKMZLS.AppendLine(@" <Folder>");
            sbKMZLS.AppendLine(@"	<name>Lift Stations</name>");
            sbKMZOutfall.AppendLine(@" <Folder>");
            sbKMZOutfall.AppendLine(@"	<name>Outfalls</name>");
            sbKMZOther.AppendLine(@" <Folder>");
            sbKMZOther.AppendLine(@"	<name>Others</name>");

            List <TVItemModel> tvItemModelInfrastructuresList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Infrastructure);

            foreach (TVItemModel tvItemModelInfrastructure in tvItemModelInfrastructuresList)
            {
                InfrastructureModel infrastructureModel = infrastructureService.GetInfrastructureModelWithInfrastructureTVItemIDDB(tvItemModelInfrastructure.TVItemID);

                List <MapInfoPointModel> mapInfoPointModelInfList    = new List <MapInfoPointModel>();
                List <MapInfoPointModel> mapInfoPointModelInfOutList = new List <MapInfoPointModel>();

                if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.WWTP)
                {
                    mapInfoPointModelInfList    = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.WasteWaterTreatmentPlant, MapInfoDrawTypeEnum.Point);
                    mapInfoPointModelInfOutList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);
                }
                else if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.LiftStation)
                {
                    mapInfoPointModelInfList    = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.LiftStation, MapInfoDrawTypeEnum.Point);
                    mapInfoPointModelInfOutList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);
                }
                else if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.Other)
                {
                    mapInfoPointModelInfList    = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.OtherInfrastructure, MapInfoDrawTypeEnum.Point);
                    mapInfoPointModelInfOutList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelInfrastructure.TVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);
                }


                Coord coord = new Coord();
                if (mapInfoPointModelInfList.Count == 0)
                {
                    coord.Lat     = (float)mapInfoPointModelMuniList[0].Lat + 0.01f;
                    coord.Lng     = (float)mapInfoPointModelMuniList[0].Lng + 0.01f;
                    coord.Ordinal = 0;
                }
                else
                {
                    coord.Lat     = (float)mapInfoPointModelInfList[0].Lat;
                    coord.Lng     = (float)mapInfoPointModelInfList[0].Lng;
                    coord.Ordinal = 0;
                }

                Coord coord2 = new Coord();
                if (mapInfoPointModelInfOutList.Count == 0)
                {
                    coord2.Lat     = (float)mapInfoPointModelMuniList[0].Lat + 0.01f;
                    coord2.Lng     = (float)mapInfoPointModelMuniList[0].Lng + 0.01f;
                    coord2.Ordinal = 0;
                }
                else
                {
                    coord2.Lat     = (float)mapInfoPointModelInfOutList[0].Lat;
                    coord2.Lng     = (float)mapInfoPointModelInfOutList[0].Lng;
                    coord2.Ordinal = 0;
                }

                if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.WWTP)
                {
                    // Doing point Infr. WWTP
                    sbKMZWWTP.AppendLine(@"	<Placemark>");
                    sbKMZWWTP.AppendLine(@"	<name>" + tvItemModelInfrastructure.TVText + "</name>");
                    sbKMZWWTP.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                    //sbKMZWWTP.AppendLine(@"	<description>");
                    //sbKMZWWTP.AppendLine(@"<![CDATA[");
                    //sbKMZWWTP.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
                    //sbKMZWWTP.AppendLine(@"]]>");
                    //sbKMZWWTP.AppendLine(@"	</description>");

                    sbKMZWWTP.AppendLine(@"		<Point>");
                    sbKMZWWTP.AppendLine(@"			<coordinates>"+ coord.Lng + "," + coord.Lat + ",0</coordinates>");
                    sbKMZWWTP.AppendLine(@"		</Point>");
                    sbKMZWWTP.AppendLine(@"	</Placemark>");
                }
                else if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.LiftStation)
                {
                    // Doing point Infr. LS
                    sbKMZLS.AppendLine(@"	<Placemark>");
                    sbKMZLS.AppendLine(@"	<name>"+ tvItemModelInfrastructure.TVText + "</name>");
                    sbKMZLS.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                    //sbKMZLS.AppendLine(@"	<description>");
                    //sbKMZLS.AppendLine(@"<![CDATA[");
                    //sbKMZLS.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
                    //sbKMZLS.AppendLine(@"]]>");
                    //sbKMZLS.AppendLine(@"	</description>");

                    sbKMZLS.AppendLine(@"		<Point>");
                    sbKMZLS.AppendLine(@"			<coordinates>"+ coord.Lng + "," + coord.Lat + ",0</coordinates>");
                    sbKMZLS.AppendLine(@"		</Point>");
                    sbKMZLS.AppendLine(@"	</Placemark>");
                }
                else if (infrastructureModel.InfrastructureType == InfrastructureTypeEnum.Other)
                {
                    // Doing point Infr. WWTP
                    sbKMZOther.AppendLine(@"	<Placemark>");
                    sbKMZOther.AppendLine(@"	<name>"+ tvItemModelInfrastructure.TVText + "</name>");
                    sbKMZOther.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                    //sbKMZOther.AppendLine(@"	<description>");
                    //sbKMZOther.AppendLine(@"<![CDATA[");
                    //sbKMZOther.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
                    //sbKMZOther.AppendLine(@"]]>");
                    //sbKMZOther.AppendLine(@"	</description>");

                    sbKMZOther.AppendLine(@"		<Point>");
                    sbKMZOther.AppendLine(@"			<coordinates>"+ coord.Lng + "," + coord.Lat + ",0</coordinates>");
                    sbKMZOther.AppendLine(@"		</Point>");
                    sbKMZOther.AppendLine(@"	</Placemark>");
                }
                else
                {
                }

                // Doing point Infr. outfall
                sbKMZOutfall.AppendLine(@"	<Placemark>");
                sbKMZOutfall.AppendLine(@"	<name>"+ tvItemModelInfrastructure.TVText + "</name>");
                sbKMZOutfall.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                //sbKMZOutfall.AppendLine(@"	<description>");
                //sbKMZOutfall.AppendLine(@"<![CDATA[");
                //sbKMZOutfall.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
                //sbKMZOutfall.AppendLine(@"]]>");
                //sbKMZOutfall.AppendLine(@"	</description>");

                sbKMZOutfall.AppendLine(@"		<Point>");
                sbKMZOutfall.AppendLine(@"			<coordinates>"+ coord2.Lng + "," + coord2.Lat + ",0</coordinates>");
                sbKMZOutfall.AppendLine(@"		</Point>");
                sbKMZOutfall.AppendLine(@"	</Placemark>");
            }
            sbKMZWWTP.AppendLine(@" </Folder>");
            sbKMZLS.AppendLine(@" </Folder>");
            sbKMZOutfall.AppendLine(@" </Folder>");
            sbKMZOther.AppendLine(@" </Folder>");

            sbKMZ.Append(sbKMZWWTP.ToString());
            sbKMZ.Append(sbKMZLS.ToString());
            sbKMZ.Append(sbKMZOutfall.ToString());
            sbKMZ.Append(sbKMZOther.ToString());

            sbKMZ.AppendLine(@" </Folder>");

            sbKMZ.AppendLine(@"	</Folder>");

            sbKMZ.AppendLine(@"</Document>");
            sbKMZ.AppendLine(@"</kml>");

            StreamWriter sw = fi.CreateText();

            sw.Write(sbKMZ.ToString());

            sw.Close();
        }
Ejemplo n.º 28
0
    public void SetInfrastructureLayerCoverageByID(uint cellID_x, uint cellID_y, uint radius, InfrastructureService type, ulong id) //Implies SetInfrastructureState() ID is ensured to be 2^n, see notes on Park.cs
    {
        //Make a reference to the layer we will modify based on service type
        GridLayer <ulong> targetLayer;

        switch (type)
        {
        case InfrastructureService.parks:
            targetLayer = parksLayer;
            break;

        case InfrastructureService.safety:
            targetLayer = policeLayer;
            break;

        case InfrastructureService.education:
            targetLayer = schoolsLayer;
            break;

        default:
            print("WARNING! Attempting to set infralayer coverage for non supporting type: " + type);
            return;
        }

        //Set the coverage similarily to SetInfrastructureState()
        uint minY = (uint)Mathf.RoundToInt(Mathf.Clamp((long)cellID_y - (long)radius, 0, noOfCells.y - 1));
        uint maxY = (uint)Mathf.RoundToInt(Mathf.Clamp((long)cellID_y + (long)radius, 0, noOfCells.y - 1));

        for (uint i = minY; i <= maxY; i++)
        {
            long sqrtVal = Mathf.RoundToInt(Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow((long)i - (long)cellID_y, 2))); //cache this calculation, since its result will be used twice.

            uint minX = (uint)Mathf.FloorToInt(Mathf.Clamp((long)cellID_x - sqrtVal, 0, noOfCells.x - 1));
            uint maxX = (uint)Mathf.CeilToInt(Mathf.Clamp((long)cellID_x + sqrtVal, 0, noOfCells.x - 1));

            for (uint j = minX; j <= maxX; j++)
            {
                targetLayer.GetCellRef(j, i)         = targetLayer.GetCellValue(j, i) | id;
                infrastructureLayer.GetCellRef(j, i) = infrastructureLayer.GetCellValue(j, i) | type;
            }
        }
    }
Ejemplo n.º 29
0
        public static Environment CreateEnvironmentResponse()
        {
            InfrastructureService environmentURL = new InfrastructureService { Name = InfrastructureServiceNames.environment, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/environments/5b72f2d4-7a83-4297-a71f-8b5fb26cbf14" };
            InfrastructureService provisionRequestsURL = new InfrastructureService { Name = InfrastructureServiceNames.provisionRequests, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/provisionRequests" };
            InfrastructureService queuesURL = new InfrastructureService { Name = InfrastructureServiceNames.queues, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/queues" };
            InfrastructureService requestsConnectorURL = new InfrastructureService { Name = InfrastructureServiceNames.requestsConnector, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/requestsConnector" };
            InfrastructureService subscriptionsURL = new InfrastructureService { Name = InfrastructureServiceNames.subscriptions, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/subscriptions" };
            IDictionary<InfrastructureServiceNames, InfrastructureService> infrastructureServices = new Dictionary<InfrastructureServiceNames, InfrastructureService>
            {
                { environmentURL.Name, environmentURL },
                { provisionRequestsURL.Name, provisionRequestsURL },
                { queuesURL.Name, queuesURL },
                { requestsConnectorURL.Name, requestsConnectorURL },
                { subscriptionsURL.Name, subscriptionsURL }
            };

            Right adminRight = new Right { Type = "ADMIN", Value = "APPROVED" };
            Right createRight = new Right { Type = "CREATE", Value = "APPROVED" };
            IDictionary<string, Right> rights = new Dictionary<string, Right> { { adminRight.Type, adminRight } };

            Infrastructure.Service studentPersonalsService = new Infrastructure.Service
            {
                ContextId = "DEFAULT",
                Name = "StudentPersonals",
                Rights = rights,
                Type = "OBJECT"
            };
            Infrastructure.Service schoolInfosService = new Infrastructure.Service
            {
                ContextId = "DEFAULT",
                Name = "SchoolInfos",
                Rights = rights,
                Type = "OBJECT"
            };
            ICollection<Infrastructure.Service> services = new SortedSet<Infrastructure.Service>
            {
                studentPersonalsService, schoolInfosService
            };

            ProvisionedZone schoolZone = new ProvisionedZone { SifId = "auSchoolTestingZone", Services = services };
            ProvisionedZone studentZone = new ProvisionedZone { SifId = "auStudentTestingZone", Services = services };

            IDictionary<string, ProvisionedZone> provisionedZones = new SortedDictionary<string, ProvisionedZone> { { schoolZone.SifId, schoolZone }, { studentZone.SifId, studentZone } };

            Environment environmentResponse = CreateEnvironmentRequest();
            environmentResponse.InfrastructureServices = infrastructureServices;
            environmentResponse.ProvisionedZones = provisionedZones;

            return environmentResponse;
        }
Ejemplo n.º 30
0
        public IHttpActionResult GetInfrastructureList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                       [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                InfrastructureService infrastructureService = new InfrastructureService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

                if (extra == "A") // QueryString contains [extra=A]
                {
                    infrastructureService.Query = infrastructureService.FillQuery(typeof(InfrastructureExtraA), lang, skip, take, asc, desc, where, extra);

                    if (infrastructureService.Query.HasErrors)
                    {
                        return(Ok(new List <InfrastructureExtraA>()
                        {
                            new InfrastructureExtraA()
                            {
                                HasErrors = infrastructureService.Query.HasErrors,
                                ValidationResults = infrastructureService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(infrastructureService.GetInfrastructureExtraAList().ToList()));
                    }
                }
                else if (extra == "B") // QueryString contains [extra=B]
                {
                    infrastructureService.Query = infrastructureService.FillQuery(typeof(InfrastructureExtraB), lang, skip, take, asc, desc, where, extra);

                    if (infrastructureService.Query.HasErrors)
                    {
                        return(Ok(new List <InfrastructureExtraB>()
                        {
                            new InfrastructureExtraB()
                            {
                                HasErrors = infrastructureService.Query.HasErrors,
                                ValidationResults = infrastructureService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(infrastructureService.GetInfrastructureExtraBList().ToList()));
                    }
                }
                else // QueryString has no parameter [extra] or extra is empty
                {
                    infrastructureService.Query = infrastructureService.FillQuery(typeof(Infrastructure), lang, skip, take, asc, desc, where, extra);

                    if (infrastructureService.Query.HasErrors)
                    {
                        return(Ok(new List <Infrastructure>()
                        {
                            new Infrastructure()
                            {
                                HasErrors = infrastructureService.Query.HasErrors,
                                ValidationResults = infrastructureService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(infrastructureService.GetInfrastructureList().ToList()));
                    }
                }
            }
        }
        public void Generate(FileInfo fi)
        {
            BaseEnumService       baseEnumService       = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService         tvItemService         = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MapInfoService        mapInfoService        = new MapInfoService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            PolSourceSiteService  polSourceSiteService  = new PolSourceSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            InfrastructureService infrastructureService = new InfrastructureService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            if (_TaskRunnerBaseService._BWObj.appTaskModel.Language == "fr")
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
            }
            else
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");
            }

            TVFileService tvFileService  = new TVFileService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            string        ServerFilePath = tvFileService.GetServerFilePath(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            DirectoryInfo di = new DirectoryInfo(ServerFilePath);

            if (!di.Exists)
            {
                di.Create();
            }

            if (fi.Exists)
            {
                fi.Delete();
            }

            StringBuilder sbKML = new StringBuilder();

            sbKML.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            sbKML.AppendLine(@"<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">");
            sbKML.AppendLine(@"<Document>");
            sbKML.AppendLine(@"	<name>" + _TaskRunnerBaseService.generateDocParams.FileName + "</name>");

            sbKML.AppendLine(@"    <StyleMap id=""msn_ylw-pushpin"">");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>normal</key>");
            sbKML.AppendLine(@"			<styleUrl>#sn_ylw-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>highlight</key>");
            sbKML.AppendLine(@"			<styleUrl>#sh_ylw-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"	</StyleMap>");
            sbKML.AppendLine(@"	<Style id=""sh_ylw-pushpin"">");
            sbKML.AppendLine(@"		<IconStyle>");
            sbKML.AppendLine(@"			<scale>1.2</scale>");
            sbKML.AppendLine(@"		</IconStyle>");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff00ff00</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>0000ff00</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");
            sbKML.AppendLine(@"	<Style id=""sn_ylw-pushpin"">");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff00ff00</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>0000ff00</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");

            sbKML.AppendLine(@"    <StyleMap id=""msn_grn-pushpin"">");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>normal</key>");
            sbKML.AppendLine(@"			<styleUrl>#sn_grn-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>highlight</key>");
            sbKML.AppendLine(@"			<styleUrl>#sh_grn-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"	</StyleMap>");
            sbKML.AppendLine(@"	<Style id=""sh_grn-pushpin"">");
            sbKML.AppendLine(@"		<IconStyle>");
            sbKML.AppendLine(@"			<scale>1.2</scale>");
            sbKML.AppendLine(@"		</IconStyle>");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff0000ff</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>000000ff</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");
            sbKML.AppendLine(@"	<Style id=""sn_grn-pushpin"">");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff0000ff</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>000000ff</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");

            TVItemModel tvItemModelSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);
            List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Point);

            sbKML.AppendLine(@"	<Folder>");
            sbKML.AppendLine(@"	<name>Subsector</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");

            // Doing Point
            sbKML.AppendLine(@"	<Placemark>");
            sbKML.AppendLine(@"	<name>" + tvItemModelSubsector.TVText + "</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
            //sbKMZ.AppendLine(@"	<description>");
            //sbKMZ.AppendLine(@"<![CDATA[");
            //sbKMZ.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelRoot) + @""">" + tvItemModelRoot.TVText + "</a>");
            //sbKMZ.AppendLine(@"]]>");
            //sbKMZ.AppendLine(@"	</description>");
            sbKML.AppendLine(@"	<Point>");
            sbKML.AppendLine(@"		<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
            sbKML.AppendLine(@"	</Point>");
            sbKML.AppendLine(@"	</Placemark>");

            // Doing Polygon
            sbKML.AppendLine(@"	<Placemark>");
            sbKML.AppendLine(@"		<name>"+ tvItemModelSubsector.TVText + " (poly)</name>");
            sbKML.AppendLine(@"	    <visibility>0</visibility>");
            sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
            //sbKMZ.AppendLine(@"	<description>");
            //sbKMZ.AppendLine(@"<![CDATA[");
            //sbKMZ.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
            //sbKMZ.AppendLine(@"]]>");
            //sbKMZ.AppendLine(@"	</description>");
            sbKML.AppendLine(@"		<Polygon>");
            sbKML.AppendLine(@"			<outerBoundaryIs>");
            sbKML.AppendLine(@"				<LinearRing>");
            sbKML.AppendLine(@"					<coordinates>");

            mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Polygon);
            foreach (MapInfoPointModel mapInfoPointModel in mapInfoPointModelList)
            {
                sbKML.AppendLine(mapInfoPointModel.Lng + "," + mapInfoPointModel.Lat + ",0 ");
            }

            sbKML.AppendLine(@"					</coordinates>");
            sbKML.AppendLine(@"				</LinearRing>");
            sbKML.AppendLine(@"			</outerBoundaryIs>");
            sbKML.AppendLine(@"		</Polygon>");
            sbKML.AppendLine(@"	</Placemark>");

            // Doing Municipalities
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Municipalities</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <TVItemModel> tvItemModelMunicipalityList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Municipality);

            foreach (TVItemModel tvItemModelMunicipality in tvItemModelMunicipalityList)
            {
                sbKML.AppendLine(@" <Folder>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMunicipality.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMunicipality.TVText + " ( Point)</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Municipality, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");

                List <TVItemModel> tvItemModelInfrastructureList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Infrastructure);

                List <InfrastructureModel> infrastructureModelList = new List <InfrastructureModel>();

                foreach (TVItemModel tvItemModelInfrastructure in tvItemModelInfrastructureList)
                {
                    infrastructureModelList.Add(infrastructureService.GetInfrastructureModelWithInfrastructureTVItemIDDB(tvItemModelInfrastructure.TVItemID));
                }

                // Doing WWTP
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.WWTP).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"DesignFlow (m3/day): " + infrastructureModel.DesignFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"Disinfection Type: " + baseEnumService.GetEnumText_DisinfectionTypeEnum(infrastructureModel.DisinfectionType) + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Average Flow (m3/day): " + infrastructureModel.AverageFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"AverageFlow_m3_day: " + infrastructureModel.PeakFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");
                    sbKML.AppendLine(@"Population Served: " + infrastructureModel.PopServed + "\r\n");
                    sbKML.AppendLine(@"Time Zone: " + infrastructureModel.TimeOffset_hour + "\r\n");
                    sbKML.AppendLine(@"Treatment Type: " + baseEnumService.GetEnumText_TreatmentTypeEnum(infrastructureModel.TreatmentType) + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.WasteWaterTreatmentPlant, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }

                // Doing LS
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.LiftStation).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.LiftStation, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }

                // Doing Line Overflow
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.LineOverflow).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.LineOverflow, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }
                sbKML.AppendLine(@" </Folder>");
            }
            sbKML.AppendLine(@" </Folder>");

            // Doing Short Pollution Source Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Short Pollution Source Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <PolSourceSiteModel> polSourceSiteModelList = polSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);

            foreach (PolSourceSiteModel polSourceSiteModel in polSourceSiteModelList.OrderBy(c => c.Site).ToList())
            {
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + polSourceSiteModel.Site.ToString() + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                sbKML.AppendLine(@"	<description>");
                sbKML.AppendLine(@"<![CDATA[");
                sbKML.AppendLine(@"<pre>");

                PolSourceObservationModel polSourceObservationModel = polSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelLatestWithPolSourceSiteTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);
                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }

                    sbKML.AppendLine("Written: \r\n" + (string.IsNullOrWhiteSpace(polSourceObservationModel.Observation_ToBeDeleted) ? "" : polSourceObservationModel.Observation_ToBeDeleted.ToString()) + "\r\n\r\n" + SelectedObservation);
                }
                else
                {
                    string SelectedObservation = "Selected: \r\n";
                    sbKML.AppendLine("Written: \r\n\r\n" + SelectedObservation);
                }

                sbKML.AppendLine(@"</pre>");
                sbKML.AppendLine(@"]]>");
                sbKML.AppendLine(@"	</description>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(polSourceSiteModel.PolSourceSiteTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");

            // Doing Long Pollution Source Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Long Pollution Source Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            polSourceSiteModelList = polSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);

            foreach (PolSourceSiteModel polSourceSiteModel in polSourceSiteModelList.OrderBy(c => c.Site).ToList())
            {
                TVItemModel tvItemModelPolSourceSite = tvItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);

                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelPolSourceSite.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                sbKML.AppendLine(@"	<description>");
                sbKML.AppendLine(@"<![CDATA[");
                sbKML.AppendLine(@"<pre>");

                PolSourceObservationModel polSourceObservationModel = polSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelLatestWithPolSourceSiteTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);
                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }

                    sbKML.AppendLine("Written: \r\n" + (string.IsNullOrWhiteSpace(polSourceObservationModel.Observation_ToBeDeleted) ? "" : polSourceObservationModel.Observation_ToBeDeleted.ToString()) + "\r\n\r\n" + SelectedObservation);
                }
                else
                {
                    string SelectedObservation = "Selected: \r\n";
                    sbKML.AppendLine("Written: \r\n\r\n" + SelectedObservation);
                }

                sbKML.AppendLine(@"</pre>");
                sbKML.AppendLine(@"]]>");
                sbKML.AppendLine(@"	</description>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelPolSourceSite.TVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");


            // Doing MWQM Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>MWQM Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <TVItemModel> tvItemModelMWQMSiteList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite);

            foreach (TVItemModel tvItemModelMWQMSite in tvItemModelMWQMSiteList)
            {
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMWQMSite.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMWQMSite.TVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");

            sbKML.AppendLine(@"	</Folder>");

            sbKML.AppendLine(@"</Document>");
            sbKML.AppendLine(@"</kml>");

            StreamWriter sw = fi.CreateText();

            sw.Write(sbKML.ToString());
            sw.Close();
        }