Beispiel #1
0
        public ActionResult DeleteConfirmed(string id)
        {
            UserTrophy userTrophy = db.UserTrophies.Find(id);

            db.UserTrophies.Remove(userTrophy);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "UserId,TrophyId")] UserTrophy userTrophy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userTrophy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId   = new SelectList(db.Users, "Id", "Email", userTrophy.UserId);
     ViewBag.TrophyId = new SelectList(db.Trophies, "TrophyId", "Description", userTrophy.TrophyId);
     return(View(userTrophy));
 }
Beispiel #3
0
        // GET: UserTrophies/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTrophy userTrophy = db.UserTrophies.Find(id);

            if (userTrophy == null)
            {
                return(HttpNotFound());
            }
            return(View(userTrophy));
        }
Beispiel #4
0
        // GET: UserTrophies/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserTrophy userTrophy = db.UserTrophies.Find(id);

            if (userTrophy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId   = new SelectList(db.Users, "Id", "Email", userTrophy.UserId);
            ViewBag.TrophyId = new SelectList(db.Trophies, "TrophyId", "Description", userTrophy.TrophyId);
            return(View(userTrophy));
        }
			public bool CompileData()
			{
				if (this.CompilerReady())
				{
					var currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");
					var filePath = Path.Combine(this.OutputPath, this.FileNameFormat + ".xml");
					var savePath = "";

					var userProfile = new UserProfile();
					var profileXml = XDocument.Load(Path.Combine(this.RawDataPath, "profile.xml")).Root;
					userProfile.Id = profileXml.Element("onlinename").Value;
					userProfile.ImageUrl = profileXml.Element("avatarurl").Value;
					userProfile.AboutMe = profileXml.Element("aboutme").Value;
					userProfile.Country = profileXml.Element("country").Value;
					userProfile.PSPlus = profileXml.Element("plusicon").Value == "1";
					var trophyXml = XDocument.Load(Path.Combine(this.RawDataPath, "trophy.xml")).Root;
					userProfile.EarnedPoints = int.Parse(trophyXml.Element("point").Value);
					userProfile.Level = int.Parse(trophyXml.Element("level").Value);
					userProfile.LevelProgress = int.Parse(trophyXml.Element("level").Attribute("progress").Value);
					userProfile.LevelBasePoints = int.Parse(trophyXml.Element("level").Attribute("base").Value);
					userProfile.LevelNextPoints = int.Parse(trophyXml.Element("level").Attribute("next").Value);
					userProfile.BronzeEarned = int.Parse(trophyXml.Element("types").Attribute("bronze").Value);
					userProfile.SilverEarned = int.Parse(trophyXml.Element("types").Attribute("silver").Value);
					userProfile.GoldEarned = int.Parse(trophyXml.Element("types").Attribute("gold").Value);
					userProfile.PlatinumEarned = int.Parse(trophyXml.Element("types").Attribute("platinum").Value);
					userProfile.TotalEarned = userProfile.BronzeEarned + userProfile.SilverEarned + userProfile.GoldEarned + userProfile.PlatinumEarned;
					var gamesFiles = new DirectoryInfo(this.RawDataPath).GetFiles("games_*.xml").Select(f => f.FullName);

					var apiGames = new List<ApiGame>();

					foreach (var gamesFile in gamesFiles)
					{
						var gamesXml = XDocument.Load(gamesFile).Root;
						var totalGames = int.Parse(gamesXml.Element("title").Value);
						if (userProfile.TotalGames == 0 || userProfile.TotalGames < totalGames)
						{
							userProfile.TotalGames = totalGames;
						}

						foreach (var game in gamesXml.Descendants("info"))
						{
							var gameInfo = new ApiGame();
							gameInfo.Id = game.Attribute("npcommid").Value;
							gameInfo.Platform = game.Attribute("pf").Value;
							gameInfo.Bronze = int.Parse(game.Element("types").Attribute("bronze").Value);
							gameInfo.Silver = int.Parse(game.Element("types").Attribute("silver").Value);
							gameInfo.Gold = int.Parse(game.Element("types").Attribute("gold").Value);
							gameInfo.Platinum = int.Parse(game.Element("types").Attribute("platinum").Value);
							gameInfo.Updated = DateTime.Parse(game.Element("last-updated").Value);

							var existingGame = apiGames.FirstOrDefault(g => g.Id == gameInfo.Id);
							if (existingGame != null && existingGame.Updated <= gameInfo.Updated)
							{
								// This game is already added, but needs to be updated.
								apiGames.Remove(existingGame);
								apiGames.Add(gameInfo);
							}
							else
							{
								apiGames.Add(gameInfo);
							}
						}
					}
					apiGames = apiGames.OrderByDescending(g => g.Updated).ToList();

					userProfile.LastUpdate = apiGames.Select(g => g.Updated).FirstOrDefault();
					if (userProfile.LastUpdate == DateTime.MinValue)
					{
						userProfile.LastUpdate = null;
					}
					// Profile is done at this point.

					var userGames = new List<UserGame>();
					int orderPlayed = 1;
					// Get game data and add to games plus create trophies- file.
					foreach (var apiGame in apiGames)
					{
						var hasTrophyDetails = File.Exists(Path.Combine(this.TrophyDetailsPath, string.Format("{0}.xml", apiGame.Id)));
						var hasEarnedDetails = File.Exists(Path.Combine(this.RawDataPath, string.Format("game-{0}.xml", apiGame.Id)));
						if (hasTrophyDetails && hasEarnedDetails)
						{
							var trophyDetailsXml = XDocument.Load(Path.Combine(this.TrophyDetailsPath, string.Format("{0}.xml", apiGame.Id))).Root;
							var earnedDetailsXml = XDocument.Load(Path.Combine(this.RawDataPath, string.Format("game-{0}.xml", apiGame.Id))).Root;

							var gameDetails = trophyDetailsXml.Descendants("Game").FirstOrDefault();

							var userGame = new UserGame();
							userGame.Id = apiGame.Id;
							userGame.IdEurope = gameDetails.Element("IdEurope").Value;
							userGame.Title = gameDetails.Element("Title").Value;
							userGame.ImageUrl = gameDetails.Element("Image").Value;
							userGame.BronzeEarned = apiGame.Bronze;
							userGame.SilverEarned = apiGame.Silver;
							userGame.GoldEarned = apiGame.Gold;
							userGame.PlatinumEarned = apiGame.Platinum;
							userGame.TotalEarned = apiGame.Bronze + apiGame.Silver + apiGame.Gold + apiGame.Platinum;
							userGame.OrderPlayed = orderPlayed++;
							userGame.LastUpdated = apiGame.Updated;
							userGame.TotalPoints = int.Parse(gameDetails.Element("TotalPoints").Value);
							// It appears that PS4 games now include platinums in the total points count. Should probably just overwrite this for all platforms.
							userGame.EarnedPoints = userGame.CalculateEarnedPoints(apiGame.Platform.ToLower() == "ps4");
							userGame.Progress = userGame.CalculateProgress().ToString();
							userGame.Platform = apiGame.Platform;

							var trophyDetails = trophyDetailsXml.Descendants("Trophy");
							userGame.PossibleTrophies = trophyDetails.Count();

							userGames.Add(userGame);

							// Compile trophy data.
							var userTrophies = new List<UserTrophy>();
							foreach (var trophyDetail in trophyDetails)
							{
								var userTrophy = new UserTrophy();
								userTrophy.Id = trophyDetail.Element("Id").Value;
								userTrophy.GameId = apiGame.Id;
								userTrophy.Title = trophyDetail.Element("Title").Value;
								userTrophy.ImageUrl = trophyDetail.Element("Image").Value;
								userTrophy.Description = trophyDetail.Element("Description").Value;
								userTrophy.Type = ParseTrophyType(trophyDetail.Element("Type").Value);
								// Trophy data can now have null values for this. If that's the case, assume it's hidden to be on the safe side.
								userTrophy.Hidden = !string.IsNullOrWhiteSpace(trophyDetail.Element("Hidden").Value) ? bool.Parse(trophyDetail.Element("Hidden").Value) : true;
								userTrophy.Platform = apiGame.Platform;

								foreach (var earnedDetail in earnedDetailsXml.Descendants("trophy"))
								{
									if (earnedDetail.Attribute("id").Value == userTrophy.Id)
									{
										userTrophy.Earned = DateTime.Parse(earnedDetail.Value).ToUniversalTime().ToLocalTime();
										break;
									}
								}
								userTrophies.Add(userTrophy);
							}

							PerformBackup("trophies-" + apiGame.Id, "__{0}-" + currentTime);
							savePath = string.Format(filePath, "trophies-" + apiGame.Id);
							SaveTrophyXml(savePath, userTrophies);
						}
						else
						{
							DebugInfo.Add(apiGame.Id);
							DebugInfo.Add(hasTrophyDetails);
							DebugInfo.Add(hasEarnedDetails);
						}
					}

					#region Save data
					// Profile
					PerformBackup("profile", "__{0}-" + currentTime);
					savePath = string.Format(filePath, "profile");
					var psnProfile = new XmlSerializer(userProfile.GetType());
					using (StreamWriter writer = new StreamWriter(savePath))
					{
						psnProfile.Serialize(writer, userProfile);
					}
					// Games
					PerformBackup("games", "__{0}-" + currentTime);
					savePath = string.Format(filePath, "games");
					var psnGames = new XmlSerializer(userGames.GetType());
					using (StreamWriter writer = new StreamWriter(savePath))
					{
						psnGames.Serialize(writer, userGames);
					}
					// Trophies
					// done above
					#endregion
					return true;
				}
				return false;
			}
            public bool CompileData()
            {
                if (this.CompilerReady())
                {
                    var currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                    var filePath    = Path.Combine(this.OutputPath, this.FileNameFormat + ".xml");
                    var savePath    = "";

                    var userProfile = new UserProfile();
                    var profileXml  = XDocument.Load(Path.Combine(this.RawDataPath, "profile.xml")).Root;
                    userProfile.Id       = profileXml.Element("onlinename").Value;
                    userProfile.ImageUrl = profileXml.Element("avatarurl").Value;
                    userProfile.AboutMe  = profileXml.Element("aboutme").Value;
                    userProfile.Country  = profileXml.Element("country").Value;
                    userProfile.PSPlus   = profileXml.Element("plusicon").Value == "1";
                    var trophyXml = XDocument.Load(Path.Combine(this.RawDataPath, "trophy.xml")).Root;
                    userProfile.EarnedPoints    = int.Parse(trophyXml.Element("point").Value);
                    userProfile.Level           = int.Parse(trophyXml.Element("level").Value);
                    userProfile.LevelProgress   = int.Parse(trophyXml.Element("level").Attribute("progress").Value);
                    userProfile.LevelBasePoints = int.Parse(trophyXml.Element("level").Attribute("base").Value);
                    userProfile.LevelNextPoints = int.Parse(trophyXml.Element("level").Attribute("next").Value);
                    userProfile.BronzeEarned    = int.Parse(trophyXml.Element("types").Attribute("bronze").Value);
                    userProfile.SilverEarned    = int.Parse(trophyXml.Element("types").Attribute("silver").Value);
                    userProfile.GoldEarned      = int.Parse(trophyXml.Element("types").Attribute("gold").Value);
                    userProfile.PlatinumEarned  = int.Parse(trophyXml.Element("types").Attribute("platinum").Value);
                    userProfile.TotalEarned     = userProfile.BronzeEarned + userProfile.SilverEarned + userProfile.GoldEarned + userProfile.PlatinumEarned;
                    var gamesFiles = new DirectoryInfo(this.RawDataPath).GetFiles("games_*.xml").Select(f => f.FullName);

                    var apiGames = new List <ApiGame>();

                    foreach (var gamesFile in gamesFiles)
                    {
                        var gamesXml   = XDocument.Load(gamesFile).Root;
                        var totalGames = int.Parse(gamesXml.Element("title").Value);
                        if (userProfile.TotalGames == 0 || userProfile.TotalGames < totalGames)
                        {
                            userProfile.TotalGames = totalGames;
                        }

                        foreach (var game in gamesXml.Descendants("info"))
                        {
                            var gameInfo = new ApiGame();
                            gameInfo.Id       = game.Attribute("npcommid").Value;
                            gameInfo.Platform = game.Attribute("pf").Value;
                            gameInfo.Bronze   = int.Parse(game.Element("types").Attribute("bronze").Value);
                            gameInfo.Silver   = int.Parse(game.Element("types").Attribute("silver").Value);
                            gameInfo.Gold     = int.Parse(game.Element("types").Attribute("gold").Value);
                            gameInfo.Platinum = int.Parse(game.Element("types").Attribute("platinum").Value);
                            gameInfo.Updated  = DateTime.Parse(game.Element("last-updated").Value);

                            var existingGame = apiGames.FirstOrDefault(g => g.Id == gameInfo.Id);
                            if (existingGame != null && existingGame.Updated <= gameInfo.Updated)
                            {
                                // This game is already added, but needs to be updated.
                                apiGames.Remove(existingGame);
                                apiGames.Add(gameInfo);
                            }
                            else
                            {
                                apiGames.Add(gameInfo);
                            }
                        }
                    }
                    apiGames = apiGames.OrderByDescending(g => g.Updated).ToList();

                    userProfile.LastUpdate = apiGames.Select(g => g.Updated).FirstOrDefault();
                    if (userProfile.LastUpdate == DateTime.MinValue)
                    {
                        userProfile.LastUpdate = null;
                    }
                    // Profile is done at this point.

                    var userGames   = new List <UserGame>();
                    int orderPlayed = 1;
                    // Get game data and add to games plus create trophies- file.
                    foreach (var apiGame in apiGames)
                    {
                        var hasTrophyDetails = File.Exists(Path.Combine(this.TrophyDetailsPath, string.Format("{0}.xml", apiGame.Id)));
                        var hasEarnedDetails = File.Exists(Path.Combine(this.RawDataPath, string.Format("game-{0}.xml", apiGame.Id)));
                        if (hasTrophyDetails && hasEarnedDetails)
                        {
                            var trophyDetailsXml = XDocument.Load(Path.Combine(this.TrophyDetailsPath, string.Format("{0}.xml", apiGame.Id))).Root;
                            var earnedDetailsXml = XDocument.Load(Path.Combine(this.RawDataPath, string.Format("game-{0}.xml", apiGame.Id))).Root;

                            var gameDetails = trophyDetailsXml.Descendants("Game").FirstOrDefault();

                            var userGame = new UserGame();
                            userGame.Id             = apiGame.Id;
                            userGame.IdEurope       = gameDetails.Element("IdEurope").Value;
                            userGame.Title          = gameDetails.Element("Title").Value;
                            userGame.ImageUrl       = gameDetails.Element("Image").Value;
                            userGame.BronzeEarned   = apiGame.Bronze;
                            userGame.SilverEarned   = apiGame.Silver;
                            userGame.GoldEarned     = apiGame.Gold;
                            userGame.PlatinumEarned = apiGame.Platinum;
                            userGame.TotalEarned    = apiGame.Bronze + apiGame.Silver + apiGame.Gold + apiGame.Platinum;
                            userGame.OrderPlayed    = orderPlayed++;
                            userGame.LastUpdated    = apiGame.Updated;
                            userGame.TotalPoints    = int.Parse(gameDetails.Element("TotalPoints").Value);
                            // It appears that PS4 games now include platinums in the total points count. Should probably just overwrite this for all platforms.
                            userGame.EarnedPoints = userGame.CalculateEarnedPoints(apiGame.Platform.ToLower() == "ps4");
                            userGame.Progress     = userGame.CalculateProgress().ToString();
                            userGame.Platform     = apiGame.Platform;

                            var trophyDetails = trophyDetailsXml.Descendants("Trophy");
                            userGame.PossibleTrophies = trophyDetails.Count();

                            userGames.Add(userGame);

                            // Compile trophy data.
                            var userTrophies = new List <UserTrophy>();
                            foreach (var trophyDetail in trophyDetails)
                            {
                                var userTrophy = new UserTrophy();
                                userTrophy.Id          = trophyDetail.Element("Id").Value;
                                userTrophy.GameId      = apiGame.Id;
                                userTrophy.Title       = trophyDetail.Element("Title").Value;
                                userTrophy.ImageUrl    = trophyDetail.Element("Image").Value;
                                userTrophy.Description = trophyDetail.Element("Description").Value;
                                userTrophy.Type        = ParseTrophyType(trophyDetail.Element("Type").Value);
                                // Trophy data can now have null values for this. If that's the case, assume it's hidden to be on the safe side.
                                userTrophy.Hidden   = !string.IsNullOrWhiteSpace(trophyDetail.Element("Hidden").Value) ? bool.Parse(trophyDetail.Element("Hidden").Value) : true;
                                userTrophy.Platform = apiGame.Platform;

                                foreach (var earnedDetail in earnedDetailsXml.Descendants("trophy"))
                                {
                                    if (earnedDetail.Attribute("id").Value == userTrophy.Id)
                                    {
                                        userTrophy.Earned = DateTime.Parse(earnedDetail.Value).ToUniversalTime().ToLocalTime();
                                        break;
                                    }
                                }
                                userTrophies.Add(userTrophy);
                            }

                            PerformBackup("trophies-" + apiGame.Id, "__{0}-" + currentTime);
                            savePath = string.Format(filePath, "trophies-" + apiGame.Id);
                            SaveTrophyXml(savePath, userTrophies);
                        }
                        else
                        {
                            DebugInfo.Add(apiGame.Id);
                            DebugInfo.Add(hasTrophyDetails);
                            DebugInfo.Add(hasEarnedDetails);
                        }
                    }

                    #region Save data
                    // Profile
                    PerformBackup("profile", "__{0}-" + currentTime);
                    savePath = string.Format(filePath, "profile");
                    var psnProfile = new XmlSerializer(userProfile.GetType());
                    using (StreamWriter writer = new StreamWriter(savePath))
                    {
                        psnProfile.Serialize(writer, userProfile);
                    }
                    // Games
                    PerformBackup("games", "__{0}-" + currentTime);
                    savePath = string.Format(filePath, "games");
                    var psnGames = new XmlSerializer(userGames.GetType());
                    using (StreamWriter writer = new StreamWriter(savePath))
                    {
                        psnGames.Serialize(writer, userGames);
                    }
                    // Trophies
                    // done above
                    #endregion
                    return(true);
                }
                return(false);
            }