コード例 #1
0
ファイル: GameController.cs プロジェクト: rover101/gangstabit
        public async Task Post([FromBody] string value)
        {
            value = value.ToHtml();
            var logPath   = $@"C:\Gangstabit\{DateTime.UtcNow.Ticks}.html";
            var logFile   = System.IO.File.Create(logPath);
            var logWriter = new System.IO.StreamWriter(logFile);

            logWriter.WriteLine(value);
            logWriter.Dispose();

            value = HttpUtility.HtmlDecode(value);
            var game = _gameInterpretor.InterpreteGameFromHtml(value, logPath);
            await _gameRepository.SaveGameAsync(game).ConfigureAwait(false);
        }
コード例 #2
0
        static async Task MainAsync()
        {
            var interpretor    = new GameInterpretor();
            var gameRepository = new GameRepository();


            var files = Directory.EnumerateFiles(
                @"C:\Gangstabit",
                "*",
                SearchOption.AllDirectories).ToList();

            int count = 0;

            foreach (string file in files)
            {
                try
                {
                    var logReader = new System.IO.StreamReader(file);
                    var html      = await logReader.ReadToEndAsync();

                    html = HttpUtility.HtmlDecode(html);
                    var game = interpretor.InterpreteGameFromHtml(html, file);
                    logReader.Dispose();

                    Console.WriteLine($"{file} interpreted");
                    await gameRepository.SaveGameAsync(game);

                    Console.WriteLine($"{file} saved");

                    count++;
                    Console.WriteLine($"{count} / {files.Count()} {(double)count/ files.Count*100}%");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }