public void Save()
        {
            GamervineDataContext gdc = new GamervineDataContext();

            var user = from usc in gdc.UserSocialConnections
                           join u in gdc.Users on usc.UserId equals u.UserId
                           where usc.ConnectionUserId == SocialConnId && usc.Type == SocialType.GetHashCode()
                           select u;

            if (user.Count() > 0)
            {
                User u = user.First();
                PropertyInfo pi = u.GetType().GetProperty(Field);
                if (pi != null)
                {
                    if(pi.PropertyType == typeof(Int16) ||
                        pi.PropertyType == typeof(Int32) ||
                        pi.PropertyType == typeof(Int64) ||
                        pi.PropertyType == typeof(Nullable<int>))
                        pi.SetValue(u, Utility.ToInt(Value), null);

                    gdc.SubmitChanges();
                }
            }
        }
Esempio n. 2
0
        public void DoWork()
        {
            GamervineDataContext dataContext = new GamervineDataContext();

            try
            {
                var tags = from g in dataContext.Gamertags
                           join j in dataContext.Jobs on g.TagId equals j.TagId
                           join u in dataContext.Users on g.UserId equals u.UserId
                           where g.State == State.Active.GetHashCode()
                                && j.Type == JobTypes.Data.GetHashCode()
                                && u.State == State.Active.GetHashCode()
                           select g;

                foreach (Gamertag gt in tags)
                    ProcessGamertag(dataContext, gt);

                SummaryTrackingService sts = new SummaryTrackingService();
                sts.DoWork();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in DataService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                Debug.WriteLine("DataService DoWork completed at " + DateTime.Now.ToString());
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public string GetPost(GamervineDataContext DataContext, Job Job)
        {
            var gamertag = from gt in DataContext.Gamertags
                           where gt.TagId == Job.TagId
                           select gt;

            var latestData = from xd in DataContext.XboxData
                             where xd.TagId == Job.TagId
                             orderby xd.RetrieveDate descending
                             select xd;

            if (latestData.Count() == 0)
                return string.Empty;

            string status = HandlerFactory.GetHandlerForType(gamertag.First().Type).GetStatusPost(DataContext, latestData.First(), Job.PostFormat);

            var lastPost = from ph in DataContext.PostHistories
                           where ph.TagId == Job.TagId
                                && ph.PostType == JobTypes.Status.GetHashCode()
                           orderby ph.PostDate descending
                           select ph;

            string strLastPost = string.Empty;
            if (lastPost.Count() > 0)
                strLastPost = lastPost.First().PostString;

            //TODO: Move all of this logic into the XboxHandler - make generic to the handlers
            if (!latestData.First().Title.ToLower().Equals("xbox 360 dashboard") &&
                !latestData.First().Title.ToLower().Contains("xbox.com"))
            {
                if (strLastPost.Equals(string.Empty) || !status.ToLower().Equals(strLastPost.ToLower()))
                {
                    if ((strLastPost.ToLower().Contains(" is currently offline (xbox 360). last seen ") &&
                        !status.ToLower().Contains(" is currently offline (xbox 360). last seen ")) ||
                        (!strLastPost.ToLower().Contains(" is currently offline (xbox 360). last seen ") &&
                        status.ToLower().Contains(" is currently offline (xbox 360). last seen ")) ||
                        (!strLastPost.ToLower().Contains(" is currently offline (xbox 360). last seen ") &&
                        !status.ToLower().Contains(" is currently offline (xbox 360). last seen ")) ||

                        (strLastPost.ToLower().Contains(" is currently away (xbox 360). last seen ") &&
                        !status.ToLower().Contains(" is currently away (xbox 360). last seen ")) ||
                        (!strLastPost.ToLower().Contains(" is currently away (xbox 360). last seen ") &&
                        status.ToLower().Contains(" is currently away (xbox 360). last seen ")) ||
                        (!strLastPost.ToLower().Contains(" is currently away (xbox 360). last seen ") &&
                        !status.ToLower().Contains(" is currently away (xbox 360). last seen ")))
                    {
                        //Log the two statuses
                        Debug.WriteLine("Status is valid." + Environment.NewLine + "Last status: " + strLastPost + Environment.NewLine + "New status: " + status);
                        return status;
                    }
                }
            }

            return string.Empty;
        }
Esempio n. 6
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (propertyGrid1.SelectedObject is UserPref)
     {
         GamervineDataContext dc = new GamervineDataContext();
         dc.UserPrefs.InsertOnSubmit((UserPref)propertyGrid1.SelectedObject);
         dc.SubmitChanges();
     }
     else
         MessageBox.Show("The selected object is not a type of UserPref");
 }
Esempio n. 7
0
        public static object GetUserGameConnectionData(string ID, SocialConnectionType SocConnType, DataConnectionType DataConnType)
        {
            GamervineDataContext dContext = new GamervineDataContext();

            var gvUserId = from usc in dContext.UserSocialConnections
                           where usc.ConnectionUserId == ID && usc.Type == SocConnType.GetHashCode()
                           select usc.UserId;

            if (gvUserId.Count() > 0)
            {
                var gamertag = from gt in dContext.Gamertags
                               where gt.Type == DataConnType.GetHashCode() && gt.UserId == gvUserId.First()
                               select new
                               {
                                   gt.TagId,
                                   gt.Tag
                               };

                if (gamertag.Count() > 0)
                {
                    var jobs = from j in dContext.Jobs
                               where j.TagId == gamertag.First().TagId
                               select new
                               {
                                   j.JobId,
                                   j.Type,
                                   j.Frequency,
                                   j.FrequencyUnits
                               };

                    var gtSocialConns = from gtsc in dContext.GamertagSocialConnections
                                        join usc in dContext.UserSocialConnections on gtsc.UserSocialConnectionId equals usc.UserSocialConnectionId
                                        where gtsc.TagId == gamertag.First().TagId
                                        select new
                                        {
                                            usc.Type
                                        };

                    return new
                    {
                        TagId = gamertag.First().TagId,
                        Tag = gamertag.First().Tag,
                        Jobs = jobs,
                        GamertagSocialConnections = gtSocialConns
                    };
                }
                else
                    return new { TagId = string.Empty };
            }
            else
                return new { Error = "Social connection ID \"" + ID + "\" does not exist."};
        }
Esempio n. 8
0
        public void PostWork(GamervineDataContext DataContext, Job Job)
        {
            var summary = from s in DataContext.SummaryData
                          where s.TagId == Job.TagId
                          select s;

            SummaryData sData = summary.First();
            XDocument xmlData = XDocument.Parse(sData.XmlData);
            xmlData.Descendants("AchievementPoints").First().Value = "0";

            sData.XmlData = xmlData.ToString();

            DataContext.SubmitChanges();
        }
        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);
            }
        }
