Example #1
0
        private void ProcessGamertag(GamervineDataContext DataContext, Gamertag Gamertag)
        {
            XDocument xdLatestData = null;

            IDataConnector dataConnector = DataConnectorFactory.GetDataConnectorForType(Gamertag.Type);
            int            count         = 0;

            do
            {
                count++;
                xdLatestData = dataConnector.GetLatestTagData(Gamertag);
            }while (xdLatestData == null && count < 5);

            if (xdLatestData == null)
            {
                Debug.WriteLine("Unable to retrieve data from gamertag \"" + Gamertag.Tag + "\".");
                return;
            }

            IHandler dataHandler = HandlerFactory.GetHandlerForType(Gamertag.Type);

            dataHandler.ProcessData(DataContext, Gamertag, xdLatestData);

            try
            {
                DataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in DataService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Example #2
0
        public static Gamertag Insert(string UserID, int TypeID, Hashtable Data)
        {
            GamervineDataContext dContext = new GamervineDataContext();

            Gamertag gamertag = new Gamertag();

            gamertag.TagId  = Guid.NewGuid().ToString();
            gamertag.Tag    = Utility.ToString(((Hashtable)Data["Data"])["Tag"]);
            gamertag.Type   = TypeID;
            gamertag.State  = State.Active.GetHashCode();
            gamertag.UserId = UserID;

            dContext.Gamertags.InsertOnSubmit(gamertag);

            //Setup the data job to start collecting data on this user
            Job dataJob = new Job();

            dataJob.JobId          = Guid.NewGuid().ToString();
            dataJob.Type           = JobTypes.Data.GetHashCode();
            dataJob.TagId          = gamertag.TagId;
            dataJob.FrequencyUnits = 1;
            dataJob.Frequency      = JobFrequency.Day.GetHashCode();
            dataJob.NextRunTime    = null;
            dataJob.LastRunTime    = null;
            dataJob.PostFormat     = string.Empty;

            dContext.Jobs.InsertOnSubmit(dataJob);
            dContext.SubmitChanges();

            return(gamertag);
        }
Example #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Gamertag?.GetHashCode() ?? 0) * 397) ^ (Xuid?.GetHashCode() ?? 0));
     }
 }
Example #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Gamertag?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (ExperienceSummary != null ? ExperienceSummary.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)ResultCode;
         return(hashCode);
     }
 }
        private void DataSubmitButton(object sender, RoutedEventArgs e)
        {
            string name     = Name.Text;
            string email    = Email.Text;
            string gamerTag = Gamertag.Text;
            string melee    = "n";
            string sm4sh    = "n";
            bool   success  = true;

            if (name == "" || email == "" || gamerTag == "")
            {
                success = false;
            }

            if (Melee.IsChecked == true)
            {
                melee = "y";
            }
            if (Sm4sh.IsChecked == true)
            {
                sm4sh = "y";
            }

            if (Melee.IsChecked == false && Sm4sh.IsChecked == false && None.IsChecked == false)
            {
                success = false;
            }

            if (success)
            {
                List <string> data = new List <string> {
                    name, email, gamerTag, melee, sm4sh
                };
                DataWriter writer = new DataWriter();
                writer.Write(filePath, data);

                Name.Clear();
                Email.Clear();
                Gamertag.Clear();
                Melee.IsChecked = false;
                Sm4sh.IsChecked = false;
                None.IsChecked  = false;
                MessageBox.Show("Submission Complete", "Submitted");
            }
            else
            {
                MessageBox.Show("Missing value(s)", "Incomplete Form");
            }
        }
