public MainWindow() { threatsInGame = new ObservableCollection <ThreatInGame>(); threatsByType = new Dictionary <ThreatType, IList <Threat> > { { ThreatType.MinorExternal, GetThreats(typeof(MinorWhiteExternalThreat)) }, { ThreatType.SeriousExternal, GetThreats(typeof(SeriousWhiteExternalThreat)) }, { ThreatType.MinorInternal, GetThreats(typeof(MinorWhiteInternalThreat)) }, { ThreatType.SeriousInternal, GetThreats(typeof(SeriousWhiteInternalThreat)) } }; var tracks = EnumFactory.All <TrackConfiguration>() .Select(trackConfiguration => new Track { Name = trackConfiguration.DisplayName(), TrackConfiguration = trackConfiguration }) .ToList(); InitializeComponent(); DataContext = this; RedTrackPicker.ItemsSource = WhiteTrackPicker.ItemsSource = BlueTrackPicker.ItemsSource = InternalTrackPicker.ItemsSource = tracks; NewThreatZonePicker.ItemsSource = EnumFactory.All <ZoneLocation>(); MinorExternalRadioButton.IsChecked = true; SelectedThreatList.ItemsSource = threatsInGame; }
protected override void PerformZAction(int currentTurn) { foreach (var zone in EnumFactory.All <ZoneLocation>()) { Attack(1 + SittingDuck.GetEnergyInReactor(zone)); } }
public InputModel NewGameInput() { var allExternalThreats = ExternalThreatFactory.AllExternalThreats .Select(threat => new ExternalThreatModel(threat)) .ToList(); var allInternalThreats = InternalThreatFactory.AllInternalThreats .Select(threat => new InternalThreatModel(threat)) .ToList(); var inputModel = new InputModel { SingleActions = ActionModel.AllSingleActionModels.OrderBy(action => action.FirstAction).ThenBy(action => action.SecondAction), DoubleActions = ActionModel.AllSelectableDoubleActionModels.OrderBy(action => action.FirstAction).ThenBy(action => action.SecondAction), SpecializationActions = PlayerSpecializationActionModel.AllPlayerSpecializationActionModels .OrderBy(action => action.PlayerSpecialization) .ThenBy(player => player.Hotkey), Tracks = TrackFactory.CreateAllTracks() .Select(track => new TrackSnapshotModel(track, new List <int>())) .ToList(), AllInternalThreats = new AllThreatsModel(allInternalThreats), AllExternalThreats = new AllThreatsModel(allExternalThreats), PlayerSpecializations = EnumFactory.All <PlayerSpecialization>().ToList(), AllDamageTokens = EnumFactory.All <DamageToken>(), DamageableZones = EnumFactory.All <ZoneLocation>() }; return(inputModel); }
protected override void PerformZAction(int currentTurn) { foreach (var zoneLocation in EnumFactory.All <ZoneLocation>()) { EnergyLeaksOutFromReactor(zoneLocation); } }
// USERS private static void SeedNotificationSettings(ModelBuilder b, IEnumerable <Guid> userSettingIds) { // missing last character // we'll use index of setting to fill that in // Other characters will be removed by counter var startGuid = "71691ddc-039f-4606-b614-ff4a19516cd"; var counter = 0; foreach (var userSettingId in userSettingIds) { if (counter % 10 == 0) { startGuid = startGuid.Remove(startGuid.Length - 1); } var values = EnumFactory.SeedEnum <NotificationType, NotificationSetting>((value, index) => new NotificationSetting() { Id = Guid.Parse(startGuid + counter + index), NotificationType = value, UserSettingId = userSettingId }).ToList(); counter++; b.Entity <NotificationSetting>().HasData(values); } }
protected override void PerformYAction(int currentTurn) { var stationsWithMultiplePlayers = EnumFactory.All <StationLocation>() .Where(stationLocation => stationLocation.IsOnShip()) .Where(stationLocation => SittingDuck.GetPlayerCount(stationLocation) > 1); SittingDuck.KnockOutPlayers(stationsWithMultiplePlayers); }
public void CanGenerateDifferentEnumValues() { var factory = new EnumFactory<CustomEnum>(); var value1 = factory.Generate(); var value2 = factory.Generate(); var value3 = factory.Generate(); Assert.NotEqual(value1,value2); Assert.NotEqual(value1, value3); Assert.NotEqual(value2, value3); }
private static void SlimeBHelper(bool isDefeated, bool isSurvived, TrackConfiguration internalTrack, int timeAppears, List <Player> players, int blueDamage, int redDamage, int whiteDamage, bool battleBotsDisabled) { var totalPoints = 0; if (isDefeated) { totalPoints = 6; } if (isSurvived) { totalPoints = 3; } var otherTracks = EnumFactory.All <TrackConfiguration>().Except(new[] { internalTrack }).ToList(); var externalTracksByZone = new Dictionary <ZoneLocation, TrackConfiguration> { { ZoneLocation.Blue, otherTracks.First() }, { ZoneLocation.Red, otherTracks.Skip(1).First() }, { ZoneLocation.White, otherTracks.Skip(2).First() } }; var externalThreats = new ExternalThreat[0]; var slimeB = new SlimeB(); slimeB.SetInitialPlacement(timeAppears); var internalThreats = new InternalThreat[] { slimeB }; var bonusThreats = new Threat[0]; var game = new Game(players, internalThreats, externalThreats, bonusThreats, externalTracksByZone, internalTrack, null); game.StartGame(); for (var currentTurn = 0; currentTurn < game.NumberOfTurns + 1; currentTurn++) { game.PerformTurn(); } Assert.AreEqual(GameStatus.Won, game.GameStatus); Assert.AreEqual(blueDamage, game.SittingDuck.BlueZone.TotalDamage); Assert.AreEqual(redDamage, game.SittingDuck.RedZone.TotalDamage); Assert.AreEqual(whiteDamage, game.SittingDuck.WhiteZone.TotalDamage); Assert.AreEqual(0, players.Count(player => player.IsKnockedOut)); Assert.AreEqual(blueDamage, game.SittingDuck.BlueZone.CurrentDamageTokens.Count); Assert.AreEqual(redDamage, game.SittingDuck.RedZone.CurrentDamageTokens.Count); Assert.AreEqual(whiteDamage, game.SittingDuck.WhiteZone.CurrentDamageTokens.Count); var battleBotsAreDisabledInPlace = game.SittingDuck.RedZone.LowerRedStation.BattleBotsComponent.BattleBots?.IsDisabled ?? false; Assert.AreEqual(battleBotsDisabled, battleBotsAreDisabledInPlace); Assert.AreEqual(isDefeated, game.ThreatController.DefeatedThreats.Any()); if (totalPoints != game.TotalPoints) { var errorMessage = $"Survived + points didn't match. Expected: {totalPoints} points, survived: {isSurvived}. Actual: {game.TotalPoints} points, survived: {game.ThreatController.SurvivedThreats.Any()}."; Assert.Fail(errorMessage); } }
private IList <DamageToken> GetNewDamageTokens(int count) { var openTokens = EnumFactory.All <DamageToken>().Except(CurrentDamageTokens).ToList(); var newDamageTokens = new List <DamageToken>(); for (var i = 0; i < count; i++) { var selectedToken = openTokens[random.Next(openTokens.Count)]; openTokens.Remove(selectedToken); newDamageTokens.Add(selectedToken); } return(newDamageTokens); }
public void pluralizer_factory_returns_unchanged_class_name_for_non_entity_type() { // Arrange string tableName = "Customer"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(tableName, result); }
public void pluralizer_factory_test() { // Arrange string tableName = "aspnet_Applications"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(tableName, result); }
public void pluralizer_factory_returns_plural_result_for_singular_class_name_based_on_plural_setting() { // Arrange string tableName = "Customer"; string result = tableName; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Plural"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType); string expected = "Customers"; // Assert Assert.AreEqual(expected, result); }
public string ToPropertyName() { if (this.Alias.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower()) { return(this.Alias); } else { ////return script.DnpUtils.SetPascalCase(this.Alias); //return this.Alias; ePluralizerTypes propertyType = EnumFactory.Parse <ePluralizerTypes>(script.Settings.Pluralizer.PropertyNames.Selected); PluralizerFactory factory = new PluralizerFactory(); string result = factory.SetWord(this.Alias, propertyType); return(result); } }
public void pluralizer_factory_isentityset_returns_correct_result_for_input_with_underscore() { // Arrange string tableName = "aspnet_Applications"; string result = tableName; bool isEntitySet = true; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType, isEntitySet); // Assert Assert.AreEqual(tableName, result); }
public void plural_table_name_is_replaced_with_singular_table_name_using_singular_type() { // Arrange string tableName = "aspnet_Applications"; string actual = ""; string expected = "aspnet_Application"; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Singular"); PluralizerFactory factory = new PluralizerFactory(); // Act actual = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(expected, actual); }
public void table_name_with_underscore_is_correctly_kept_using_unchanged_pluralizerfactory() { // Arrange string tableName = "aspnet_Applications"; string actual = ""; string expected = "aspnet_Applications"; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act actual = factory.SetWord(tableName, classType); // Assert Assert.AreEqual(expected, actual); }
public void pluralizer_factory_isentityset_returns_plural_entitysetname_for_non_underscore_class_name() { // Arrange string tableName = "Project"; string result = tableName; bool isEntitySet = true; ePluralizerTypes classType = EnumFactory.Parse <ePluralizerTypes>("Unchanged"); PluralizerFactory factory = new PluralizerFactory(); // Act result = factory.SetWord(tableName, classType, isEntitySet); string expected = "Projects"; // Assert Assert.AreEqual(expected, result); }
private void TeleportPlayersToOppositeDecks() { var playersByStation = EnumFactory.All <StationLocation>() .Where(stationLocation => stationLocation.IsOnShip()) .Select(stationLocation => new { Players = SittingDuck.GetPlayersInStation(stationLocation).ToList(), StationLocation = stationLocation }) .ToList(); foreach (var playerList in playersByStation) { SittingDuck.TeleportPlayers( playerList.Players, playerList.StationLocation.OppositeStationLocation().GetValueOrDefault()); } }
private void OnJumpingToHyperspace(object sender, EventArgs args) { SittingDuck.KnockOutPlayers(EnumFactory.All <StationLocation>()); }
/// <summary> /// 获取用户 /// </summary> /// <param name="userDictionary"></param> /// <param name="host"></param> /// <param name="isMatch"></param> /// <param name="matchPlatform"></param> /// <param name="loginFuc"></param> /// <param name="cookie"></param> /// <returns></returns> public static DataResult <User> GetUser(ConcurrentDictionary <User, CookieContainer> userDictionary, string host, bool isMatch, MatchPlatform matchPlatform, Func <string, string, string, DataResult <CookieContainer> > loginFuc, out CookieContainer cookie) { var dataResult = new DataResult <User>(); var messageSubjectEnum = EnumFactory <MessageSubjectEnum> .Parse(matchPlatform); User user; cookie = null; var dateTime = DateTime.UtcNow.Date.AddHours(-8); using (var db = new ResumeMatchDBEntities()) { if (userDictionary.Keys.All(a => a.Host != host)) { List <User> users; if (isMatch) { users = db.User.Where(w => w.IsEnable && w.Platform == (short)matchPlatform && w.Status == 1 && w.Host == host).ToList(); } else { users = db.User.Where(w => w.IsEnable && w.Platform == (short)matchPlatform && w.Status == 1 /* && w.Host == host*/ && (w.LastLoginTime == null || w.DownloadNumber > 0 || w.LastLoginTime < dateTime)).ToList(); } if (!users.Any()) { dataResult.IsSuccess = false; dataResult.Code = ResultCodeEnum.NoUsers; return(dataResult); } foreach (var item in users) { for (var i = 0; i < 5; i++) { if (userDictionary.TryAdd(item, null)) { break; } if (i == 4) { LogFactory.Warn($"向字典中添加用户 {item.Email} 失败!", messageSubjectEnum); } } } } Next: if (isMatch) { var userQuery = userDictionary.Keys.Where(f => f.IsEnable && f.Host == host); if (!string.IsNullOrWhiteSpace(host)) { userQuery = userQuery.Where(w => w.RequestDate == null || w.RequestDate.Value.Date < DateTime.UtcNow.Date || w.RequestDate.Value.Date == DateTime.UtcNow.Date && w.RequestNumber < Global.TodayMaxRequestNumber); } user = userQuery.OrderBy(o => o.RequestNumber).FirstOrDefault(); } else { user = userDictionary.Keys .Where(f => f.IsEnable /*&& f.Host == host */ && (f.LastLoginTime == null || f.DownloadNumber > 0 || f.LastLoginTime < dateTime)) .OrderBy(o => o.Email) .FirstOrDefault(); } if (user == null) { dataResult.IsSuccess = false; if (isMatch) { dataResult.Code = ResultCodeEnum.RequestUpperLimit; } else { dataResult.Code = ResultCodeEnum.NoUsers; } LogFactory.Warn(JsonConvert.SerializeObject(userDictionary), messageSubjectEnum); var list = userDictionary.Keys.Where(w => w.Host == host); foreach (var item in list) { for (var i = 0; i < 5; i++) { if (userDictionary.TryRemove(item, out cookie)) { break; } if (i == 4) { LogFactory.Warn($"从字典中移除用户 {item.Email} 失败!", messageSubjectEnum); dataResult.ErrorMsg += $"向字典中移除用户 {item.Email} 失败!"; return(dataResult); } } } return(dataResult); } if (isMatch) { if (user.RequestDate == null || user.RequestDate.Value.Date < DateTime.UtcNow.Date) { user.RequestDate = DateTime.UtcNow.Date; user.RequestNumber = 0; } user.RequestNumber++; } for (var i = 0; i < 5; i++) { if (userDictionary.TryGetValue(user, out cookie)) { break; } } if (cookie == null) { var result = loginFuc(user.Email, user.Password, host); if (!result.IsSuccess) { LogFactory.Warn(result.ErrorMsg, messageSubjectEnum); userDictionary.TryRemove(user, out cookie); dataResult.IsSuccess = false; return(dataResult); } cookie = result.Data; if (cookie != null) { for (var i = 0; i < 5; i++) { if (userDictionary.TryUpdate(user, cookie, null)) { break; } } } } if (cookie == null) { goto Next; } var userEntity = db.User.FirstOrDefault(f => f.Id == user.Id); if (userEntity != null) { userEntity.RequestDate = user.RequestDate; userEntity.RequestNumber = user.RequestNumber; } db.TransactionSaveChanges(); } dataResult.Data = user; return(dataResult); }
/// <summary> /// 过滤器 /// </summary> /// <param name="list"></param> /// <returns></returns> private static List <FilterResult> FilterExist(List <ResumeSearch> list) { var filterResult = new List <FilterResult>(); filterResult.AddRange(list.Select(s => new FilterResult { ResumeId = s.ResumeId, ResumeNumber = s.ResumeNumber, UserMasterExtId = s.UserMasterExtId })); if (!isFirst) { using (var db = new ResumeRepairDBEntities()) { var filterResultArr = filterResult.Select(s => s.ResumeId).ToArray(); var resumeIdArr = db.ResumeRecord.Where(w => filterResultArr.Any(a => w.ResumeId == a)).Select(s => s.ResumeId).ToArray(); filterResult.RemoveAll(r => resumeIdArr.Any(a => r.ResumeId == a)); var resumeList = filterResult.Select(s => new ResumeRecord { LibraryExist = 2, ResumePlatform = 1, ResumeId = s.ResumeId, Status = (short)ResumeRecordStatus.WaitMatch, PostBackStatus = 0 }).ToList(); db.ResumeRecord.AddRange(resumeList); db.SaveChanges(); var query = from n in resumeList.AsQueryable() join l in list.AsQueryable() on new { n.ResumeId } equals new { l.ResumeId } select new MatchResumeSearch { LastCompany = l.LastCompany, Name = l.Name, ResumeId = n.ResumeId, ResumeNumber = l.ResumeNumber, University = l.University, UserMasterExtId = l.UserMasterExtId, ResumeRecodeId = n.Id }; db.MatchResumeSearch.AddRange(query); db.SaveChanges(); } } isFirst = false; To: var result = RequestFactory.QueryRequest(Global.FilterAuthUrl, "{\"Username\": \"longzhijie\",\"Password\": \"NuRQe6kC\"}", RequestEnum.POST, contentType: EnumFactory.Codes(ContentTypeEnum.Json)); if (!string.IsNullOrWhiteSpace(result)) { var jObject = JsonConvert.DeserializeObject(result) as JObject; if ((int)jObject["Code"] == 0) { dynamic param = new { Username = "******", Signature = (string)jObject["Signature"], ResumeSummaries = new List <object>() }; param.ResumeSummaries.AddRange(list.Select(s => new { ResumeNumber = s.ResumeNumber, UserMasterExtendId = s.UserMasterExtId, ResumeId = s.ResumeId }).ToList()); result = RequestFactory.QueryRequest(Global.FilterUrl, JsonConvert.SerializeObject(param), RequestEnum.POST, contentType: EnumFactory.Codes(ContentTypeEnum.Json)); if (!string.IsNullOrWhiteSpace(result)) { jObject = JsonConvert.DeserializeObject(result) as JObject; if ((int)jObject["Code"] == 3) { goto To; } if ((int)jObject["Code"] == 0) { using (var db = new ResumeRepairDBEntities()) { var jArray = jObject["ResumeSummaries"] as JArray; var isSuccessBack = true; if (jArray.Count > 0) { Global.TotalMatchSuccess += jArray.Count; Global.TotalDownload += jArray.Count; var matchedResult = jArray.Select(s => new ResumeMatchResult { Cellphone = (string)s["Cellphone"], Email = (string)s["Email"], ResumeNumber = ((string)s["ResumeNumber"]).Substring(0, 10), Status = 2 }).ToList(); var data = RequestFactory.QueryRequest(Global.PostResumesUrl, JsonConvert.SerializeObject(matchedResult), RequestEnum.POST, contentType: "application/json"); if (!data.Contains("成功")) { isSuccessBack = false; } } foreach (var item in jArray) { var resumeId = (string)item["ResumeId"]; var resume = db.ResumeRecord.FirstOrDefault(f => f.ResumeId == resumeId); filterResult.RemoveAll(f => f.ResumeNumber == (string)item["ResumeNumber"] && f.UserMasterExtId == (string)item["UserMasterExtendId"]); if (resume != null) { resume.LibraryExist = 1; resume.Status = (short)ResumeRecordStatus.DownLoadSuccess; resume.DownLoadTime = DateTime.UtcNow; resume.Cellphone = (string)item["Cellphone"]; resume.Email = (string)item["Email"]; resume.PostBackStatus = isSuccessBack ? (short)1 : (short)2; } } db.SaveChanges(); } } } } } return(filterResult); }
public override void PerformZAction() { sittingDuck.KnockOutPlayers(EnumFactory.All <StationLocation>().Except(new[] { StationLocation.UpperWhite })); }
protected override void PerformZAction(int currentTurn) { SittingDuck.KnockOutCaptain(); SittingDuck.ShiftPlayersAfterPlayerActions(EnumFactory.All <StationLocation>(), currentTurn + 1); }
public PlayerDamage PerformAttack(Player performingPlayer) { return(new PlayerDamage(IsDoubleRocket ? 5 : 3, PlayerDamageType.Rocket, new [] { 1, 2 }, EnumFactory.All <ZoneLocation>(), performingPlayer)); }
protected override void PerformXAction(int currentTurn) { SittingDuck.DrainShields(EnumFactory.All <ZoneLocation>()); }
protected override void OnHealthReducedToZero() { base.OnHealthReducedToZero(); SittingDuck.RemoveZoneDebuffForSource(EnumFactory.All <ZoneLocation>(), this); }
protected override void PerformXAction(int currentTurn) { SittingDuck.AddZoneDebuff(EnumFactory.All <ZoneLocation>(), ZoneDebuff.IneffectiveShields, this); }
protected override void PerformYAction(int currentTurn) { SittingDuck.RemoveZoneDebuffForSource(EnumFactory.All <ZoneLocation>(), this); SittingDuck.AddZoneDebuff(EnumFactory.All <ZoneLocation>(), ZoneDebuff.ReversedShields, this); }
public override void PerformYAction() { sittingDuck.DrainShields(EnumFactory.All <ZoneLocation>(), 1); }
protected override void PerformYAction(int currentTurn) { SittingDuck.DrainReactors(EnumFactory.All <ZoneLocation>(), 1); }
protected override void PerformZAction(int currentTurn) { SittingDuck.KnockOutPlayers(EnumFactory.All <StationLocation>().Where(stationLocation => stationLocation.IsOnShip()).Except(new[] { StationLocation.UpperWhite })); }