Esempio n. 10
0
        public static object GetLatestPosts(int Count)
        {
            GamervineDataContext dContext = new GamervineDataContext();

            var posts = from ph in dContext.PostHistories
                           join gt in dContext.Gamertags on ph.TagId equals gt.TagId
                           where gt.XboxDatas.FirstOrDefault() != null
                           orderby ph.PostDate descending
                           select new
                           {
                               PostString = (ph.PostString.Length > 130 ? ph.PostString.Substring(0, 125) + "..." : ph.PostString),
                               gt.XboxDatas.First().TileUrl
                           };

            return posts.Take(Count);
        }
Esempio n. 11
0
        public string GetPost(GamervineDataContext DataContext, Job Job)
        {
            var gamertag = from gt in DataContext.Gamertags
                           where gt.TagId == Job.TagId
                           select gt;

            var summary = from s in DataContext.SummaryData
                          where s.TagId == Job.TagId
                          select s;

            string strPost = string.Empty;
            if (summary.Count() > 0)
            {
                strPost = HandlerFactory.GetHandlerForType(gamertag.First().Type).GetSummaryPost(DataContext, summary.First(), Job.PostFormat);
                strPost = strPost.Replace("[@Timeframe]", Job.GetFrequencyDisplayText());
            }

            return strPost;
        }