Example #6
0
        public void ProcessGamertag(GamervineDataContext DataContext, Gamertag Gamertag)
        {
            IHandler dataHandler = HandlerFactory.GetHandlerForType(Gamertag.Type);

            dataHandler.ProcessSummary(DataContext, Gamertag);

            try
            {
                DataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in DataService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        public XDocument GetLatestTagData(Gamertag Gamertag)
        {
            XDocument xmlDoc = null;

            try
            {
                WebRequest  wRequest  = HttpWebRequest.Create("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=" + Gamertag.Tag);
                WebResponse wResponse = wRequest.GetResponse();

                StreamReader sr     = new StreamReader(wResponse.GetResponseStream());
                string       result = sr.ReadToEnd();

                xmlDoc = XDocument.Parse(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in XboxEndPoint.GetLatestTagData:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }

            return(xmlDoc);
        }
Example #8
0
        public static object PostUserGameConnectionData(string ID, DataConnectionType TypeID, Hashtable Data)
        {
            try
            {
                GamervineDataContext dContext = new GamervineDataContext();

                var gvUser = from usc in dContext.UserSocialConnections
                             where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode()
                             select usc;

                if (gvUser.Count() > 0)
                {
                    var dGamertag = from gt in dContext.Gamertags
                                    where gt.Type == TypeID.GetHashCode() && gt.UserId == gvUser.First().UserId
                                    select gt;

                    bool isStatusJobEnabled  = false;
                    bool isSummaryJobEnabled = false;
                    bool isFacebookEnabled   = false;
                    //bool isTagInsert = false;

                    if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"])["Enabled"]) == 1)
                    {
                        isStatusJobEnabled = true;
                    }
                    if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"])["Enabled"]) == 1)
                    {
                        isSummaryJobEnabled = true;
                    }
                    if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"])["Enabled"]) == 1)
                    {
                        isFacebookEnabled = true;
                    }

                    Gamertag gamertag = new Gamertag();
                    if (dGamertag.Count() == 0)
                    {
                        //isTagInsert = true;
                        gamertag = Insert(gvUser.First().UserId, TypeID.GetHashCode(), Data);
                    }
                    else
                    {
                        gamertag     = dGamertag.First();
                        gamertag.Tag = Utility.ToString(((Hashtable)Data["Data"])["Tag"]);

                        var statusPost = from j in dContext.Jobs
                                         where j.TagId == gamertag.TagId &&
                                         j.Type == JobTypes.Status.GetHashCode()
                                         select j;

                        var summaryPost = from j in dContext.Jobs
                                          where j.TagId == gamertag.TagId &&
                                          j.Type == JobTypes.Summary.GetHashCode()
                                          select j;

                        var fbConnection = from gtsc in dContext.GamertagSocialConnections
                                           where gtsc.TagId == gamertag.TagId &&
                                           gtsc.UserSocialConnectionId == gvUser.First().UserSocialConnectionId
                                           select gtsc;

                        if (isStatusJobEnabled)
                        {
                            Hashtable statusData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"];
                            Job       statusJob  = new Job();

                            //We have an existing status job and the enabled flag is true - persist settings
                            if (statusPost.Count() > 0)
                            {
                                statusJob = statusPost.First();
                            }
                            else
                            {
                                statusJob.JobId       = Guid.NewGuid().ToString();
                                statusJob.LastRunTime = null;
                                statusJob.TagId       = gamertag.TagId;
                                statusJob.PostFormat  = string.Empty;
                                statusJob.Type        = JobTypes.Status.GetHashCode();

                                dContext.Jobs.InsertOnSubmit(statusJob);
                            }

                            statusJob.Frequency      = Utility.ToInt(statusData["Frequency"]);
                            statusJob.FrequencyUnits = Utility.ToInt(statusData["FrequencyUnits"]);

                            statusJob.NextRunTime = statusJob.CalculateNextRunTime();
                        }
                        else
                        {
                            //The enabled flag is false and if we have an existing status job - delete the job
                            if (statusPost.Count() > 0)
                            {
                                dContext.Jobs.DeleteOnSubmit(statusPost.First());
                            }
                        }

                        if (isSummaryJobEnabled)
                        {
                            Hashtable summaryData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"];
                            Job       summaryJob  = new Job();

                            //We have an existing summary job and the enabled flag is true - persist settings
                            if (summaryPost.Count() > 0)
                            {
                                summaryJob = summaryPost.First();
                            }
                            else
                            {
                                summaryJob.JobId       = Guid.NewGuid().ToString();
                                summaryJob.LastRunTime = null;
                                summaryJob.TagId       = gamertag.TagId;
                                summaryJob.PostFormat  = string.Empty;
                                summaryJob.Type        = JobTypes.Summary.GetHashCode();

                                dContext.Jobs.InsertOnSubmit(summaryJob);
                            }

                            summaryJob.Frequency      = Utility.ToInt(summaryData["Frequency"]);
                            summaryJob.FrequencyUnits = Utility.ToInt(summaryData["FrequencyUnits"]);

                            summaryJob.NextRunTime = summaryJob.CalculateNextRunTime();
                        }
                        else
                        {
                            //The enabled flag is false and if we have an existing summary job - delete the job
                            if (summaryPost.Count() > 0)
                            {
                                dContext.Jobs.DeleteOnSubmit(summaryPost.First());
                            }
                        }

                        if (isFacebookEnabled)
                        {
                            Hashtable fbData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"];
                            GamertagSocialConnection fbSocialConn = new GamertagSocialConnection();

                            //We have an existing summary job and the enabled flag is true - persist settings
                            if (fbConnection.Count() > 0)
                            {
                                fbSocialConn = fbConnection.First();
                            }
                            else
                            {
                                fbSocialConn.TagId = gamertag.TagId;
                                fbSocialConn.UserSocialConnectionId = gvUser.First().UserSocialConnectionId;

                                dContext.GamertagSocialConnections.InsertOnSubmit(fbSocialConn);
                            }
                        }
                        else
                        {
                            //The enabled flag is false and if we have an existing facebook connection - delete the connection
                            if (fbConnection.Count() > 0)
                            {
                                dContext.GamertagSocialConnections.DeleteOnSubmit(fbConnection.First());
                            }
                        }
                    }

                    dContext.SubmitChanges();

                    return(string.Empty);
                }
                else
                {
                    return new { Error = "Social connection ID \"" + ID + "\" does not exist." }
                };
            }
            catch (Exception ex)
            {
                return(new { Error = ex.ToString() });
            }
        }
Example #9
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("reg")
                .Description("Register your Gamertag.")
                .Parameter("text", ParameterType.Multiple)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        switch (e.Args[0].ToLower())
                        {
                        case "xbl":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Xbox Live",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "psn":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Playstation Network",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "nnid":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Nintendo Network",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "steam":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Steam", e.Message.User.Name,
                                                                e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "b.n":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Battle.Net",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        default:
                            await
                            e.Channel.SendMessage(
                                "Sorry, I don't recognize that type of gamertag. I currently recognize the following types of Gamertags (With explination in parenthesis): ");
                            await
                            e.Channel.SendMessage(
                                "XBL (Xbox Live), PSN (Playstation Network), NNID (Nintendo Network), Steam, B.N (Battle.Net)");
                            break;
                        }
                    }
                });

                /* LEGACY REGISTER COMMANDS */

                /*
                 * cgb.CreateCommand("regpsn")
                 *  .Description("Register your PSN Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Playstation Network", e.Message.User.Name,e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 *
                 * cgb.CreateCommand("regxbl")
                 *  .Description("Register your Xbox Live Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Xbox Live", e.Message.User.Name,e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 *
                 * cgb.CreateCommand("regb.n")
                 *  .Description("Register your Battle.Net Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Battle.Net", e.Message.User.Name, e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 */
                /*                                                                                                                                  */

                cgb.CreateCommand("glist")
                .Description("Returns a list of every stored Gamertag.")
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        bool anyExist = false;
                        string list   = "";
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Steam") != null)
                        {
                            list += "**Steam Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Steam")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** Steam: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Battle.Net") !=
                            null)
                        {
                            list += "**Battle.Net Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Battle.Net")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** Battle.Net: **" + tag.GTag +
                                               "**\n";
                                }
                            }
                        }
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Xbox Live") !=
                            null)
                        {
                            list += "**Xbox Live Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Xbox Live")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** XBL: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (
                            Beta.GamertagRepository.Gamertags.FirstOrDefault(
                                g => g.GamertagType == "Playstation Network") != null)
                        {
                            list += "**Playstation Network Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Playstation Network")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** PSN: **" + tag.GTag + "**";
                                }
                            }
                        }
                        if (
                            Beta.GamertagRepository.Gamertags.FirstOrDefault(
                                g => g.GamertagType == "Nintendo Network") != null)
                        {
                            list += "**Nintendo Network Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Nintendo Network")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** NNID: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (anyExist)
                        {
                            await e.Channel.SendMessage(list);
                        }
                        else
                        {
                            await e.Channel.SendMessage("Sorry, I don't have any Gamertags stored yet :-/");
                        }
                    }
                });

                cgb.CreateCommand("retrieve")
                .Description("Returns all of the Gamertags stored for specified Discord user.")
                .Parameter("text", ParameterType.Required)
                .Do(async e => {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        bool found       = false;
                        string retrieved = "";
                        foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                        {
                            if (tag.DiscordUsername == e.GetArg("text"))
                            {
                                found      = true;
                                retrieved += "Discord Username: **" + tag.DiscordUsername +
                                             "** Gamertag: **" + tag.GTag + "** Network: **" +
                                             tag.GamertagType + "** Gamertag ID: **" + tag.ID + "**\n";
                            }
                        }
                        if (found)
                        {
                            await e.Channel.SendMessage(retrieved);
                        }
                        else
                        {
                            await
                            e.Channel.SendMessage(
                                "Sorry, I didn't see any gamertags for that person.");
                        }
                    }
                });

                cgb.CreateCommand("remove")
                .Description("Removes the specified gamertag. Please provide the GamertagID, which can be retrieved using the '$retrieve' command.")
                .Parameter("ID", ParameterType.Required)
                .Do(async e => {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        int id;
                        if (Int32.TryParse(e.GetArg("ID"), out id))
                        {
                            Gamertag removeTag =
                                Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.ID == id);
                            if (removeTag != null)
                            {
                                if (removeTag.DiscordID == e.Message.User.Id)
                                {
                                    Beta.GamertagRepository.Gamertags.Remove(removeTag);
                                    await
                                    e.Channel.SendMessage(
                                        "Ok cool I've removed that gamertag for you! ");
                                    Beta.GamertagRepository.Save();
                                }
                                else
                                {
                                    await
                                    e.Channel.SendMessage(
                                        "Hey that's not yours! Leave it alone, dude.");
                                }
                            }
                            else
                            {
                                await
                                e.Channel.SendMessage(
                                    "Sorry, I didn't find that gamertag. Are you sure you have the right number?");
                            }
                        }
                    }
                });
            });
        }
