コード例 #1
0
        public void SyncScreenshots()
        {
            // get all xbox users that haven't been sync'ed in the last hour.
            var xboxUsers = xboxUserService.GetXboxUsers().Where(x => x.ActivitiesLastSyncedAtt < DateTime.UtcNow.AddMinutes(-5));

            foreach (var xboxUser in xboxUsers)
            {
                var apiXboxUserScreenshots = xboxApi.GetUserScreenshots(xboxUser.XboxUserID);
                var xboxUserScreenshots    = screenshotService.GetXboxUserScreenshots(xboxUser.XboxUserID);

                foreach (var screenshot in apiXboxUserScreenshots)
                {
                    var xboxUserScreenshot = xboxUserScreenshots.Where(x => x.XblID == screenshot.screenshotId).FirstOrDefault();

                    if (xboxUserScreenshot != null)
                    {
                        xboxUserScreenshot.State         = screenshot.state;
                        xboxUserScreenshot.DatePublished = screenshot.datePublished;
                        screenshotService.UpdateScreenshot(xboxUserScreenshot);
                    }
                    else
                    {
                        screenshotService.CreateScreenshot(new Screenshot()
                        {
                            XblID          = screenshot.screenshotId,
                            DateTaken      = screenshot.dateTaken,
                            DatePublished  = screenshot.datePublished,
                            ScreenshotUris = screenshot.screenshotUris.Select(x => new ScreenshotUri()
                            {
                                Uri        = x.uri,
                                UriType    = x.uriType,
                                Expiration = x.expiration,
                                FileSize   = x.fileSize
                            }).ToList(),
                            Thumbnails = screenshot.thumbnails.Select(x => new ScreenshotThumbnail()
                            {
                                Uri           = x.uri,
                                FileSize      = x.fileSize,
                                ThumbnailType = x.thumbnailType
                            }).ToList(),
                            XboxUserID = xboxUser.XboxUserID,
                            XboxUser   = xboxUser,
                            TitleName  = screenshot.titleName,
                            DeviceType = screenshot.deviceType,
                            State      = screenshot.state
                        });
                    }
                }

                screenshotService.Save();
            }
        }
コード例 #2
0
        public void SyncGameClips()
        {
            // get all xbox users that haven't been sync'ed in the last hour.
            var xboxUsers = xboxUserService.GetXboxUsers().Where(x => x.ActivitiesLastSyncedAtt < DateTime.UtcNow.AddMinutes(-5));

            foreach (var xboxUser in xboxUsers)
            {
                var apiXboxUserGameClips = xboxApi.GetUserGameClips(xboxUser.XboxUserID);
                var xboxUserGameClips    = gameClipService.GetXboxUserGameClips(xboxUser.XboxUserID);

                foreach (var gameClip in apiXboxUserGameClips)
                {
                    var xboxUserGameClip = xboxUserGameClips.Where(x => x.XblID == gameClip.gameClipId).FirstOrDefault();

                    if (xboxUserGameClip != null)
                    {
                        xboxUserGameClip.State         = gameClip.state;
                        xboxUserGameClip.DatePublished = gameClip.datePublished;
                        gameClipService.UpdateGameClip(xboxUserGameClip);
                    }
                    else
                    {
                        gameClipService.CreateGameClip(new GameClip()
                        {
                            XblID         = gameClip.gameClipId,
                            DateRecorded  = gameClip.dateRecorded,
                            DatePublished = gameClip.datePublished,
                            ClipUris      = gameClip.gameClipUris.Select(x => new GameClipUri()
                            {
                                Uri        = x.uri,
                                UriType    = x.uriType,
                                Expiration = x.expiration,
                                FileSize   = x.fileSize
                            }).ToList(),
                            Thumbnails = gameClip.thumbnails.Select(x => new GameClipThumbnail()
                            {
                                Uri           = x.uri,
                                FileSize      = x.fileSize,
                                ThumbnailType = x.thumbnailType
                            }).ToList(),
                            XboxUserID = xboxUser.XboxUserID,
                            XboxUser   = xboxUser,
                            TitleName  = gameClip.titleName,
                            DeviceType = gameClip.deviceType,
                            State      = gameClip.state
                        });
                    }
                }

                gameClipService.Save();
            }
        }