Esempio n. 12
0
        public static object GetUser(string ID, SocialConnectionType TypeID)
        {
            GamervineDataContext dContext = new GamervineDataContext();

            var userInfo = from usc in dContext.UserSocialConnections
                           join u in dContext.Users on usc.UserId equals u.UserId
                           join gt in dContext.Gamertags on u.UserId equals gt.UserId
                           join xd in dContext.XboxData on gt.TagId equals xd.TagId
                           where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode()
                           orderby xd.RetrieveDate descending
                           select new
                           {
                               xd.TileUrl,
                               xd.Gamerscore,
                               xd.Gamertag,
                               xd.ReputationImageUrl
                           };

            if (userInfo.Count() > 0)
                return userInfo.First();
            else
                return new Exception("Invalid social user ID \"" + ID + "\" for type \"" + TypeID + "\".");
        }
        public void DoWork()
        {
            GamervineDataContext dataContext = new GamervineDataContext();

            try
            {
                //Process the recent data pull for anyone configured to have a summary post
                var tags = from g in dataContext.Gamertags
                           join j in dataContext.Jobs on g.TagId equals j.TagId
                           where g.State == State.Active.GetHashCode() && j.Type == JobTypes.Summary.GetHashCode()
                           select g;

                foreach (Gamertag gt in tags)
                    ProcessGamertag(dataContext, gt);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in DataService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                Debug.WriteLine("SummaryTrackingService DoWork completed at " + DateTime.Now.ToString());
            }
        }
Esempio n. 14
0
        private void postStatusToPing()
        {
            GamervineDataContext dataContext = new GamervineDataContext();

            try
            {
                var users = from u in dataContext.Users
                            join up in dataContext.UserPrefs on u.UserId equals up.UserId
                            join gt in dataContext.Gamertags on u.UserId equals gt.UserId
                            where gt.State != 2
                            select new
                            {
                                u.UserId,
                                u.PingFmKey,
                                up.PublishGameFrequency,
                                up.PublishInterval,
                                up.PublishStatus,
                                up.PublishUniqueStatus,
                                up.StatusFormat,
                                gt.TagId,
                                gt.State,
                                gt.Type
                            };

                foreach (var user in users)
                {
                    var latestData = from xd in dataContext.XboxData
                                     where xd.TagId == user.TagId
                                     orderby xd.RetrieveDate descending
                                     select xd;

                    string status = bcXboxData.GetStatusString(user.StatusFormat, latestData.First());

                    var lastPost = from ph in dataContext.PostHistories
                                   where ph.UserId == user.UserId
                                   orderby ph.PostDate descending
                                   select ph;

                    string strLastPost = string.Empty;
                    if(lastPost.Count() > 0)
                        strLastPost = lastPost.First().PostString;

                    if (strLastPost.Equals(string.Empty) || !status.ToLower().Equals(strLastPost.ToLower()))
                    {
                        if ((strLastPost.ToLower().Contains(" is currently offline. last seen ") &&
                            !status.ToLower().Contains(" is currently offline. last seen ")) ||
                            (!strLastPost.ToLower().Contains(" is currently offline. last seen ") &&
                            status.ToLower().Contains(" is currently offline. last seen ")) ||
                            (!strLastPost.ToLower().Contains(" is currently offline. last seen ") &&
                            !status.ToLower().Contains(" is currently offline. last seen ")))
                        {
                            //Hit the Ping.fm service
                            PingFMApi.api_key = "29e2b905210c5a0cf77f74e2462f8ea4";
                            PingFMApi ping = new PingFMApi(user.PingFmKey);
                            PingFMApi.PingResponse pr = ping.Post(new PingFMApi.OutgoingMessage(status));

                            //Record the post history in the database
                            PostHistory ph = new PostHistory();
                            ph.PostDate = DateTime.UtcNow;
                            ph.PostHistoryId = _nextPostHistoryID++;
                            ph.PostString = status;
                            ph.UserId = user.UserId;

                            dataContext.PostHistories.InsertOnSubmit(ph);
                        }
                    }
                }
            }
            finally
            {
                dataContext.SubmitChanges();
            }
        }
