public void FetchData(bool cache)
        {
            try {
                XmlDocument profile = new XmlDocument();
                profile.LoadUrl(BaseUrl + "?xml=1");

                // TODO: check for error, throw exception

                Nickname        =                profile.GetInnerText("steamID");
                SteamID64       =     long.Parse(profile.GetInnerText("steamID64"));
                VacBanned       =                profile.GetInnerText("vacBanned").Equals("1");
                ImageUrl        =                profile.GetInnerText("avatarIcon");
                OnlineState     =                profile.GetInnerText("onlineState");
                PrivacyState    =                profile.GetInnerText("privacyState");
                StateMessage    =                profile.GetInnerText("stateMessage");
                VisibilityState =      int.Parse(profile.GetInnerText("visibilityState"));
                Headline        =                profile.GetInnerText("headline");
                HoursPlayed     =    float.Parse(profile.GetInnerText("hoursPlayed2Wk"));
                Location        =                profile.GetInnerText("location");
                MemberSince     = DateTime.Parse(profile.GetInnerText("memberSince"));
                Realname        =                profile.GetInnerText("realname");
                SteamRating     =    float.Parse(profile.GetInnerText("steamRating"));
                Summary         =                profile.GetInnerText("summary");

                if (profile.GetElementsByTagName("privacyMessage").Count > 0)
                    throw new SteamCondenserException(profile.GetInnerText("privacyMessage"));

                if (PrivacyState == "public") {
                    CustomUrl = profile.GetInnerText("customURL");
                    if (CustomUrl.Length == 0) CustomUrl = null;
                    else Cache();
                }

                var favGame = profile.GetElementsByTagName("favoriteGame").Item(0);
                if (favGame != null)
                {
                    // TODO: implement this
                }

                var mostPlayedGamesNode = profile.GetElementsByTagName("mostPlayedGames").Item(0);
                MostPlayedGames = new Dictionary<string, float>();
                if (mostPlayedGamesNode != null) {
                    foreach (XmlElement node in mostPlayedGamesNode) {
                        string gameName   =             node.GetInnerText("gameName");
                        float hoursPlayed = float.Parse(node.GetInnerText("hoursPlayed"));
                        MostPlayedGames.Add(gameName, hoursPlayed);
                    }
                }

                var groupsNode = profile.GetElementsByTagName("groups").Item(0);
                if (groupsNode != null) {
                    List<SteamGroup> grps = new List<SteamGroup>();
                    foreach (XmlElement node in groupsNode) {
                        grps.Add(SteamGroup.Create(long.Parse(node.GetInnerText("groupID64")), false));
                    }
                    Groups = grps.ToArray();
                }

                var weblinksNode = profile.GetXmlElement("weblinks");
                if (weblinksNode != null) {
                    Links = new Dictionary<string, string>();
                    if (groupsNode != null) {
                        foreach (XmlElement node in weblinksNode) {
                            string title = node.GetInnerText("title");
                            string link  = node.GetInnerText("link");
                            Links.Add(title, link);
                        }
                    }
                } else { }
            } catch (XmlException) {
                throw new SteamCondenserException("XML data could not be parsed.");
            }
            FetchTime = DateTime.Now;
        }
Exemple #2
0
        public bool Load(XmlDocument doc)
        {
            try {
            var config = doc.GetXmlElement("mysql");

            Client.IPEndPoint = new IPEndPoint(IPAddress.Parse(config.GetInnerText("hostname")),
                                               int.Parse(config.GetInnerText("port")));
            Client.Username  = config.GetInnerText("username");
            Client.Password  = config.GetInnerText("password");
            Client.Database  = config.GetInnerText("database");

            Client.Connect();
            Client.Query(string.Format("use {0}", Client.Database));
            CreateTables();

              } catch {
            return false;
              }
              return true;
        }