コード例 #1
0
ファイル: GameSL.cs プロジェクト: l46kok/fate-web-server
        public GameReplayData GetReplayData(int gameId)
        {
            GameReplayData data = _gameDal.GetReplayData(gameId);

            if (data == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(data.ReplayPath))
            {
                return(null);
            }
            data.ReplayPath = Path.Combine(ConfigHandler.ReplayFileLocation, Path.GetFileName(data.ReplayPath));
            return(data);
        }
コード例 #2
0
ファイル: GameDAL.cs プロジェクト: l46kok/fate-web-server
 public GameReplayData GetReplayData(int gameId)
 {
     using (var db = frsDatabase.Create())
     {
         GameReplayData data = new GameReplayData();
         game           game = db.game.FirstOrDefault(x => x.GameID == gameId);
         if (game == null)
         {
             return(null);
         }
         data.PlayedDateTime = game.PlayedDate;
         data.ReplayPath     = game.ReplayUrl;
         return(data);
     }
 }
コード例 #3
0
        public FileDownloadModule(GameSL gameSl)
        {
            Get["/download/replay/{gameId}"] = param =>
            {
                GameReplayData replayData = gameSl.GetReplayData(param.gameId);

                if (replayData == null || !File.Exists(replayData.ReplayPath))
                {
                    _logger.Info($"Replay file not found. GameId: {param.gameId}, path: {replayData.ReplayPath}");
                    return(Response.AsError(HttpStatusCode.NotFound, "Replay file cannot be found from the server"));
                }
                var    file     = new FileStream(replayData.ReplayPath, FileMode.Open);
                string fileName = "Fate Another Replay " + replayData.PlayedDateTime.ToString(CultureInfo.InvariantCulture) + ".w3g";

                var response = new StreamResponse(() => file, MimeTypes.GetMimeType(fileName));
                return(response.AsAttachment(fileName));
            };

            Get["/download/{fileName}"] = param => SendAttachmentResponse(param.fileName);
            Get["/download/map"]        = param => SendAttachmentResponse(ConfigHandler.MapName);
        }