예제 #1
0
        //On Country button click
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Write Category Label only once - dont waste resources
            if (leftLabel.Content.Equals(""))
            {
                showCategories();
            }

            //Use query to get desired country based, on button content
            Button     btnClicked  = (Button)sender;
            JsonObject countryJSON = GetJSON.GetData(string.Join(",", CountryJsonLink.abbreviationMap.Where(n => n.Key.Equals(btnClicked.Content)).Select(n => n.Value).ToArray()));

            //Write all the data from API
            rightLabel.FontWeight = FontWeight.FromOpenTypeWeight(150);
            rightLabel.Content    = countryJSON.countrydata[0].info.title + "\n" +
                                    countryJSON.countrydata[0].total_new_cases_today + "\n" +
                                    countryJSON.countrydata[0].total_new_deaths_today + "\n" +
                                    countryJSON.countrydata[0].total_cases + "\n" +
                                    countryJSON.countrydata[0].total_deaths + "\n" +
                                    countryJSON.countrydata[0].total_unresolved + "\n" +
                                    countryJSON.countrydata[0].total_recovered + "\n" +
                                    countryJSON.countrydata[0].total_active_cases + "\n" +
                                    countryJSON.countrydata[0].total_serious_cases + "\n" +
                                    countryJSON.countrydata[0].total_danger_rank + "\n";
        }
예제 #2
0
        public GetJSON HandleGet(string id)
        {
            GetJSON dataContext = new GetJSON();
            GetJSON dataJSON    = dataContext.GetValues(id);

            return(dataJSON);
        }
예제 #3
0
        private void btn_count(object sender, RoutedEventArgs e)
        {
            int NumOfP = Int32.Parse(perDay.Text); // liczba ludzi spotykanych jednego dnia
            //int PerInContry;
            JsonObject CountryData = GetJSON.GetData(Country);
            int        TotalCases  = CountryData.countrydata[0].total_cases;

            Chance.Content = TotalCases / NumOfP;
        }
예제 #4
0
 public void GetCountryLinkTest()
 {
     Assert.AreEqual("Poland", GetJSON.GetData(CountryJsonLink.addrPL).countrydata[0].info.title);
     Assert.AreEqual("Germany", GetJSON.GetData(CountryJsonLink.addrDE).countrydata[0].info.title);
     Assert.AreEqual("Czechia", GetJSON.GetData(CountryJsonLink.addrCZ).countrydata[0].info.title);
     Assert.AreEqual("Slovakia", GetJSON.GetData(CountryJsonLink.addrSK).countrydata[0].info.title);
     Assert.AreEqual("Ukraine", GetJSON.GetData(CountryJsonLink.addrUA).countrydata[0].info.title);
     Assert.AreEqual("Belarus", GetJSON.GetData(CountryJsonLink.addrBY).countrydata[0].info.title);
     Assert.AreEqual("Lithuania", GetJSON.GetData(CountryJsonLink.addrLT).countrydata[0].info.title);
     Assert.AreEqual("Russia", GetJSON.GetData(CountryJsonLink.addrRU).countrydata[0].info.title);
 }
예제 #5
0
        public ActionResult GetAnswers(int question_id)
        {
            GetJSON getJSON           = new GetJSON();
            String  answerQueryFormat = String.Format(getAnswer_URL, question_id);
            SOModel result            = getJSON.GetStackoverflowJsonObject(answerQueryFormat);
            Item    selectedItem      = result.items.FirstOrDefault(so => so.question_id == question_id);

            if (selectedItem == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("~/Views/StackOverflow/StackOverflow_PartialViews/StackOverflow_Answers.cshtml", selectedItem));
        }
예제 #6
0
        //Display details about selected question
        public ActionResult DisplayQuestionDetails(int question_id)
        {
            GetJSON getJSON           = new GetJSON();
            String  answerQueryFormat = String.Format(getSelectedObject_URL, question_id);
            SOModel model             = getJSON.GetStackoverflowJsonObject(answerQueryFormat);
            Item    selectedItem      = model.items.FirstOrDefault(so => so.question_id == question_id);

            if (selectedItem == null)
            {
                return(HttpNotFound());
            }
            return(View(selectedItem));
        }
예제 #7
0
 // GET: StackOverflow
 //Display all Stackoverflow data
 public ActionResult Index()
 {
     try
     {
         GetJSON getJSON = new GetJSON();
         SOModel model   = getJSON.GetStackoverflowJsonObject(getJSON_URL); //URL might not be accessible
         return(View(model));
     }
     catch (Exception)
     {
         return(HttpNotFound("No response received from the server"));
     }
 }
예제 #8
0
        public void GetCountryInfoTest()
        {
            JsonObject countryInfo;

            //Dispose WebClient resource immediately
            using (var client = new WebClient())
            {
                String trueJson = client.DownloadString(CountryJsonLink.addrDE);
                countryInfo = JsonConvert.DeserializeObject <JsonObject>(trueJson);
            }

            Assert.AreEqual(countryInfo, GetJSON.GetData(CountryJsonLink.addrDE));
        }
예제 #9
0
        //Insert record
        public static String putIntoDB(string countryAddr)
        {
            //Assumption: Only data form PL
            if (!countryAddr.Equals(CountryJsonLink.addrPL))
            {
                Logger.log.Error("DB can only contain data from Poland :(");
                return("DB can only contain data from Poland :(");
            }

            JsonObject countryPL = GetJSON.GetData(countryAddr);

            //Create new data object
            var todayPoland = new HistoricalData
            {
                Date = DateTime.Now,
                Name = countryPL.countrydata[0].info.title,
                Total_active_cases    = countryPL.countrydata[0].total_active_cases - countryPL.countrydata[0].total_new_cases_today, //Take from yesterday
                Total_new_cases_today = countryPL.countrydata[0].total_new_cases_today
            };

            //Perform on DB
            using (var db = new HistoricalDataDBContext())
            {
                var record = db.Datas.OrderByDescending(n => n.Id).FirstOrDefault();

                //If Table == empty add first
                if (record == null)
                {
                    db.Datas.Add(todayPoland);
                    db.SaveChanges();
                    return("");
                }

                //Insert only if data from the following day does not exist
                if (!record.Date.Date.Equals(DateTime.Now.Date))
                {
                    db.Datas.Add(todayPoland);
                    db.SaveChanges();
                }
            }

            return("");
        }
예제 #10
0
        private static async Task <string> Update(IMongoCollection <BsonDocument> collection, GetJSON note)
        {
            var result = await collection.ReplaceOneAsync(new BsonDocument("_id", new ObjectId(note.Id)), note.ToBsonDocument());

            return(result.ToJson());
        }