コード例 #3
0
        public void SyncActivity()
        {
            // get all xbox users that haven't been sync'ed in the last hour.
            var xboxUsers = xboxUserService.GetXboxUsers().Where(x => x.ActivitiesLastSyncedAtt < DateTime.UtcNow.AddMinutes(-5));

            foreach (var xboxUser in xboxUsers)
            {
                var apiXboxUserActivities = xboxApi.GetUserActivities(xboxUser.XboxUserID);
                var xboxdUserActivities   = activityService.GetXboxUserActivities(xboxUser.XboxUserID);
                var fiveyearsago          = DateTime.Now.AddYears(-5);

                foreach (var activity in apiXboxUserActivities)
                {
                    var xboxUserActivity = xboxdUserActivities.Where(x => TrimMilliseconds(x.Date.Value) == TrimMilliseconds(activity.date)).FirstOrDefault();

                    if (xboxUserActivity != null)
                    {
                        xboxUserActivity.StartTime                = activity.startTime;
                        xboxUserActivity.EndTime                  = activity.endTime;
                        xboxUserActivity.ActivityItemType         = activity.activityItemType;
                        xboxUserActivity.SessionDurationInMinutes = activity.sessionDurationInMinutes;
                        xboxUserActivity.Description              = activity.description;
                        xboxUserActivity.ImageUrl                 = activity.itemImage;
                        xboxUserActivity.Platform                 = activity.platform;
                        xboxUserActivity.ContentType              = activity.contentType;

                        activityService.UpdateActivity(xboxUserActivity);
                    }
                    else
                    {
                        activityService.CreateActivity(new Activity()
                        {
                            Date                     = activity.date,
                            StartTime                = activity.startTime,
                            EndTime                  = activity.endTime,
                            ActivityItemType         = activity.activityItemType,
                            SessionDurationInMinutes = activity.sessionDurationInMinutes,
                            Description              = activity.description,
                            ImageUrl                 = activity.itemImage,
                            Platform                 = activity.platform,
                            ContentType              = activity.contentType,
                            XboxUserID               = xboxUser.XboxUserID,
                            XboxUser                 = xboxUser
                        });
                    }
                }

                xboxUser.ActivitiesLastSyncedAtt = DateTime.UtcNow;
            }

            activityService.Save();
        }
コード例 #4
0
        public void SyncXboxUsers()
        {
            // get all xbox users that haven't been sync'ed in the last hour.
            var xboxUsers = xboxUserService.GetXboxUsers().Where(x => x.ProfileLastSyncedAt < DateTime.UtcNow.AddHours(-1));

            // get all xbox users linked with an account
            var userXboxUserIds = userService.GetUsers().Select(x => x.XboxUserID);

            foreach (var xboxUser in xboxUsers)
            {
                //--------------------------------------------//
                // -- update xbox user general information -- //
                //--------------------------------------------//

                var apiXboxUser = xboxApi.GetUser(xboxUser.XboxUserID);

                xboxUser.Gamerscore          = apiXboxUser.Gamerscore;
                xboxUser.AccountTier         = apiXboxUser.AccountTier;
                xboxUser.GameDisplayName     = apiXboxUser.GameDisplayName;
                xboxUser.GameDisplayPicRaw   = apiXboxUser.GameDisplayPicRaw;
                xboxUser.PreferredColor      = apiXboxUser.PreferredColor;
                xboxUser.AccountTier         = apiXboxUser.AccountTier;
                xboxUser.XboxOneRep          = apiXboxUser.XboxOneRep;
                xboxUser.ProfileLastSyncedAt = DateTime.UtcNow;

                //----------------------------------------------------------------------//
                // -- refresh xbox user friends --(for linked xbox user accounts only)--//
                //----------------------------------------------------------------------//

                if (userXboxUserIds.Contains(xboxUser.XboxUserID))
                {
                    var apiXboxUserFriends = xboxApi.GetFriends(xboxUser.XboxUserID);

                    // remove xbox users that are no longer friends
                    xboxUser.Friends.RemoveAll(x => !apiXboxUserFriends.Select(y => y.id).Contains(x.XboxUserID));

                    // refresh information for existing friends
                    var apiXboxUserFriendsDic = apiXboxUserFriends.ToDictionary(x => x.id);

                    foreach (var xboxUserFriend in xboxUser.Friends)
                    {
                        xboxUserFriend.Gamerscore              = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].Gamerscore;
                        xboxUserFriend.AccountTier             = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].AccountTier;
                        xboxUserFriend.GameDisplayName         = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].GameDisplayName;
                        xboxUserFriend.GameDisplayPicRaw       = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].GameDisplayPicRaw;
                        xboxUserFriend.PreferredColor          = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].PreferredColor;
                        xboxUserFriend.AccountTier             = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].AccountTier;
                        xboxUserFriend.XboxOneRep              = apiXboxUserFriendsDic[xboxUserFriend.XboxUserID].XboxOneRep;
                        xboxUserFriend.ProfileLastSyncedAt     = DateTime.UtcNow;
                        xboxUserFriend.ActivitiesLastSyncedAtt = xboxUserFriend.ActivitiesLastSyncedAtt;
                    }

                    // add new friends :)
                    xboxUser.Friends.AddRange(apiXboxUserFriends.Where(x => !xboxUser.Friends.Select(c => c.XboxUserID).Contains(x.id)).Select(x => new XboxUser()
                    {
                        XboxUserID              = x.id,
                        GamerTag                = x.Gamertag,
                        GameDisplayName         = x.GameDisplayName,
                        Gamerscore              = x.Gamerscore,
                        GameDisplayPicRaw       = x.GameDisplayPicRaw,
                        AccountTier             = x.AccountTier,
                        XboxOneRep              = x.XboxOneRep,
                        TenureLevel             = x.TenureLevel,
                        PreferredColor          = x.PreferredColor,
                        ProfileLastSyncedAt     = DateTime.UtcNow,
                        ActivitiesLastSyncedAtt = DateTime.UtcNow.AddHours(-1)
                    }));
                }

                xboxUserService.UpdateXboxUser(xboxUser);
            }

            xboxUserService.Save();
        }