protected void Page_Load(object sender, EventArgs e) { int lobbyID = Int32.Parse(Request.Params["lobbyID"]); using(DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var motd = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if(motd == null) throw new Exception("No motd for lobby id: " + lobbyID); LogoImage = FixupCrlf(motd.Logo); Banner = FixupCrlf(motd.Banner); LastUpdated = motd.LastUpdated.ToShortDateString(); PrimaryHeading = FixupCrlf(motd.PrimaryHeading); PrimaryText = FixupCrlf(motd.PrimaryText); SecondaryHeading = FixupCrlf(motd.SecondaryHeading); SecondaryText = FixupCrlf(motd.SecondaryText); Details = FixupCrlf(motd.Details); PaddingCrLfs = String.Empty; for (int i = 0; i < motd.PaddingCrCount; i++) PaddingCrLfs += "\\n"; } }
protected void Page_Load(object sender, EventArgs e) { int lobbyID = Int32.Parse(Request.Params["lobbyID"]); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var motd = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if (motd == null) { throw new Exception("No motd for lobby id: " + lobbyID); } LogoImage = FixupCrlf(motd.Logo); Banner = FixupCrlf(motd.Banner); LastUpdated = motd.LastUpdated.ToShortDateString(); PrimaryHeading = FixupCrlf(motd.PrimaryHeading); PrimaryText = FixupCrlf(motd.PrimaryText); SecondaryHeading = FixupCrlf(motd.SecondaryHeading); SecondaryText = FixupCrlf(motd.SecondaryText); Details = FixupCrlf(motd.Details); PaddingCrLfs = String.Empty; for (int i = 0; i < motd.PaddingCrCount; i++) { PaddingCrLfs += "\\n"; } } }
public List<ActivePlayerData> GetActivePlayers(string token) { ValidateToken(token); string cacheKey = "Stats::GetActivePlayers"; List<ActivePlayerData> returnValue = (List<ActivePlayerData>)HttpRuntime.Cache.Get(cacheKey); if (returnValue == null) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { //var activeLogins = db.Logins // .Where(p => p.Sessions.Where(r => r.DateLastCheckIn > DateTime.Now.AddMinutes(-3)).Count() > 0) // .OrderBy(p => p.Username) // .ToList(); var activeSessions = db.Sessions .Where(r => r.DateLastCheckIn > DateTime.Now.AddMinutes(-3)) .OrderBy(p => p.Alias.Callsign) .ToList(); using (DataAccess.CSSStatsDataContext statsDB = new DataAccess.CSSStatsDataContext()) { returnValue = activeSessions.GroupJoin(statsDB.StatsLeaderboards, p => p.LoginId, r => r.LoginID, (session, leaderboard) => new { session, leaderboard }) .SelectMany(z => z.leaderboard.DefaultIfEmpty(), (z, leaderboard) => new { z.session, leaderboard }) .Select(p => new ActivePlayerData() { PlayerName = p.session.Alias.Callsign, Rank = p.leaderboard == null ? 0 : (int)Math.Floor(p.leaderboard.Rank) }) .OrderBy(p => p.PlayerName) .ToList(); //returnValue = activeLogins.GroupJoin(statsDB.StatsLeaderboards, p => p.Id, r => r.LoginID, (login, leaderboard) => new {login, leaderboard}) // .SelectMany(z => z.leaderboard.DefaultIfEmpty(), (z, leaderboard) => new { z.login, leaderboard } ) // .Select(p => new ActivePlayerData() // { // PlayerName = p.login.Username, // Rank = p.leaderboard == null ? 0 : (int) Math.Floor(p.leaderboard.Rank) // }) // .OrderBy(p => p.PlayerName) // .ToList(); //var loginStats = statsDB.StatsLeaderboards // .Join(activeLogins, p => p.LoginID, r => r.Id, ( p, // .Where(p => activeLogins.Select(r => r.Id).Contains(p.LoginID) == true).OrderBy(p => p.LoginUsername); //returnValue = loginStats.ToList(); } HttpRuntime.Cache.Add(cacheKey, returnValue, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 30), CacheItemPriority.Normal, null); } } return returnValue; }
public List <ActivePlayerData> GetActivePlayers(string token) { ValidateToken(token); string cacheKey = "Stats::GetActivePlayers"; List <ActivePlayerData> returnValue = (List <ActivePlayerData>)HttpRuntime.Cache.Get(cacheKey); if (returnValue == null) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { //var activeLogins = db.Logins // .Where(p => p.Sessions.Where(r => r.DateLastCheckIn > DateTime.Now.AddMinutes(-3)).Count() > 0) // .OrderBy(p => p.Username) // .ToList(); var activeSessions = db.Sessions .Where(r => r.DateLastCheckIn > DateTime.Now.AddMinutes(-3)) .OrderBy(p => p.Alias.Callsign) .ToList(); using (DataAccess.CSSStatsDataContext statsDB = new DataAccess.CSSStatsDataContext()) { returnValue = activeSessions.GroupJoin(statsDB.StatsLeaderboards, p => p.LoginId, r => r.LoginID, (session, leaderboard) => new { session, leaderboard }) .SelectMany(z => z.leaderboard.DefaultIfEmpty(), (z, leaderboard) => new { z.session, leaderboard }) .Select(p => new ActivePlayerData() { PlayerName = p.session.Alias.Callsign, Rank = p.leaderboard == null ? 0 : (int)Math.Floor(p.leaderboard.Rank) }) .OrderBy(p => p.PlayerName) .ToList(); //returnValue = activeLogins.GroupJoin(statsDB.StatsLeaderboards, p => p.Id, r => r.LoginID, (login, leaderboard) => new {login, leaderboard}) // .SelectMany(z => z.leaderboard.DefaultIfEmpty(), (z, leaderboard) => new { z.login, leaderboard } ) // .Select(p => new ActivePlayerData() // { // PlayerName = p.login.Username, // Rank = p.leaderboard == null ? 0 : (int) Math.Floor(p.leaderboard.Rank) // }) // .OrderBy(p => p.PlayerName) // .ToList(); //var loginStats = statsDB.StatsLeaderboards // .Join(activeLogins, p => p.LoginID, r => r.Id, ( p, // .Where(p => activeLogins.Select(r => r.Id).Contains(p.LoginID) == true).OrderBy(p => p.LoginUsername); //returnValue = loginStats.ToList(); } HttpRuntime.Cache.Add(cacheKey, returnValue, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 30), CacheItemPriority.Normal, null); } } return(returnValue); }
private void MergeLogins(int primaryLoginID, int mergeLoginID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var principalLogin = db.Logins.FirstOrDefault(p => p.Id == primaryLoginID); var loginToMerge = db.Logins.FirstOrDefault(p => p.Id == mergeLoginID); DataAccess.Identity.MergeLogin(db, principalLogin, loginToMerge); } }
private void UnlinkLogins(int primaryLoginID, int unlinkLoginID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var principal = db.Logins.FirstOrDefault(p => p.Id == primaryLoginID).Identity; var loginToUnlink = db.Logins.FirstOrDefault(p => p.Id == unlinkLoginID); DataAccess.Identity.UnlinkLogin(db, principal, loginToUnlink); } }
public void TestSaveGameDataWithGameXmlFiles() { Console.WriteLine("Processing: " + ConfigurationManager.AppSettings["gameTestDataDirectory"]); // Increase this to simulate multiple game file loads. Takes a long time for each load. for (int i = 0; i < 1; i++) { Console.WriteLine("Creating TAG object."); Allegiance.CommunitySecuritySystem.Server.Tag tag = new Allegiance.CommunitySecuritySystem.Server.Tag(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { Console.WriteLine("Looking for files."); foreach (string file in Directory.GetFiles(ConfigurationManager.AppSettings["gameTestDataDirectory"], ConfigurationManager.AppSettings["gameTestDataFileFilter"])) { Console.WriteLine("Loading: " + file); string gameData = File.ReadAllText(file); GameDataset gameDataset = new GameDataset(); gameDataset.ReadXml(new StringReader(gameData), System.Data.XmlReadMode.IgnoreSchema); foreach (GameDataset.TeamRow team in gameDataset.Team) { var alias = DataAccess.Alias.GetAliasByCallsign(db, team.Commander); if (alias == null) { CreateUser(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, team.Commander), "test12", "*****@*****.**", 10); } } foreach (GameDataset.TeamMemberRow teamMember in gameDataset.TeamMember) { var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.Callsign); if (alias == null) { CreateUser(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, teamMember.Callsign), "test12", "*****@*****.**", 20); } } string message; int result = tag.SaveGameData(gameData, false, out message); Assert.IsTrue(result > 0, message); } } } }
protected void lnkSelect_Command(object sender, CommandEventArgs e) { int targetLoginID = Int32.Parse(e.CommandArgument.ToString()); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var primaryIdentity = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID).Identity; var secondaryIdentity = db.Logins.FirstOrDefault(p => p.Id == targetLoginID).Identity; DataAccess.Identity.MergeIdentities(db, new DataAccess.Identity[] { primaryIdentity, secondaryIdentity }); db.SubmitChanges(); } Response.Redirect("~/Users/ManageLinks.aspx?loginID=" + PrimaryLoginID + "&searchText=" + Server.UrlEncode(Request.Params["searchText"]), true); }
protected void lnkSelect_Command(object sender, CommandEventArgs e) { int targetLoginID = Int32.Parse(e.CommandArgument.ToString()); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var primaryIdentity = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID).Identity; var secondaryIdentity = db.Logins.FirstOrDefault(p => p.Id == targetLoginID).Identity; DataAccess.Identity.MergeIdentities(db, new DataAccess.Identity[] { primaryIdentity, secondaryIdentity }); db.SubmitChanges(); } Response.Redirect("~/Users/ManageLinks.aspx?loginID=" + PrimaryLoginID + "&searchText=" + Server.UrlEncode(Request.Params["searchText"]), true); }
private void RemoveCallsignFromGroup(string callsign, int groupID) { Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(groupID); if (currentUserGroupRole != Business.GroupRole.AssistantSquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead) { throw new Exception("Access denied."); } Business.GroupRole callsignGroupRole = GetGroupRoleForCallsign(callsign, groupID); if (callsignGroupRole == Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead) { throw new Exception("Only squad leaders can perform this action."); } using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var alias = DataAccess.Alias.GetAliasByCallsign(db, callsign); var callsignAssignmentsToGroup = db.Group_Alias_GroupRoles.Where(p => p.GroupId == groupID && p.Alias.Id == alias.Id); db.Group_Alias_GroupRoles.DeleteAllOnSubmit(callsignAssignmentsToGroup); var group = db.Groups.FirstOrDefault(p => p.Id == groupID); if (group == null) { throw new Exception("invalid group: " + groupID); } // If the group name is the Moderators group, then add the Moderator role to the group member. if (group.Name.Equals("Moderators", StringComparison.InvariantCultureIgnoreCase) == true) { var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator"); db.Login_Roles.DeleteAllOnSubmit(db.Login_Roles.Where(p => p.LoginId == alias.LoginId && p.RoleId == moderatorRole.Id)); } // If the group is ACS, then unbank the original hider. if (group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true) { UnbankAlias(db, alias); } db.SubmitChanges(); } Response.Redirect("~/Squads/Default.aspx?groupID=" + groupID, true); }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { string banListType = Request.Params["type"] ?? String.Empty; if (banListType.Equals("mostRecent", StringComparison.CurrentCultureIgnoreCase) == true) { gvBanList.DataSource = db.Bans .OrderByDescending(p => p.DateCreated) .Take(20) .Select(p => new Data.BanData() { Username = String.IsNullOrEmpty(p.Alias.Callsign) ? p.Login.Username : p.Alias.Callsign, BannedBy = p.BanningLogin.Username, Reason = p.Reason == null ? (p.BanTypeId != null ? p.BanType.Description : "") : p.Reason, DateCreated = p.DateCreated.ToString(), Duration = FormatTimespan(p.DateCreated, p.DateExpires), TimeLeft = FormatTimeLeft(p.DateCreated, p.DateExpires, p.InEffect) }); } else { gvBanList.DataSource = db.Bans .Where(p => p.DateExpires > DateTime.Now && p.InEffect == true) .OrderByDescending(p => DateTime.Now - p.DateExpires) .Take(20) .Select(p => new Data.BanData() { Username = String.IsNullOrEmpty(p.Alias.Callsign) ? p.Login.Username : p.Alias.Callsign, BannedBy = p.BanningLogin.Username, Reason = p.Reason == null ? (p.BanTypeId != null ? p.BanType.Description : "") : p.Reason, DateCreated = p.DateCreated.ToString(), Duration = FormatTimespan(p.DateCreated, p.DateExpires), TimeLeft = FormatTimeLeft(p.DateCreated, p.DateExpires, p.InEffect) }); } gvBanList.DataBind(); if (gvBanList.Rows.Count == 0) { pNoBannedUsers.Visible = true; } } }
protected void lnkRemovePermanentUnlink_Command(object sender, CommandEventArgs e) { int loginID = Int32.Parse(e.CommandArgument.ToString()); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var permanentUnlink = db.Login_UnlinkedLogins .FirstOrDefault(p => (p.LoginId1 == PrimaryLoginID && p.LoginId2 == loginID) || (p.LoginId1 == loginID && p.LoginId2 == PrimaryLoginID)); if (permanentUnlink != null) { db.Login_UnlinkedLogins.DeleteOnSubmit(permanentUnlink); db.SubmitChanges(); } } BindData(); }
protected void lnkRemovePermanentUnlink_Command(object sender, CommandEventArgs e) { int loginID = Int32.Parse(e.CommandArgument.ToString()); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var permanentUnlink = db.Login_UnlinkedLogins .FirstOrDefault(p => (p.LoginId1 == PrimaryLoginID && p.LoginId2 == loginID) || (p.LoginId1 == loginID && p.LoginId2 == PrimaryLoginID)); if (permanentUnlink != null) { db.Login_UnlinkedLogins.DeleteOnSubmit(permanentUnlink); db.SubmitChanges(); } } BindData(); }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { string banListType = Request.Params["type"] ?? String.Empty; if (banListType.Equals("mostRecent", StringComparison.CurrentCultureIgnoreCase) == true) { gvBanList.DataSource = db.Bans .OrderByDescending(p => p.DateCreated) .Take(20) .Select(p => new Data.BanData() { Username = String.IsNullOrEmpty(p.Alias.Callsign) ? p.Login.Username : p.Alias.Callsign, BannedBy = p.BanningLogin.Username, Reason = p.Reason == null ? (p.BanTypeId != null ? p.BanType.Description : "") : p.Reason, DateCreated = p.DateCreated.ToString(), Duration = FormatTimespan(p.DateCreated, p.DateExpires), TimeLeft = FormatTimeLeft(p.DateCreated, p.DateExpires, p.InEffect) }); } else { gvBanList.DataSource = db.Bans .Where(p => p.DateExpires > DateTime.Now && p.InEffect == true) .OrderByDescending(p => DateTime.Now - p.DateExpires) .Take(20) .Select(p => new Data.BanData() { Username = String.IsNullOrEmpty(p.Alias.Callsign) ? p.Login.Username : p.Alias.Callsign, BannedBy = p.BanningLogin.Username, Reason = p.Reason == null ? (p.BanTypeId != null ? p.BanType.Description : "") : p.Reason, DateCreated = p.DateCreated.ToString(), Duration = FormatTimespan(p.DateCreated, p.DateExpires), TimeLeft = FormatTimeLeft(p.DateCreated, p.DateExpires, p.InEffect) }); } gvBanList.DataBind(); if (gvBanList.Rows.Count == 0) pNoBannedUsers.Visible = true; } }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var allSquads = db.Groups.Where(p => p.IsSquad == true).OrderBy(p => p.Name); List <Data.SquadData> squadDatas = new List <Allegiance.CommunitySecuritySystem.Management.Stats.Data.SquadData>(); foreach (var squad in allSquads) { Data.SquadData squadData = new Allegiance.CommunitySecuritySystem.Management.Stats.Data.SquadData(); squadData.SquadName = squad.Name; foreach (var gagr in squad.Group_Alias_GroupRoles) { squadData.Members.Add(new Data.MemberData() { Token = gagr.GroupRole.Token.ToString(), Callsign = gagr.Alias.Callsign, IsActive = gagr.Alias.Login.Identity.DateLastLogin > DateTime.Now.AddDays(-30) }); } //squadData.Members.OrderBy(p => p.IsActive).ThenBy(p => p.Token); if (squadData.Members.Count > 0) { squadDatas.Add(squadData); } } SquadList = squadDatas; rptHeaders.DataSource = squadDatas.ToArray(); rptHeaders.DataBind(); rptSquads.DataSource = squadDatas.ToArray(); rptSquads.DataBind(); rptFooter.DataSource = squadDatas.ToArray(); rptFooter.DataBind(); } }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var primaryLogin = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID); if (primaryLogin == null) { lblErrorMessage.Text = "The login for login id: " + PrimaryLoginID + " couldn't be found."; } lblPrimaryLogin.Text = primaryLogin.Username; lblPermanentUnlinkPrimaryLogin.Text = primaryLogin.Username; var linkedLogins = db.Logins.Where(p => p.IdentityId == primaryLogin.Identity.Id && p.Id != primaryLogin.Id); pLinkedLogins.Visible = linkedLogins.Count() > 0; gvLinkedLogins.DataSource = linkedLogins; gvLinkedLogins.DataBind(); var permanentUnlinks = db.Login_UnlinkedLogins.Where(p => p.LoginId1 == PrimaryLoginID).Select(p => new { UserName = p.Login1.Username, Id = p.Login1.Id, Email = p.Login1.Email, DateCreated = p.Login1.DateCreated }).Union(db.Login_UnlinkedLogins.Where(p => p.LoginId2 == PrimaryLoginID).Select(p => new { UserName = p.Login.Username, Id = p.Login.Id, Email = p.Login1.Email, DateCreated = p.Login1.DateCreated })); pPermanentUnlinks.Visible = permanentUnlinks.Count() > 0; gvPermanentUnlinks.DataSource = permanentUnlinks; gvPermanentUnlinks.DataBind(); } }
private void AddRandomPlayersToTeam(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int teamID, int playerCount) { Random random = new Random(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Alias[] aliases = db.Alias.GroupBy(p => p.LoginId, r => r).Select(p => p.First()).Where(p => p.Callsign.StartsWith("Test")).ToArray(); for (int i = 0; i < playerCount; i++) { Server.Data.GameDataset.TeamMemberRow teamMemberRow = gameData.TeamMember.NewTeamMemberRow(); teamMemberRow.Callsign = aliases[i + (playerCount * teamID)].Callsign; teamMemberRow.Duration = random.Next(10, 30); teamMemberRow.JoinTime = DateTime.Now.AddMinutes(-30); teamMemberRow.LeaveTime = teamMemberRow.JoinTime.AddMinutes(teamMemberRow.Duration); teamMemberRow.TeamID = teamID; gameData.TeamMember.AddTeamMemberRow(teamMemberRow); } } }
protected void lnkPermanentUnlink_Click(object sender, CommandEventArgs e) { int unlinkLoginID = Int32.Parse(e.CommandArgument.ToString()); UnlinkLogins(PrimaryLoginID, unlinkLoginID); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Login_UnlinkedLogin unlinkRecord = new Allegiance.CommunitySecuritySystem.DataAccess.Login_UnlinkedLogin() { LoginId1 = PrimaryLoginID, LoginId2 = unlinkLoginID }; db.Login_UnlinkedLogins.InsertOnSubmit(unlinkRecord); db.SubmitChanges(); } BindData(); }
protected void lnkPermanentUnlink_Click(object sender, CommandEventArgs e) { int unlinkLoginID = Int32.Parse(e.CommandArgument.ToString()); UnlinkLogins(PrimaryLoginID, unlinkLoginID); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Login_UnlinkedLogin unlinkRecord = new Allegiance.CommunitySecuritySystem.DataAccess.Login_UnlinkedLogin() { LoginId1 = PrimaryLoginID, LoginId2 = unlinkLoginID }; db.Login_UnlinkedLogins.InsertOnSubmit(unlinkRecord); db.SubmitChanges(); } BindData(); }
public string GetCompressedGameDataXml() { int testPilot1ID; int testPilot2ID; using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var testPilot1Alias = DataAccess.Alias.GetAliasByCallsign(db, "BackTrak"); testPilot1ID = testPilot1Alias.Id; var testPilot2Alias = DataAccess.Alias.GetAliasByCallsign(db, "TheBored"); testPilot2ID = testPilot2Alias.Id; } int gameID = 1234567; Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData = new Allegiance.CommunitySecuritySystem.Server.Data.GameDataset(); AddGame(gameData, gameID); AddRandomGameEvents(gameData, gameID, 10); AddTeams(gameData, gameID); AddRandomPlayersToTeam(gameData, 1, 5); AddRandomPlayersToTeam(gameData, 2, 5); AddCommanderToTeam(gameData, "^Orion@PK", 1); AddCommanderToTeam(gameData, "BackTrak", 1); AddChatLogMessages(gameData, gameID, 10); string xml = gameData.GetXml(); string compressedXml = Compress(xml); return(compressedXml); }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var allSquads = db.Groups.Where(p => p.IsSquad == true).OrderBy(p => p.Name); List<Data.SquadData> squadDatas = new List<Allegiance.CommunitySecuritySystem.Management.Stats.Data.SquadData>(); foreach (var squad in allSquads) { Data.SquadData squadData = new Allegiance.CommunitySecuritySystem.Management.Stats.Data.SquadData(); squadData.SquadName = squad.Name; foreach (var gagr in squad.Group_Alias_GroupRoles) { squadData.Members.Add(new Data.MemberData() { Token = gagr.GroupRole.Token.ToString(), Callsign = gagr.Alias.Callsign, IsActive = gagr.Alias.Login.Identity.DateLastLogin > DateTime.Now.AddDays(-30) }); } //squadData.Members.OrderBy(p => p.IsActive).ThenBy(p => p.Token); if(squadData.Members.Count > 0) squadDatas.Add(squadData); } SquadList = squadDatas; rptHeaders.DataSource = squadDatas.ToArray(); rptHeaders.DataBind(); rptSquads.DataSource = squadDatas.ToArray(); rptSquads.DataBind(); rptFooter.DataSource = squadDatas.ToArray(); rptFooter.DataBind(); } }
private void AddChatLogMessages(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int gameID, int chatLogCount) { Random random = new Random(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Alias[] aliases = db.Alias.ToArray(); for (int i = 0; i < chatLogCount; i++) { Server.Data.GameDataset.ChatLogRow chatLogRow = gameData.ChatLog.NewChatLogRow(); chatLogRow.ChatTime = DateTime.Now.AddMinutes(-1 * random.Next(0, 30)); chatLogRow.GameID = gameID; chatLogRow.SpeakerName = aliases[random.Next(0, 10)].Callsign; chatLogRow.TargetName = aliases[random.Next(0, 10)].Callsign; chatLogRow.Text = "This is a chat message: " + i; gameData.ChatLog.AddChatLogRow(chatLogRow); } } }
private void AddRandomGameEvents(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int gameID, int eventCount) { Random random = new Random(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { //Alias.GroupBy(p => p.LoginId, r => r.Id).Select(p => p.First()) DataAccess.Alias[] aliases = db.Alias.GroupBy(p => p.LoginId, r => r).Select(p => p.First()).Where(p => p.Callsign.StartsWith("Test")).ToArray(); //DataAccess.Alias [] aliases = db.Alias.ToArray(); for (int i = 0; i < eventCount; i++) { int performerID = random.Next(0, aliases.Length); int targetID = random.Next(0, aliases.Length); while (targetID == performerID) { targetID = random.Next(0, aliases.Length); } int indirectID = random.Next(0, aliases.Length); while (indirectID == performerID || indirectID == targetID) { indirectID = random.Next(0, aliases.Length); } Allegiance.CommunitySecuritySystem.Server.Data.GameDataset.GameEventRow gameEventRow = gameData.GameEvent.NewGameEventRow(); gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.ShipKilled;; gameEventRow.EventTime = DateTime.Now.AddMinutes(-1 * random.Next(0, 10)); gameEventRow.GameID = gameID; gameEventRow.IndirectID = indirectID; gameEventRow.IndirectName = aliases[indirectID].Callsign; gameEventRow.PerformerID = performerID; gameEventRow.PerformerName = aliases[performerID].Callsign; gameEventRow.TargetID = targetID; gameEventRow.TargetName = aliases[targetID].Callsign; if (((int)Math.Floor(eventCount / 2M)) == i) { gameEventRow.TargetID = 11; gameEventRow.TargetName = ".Miner 230"; } if (((int)Math.Floor(eventCount / 3M)) == i) { gameEventRow.TargetID = 12; gameEventRow.TargetName = "Outpost"; gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed; } if (((int)Math.Floor(eventCount / 4M)) == i) { gameEventRow.TargetID = 13; gameEventRow.TargetName = "Supremecy Center"; gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.StationCaptured; } gameData.GameEvent.AddGameEventRow(gameEventRow); } } }
public void TestSaveGameDataWithGameXmlFiles() { Console.WriteLine("Processing: " + ConfigurationManager.AppSettings["gameTestDataDirectory"]); // Increase this to simulate multiple game file loads. Takes a long time for each load. for (int i = 0; i < 1; i++) { Console.WriteLine("Creating TAG object."); Allegiance.CommunitySecuritySystem.Server.Tag tag = new Allegiance.CommunitySecuritySystem.Server.Tag(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { Console.WriteLine("Looking for files."); foreach (string file in Directory.GetFiles(ConfigurationManager.AppSettings["gameTestDataDirectory"], ConfigurationManager.AppSettings["gameTestDataFileFilter"])) { Console.WriteLine("Loading: " + file); string gameData = File.ReadAllText(file); GameDataset gameDataset = new GameDataset(); gameDataset.ReadXml(new StringReader(gameData), System.Data.XmlReadMode.IgnoreSchema); foreach (GameDataset.TeamRow team in gameDataset.Team) { var alias = DataAccess.Alias.GetAliasByCallsign(db, team.Commander); if (alias == null) CreateUser(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, team.Commander), "test12", "*****@*****.**", 10); } foreach (GameDataset.TeamMemberRow teamMember in gameDataset.TeamMember) { var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.Callsign); if (alias == null) CreateUser(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, teamMember.Callsign), "test12", "*****@*****.**", 20); } string message; int result = tag.SaveGameData(gameData, false, out message); Assert.IsTrue(result > 0, message); } } } }
private void MergeLogins(int primaryLoginID, int mergeLoginID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var principalLogin = db.Logins.FirstOrDefault(p => p.Id == primaryLoginID); var loginToMerge = db.Logins.FirstOrDefault(p => p.Id == mergeLoginID); DataAccess.Identity.MergeLogin(db, principalLogin, loginToMerge); } }
private void AddRandomGameEvents(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int gameID, int eventCount) { Random random = new Random(); using(DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { //Alias.GroupBy(p => p.LoginId, r => r.Id).Select(p => p.First()) DataAccess.Alias[] aliases = db.Alias.GroupBy(p => p.LoginId, r => r).Select(p => p.First()).Where(p => p.Callsign.StartsWith("Test")).ToArray(); //DataAccess.Alias [] aliases = db.Alias.ToArray(); for(int i = 0; i < eventCount; i++) { int performerID = random.Next(0, aliases.Length); int targetID = random.Next(0, aliases.Length); while(targetID == performerID) targetID = random.Next(0, aliases.Length); int indirectID = random.Next(0, aliases.Length); while (indirectID == performerID || indirectID == targetID) indirectID = random.Next(0, aliases.Length); Allegiance.CommunitySecuritySystem.Server.Data.GameDataset.GameEventRow gameEventRow = gameData.GameEvent.NewGameEventRow(); gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.ShipKilled; ; gameEventRow.EventTime = DateTime.Now.AddMinutes(-1 * random.Next(0, 10)); gameEventRow.GameID = gameID; gameEventRow.IndirectID = indirectID; gameEventRow.IndirectName = aliases[indirectID].Callsign; gameEventRow.PerformerID = performerID; gameEventRow.PerformerName = aliases[performerID].Callsign; gameEventRow.TargetID = targetID; gameEventRow.TargetName = aliases[targetID].Callsign; if (((int) Math.Floor(eventCount / 2M)) == i) { gameEventRow.TargetID = 11; gameEventRow.TargetName = ".Miner 230"; } if (((int)Math.Floor(eventCount / 3M)) == i) { gameEventRow.TargetID = 12; gameEventRow.TargetName = "Outpost"; gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed; } if (((int)Math.Floor(eventCount / 4M)) == i) { gameEventRow.TargetID = 13; gameEventRow.TargetName = "Supremecy Center"; gameEventRow.EventID = (int)Common.Enumerations.AllegianceEventIDs.StationCaptured; } gameData.GameEvent.AddGameEventRow(gameEventRow); } } }
private void RemoveCallsignFromGroup(string callsign, int groupID) { Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(groupID); if (currentUserGroupRole != Business.GroupRole.AssistantSquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead) throw new Exception("Access denied."); Business.GroupRole callsignGroupRole = GetGroupRoleForCallsign(callsign, groupID); if (callsignGroupRole == Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead) throw new Exception("Only squad leaders can perform this action."); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var alias = DataAccess.Alias.GetAliasByCallsign(db, callsign); var callsignAssignmentsToGroup = db.Group_Alias_GroupRoles.Where(p => p.GroupId == groupID && p.Alias.Id == alias.Id); db.Group_Alias_GroupRoles.DeleteAllOnSubmit(callsignAssignmentsToGroup); var group = db.Groups.FirstOrDefault(p => p.Id == groupID); if (group == null) throw new Exception("invalid group: " + groupID); // If the group name is the Moderators group, then add the Moderator role to the group member. if (group.Name.Equals("Moderators", StringComparison.InvariantCultureIgnoreCase) == true) { var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator"); db.Login_Roles.DeleteAllOnSubmit(db.Login_Roles.Where(p => p.LoginId == alias.LoginId && p.RoleId == moderatorRole.Id)); } // If the group is ACS, then unbank the original hider. if (group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true) UnbankAlias(db, alias); db.SubmitChanges(); } Response.Redirect("~/Squads/Default.aspx?groupID=" + groupID, true); }
private void AddRandomPlayersToTeam(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int teamID, int playerCount) { Random random = new Random(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Alias[] aliases = db.Alias.GroupBy(p => p.LoginId, r => r).Select(p => p.First()).Where(p => p.Callsign.StartsWith("Test")).ToArray(); for (int i = 0; i < playerCount; i++) { Server.Data.GameDataset.TeamMemberRow teamMemberRow = gameData.TeamMember.NewTeamMemberRow(); teamMemberRow.Callsign = aliases[i + (playerCount * teamID)].Callsign; teamMemberRow.Duration = random.Next(10, 30); teamMemberRow.JoinTime = DateTime.Now.AddMinutes(-30); teamMemberRow.LeaveTime = teamMemberRow.JoinTime.AddMinutes(teamMemberRow.Duration); teamMemberRow.TeamID = teamID; gameData.TeamMember.AddTeamMemberRow(teamMemberRow); } } }
public string GetCompressedGameDataXml() { int testPilot1ID; int testPilot2ID; using(DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var testPilot1Alias = DataAccess.Alias.GetAliasByCallsign(db, "BackTrak"); testPilot1ID = testPilot1Alias.Id; var testPilot2Alias = DataAccess.Alias.GetAliasByCallsign(db, "TheBored"); testPilot2ID = testPilot2Alias.Id; } int gameID = 1234567; Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData = new Allegiance.CommunitySecuritySystem.Server.Data.GameDataset(); AddGame(gameData, gameID); AddRandomGameEvents(gameData, gameID, 10); AddTeams(gameData, gameID); AddRandomPlayersToTeam(gameData, 1, 5); AddRandomPlayersToTeam(gameData, 2, 5); AddCommanderToTeam(gameData, "^Orion@PK", 1); AddCommanderToTeam(gameData, "BackTrak", 1); AddChatLogMessages(gameData, gameID, 10); string xml = gameData.GetXml(); string compressedXml = Compress(xml); return compressedXml; }
private void AddChatLogMessages(Allegiance.CommunitySecuritySystem.Server.Data.GameDataset gameData, int gameID, int chatLogCount) { Random random = new Random(); using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { DataAccess.Alias[] aliases = db.Alias.ToArray(); for (int i = 0; i < chatLogCount; i++) { Server.Data.GameDataset.ChatLogRow chatLogRow = gameData.ChatLog.NewChatLogRow(); chatLogRow.ChatTime = DateTime.Now.AddMinutes(-1 * random.Next(0, 30)); chatLogRow.GameID = gameID; chatLogRow.SpeakerName = aliases[random.Next(0, 10)].Callsign; chatLogRow.TargetName = aliases[random.Next(0, 10)].Callsign; chatLogRow.Text = "This is a chat message: " + i; gameData.ChatLog.AddChatLogRow(chatLogRow); } } }
private void BindData() { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var primaryLogin = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID); if (primaryLogin == null) lblErrorMessage.Text = "The login for login id: " + PrimaryLoginID + " couldn't be found."; lblPrimaryLogin.Text = primaryLogin.Username; lblPermanentUnlinkPrimaryLogin.Text = primaryLogin.Username; var linkedLogins = db.Logins.Where(p => p.IdentityId == primaryLogin.Identity.Id && p.Id != primaryLogin.Id); pLinkedLogins.Visible = linkedLogins.Count() > 0; gvLinkedLogins.DataSource = linkedLogins; gvLinkedLogins.DataBind(); var permanentUnlinks = db.Login_UnlinkedLogins.Where(p => p.LoginId1 == PrimaryLoginID).Select(p => new { UserName = p.Login1.Username, Id = p.Login1.Id, Email = p.Login1.Email, DateCreated = p.Login1.DateCreated }).Union(db.Login_UnlinkedLogins.Where(p => p.LoginId2 == PrimaryLoginID).Select(p => new { UserName = p.Login.Username, Id = p.Login.Id, Email = p.Login1.Email, DateCreated = p.Login1.DateCreated })); pPermanentUnlinks.Visible = permanentUnlinks.Count() > 0; gvPermanentUnlinks.DataSource = permanentUnlinks; gvPermanentUnlinks.DataBind(); } }
private void UnlinkLogins(int primaryLoginID, int unlinkLoginID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { var principal = db.Logins.FirstOrDefault(p => p.Id == primaryLoginID).Identity; var loginToUnlink = db.Logins.FirstOrDefault(p => p.Id == unlinkLoginID); DataAccess.Identity.UnlinkLogin(db, principal, loginToUnlink); } }