Example #10
0
        public void ProcessData(GamervineDataContext DataContext, Gamertag Gamertag, XDocument CurrentData)
        {
            var latestData = from xd in DataContext.XboxData
                             where xd.TagId == Gamertag.TagId
                             orderby xd.RetrieveDate descending
                             select xd;

            //If we have a set of most recent data & the most recent data doesn't equal the data just retrieved, store it
            //Or, if the RecentGames element doesn't have any children, their authorization isn't set correctly and move on

            //TODO: Need to flag the account and notify the user that we are unable to retrieve their data
            if ((latestData.Count() != 0 && latestData.First().XmlData.Equals(CurrentData.ToString())) ||
                CurrentData.Descendants("RecentGames").Descendants().Count() == 0)
            {
                return;
            }

            XboxData dcXboxInfo = new XboxData();

            dcXboxInfo.XboxDataId   = Guid.NewGuid().ToString();
            dcXboxInfo.TagId        = Gamertag.TagId;
            dcXboxInfo.XmlData      = CurrentData.ToString();
            dcXboxInfo.RetrieveDate = DateTime.UtcNow;

            var xboxInfos = from xi in CurrentData.Descendants("XboxInfo")
                            select new bcXboxInfo
            {
                AccountStatus      = xi.Element("AccountStatus").Value,
                State              = xi.Element("State").Value,
                Gamertag           = xi.Element("Gamertag").Value,
                ProfileUrl         = new Uri(xi.Element("ProfileUrl").Value),
                TileUrl            = new Uri(xi.Element("TileUrl").Value),
                Country            = xi.Element("Country").Value,
                Reputation         = decimal.Parse(xi.Element("Reputation").Value),
                Bio                = xi.Element("Bio").Value,
                Location           = xi.Element("Location").Value,
                ReputationImageUrl = new Uri(xi.Element("ReputationImageUrl").Value),
                GamerScore         = int.Parse(xi.Element("GamerScore").Value),
                Zone               = xi.Element("Zone").Value,
            };

            var presenceInfos = from p in CurrentData.Descendants("PresenceInfo")
                                select new bcPresenceInfo
            {
                Valid      = bool.Parse(p.Element("Valid").Value),
                Info       = p.Element("Info").Value.Trim(' '),
                Info2      = p.Element("Info2").Value.Trim(' '),
                LastSeen   = p.Element("LastSeen").Value.Trim(' '),
                Online     = bool.Parse(p.Element("Online").Value),
                StatusText = p.Element("StatusText").Value.Trim(' '),
                Title      = p.Element("Title").Value.Trim(' ')
            };

            bcXboxInfo xInfo = xboxInfos.First <bcXboxInfo>();

            xInfo.PresenceInfo = presenceInfos.First <bcPresenceInfo>();

            if (latestData.Count() != 0)
            {
                //If the most recent data was offline and the current data is offline, move on - unless gamerscore changed
                if (latestData.First().Online.HasValue&& latestData.First().Online == 0 && !xInfo.PresenceInfo.Online &&
                    latestData.First().Gamerscore == xInfo.GamerScore)
                {
                    return;
                }

                //If the most recent data was away and the current data is away, move on - unless gamerscore changed
                if (latestData.First().StatusText.ToLower().Equals("away") && !xInfo.PresenceInfo.StatusText.ToLower().Equals("away") &&
                    latestData.First().Gamerscore == xInfo.GamerScore)
                {
                    return;
                }
            }

            dcXboxInfo.AccountStatus = xInfo.AccountStatus;
            dcXboxInfo.Bio           = xInfo.Bio;
            dcXboxInfo.Country       = xInfo.Country;
            dcXboxInfo.Gamerscore    = xInfo.GamerScore;
            dcXboxInfo.Gamertag      = xInfo.Gamertag;
            dcXboxInfo.Info          = xInfo.PresenceInfo.Info;
            dcXboxInfo.Info2         = xInfo.PresenceInfo.Info2;
            if (DateTime.Parse(xInfo.PresenceInfo.LastSeen) != DateTime.MinValue)
            {
                dcXboxInfo.LastSeen = DateTime.Parse(xInfo.PresenceInfo.LastSeen);
            }
            dcXboxInfo.Location           = xInfo.Location;
            dcXboxInfo.Online             = (xInfo.PresenceInfo.Online ? bcPresenceInfo.Status.Online.GetHashCode() : bcPresenceInfo.Status.Offline.GetHashCode());
            dcXboxInfo.ProfileUrl         = xInfo.ProfileUrl.ToString();
            dcXboxInfo.Reputation         = xInfo.Reputation;
            dcXboxInfo.ReputationImageUrl = xInfo.ReputationImageUrl.ToString();
            dcXboxInfo.StatusText         = xInfo.PresenceInfo.StatusText;
            dcXboxInfo.TileUrl            = xInfo.TileUrl.ToString();
            dcXboxInfo.Title = xInfo.PresenceInfo.Title;
            dcXboxInfo.Valid = (xInfo.PresenceInfo.Valid ? 1 : 0);
            dcXboxInfo.Zone  = xInfo.Zone;

            //xboxInfo.First<XboxInfo>().PresenceInfo = presence.First<PresenceInfo>();

            //var recentGames = from xugi in xmlDoc.Descendants("XboxUserGameInfo")
            //                  select new XboxUserGameInfo
            //                  {
            //                      Game = new Game
            //                      {
            //                          Name = xugi.Element("Game").Element("Name").Value,
            //                          TotalAchievements = int.Parse(xugi.Element("Game").Element("TotalAchievements").Value),
            //                          TotalGamerScore = int.Parse(xugi.Element("Game").Element("TotalGamerScore").Value),
            //                          Image32Url = new Uri(xugi.Element("Game").Element("Image32Url").Value),
            //                          Image64Url = new Uri(xugi.Element("Game").Element("Image64Url").Value)
            //                      },
            //                      LastPlayed = xugi.Element("LastPlayed").Value,
            //                      Achievements = int.Parse(xugi.Element("Achievements").Value),
            //                      GamerScore = int.Parse(xugi.Element("GamerScore").Value),
            //                      DetailsUrl = new Uri(xugi.Element("DetailsURL").Value)
            //                  };

            //XboxInfo xInfo = xboxInfo.First<XboxInfo>();
            //PresenceInfo pInfo = presence.First<PresenceInfo>();
            //List<XboxUserGameInfo> rGames = recentGames.ToList<XboxUserGameInfo>();

            //xInfo.PresenceInfo = pInfo;
            //xInfo.RecentGames = rGames;

            DataContext.XboxData.InsertOnSubmit(dcXboxInfo);
        }