Esempio n. 15
0
        private void retrieveGamerData()
        {
            GamervineDataContext dataContext = new GamervineDataContext();

            try
            {
                var tags = from t in dataContext.Gamertags
                           where t.State == 1
                           select t;

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

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

                    XDocument xmlDoc = XDocument.Parse(result);

                    XboxData dcXboxInfo = new XboxData();
                    dcXboxInfo.XboxDataId = _nextXboxDataID++;
                    dcXboxInfo.TagId = gt.TagId;
                    dcXboxInfo.XmlData = xmlDoc.ToString();
                    dcXboxInfo.RetrieveDate = DateTime.UtcNow;

                    var xboxInfos = from xi in xmlDoc.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 xmlDoc.Descendants("PresenceInfo")
                                        select new bcPresenceInfo
                                        {
                                            Valid = bool.Parse(p.Element("Valid").Value),
                                            Info = p.Element("Info").Value,
                                            Info2 = p.Element("Info2").Value,
                                            LastSeen = p.Element("LastSeen").Value,
                                            Online = bool.Parse(p.Element("Online").Value),
                                            StatusText = p.Element("StatusText").Value,
                                            Title = p.Element("Title").Value
                                        };

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

                    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;
                    dcXboxInfo.LastSeen = DateTime.Parse(xInfo.PresenceInfo.LastSeen);
                    dcXboxInfo.Location = xInfo.Location;
                    dcXboxInfo.Online = (xInfo.PresenceInfo.Online ? 1 : 0);
                    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;

                    dataContext.XboxData.InsertOnSubmit(dcXboxInfo);

                    //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;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                dataContext.SubmitChanges();
            }
        }
