Exemple #1
0
        public JsonStringResult Get(double lon, double lat, double Scale, string CalcType, string Adminpwd, string ReportToken, string ProjectName, string CustomerName, string Recipients, bool DelCalcTables = true)
        {
            //this function received the WS parameters
            //and extract the osm data according to it


            // let's avoid low scale calculation and quit the calculation with an alert message
            if (Scale > 0.5)
            {
                return(new JsonStringResult(ExtractOSMMapProdProd.Properties.Resources.BigScale));
            }

            coor = new Coordinates()
            {
                lon = lon, lat = lat, zoomLevel = Scale
            };
            string strContent = string.Empty;

            try
            {
                initLogger();

                // let's extract the osm data and insert it to the PGSQL DB as tables
                ExtractOSMMap OSMData = new ExtractOSMMap();
                tblprefix = OSMData.OsmFileDownload(lon, lat, Scale);

                // let's get set background rank according to the coordinates geocoding (coordinates in a city, suburb, village and etc)
                GeoCodingServices service = new GeoCodingServices();
                int Rank = service.GetCityRank(coor.lon, coor.lat);

                switch (Rank)
                {
                case 1:
                    m_BackgroundInterference = 36;
                    break;

                case 2:
                    m_BackgroundInterference = 20;
                    break;

                case 3:
                    m_BackgroundInterference = 15;
                    break;

                case 4:
                    m_BackgroundInterference = 8;
                    break;

                case 5:
                    m_BackgroundInterference = 4;
                    break;

                default:
                    m_BackgroundInterference = 0;
                    break;
                }

                // convert string to enum
                Types type = ((Types)Enum.Parse(typeof(Types), CalcType, true));

                // let's calculate the attributes Indcies according to the coordinates location and other parameters
                dataClass = new SQLDataClass(Connectionstr);
                List <Results> lstResults = dataClass.CalculateIndcies(tblprefix, coor, m_BackgroundInterference, ProjectName + StringDot + CustomerName, true, type);
                strContent += ParseData(lstResults);

                // let's get the address of teh location as a string and add it to the result JSON
                string Address = GetAddress(coor);
                strContent += StringSeparator + "Address:" + Address;

                // the report is disabled, later on will be added back to the results
                string reportName = StringSeparator + "Report:N.A.";
                strContent += reportName;

                if (DelCalcTables)
                {
                    dataClass.DeleteTables(tblprefix);
                }

                // let's calc the total index value and add it to the list
                Results result = new Results {
                    type = Types.All, category = 6, indexvalue = lstResults.Average(x => x.indexvalue)
                };
                lstResults.Add(result);
                // let's send the shorty report email and update the email send status
                strContent += StringSeparator + "Email:" + GenerateShortReport(coor, Address, CustomerName, Recipients, lstResults);

                // ** report code - disabled at this stage **
                //if (!string.IsNullOrEmpty(ReportToken) && ReportToken == "Report56562")
                //{
                //GenerateReport generateReport = new GenerateReport();
                //GenerateReport.Coordinates coordinates = new GenerateReport.Coordinates { lon = Convert.ToSingle(lon), lat = Convert.ToSingle(lat), zoomlevel = 17 };
                //GenerateReport.Marks marks = new GenerateReport.Marks { AirQuality = AirQualityVal, Ecology = EcologyVal, NoiseInterference = noiseVal, RadiationEG = radiationVal, SoilPollution = soilVal, FinalMark = ((noiseVal + soilVal + radiationVal + AirQualityVal + EcologyVal) / 5) };
                //GenerateReport.ReportExtraInfo ReportExtraInfo = new GenerateReport.ReportExtraInfo { CustomerName = CustomerName, ProjName = ProjectName };
                //string reportName = generateReport.GenerateReportPdf(marks, coordinates, ReportExtraInfo);";
                //strContent += reportName;
                //}
                //else
                //{
                //    strContent += "N.A.";
                //}
            }
            catch (Exception ex)
            {
                strContent = ex.Message;
            }

            return(new JsonStringResult(strContent));
        }