Example #11
0
        public void ProcessSummary(GamervineDataContext DataContext, Gamertag Gamertag)
        {
            var summaryData = from s in DataContext.SummaryData
                              where s.TagId == Gamertag.TagId
                              select s;

            SummaryData sData     = null;
            XDocument   xdXmlData = null;
            bool        isNew     = false;

            if (summaryData.Count() == 0)
            {
                isNew                   = true;
                sData                   = new SummaryData();
                sData.TagId             = Gamertag.TagId;
                sData.LastProcessedDate = DateTime.Parse("01/01/1753");
                xdXmlData               = GetSummaryXml();
                sData.XmlData           = xdXmlData.ToString();
            }
            else
            {
                sData     = summaryData.First();
                xdXmlData = XDocument.Parse(sData.XmlData);
            }

            var dataToProcess = from xd in DataContext.XboxData
                                where xd.TagId == Gamertag.TagId &&
                                xd.RetrieveDate > sData.LastProcessedDate
                                orderby xd.RetrieveDate ascending
                                select xd;

            if (dataToProcess.Count() == 0)
            {
                return;
            }

            //This handles the first row of data - everything else is then based off of it's successor
            int?lastGamerscore    = int.Parse(xdXmlData.Descendants("Gamerscore").First().Value);
            int?achievementPoints = int.Parse(xdXmlData.Descendants("AchievementPoints").First().Value);

            if (lastGamerscore == 0)
            {
                lastGamerscore = dataToProcess.First().Gamerscore;
            }

            DateTime lastProcessedDate = DateTime.MinValue;

            foreach (XboxData currXboxData in dataToProcess)
            {
                if (currXboxData.Gamerscore != lastGamerscore)
                {
                    achievementPoints += currXboxData.Gamerscore - lastGamerscore;

                    lastGamerscore = currXboxData.Gamerscore;
                }

                lastProcessedDate = currXboxData.RetrieveDate;
            }

            XDocument lastXboxData_XmlData = XDocument.Parse(dataToProcess.AsEnumerable().Last().XmlData);

            var lastGames = from xugi in lastXboxData_XmlData.Descendants("XboxUserGameInfo")
                            select new bcGame
            {
                Name = xugi.Element("Game").Element("Name").Value,
                TotalAchievements = int.Parse(xugi.Element("Game").Element("TotalAchievements").Value),
                TotalGamerScore   = int.Parse(xugi.Element("Game").Element("TotalGamerScore").Value),
                Image32Url        = new Uri(xugi.Element("Game").Element("Image32Url").Value),
                Image64Url        = new Uri(xugi.Element("Game").Element("Image64Url").Value)
            };

            sData.LastProcessedDate = lastProcessedDate;

            xdXmlData.Descendants("Gamerscore").First().SetValue(lastGamerscore);
            xdXmlData.Descendants("AchievementPoints").First().SetValue(achievementPoints);

            StringBuilder sbGames = new StringBuilder();

            int maxVal = (lastGames.Count() >= 5 ? 5 : lastGames.Count());

            for (int i = 0; i < maxVal; i++)
            {
                sbGames.Append(lastGames.AsEnumerable().ElementAt(i).Name + ",");
            }

            xdXmlData.Descendants("Games").First().SetValue(sbGames.ToString().TrimEnd(new char[] { ',' }));

            sData.XmlData = xdXmlData.ToString();

            if (isNew)
            {
                DataContext.SummaryData.InsertOnSubmit(sData);
            }
        }