public static void GetObjectsAsync(Score p2) { using (ScoreContext db = new ScoreContext()) { MessageBox.Show("Your Level: " + p2.Level.ToString()); } }
protected internal override void OnScoreKill(ScoreContext killer, ScoreContext assist, ScoreContext target, AttackAttribute attackAttribute) { if (target.IsSentry) { SendScoreKill(killer, assist, target, attackAttribute); return; } killer.Score.Kills++; target.Score.Deaths++; if (assist != null) { assist.Score.KillAssists++; } SendScoreKill(killer, assist, target, attackAttribute); killer.Player.Team.Score++; if (killer.Player.Team.Score == Room.Options.ScoreLimit / 2) { StateMachine.StartHalfTime(); } else if (killer.Player.Team.Score == Room.Options.ScoreLimit) { StateMachine.StartResult(); } }
public LevelTable() { InitializeComponent(); db = new ScoreContext(); db.Scores.Load(); tasksGrid.ItemsSource = db.Scores.Local.ToBindingList(); }
public List <Game> all() { using var gameDataContext = new GameDataContext(); var gameDatas = gameDataContext.GameDatas; using var matchContext = new MatchContext(); var matchesByGameId = matchContext .Matches .AsEnumerable() .GroupBy(m => m.GameId) .ToDictionary(g => g.Key, g => g.ToList()); using var scoreContext = new ScoreContext(); var scores = scoreContext.Scores.ToDictionary(g => g.Id, g => g); var games = new List <Game>(); foreach (var gameData in gameDatas) { var id = gameData.Id; var score = scores[id]; var matches = matchesByGameId[id]; DateTime date = DateTime.ParseExact(gameData.Date, "u", System.Globalization.CultureInfo.InvariantCulture); games.Add(createGame(matches, score?.Result, id, date)); } return(games); }
public string GetScore(ref ScoreContext scContext) { string answer = null; string rawScript = scContext.taskItems.ElementAt(scContext.currentIndex).question; string script = rawScript.Replace(",", "").Replace("?", "").Replace("!", "").Replace(".", ""); string mp3Path = scContext.UserInput; string wavPath = mp3Path.Replace("mp3", "wav"); try { using (Mp3FileReader reader = new Mp3FileReader(mp3Path)) { using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) { WaveFileWriter.CreateWaveFile(wavPath, pcmStream); } } } catch { return(null); } var result = ScoringHost.Evaluate( SupportedLanguage.English, script, File.ReadAllBytes(wavPath)); scContext.taskItems.ElementAt(scContext.currentIndex).score = result.Score; answer = string.Format("Your score: {0}\r\n", result.Score.ToString()); scContext.currentIndex++; return(answer); }
public Score_Window() { InitializeComponent(); _scoreContext = new ScoreContext(); _scores = new ObservableCollection <Score>(_scoreContext.Set <Score>().Take(10).ToList()); tasks.ItemsSource = _scores; }
public override void WonPoint(string player) { ScoreContext.PlayerScored(player); if (Player1Score != Player2Score) { ScoreContext.GameState = new Advantage(ScoreContext); } }
public ImmersiveQuizAPI(CourseContext courseContext, LocationContext locationContext, QuestionContext questionContext, AnswerContext answerContext, ScoreContext scoreContext) { _courseContext = courseContext; _locationContext = locationContext; _questionContext = questionContext; _answerContext = answerContext; _scoreContext = scoreContext; }
public static async Task SaveObjectsAsync(Score p) { using (ScoreContext db = new ScoreContext()) { db.Scores.Add(p); await db.SaveChangesAsync(); } }
private ScoreContext InitScoreContext(string userId, ScoreLUInfo currentLUInfo) { ScoreContext scContext = new ScoreContext(userId); scContext.Intent = currentLUInfo.Intent.intent; scContext.currentIndex = 0; return(scContext); }
public ActionResult <Game> Update(Game game) { using var gameDataContext = new GameDataContext(); var gameData = gameDataContext.GameDatas.Where(g => g.Id == game.Id).SingleOrDefault(); gameData.Date = game.Date; gameDataContext.SaveChanges(); using var matchContext = new MatchContext(); var matches = matchContext.Matches.Where(m => m.GameId == game.Id); matchContext.Matches.RemoveRange(matches); foreach (var player in game.Team1) { matchContext.Add(new Match { GameId = game.Id, Player = player, Team = 1, }); } foreach (var player in game.Team2) { matchContext.Add(new Match { GameId = game.Id, Player = player, Team = 2, }); } matchContext.SaveChanges(); using var scoreContext = new ScoreContext(); var score = scoreContext.Scores.Where(s => s.GameId == game.Id).Single(); if (game.Score == '1') { score.Result = 1f; } else if (game.Score == '2') { score.Result = 0f; } else if (game.Score == 'D') { score.Result = 0.5f; } else if (game.Score == 'C') { score.Result = -1f; } else { score.Result = null; } scoreContext.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = game.Id }, game)); }
public string StartTest(ref ScoreContext scContext) { string answer = null; Init(ref scContext); answer = "发送语音消息,读出给定的句子。尽量做到大声嘹亮,富有感情。加油!\r\n"; answer += string.Format("本次测试共有{0}道题。\r\n", TESTITEMCOUNT); answer += GetText(ref scContext); return(answer); }
static void ConfigureDB() { using (var db = new ScoreContext()) { db.Database.EnsureCreated(); // Note migrations are not yet 100% // this would handle drop/create and data seeding } }
protected internal override void OnScoreTeamKill(ScoreContext killer, ScoreContext target, AttackAttribute attackAttribute) { if (!target.IsSentry) { target.Score.Deaths++; } SendScoreTeamKill(killer, target, attackAttribute); }
public Window_Gameover(long tScore) { _Score = tScore; ScoreContext _scoreContext = new ScoreContext(); Score score = new Score(); score.ScoreId = DateTimeOffset.Now.ToUnixTimeMilliseconds(); score.ScoreValue = (int)tScore; _scoreContext.Add(score); _scoreContext.SaveChanges(); InitializeComponent(); }
public string GetText(ref ScoreContext scContext) { if (scContext.currentIndex == TESTITEMCOUNT) { scContext.IsInTesting = false; string answer = null; answer = "测试结束~\r\n"; answer += GenerateReport(ref scContext); return(answer); } return(string.Format("{0}. {1}", (scContext.currentIndex + 1).ToString(), scContext.taskItems.ElementAt(scContext.currentIndex).question)); }
protected internal override void OnScoreKill(ScoreContext killer, ScoreContext assist, ScoreContext target, AttackAttribute attackAttribute) { killer.Score.Kills++; killer.Player.Team.Score++; SendScoreKill(killer, null, target, attackAttribute); if (killer.Score.Kills >= Room.Options.ScoreLimit) { StateMachine.StartResult(); } }
public string GenerateReport(ref ScoreContext scContext) { string answer = null; answer = "您的平均分是:"; double sum = 0; foreach (var i in scContext.taskItems) { sum += i.score; } answer += (sum / scContext.currentIndex).ToString() + "\r\n"; answer += "继续努力!"; return(answer); }
public string ReceiveAnswer(ref ScoreContext scContext) { string answer = null; answer = GetScore(ref scContext); if (string.IsNullOrEmpty(answer)) { answer += "请发送语音消息,读出给定的句子。\r\n"; } else { answer += "下一题:\r\n"; answer += GetText(ref scContext); } return(answer); }
public void Find_searches_name() { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <ScoreContext>() .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new ScoreContext(options)) { context.Database.EnsureCreated(); } // Insert seed data into the database using one instance of the context using (var context = new ScoreContext(options)) { context.Scores.Add(new Score { Name = "John F.", Point = 9 }); context.Scores.Add(new Score { Name = "Tesfa S.", Point = 4 }); context.Scores.Add(new Score { Name = "Gebere O.", Point = 6 }); context.SaveChanges(); } //TODO //// Use a clean instance of the context to run the test //using (var context = new ScoreContext(options)) //{ // var service = new ScoreBoardService(context); // var result = service.Find("Anders"); // Assert.Equal(1, result.Count()); //} } finally { connection.Close(); } }
private BotContext GetValidContext(string userId) { ContextInfo ci = cManager.GetContext(userId); if (ci == null) { return(null); } DateTime currentTime = DateTime.Now; if (currentTime.Subtract(ci.lastUpdatedTime).TotalMinutes > 480) // 8 hours { return(null); } else { if (ci.type == ContextType.PSAContext) { PSAContext psaContext = JsonConvert.DeserializeObject <PSAContext>(ci.jsonString); if (IsValid(psaContext)) { return(psaContext); } else { return(null); } } else if (ci.type == ContextType.ExamSuitContext) { ExamSuitContext esContext = JsonConvert.DeserializeObject <ExamSuitContext>(ci.jsonString); return(esContext); } else if (ci.type == ContextType.ScoreContext) { ScoreContext scContext = JsonConvert.DeserializeObject <ScoreContext>(ci.jsonString); return(scContext); } else { TaskFlowContext tfContext = JsonConvert.DeserializeObject <TaskFlowContext>(ci.jsonString); return(tfContext); } } }
public ActionResult <Game> GetById(int id) { using var gameDataContext = new GameDataContext(); var gameData = gameDataContext.GameDatas.Where(x => x.Id == id).FirstOrDefault(); if (gameData == null) { return(NotFound()); } using var matchContext = new MatchContext(); var matches = matchContext.Matches.Where(x => x.GameId == id); using var scoreContext = new ScoreContext(); var score = scoreContext.Scores.Where(x => x.GameId == id).FirstOrDefault(); DateTime date = DateTime.ParseExact(gameData.Date, "u", System.Globalization.CultureInfo.InvariantCulture); return(createGame(matches, score?.Result, id, date)); }
public ValuesController(ScoreContext context) { _context = context; //Score sc = new Score //{ // HomeName = "Chester", // HomeScore = "3", // AwayName = "Alfreton", // AwayScore = "2", // Id = 999 //}; //MemoryStream stream1 = new MemoryStream(); //DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Score)); //ser.WriteObject(stream1, sc); //stream1.Position = 0; //StreamReader sr = new StreamReader(stream1); //var res = sr.ReadToEnd(); }
public string Answer(string userId, ref ScoreContext scContext) { string answer = null; switch (scContext.Intent) { case "Score": if (!scContext.IsInTesting) { answer = this.scSrv.StartTest(ref scContext); } else { answer = this.scSrv.ReceiveAnswer(ref scContext); } break; } return(answer); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //enable web sockets app.UseWebSockets(); //wire our chat service app.UseMiddleware <ChatService>(); // this enables routing / controller framework app.UseMvc(); //ensure DB is configured using (var context = new ScoreContext()) { context.Database.EnsureCreated(); } }
public void Add_writes_to_database() { // In-memory database only exists while the connection is open var connection = new SQLiteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <ScoreContext>() .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new ScoreContext(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new ScoreContext(options)) { var service = new ScoreBoardService(context); service.Add("Shewawa"); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ScoreContext(options)) { Assert.Equal(1, context.Scores.Count()); Assert.Equal("Shewawa", context.Scores.Single().Name); } } finally { connection.Close(); } }
protected internal override void OnScoreKill(ScoreContext killer, ScoreContext assist, ScoreContext target, AttackAttribute attackAttribute) { if (IsInTouchdown) { return; } if (target.IsSentry) { SendScoreKill(killer, assist, target, attackAttribute); return; } killer.Score.Kills++; target.Score.Deaths++; if (assist != null) { assist.Score.KillAssists++; } SendScoreKill(killer, assist, target, attackAttribute); }
protected internal override void OnScoreDefense(ScoreContext killer, ScoreContext assist, ScoreContext target, AttackAttribute attackAttribute) { if (IsInTouchdown) { return; } if (target.IsSentry) { SendScoreDefense(killer, assist, target, attackAttribute); return; } GetScore(killer).DefenseScore++; target.Score.Deaths++; if (assist != null) { GetScore(killer).DefenseAssistScore++; } SendScoreDefense(killer, assist, target, attackAttribute); }
public ControlerScoreTable(ScoreContext score) { scoreContext = score; }
public ActionResult <Game> Create(Game game) { using var gameDataContext = new GameDataContext(); using var matchContext = new MatchContext(); long id = (gameDataContext.GameDatas.Max(m => (int?)m.Id) ?? 0) + 1; game.Id = id; if (game.Date == null) { game.Date = DateTime.Now.ToString("u", System.Globalization.CultureInfo.InvariantCulture); } gameDataContext.Add(new GameData { Id = id, Date = game.Date, }); gameDataContext.SaveChanges(); var matches = new List <Match>(); foreach (var player in game.Team1) { matches.Add(new Match { GameId = id, Player = player, Team = 1, }); } foreach (var player in game.Team2) { matches.Add(new Match { GameId = id, Player = player, Team = 2, }); } matchContext.AddRange(matches); matchContext.SaveChanges(); using var scoreContext = new ScoreContext(); float?result = null; if (game.Score == '1') { result = 1; } else if (game.Score == '2') { result = 0; } else if (game.Score == 'D') { result = 0.5f; } else if (game.Score == 'C') { result = -1; } scoreContext.Add(new Score { GameId = id, Result = result, }); scoreContext.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = id }, game)); }