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 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. 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
 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. 5
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();
        }
Esempio n. 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);
            }
        }
Esempio n. 7
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. 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() });
            }
        }
Esempio n. 9
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. 10
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. 11
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());
            }
        }