Exemple #1
0
        private string GetAddress(Coordinates coor)
        {
            // this function get the address according to the coordinates (geocoding)
            string content = "";

            try
            {
                GeoCodingServices service = new GeoCodingServices();
                AddressResult     address = service.ReverseGeoCoding(coor.lon, coor.lat);

                string country     = string.IsNullOrEmpty(address.Country) ? "" : Convert.ToString(address.Country);
                string city        = string.IsNullOrEmpty(address.City) ? "" : ", " + Convert.ToString(address.City);
                string road        = string.IsNullOrEmpty(address.Road) ? "" : ", " + Convert.ToString(address.Road);
                string housenumber = string.IsNullOrEmpty(address.HouseNumber) ? "" : ", " + Convert.ToString(address.HouseNumber);
                string postalcode  = address.PostCode == "no" ? "" : ", " + Convert.ToString(address.PostCode);
                string Fulladdress = country + city + road + housenumber + postalcode;
                if (!string.IsNullOrEmpty(Fulladdress))
                {
                    content = Fulladdress;
                }
            }
            catch (Exception ex)
            {
                content = ex.Message;
            }
            return(content);
        }
Exemple #2
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));
        }
Exemple #3
0
        public string GenerateReportPdf(Marks marks, Coordinates coor, ReportExtraInfo reportextrainfo)
        {
            try
            {
                string serial = Guid.NewGuid().ToString();
                string FinalAddressAndReportName = string.Empty;
                string WordReport = docxReportPath + Path.DirectorySeparatorChar + serial + wordExnt;
                File.Copy(templateDoc, WordReport, true);
                Application wordApp = new Application {
                    Visible = true
                };
                Document aDoc = wordApp.Documents.Open(WordReport, ReadOnly: false, Visible: true);
                aDoc.Activate();
                FindAndReplaceMainDoc(wordApp, "[Date]", DateTime.Now.ToString("dd/MM/yyyy"));
                FindAndReplaceMainDoc(wordApp, "[Serial_Number]", serial);
                FindAndReplaceMainDoc(wordApp, "[Project Name]", reportextrainfo.ProjName);
                FindAndReplaceMainDocHeaderAndFooter(aDoc, "[Project Name]", reportextrainfo.ProjName);
                FindAndReplaceMainDoc(wordApp, "[Company Name]", reportextrainfo.CustomerName);
                FindAndReplaceMainDoc(wordApp, "[Title]", "Indexes Value of - Coordinates " + Math.Round(coor.lon, 4) + "/" +
                                      Math.Round(coor.lat, 4));
                FindAndReplaceMainDoc(wordApp, "[Coordinates]", "Coordinates " + Math.Round(coor.lon, 4) + "/" +
                                      Math.Round(coor.lat, 4));

                // let's get the full address of the location according to the coordinates using OSM reverse geocoding service
                GeoCodingServices service = new GeoCodingServices();

                AddressResult address = service.ReverseGeoCoding(coor.lon, coor.lat);

                string country     = string.IsNullOrEmpty(address.Country) ? "" : Convert.ToString(address.Country);
                string city        = string.IsNullOrEmpty(address.City) ? "" : ", " + Convert.ToString(address.City);
                string road        = string.IsNullOrEmpty(address.Road) ? "" : ", " + Convert.ToString(address.Road);
                string housenumber = string.IsNullOrEmpty(address.HouseNumber) ? "" : ", " + Convert.ToString(address.HouseNumber);
                string postalcode  = address.PostCode == "no" ? "" : ", " + Convert.ToString(address.PostCode);
                string Fulladdress = country + city + road + housenumber + postalcode;
                if (!string.IsNullOrEmpty(Fulladdress))
                {
                    FinalAddressAndReportName += StringSeparator + "Address:" + Fulladdress;
                    FindAndReplaceMainDoc(wordApp, "[Address]", Fulladdress);
                    FindAndReplaceMainDoc(wordApp, "[Site Name]", Fulladdress);

                    // if the city name exist, then let's check if the city name have value in wikipedia or not
                    if (!string.IsNullOrEmpty(address.City))
                    {
                        wikidata data = GetDataFromWiki(address.City);
                        if (data.key != -1)
                        {
                            object oBookMark = "SiteInfo";
                            aDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = data.value;
                        }
                        else
                        {
                            FindAndReplaceMainDoc(wordApp, "[Site Brief Info]", " ");
                            FindAndReplaceMainDoc(wordApp, "Source: https://en.wikipedia.org/", " ");
                        }
                    }
                }
                else
                {
                    FinalAddressAndReportName += StringSeparator + "Address:" + " ";
                    FindAndReplaceMainDoc(wordApp, "[Address]", " ");
                    FindAndReplaceMainDoc(wordApp, "[Site Name]", " ");
                    FindAndReplaceMainDoc(wordApp, "[Site Brief Info]", " ");
                    FindAndReplaceMainDoc(wordApp, "Source: https://en.wikipedia.org/", " ");
                }

                // let's get the site


                FindAndReplaceMainDoc(wordApp, "{EG}", Math.Round(marks.RadiationEG, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{EG}", Math.Round(marks.RadiationEG, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[EG Comments]", CheckinterferenceValue(Types.Radiation, Math.Round(marks.RadiationEG, 2)));
                FindAndReplaceMainDoc(wordApp, "{SC}", Math.Round(marks.SoilPollution, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{SC}", Math.Round(marks.SoilPollution, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[SC Comments]", CheckinterferenceValue(Types.Soil, Math.Round(marks.SoilPollution, 2)));
                FindAndReplaceMainDoc(wordApp, "{EC}", Math.Round(marks.Ecology, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{EC}", Math.Round(marks.Ecology, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[EC Comments]", CheckinterferenceValue(Types.Ecology, Math.Round(marks.Ecology, 2)));
                FindAndReplaceMainDoc(wordApp, "{NO}", Math.Round(marks.NoiseInterference, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{NO}", Math.Round(marks.NoiseInterference, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[NO Comments]", CheckinterferenceValue(Types.Noise, Math.Round(marks.NoiseInterference, 2)));
                FindAndReplaceMainDoc(wordApp, "{AQ}", Math.Round(marks.AirQuality, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{AQ}", Math.Round(marks.AirQuality, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[AO Comments]", CheckinterferenceValue(Types.AirQuality, Math.Round(marks.AirQuality, 2)));

                // will be change in the future to Solid Waste Management Mark and comments
                FindAndReplaceMainDoc(wordApp, "{SW}", Math.Round(marks.SoilPollution, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{SW}", Math.Round(marks.SoilPollution, 2).ToString());
                FindAndReplaceMainDoc(wordApp, "[SW Comments]", " ");

                // overall index value
                FindAndReplaceMainDoc(wordApp, "{M}", Math.Round(marks.FinalMark, 2).ToString());
                FindAnndReplaceShapes(aDoc, "{M}", Math.Round(marks.FinalMark, 2).ToString());
                AddMap(aDoc, coor);

                //string WordReport = docxReportPath + Path.DirectorySeparatorChar + serial + wordExnt;
                //wordApp.Documents[1].SaveAs2(WordReport, WdSaveFormat.wdFormatDocumentDefault);
                wordApp.Documents[1].Save();
                string pdfReport = pdfReportPath + Path.DirectorySeparatorChar + serial + PdfExnt;
                wordApp.Documents[1].SaveAs2(pdfReport, WdSaveFormat.wdFormatPDF);
                wordApp.Documents[1].Close();
                wordApp.Quit();
                int res  = System.Runtime.InteropServices.Marshal.ReleaseComObject(aDoc);
                int res1 = System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
                GC.Collect();

                // let's copy the file to authenticate folder for user downloads.
                FinalAddressAndReportName += StringSeparator + "Report:" + serial + PdfExnt;
                string downloadFile = pdfReportDownlaodPath + Path.DirectorySeparatorChar + serial + PdfExnt;
                File.Copy(pdfReport, downloadFile, true);

                return(FinalAddressAndReportName);
            }
            catch (Exception e)
            {
                log.Error(e);
                return(String.Empty);
            }
        }