public async Task <ActionResult <CityInformation> > Get([FromRoute] string name)
        {
            //Todo - real scenario => get city Id from database by name
            string weatherApiUrl = this.configuration.GetSection("WeatherApiUrl").Value + "/" + name;

            this.httpClient.DefaultRequestHeaders.Add(Headers.CorrelationId, correlationProvider.CorrelationId);
            var weather = await this.httpClient.GetStringAsync(weatherApiUrl);

            var actualWeather = JsonConvert.DeserializeObject <WeatherForecast>(weather);

            this.logger.LogInformation($"{ System.DateTime.UtcNow} - Fetched data from : { weatherApiUrl }. "
                                       + $"| CorrelationId: { correlationProvider.CorrelationId }");

            var rand = new Random();

            var cityInfo = new CityInformation
            {
                Name          = name,
                Population    = rand.Next(100000, 2500000),
                DateOfBuild   = new System.DateTime(rand.Next(1600, 2000), 12, 1),
                ActualWeather = actualWeather
            };

            this.logger.LogInformation($"{ System.DateTime.UtcNow} - Returned information about: { name }. "
                                       + $"| CorrelationId: { correlationProvider.CorrelationId }");


            return(Ok(cityInfo));
        }
Example #2
0
        public void ATemplateWithNoPlaceholdersIsUnchanged()
        {
            var template        = "AutosaveName";
            var cityInformation = new CityInformation {
                Name = "CityName"
            };
            var expected = "AutosaveName";

            Assert.That(template.FillTemplate(cityInformation), Is.EqualTo(expected));
        }
Example #3
0
        public void AComplexTemplateIsUpdated()
        {
            var template        = "Autosave: {{CityName}} - {{Year}}-{{Month}}-{{Day}}";
            var cityInformation = new CityInformation {
                Name = "Lakevalley", CurrentDate = new DateTime(2020, 6, 2)
            };
            var expected = "Autosave: Lakevalley - 2020-06-02";

            Assert.That(template.FillTemplate(cityInformation), Is.EqualTo(expected));
        }
Example #4
0
        public void ATemplateWithANamePaceholderAndTextIsUpdated()
        {
            var template        = "Autosave: {{CityName}}";
            var cityInformation = new CityInformation {
                Name = "Lakevalley"
            };
            var expected = "Autosave: Lakevalley";

            Assert.That(template.FillTemplate(cityInformation), Is.EqualTo(expected));
        }
