Esempio n. 1
0
        public void GetDKPInformationJson()
        {
            fGuildRoster.Clear();
            string html = string.Empty;
            string url  = @"https://7gnjtigho4.execute-api.us-east-2.amazonaws.com/beta/dkp";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AutomaticDecompression = DecompressionMethods.GZip;

            try
            {
                try
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                html = reader.ReadToEnd();
                                Properties.Settings.Default.DkpInfo = html;
                                Properties.Settings.Default.Save();
                                Messenger.Default.Send <GenericMessage>(new GenericMessage()
                                {
                                    Message = "Was able to get the latest DKP successfully"
                                });
                            }
                }
                catch (Exception)
                {
                    Messenger.Default.Send <GenericMessage>(new GenericMessage()
                    {
                        Message = "Was NOT able to get the latest DKP, using last known data on file"
                    });
                    html = Properties.Settings.Default.DkpInfo;
                }


                DKPRootObject fDKPRoot = JsonConvert.DeserializeObject <DKPRootObject>(html);

                Messenger.Default.Send <GenericMessage>(new GenericMessage()
                {
                    Message = string.Format("DKP site was last updated on: {0}", fDKPRoot.AsOfDate)
                });


                foreach (DKPModel model in fDKPRoot.Models)
                {
                    MadeMan vMadeMan = new MadeMan()
                    {
                        Name = model.CharacterName,
                        Rank = model.CharacterRank,
                        DKP  = Convert.ToUInt32(model.CurrentDKP),
                        RA30 = Convert.ToUInt32(model.Calculated_30 * 100),
                        RA60 = Convert.ToUInt32(model.Calculated_60 * 100),
                    };
                    fGuildRoster.Add(vMadeMan);
                }
            }
            catch (Exception e)
            {
                //Typically bad practice to catch all, but f**k it
                Messenger.Default.Send <GenericMessage>(new GenericMessage()
                {
                    Message = "Critical Error in DKPService"
                });
            }
        }
Esempio n. 2
0
        public void GetDKPInformation()
        {
            fGuildRoster.Clear();
            string html = string.Empty;
            string url  = @"http://modestman.club/dkp";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AutomaticDecompression = DecompressionMethods.GZip;

            try
            {
                try
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        using (Stream stream = response.GetResponseStream())
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                html = reader.ReadToEnd();
                                Properties.Settings.Default.DkpInfo = html;
                                Properties.Settings.Default.Save();
                                Messenger.Default.Send <GenericMessage>(new GenericMessage()
                                {
                                    Message = "Was able to get the latest DKP successfully"
                                });
                            }
                }
                catch (Exception)
                {
                    Messenger.Default.Send <GenericMessage>(new GenericMessage()
                    {
                        Message = "Was NOT able to get the latest DKP, using last known data on file"
                    });
                    var LogEvent = new LogglyEvent();
                    LogEvent.Data.Add("Fetching DKP", "{0}: Error fetching latest DKP, site must be down", DateTime.Now);
                    fLoggly.Log(LogEvent);
                    html = Properties.Settings.Default.DkpInfo;
                }
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(html);

                HtmlNodeCollection playerList = htmlDoc.DocumentNode.SelectNodes("//table[@class=\"table fullwidth trcheckboxclick hptt colorswitch scrollable-x\"]/tr");

                foreach (HtmlNode player in playerList)
                {
                    if (player.ChildNodes.Count >= 9 && !player.ChildNodes[3].InnerText.Trim().Equals("Name"))
                    {
                        MadeMan vMadeMan = new MadeMan()
                        {
                            Name = player.ChildNodes[3].InnerText,
                            Rank = player.ChildNodes[5].InnerText,
                            DKP  = player.ChildNodes[7].InnerText,
                            RA   = player.ChildNodes[9].InnerText,
                        };
                        fGuildRoster.Add(vMadeMan);
                    }
                }
            }
            catch (Exception e)
            {
                //Typically bad practice to catch all, but f**k it
                Messenger.Default.Send <GenericMessage>(new GenericMessage()
                {
                    Message = "Critical Error in DKPService"
                });
                var LogEvent = new LogglyEvent();
                LogEvent.Data.Add("Catch All DKP", "{0}:{1}", DateTime.Now, e);
                fLoggly.Log(LogEvent);
            }
        }