public MonsterEngine(List<Monster> monsters, List<BaseEntity> surroundings) { List<MonsterAI> monsterAIs = monsters.Select(x => new MonsterAI(x, surroundings)).ToList(); this.ActiveMonsters = monsterAIs; RegisterAIEvents(); activeThread = new Thread(AIOperation); activeThread.IsBackground = true; }
public IEnumerable<string> GetAllById(Guid id) { IEnumerable<GoalLog> goalLogs = database.GetTheDatabase().GoalLog.FindAllByGoalId(id).ToList<GoalLog>(); var accountIds = new HashSet<Guid>(); var domainEvents = new List<GoalDomainEvent>(); var accounts = new Dictionary<Guid, Account>(); foreach (var goalLog in goalLogs) { var type = Type.GetType(goalLog.Event); var goalDomainEvent = (GoalDomainEvent)JsonConvert.DeserializeObject(goalLog.Data, type); accountIds.Add(goalDomainEvent.AccountId); domainEvents.Add(goalDomainEvent); } foreach (var accountId in accountIds) { accounts[accountId] = accountRepository.FindById(accountId); } return domainEvents.Select(domainEvent => domainEvent.GetMessage(accounts[domainEvent.AccountId])).ToList(); }
public List<TaskModel> GetModelList(List<Task> tasks) { return tasks.Select(GetModel).ToList(); }
public IEnumerable<KeyValuePair<int, string>> Search(string customerName) { if (string.IsNullOrEmpty(customerName) || string.IsNullOrWhiteSpace(customerName)) { yield return new KeyValuePair<int, string>(); } var search = new CustomerSearch(new LevenshteinDistance()); IEnumerable<KeyValuePair<int, string>> values = new List<KeyValuePair<int, string>>(); if (_customerRespository.Persistence == Persistence.SQL) { values = _customerRespository.All.Select(i => new KeyValuePair<int, string>(i.Id, i.Name)).ToList(); } else if (_customerRespository.Persistence == Persistence.Graph) { var graph = _customerRespository.GraphClient; values = graph.Cypher.Match("(p:Customer)").Return(p => p.As<CustomerGraph.Node>()).Results .Select(p => new KeyValuePair<int, string>((int)p.Id, p.Name)); } foreach (var match in search.FindClosestMatches(customerName, values.Select(i => i.Value), 5)) { yield return (new KeyValuePair<int, string>(values.First(c => c.Value == match).Key, match)); } }
public List<TagsModel> GetModelList(List<Tag> tags) { return tags.Select(GetModel).ToList(); }
public List<UserModel> GetModelList(List<User> users) { return users.Select(GetModel).ToList(); }
/// <summary> /// 登录。如果返回异常则说明登录失败 /// </summary> /// <param name="verifyPoints"></param> /// <returns></returns> public async Task<Exception> LoginAsync(string username, string password, List<Point> verifyPoints) { IsLogined = false; LoginInfo = new LoginInfo() { UserName = username, Password = password }; var loginData = new Dictionary<string, string>() { ["loginUserDTO.user_name"] = LoginInfo.UserName, ["userDTO.password"] = LoginInfo.Password, ["randCode"] = verifyPoints.Select(s => s.X + "," + s.Y).JoinAsString(",") }; var loginCheck = NetClient.Create<WebResponseResult<LoginAsyncResult>>( HttpMethod.Post, "https://kyfw.12306.cn/otn/login/loginAysnSuggest", "https://kyfw.12306.cn/otn/login/init", loginData ); await loginCheck.SendTask(); if (!loginCheck.IsValid()) { return loginCheck.Exception ?? new Exception("未能提交请求"); } if (!loginCheck.Result.Data.IsSuceess) { return new Exception(loginCheck.Result.GetErrorMessage()); } //登录成功 var postLogin = NetClient.Create<string>( HttpMethod.Post, "https://kyfw.12306.cn/otn/login/userLogin", "https://kyfw.12306.cn/otn/login/init" ); await postLogin.SendTask(); //这里的返回值我们不care .... //登录好了。等等。。我们好像想拿到显示的中文名? //所以多加一个请求吧。 var realNameCtx = NetClient.Create<string>( HttpMethod.Get, "https://kyfw.12306.cn/otn/index/initMy12306", "https://kyfw.12306.cn/otn/login/init" ); await realNameCtx.SendTask(); if (realNameCtx.IsValid()) { //匹配出名字信息 var realMatch = Regex.Match(realNameCtx.Result, @"user_name\s*=\s*['""]([^'""]+)['""]", RegexOptions.Singleline); if (realMatch.Success) { LoginInfo.DisplayName = realMatch.GetGroupValue(1).DecodeFromJsExpression(); } } //这里失败了我们就随便起个名字,嗯。 if (LoginInfo.DisplayName.IsNullOrEmpty()) LoginInfo.DisplayName = "路人甲"; IsLogined = true; return null; }
public List<CompanyVM> GetAllCompanyVMByUser(int customerType, int userId) { User user = UserDAL.GetById(userId, new List<string> { "RelUserCompanies.Company" }); var companyList = new List<Company>(); foreach (var relCompany in user.RelUserCompanies) { if (!relCompany.IsDeleted && relCompany.Company.Type == customerType) { companyList.Add(relCompany.Company); } } return companyList.Select(o => new CompanyVM { Id = o.Id, Name = o.Name }).ToList(); }