Example #5
0
        private double GetDistance(City cityA, City cityB)
        {
            CityInformation infoA = this.cityInfo.Where(l => l.Name == cityA).Single();
            CityInformation infoB = this.cityInfo.Where(l => l.Name == cityB).Single();

            var    earthsRadius   = 6373;
            var    deltaLatitude  = infoA.Latitude - infoB.Latitude;
            var    deltaLongitude = infoA.Longitude - infoB.Longitude;
            double a = Math.Pow(Math.Sin(deltaLatitude / 2), 2) + Math.Cos(infoA.Latitude) * Math.Cos(infoB.Latitude) * Math.Pow(Math.Sin(deltaLongitude / 2), 2);
            var    c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            return(earthsRadius * c);
        }
    public void selectemail()
    {
        count = 0;

              if (indiaemail() == 0)
        {
            //Alert.Show("email");
            return;
        }
        string[] strArray = new string[] { "Deli", "CHENNAI", "DELHI", "Ghaziabad", "Gurgaon", "INDORE", "KANPUR", "MUMBAI", "NAVI MUMBAI", "Noida", "Pune"};

                    OdbcDataReader reader;
                    OdbcCommand cmd = new OdbcCommand();
                    Conn.Open();
                    cmd.Connection = Conn;
                    foreach (string city in strArray)
                    {
                      //  Alert.Show(city);

                        cmd.CommandText = "select * from cities  where emailsent <> " + indiaemailid + " and currentlocation='" + city + "'";
                        reader = cmd.ExecuteReader();

                        if (reader.HasRows )
                        {
                         //   cviv = cviv + city;
                          //  Alert.Show((string)reader["Email"]);
                            CityInformation newcity = new CityInformation();
                            while (reader.Read() & (mailcount <= maxmailcount))
                            {
                                string emailaddress = (string)reader["Email"];
                                if (emailaddress != null)
                                 {

                                   SendEmail(emailaddress, indiaemailid, city);
                                   // Alert.Show(((int)count).ToString());
                                   mailcount++;
                                 }
                            }

                            //GridView1.DataSource = reader;
                            //GridView1.DataBind();

                          // break;
                        }
                        reader.Close();
                        Label1.Text = " Total email sent :" + count ;
                    }
                    Conn.Close();
    }
        private static Stream GetWeatherInformationFromStream(CityInformation CityKey)
        {
            string infouri = @"http://wthrcdn.etouch.cn/WeatherApi?citykey=" + CityKey.ToString("D");
            //请求头
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(infouri);

            request.Headers.Add("Accept-Encoding", "gzip,deflate");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            request.Method = "GET";

            Stream stream;
            string xmlResponseString = string.Empty;

            try
            {
                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                {
                    //Stream stream = new System.IO.Compression.GZipStream(webResponse.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                    stream = webResponse.GetResponseStream();
                    using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8))
                    {
                        xmlResponseString = streamReader.ReadToEnd();
                        //stream.Dispose();
                    }
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xmlResponseString);

                using (StringWriter stringWriter = new StringWriter())
                {
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Indentation = 2;  // the Indentation
                        xmlTextWriter.Formatting  = Formatting.Indented;
                        xmlDocument.WriteContentTo(xmlTextWriter);
                    }
                    xmlResponseString = stringWriter.ToString();
                }
                byte[]       array     = Encoding.UTF8.GetBytes(xmlResponseString);
                MemoryStream xmlstream = new MemoryStream(array);
                return(xmlstream);
            }
            catch (WebException)
            {
                return(null);
            }
        }
    string strsubject = "My Testing"; //This subject will be dynamic

    #endregion Fields

    #region Methods

    //public void GridViewBindToExcel()
    //{
    //    try
    //    {
    //        // Open connection
    //        Conn.Open();
    //        // Create OleDbCommand object and select data from worksheet Sheet1
    //        OdbcCommand cmd = new OdbcCommand("SELECT * FROM [Test$]", Conn);
    //        // Create new OleDbDataAdapter
    //        OdbcDataAdapter Ada = new OdbcDataAdapter();
    //        Ada.SelectCommand = cmd;
    //        DataTable  dt = new DataTable();
    //        Ada.Fill(dt);
    //        // Bind the data to the GridView
    //        GrdExccel.DataSource = dt;
    //        GrdExccel.DataBind();
    //    }
    //    catch (Exception ex)
    //    {
    //        Alert.Show("Not Bind To GridView");
    //    }
    //    finally
    //    {
    //        // Close connection
    //        Conn.Close();
    //    }
    //}
    public void selectemail()
    {
        string[] strArray = new string[] { "Deli","CHENNAI", "DELHI", "GZB.", "GRG.", "INDORE", "KANPUR", "MUMBAI -1", "MUMBAI-2", "NAVI MUMBAI", "Noida", "Pune" };
        int indiaemailid = 1;
        OdbcDataReader reader;
        OdbcCommand cmd = new OdbcCommand();
        Conn.Open();
        cmd.Connection = Conn;

        foreach (string city in strArray)
        {

            cmd.CommandText = "select top 300 * from  [" + city + "$] where emailsent <> " + indiaemailid;
            reader = cmd.ExecuteReader();

               if (reader.HasRows)
                {
                    CityInformation newcity = new CityInformation();
                    while (reader.Read())
                    {
                        string emailaddress =(string)reader["Email"];
                        if (emailaddress != null)
                        {
                            //newcity.S_No=(int)reader["S. NO"];
                           // newcity.Name = (string)reader["Name"];
                           // newcity.Email = emailaddress;
                           // newcity.CurrentLocation = (string)reader["Current Location"];

                            SendEmail(emailaddress,indiaemailid,city);
                        }
                    }
                    GridView1.DataSource = reader;
                    GridView1.DataBind();

                    break;
                }
               reader.Close();

        }
        Conn.Close();
    }
Example #9
0
 public static string FillTemplate(this string template, CityInformation cityInformation) =>
 template.Replace("{{CityName}}", cityInformation.Name)
 .Replace("{{Day}}", cityInformation.CurrentDate.Day.ToString("D2"))
 .Replace("{{Month}}", cityInformation.CurrentDate.Month.ToString("D2"))
 .Replace("{{Year}}", cityInformation.CurrentDate.Year.ToString());