private async Task CheckForCsgoUpdate()
        {
            //Only check every 5 minutes (So Valve doesnt get mad at me)
            if (DateTime.Now.Minute % 5 == 0)
            {
                try
                {
                    var result = await _httpHandler.Get("https://blog.counter-strike.net/index.php/category/updates/");

                    var resultString = await result.Content.ReadAsStringAsync();

                    HtmlDocument pageDocument = new HtmlDocument();
                    pageDocument.LoadHtml(resultString);

                    var linkElement = pageDocument.DocumentNode.SelectSingleNode("//*[@id=\"post_container\"]/div[1]/h2/a");

                    var    newestCsUpdate = linkElement.InnerText;
                    string dateString     = Regex.Replace(newestCsUpdate, "[^(0-9/).]", "");
                    string lastCsUpdate   = (await _dapperDB.LoadFromDBStorage("lastCsgoUpdate")).value;

                    var link = linkElement.Attributes[0].Value;

                    if (lastCsUpdate != dateString)
                    {
                        await _dapperDB.SaveToDBStorage(new DBStorage()
                        {
                            key   = "lastCsgoUpdate",
                            value = dateString
                        });

                        var    firstUpdateLogs = pageDocument.DocumentNode.SelectSingleNode("//*[@id=\"post_container\"]/div[1]");
                        string releaseNotes    = "Release Notes:\n";
                        foreach (var element in firstUpdateLogs.ChildNodes)
                        {
                            if (element.Name == "p")
                            {
                                releaseNotes += element.InnerText + "\n";
                            }
                        }

                        releaseNotes = HttpUtility.HtmlDecode(releaseNotes);

                        var subs = await _dapperDB.GetAllCsgoUpdateSubscriber();

                        foreach (var sub in subs)
                        {
                            await _telegram.SendMessage(sub.chatId, "<b>New CS:GO release for " + dateString + "</b>\n" + link + "\n\nAll past updates: https://blog.counter-strike.net/index.php/category/updates/ \n\n" + releaseNotes);
                        }
                    }
                }
                catch (Exception e)
                {
                    _dapperDB.WriteEventLog("Init", "Error", "Could not check for CS updates - Exception: " + e.Message);
                    _telegram.SendErrorMessage("There is something wrong with the CSUpdate checker - FIX IT!");
                    _telegram.SendErrorMessage("Error was: " + e.Message);
                }
            }
        }
        public async Task <IEnumerable <Heatmap> > GetAllHeatmapAsync()
        {
            // Call asynchronous network methods in a try/catch block to handle exceptions.
            try
            {
                HeatClient.DefaultRequestHeaders.Add("ApiKey", "829320-adajdasd-12vasdas-baslk3"); //Server side API Token

                var handler = _httpHandler.Get("https://fruitflywebapi.azurewebsites.net/api/Heatmap", HeatClient).EnsureSuccessStatusCode();

                if (handler.IsSuccessStatusCode)
                {
                    var responseBody = await handler.Content.ReadAsStringAsync();

                    Console.WriteLine("Connection established");

                    //Splits the responsebody into each datatype and it's value. Items * 1000 to make sure that a thousand heatmapID's can be loaded.
                    var _line = responseBody.Split(',', items * 1000);

                    //Checks for 3 specific strings that contain: 'x', 'y' and ('h', 'e', 'a' and 't').
                    CheckEachString.CheckStringHeatmap(_line, LineX, LineY, LineHeat);

                    for (int i = 0; i < LineHeat.Count; i++)
                    {
                        //Here a new object of heatmap is created for each heatmap ID in the database. The values are collected from the sepereate list of x, y and heatmapID.
                        var obj = new Heatmap
                        {
                            x         = Extractor.ExtractFromString(LineX[i]),
                            y         = Extractor.ExtractFromString(LineY[i]),
                            HeatmapID = Extractor.ExtractFromString(LineHeat[i]),
                            Value     = 1
                        };

                        //adds all the added heatmaps into a list of heatmaps.
                        Heatmaps.Add(obj);
                    }

                    //compares if there are more than 1 element with the same x and y coordinates. If so, the value of the item will increase with 1 pr matching elements.
                    CompareElements.CompareHeatmapValues(Heatmaps);
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }

            //DeleteAllHeatmapAsync();

            //returns all data stored in the list of heatmaps to the GET method
            Console.WriteLine("All heatmap data stored");
            return(Heatmaps);
        }
        private GitHubUserViewModel GetUser(string userName)
        {
            //Build URL string for API call
            var apiUrl = string.Format("{0}users/{1}", GetGitHubApiURL(), userName);

            var response = _httpHandler.Get(apiUrl);

            if (response.IsSuccessStatusCode)
            {
                var result = response.Content.ReadAsStringAsync().Result;
                return(MapGitUserViewModel(JsonConvert.DeserializeObject <GitHubUser>(result)));
            }
            else
            {
                return(new GitHubUserViewModel());
            }
        }
Esempio n. 4
0
        public async Task <List <RedditPostData> > GetRedditTopPostsData(string subreddit, int maxNumberOfPosts)
        {
            var returnList = new List <RedditPostData>();

            var response = await _httpHandler.Get("https://www.reddit.com/r/" + subreddit + "/top.json?limit=" + maxNumberOfPosts + "&raw_json=1");

            string responseBody = await response.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(responseBody);

            for (int i = 0; i < maxNumberOfPosts; i++)
            {
                try
                {
                    var post = new RedditPostData()
                    {
                        title     = data.data.children[i].data.title,
                        permalink = data.data.children[i].data.permalink
                    };


                    try
                    {
                        post.imageUrl = data.data.children[i].data.preview.images[0].source.url; //imageUrl needn't be provided - thats why this try catch is necessary
                    }
                    catch
                    {
                        /* Fall through */
                    }

                    returnList.Add(post);
                }
                catch
                {
                    //if this fails it means, that there were less then the through maxNumberOfPosts provided posts
                    break;
                }
            }

            return(returnList);
        }
Esempio n. 5
0
 public async System.Threading.Tasks.Task <List <Photo> > GetPhotosByAlbumIdAsync(int albumId)
 {
     return(await _httpHandler.Get <List <Photo> >(GetUrlWithAlbumId(albumId)));
 }
Esempio n. 6
0
 public void Get(string url, Callback callback)
 {
     httpHandler.Get(url, callback);
 }