Esempio n. 16
0
        public void DoWork()
        {
            GamervineDataContext dataContext = new GamervineDataContext();

            try
            {
                //Get all jobs where the user & gamertags are active and the next run time is in the past or now
                var jobs = from j in dataContext.Jobs
                           join gt in dataContext.Gamertags on j.TagId equals gt.TagId
                           join u in dataContext.Users on gt.UserId equals u.UserId
                           where gt.State == State.Active.GetHashCode()
                                && u.State == State.Active.GetHashCode()
                                && j.NextRunTime <= DateTime.UtcNow
                           select j;

                foreach (Job job in jobs)
                {
                    try
                    {
                        IJobHandler jobHandler = JobHandlerFactory.GetHandlerForType(job.Type);
                        string post = jobHandler.GetPost(dataContext, job);

                        if (!post.Equals(string.Empty))
                        {
                            var socialConnectors = from sc in dataContext.UserSocialConnections
                                                   join gtsc in dataContext.GamertagSocialConnections on sc.UserSocialConnectionId equals gtsc.UserSocialConnectionId
                                                   where gtsc.TagId == job.TagId
                                                   select sc;

                            if (socialConnectors.Count() > 0)
                            {
                                foreach (UserSocialConnection conn in socialConnectors)
                                {
                                    ISocialConnector socialConnector = SocialConnectorFactory.GetSocialConnectorForType(conn.Type);
                                    socialConnector.Post(conn, post);
                                }
                            }
                            else
                            {
                                //TODO: Perform logic to flag the account that it doesn't have social connectors and they should sign up
                            }

                            //Do any post work that the handler may need to do
                            jobHandler.PostWork(dataContext, job);

                            //Record the post history in the database
                            PostHistory ph = new PostHistory();
                            ph.PostDate = DateTime.UtcNow;
                            ph.PostHistoryId = Guid.NewGuid().ToString();
                            ph.PostString = post;
                            ph.PostType = job.Type;
                            ph.TagId = job.TagId;

                            dataContext.PostHistories.InsertOnSubmit(ph);
                        }

                        job.NextRunTime = job.CalculateNextRunTime();
                        job.LastRunTime = DateTime.UtcNow;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Exception occurred in PostService.DoWork processing Job ID #" + job.JobId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                    }
                    finally
                    {
                        try
                        {
                            dataContext.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Exception occurred in PostService.DoWork -> dataContext.SubmitChanges for Job ID #" + job.JobId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in PostService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                Debug.WriteLine("PostService DoWork completed at " + DateTime.Now.ToString());
            }
        }
Esempio n. 17
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() };
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public static object GetUserProfile(string ID, SocialConnectionType TypeID)
        {
            GamervineDataContext dContext = new GamervineDataContext();

            var gvUserId = from usc in dContext.UserSocialConnections
                           join u in dContext.Users on usc.UserId equals u.UserId
                           where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode()
                           select new
                           {
                               usc.UserId,
                               u.State,
                               u.IncludeDetailedStatus,
                               u.IncludeGamertag,
                               u.PostUniqueGames
                           };

            if (gvUserId.Count() > 0)
            {
                string strGVUserId = gvUserId.First().UserId;

                var tags = from u in dContext.Users
                           join gt in dContext.Gamertags on u.UserId equals gt.UserId
                           where u.UserId == strGVUserId
                           select new
                           {
                               gt.Type,
                               gt.State
                           };

                var socialConnections = from usc in dContext.UserSocialConnections
                                        where usc.UserId == strGVUserId
                                        select new
                                        {
                                            usc.ConnectionUserId,
                                            usc.Type
                                        };

                var gamertagSocialConns = from gtsc in dContext.GamertagSocialConnections
                                    join usc in dContext.UserSocialConnections on gtsc.UserSocialConnectionId equals usc.UserSocialConnectionId
                                    join gt in dContext.Gamertags on gtsc.TagId equals gt.TagId
                                    where usc.UserId == strGVUserId
                                    select new
                                    {
                                        usc.Type,
                                        GCType = gt.Type
                                    };

                var userProfile = new
                                {
                                    State = gvUserId.First().State,
                                    IncludeDetailedStatus = gvUserId.First().IncludeDetailedStatus,
                                    IncludeGamertag = gvUserId.First().IncludeGamertag,
                                    PostUniqueGames = gvUserId.First().PostUniqueGames,
                                    Tags = tags,
                                    SocialConnections = socialConnections,
                                    GamertagSocialConnections = gamertagSocialConns
                                };

                return userProfile;
            }
            else
                return new Exception("Invalid social user ID \"" + ID + "\" for type \"" + TypeID + "\".");
        }
Esempio n. 20
0
        public static void ValidateUser(string ID, SocialConnectionType TypeID, string Token)
        {
            try
            {
                GamervineDataContext dContext = new GamervineDataContext();

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

                if (gvUserId.Count() == 0)
                {
                    //User doesn't exist in the system, create new user records
                    User u = new User();
                    u.Email = string.Empty;
                    u.UserId = Guid.NewGuid().ToString();
                    u.State = State.Active.GetHashCode();
                    u.CreatedDate = DateTime.UtcNow;

                    UserSocialConnection usc = new UserSocialConnection();
                    usc.ConnectionUserId = ID;
                    usc.Token = Token;
                    usc.Type = TypeID.GetHashCode();
                    usc.UserId = u.UserId;
                    usc.UserSocialConnectionId = Guid.NewGuid().ToString();

                    dContext.Users.InsertOnSubmit(u);
                    dContext.UserSocialConnections.InsertOnSubmit(usc);

                    dContext.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in bcUser.ValidateUser -> " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
 public string GetSummaryPost(GamervineDataContext DataContext, SummaryData Data, string Format)
 {
     return bcXboxData.GetSummaryPost(Format, Data);
 }
Esempio n. 23
0
 public void PostWork(GamervineDataContext DataContext, Job Job)
 {
     //Do Nothing
 }
Esempio n. 24
0
 public string GetStatusPost(GamervineDataContext DataContext, XboxData Data, string Format)
 {
     return bcXboxData.GetStatusPost(Format, Data);
 }