Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
        }
        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);
            }
        }
Exemplo n.º 4
0
        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;
        }
 partial void DeleteGamertag(Gamertag instance);
 partial void UpdateGamertag(Gamertag instance);
 partial void InsertGamertag(Gamertag instance);
		private void detach_Gamertags(Gamertag entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
		private void attach_Gamertags(Gamertag entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
Exemplo n.º 10
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() };
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }