コード例 #1
0
ファイル: IndexController.cs プロジェクト: Tiller431/yes
        public ActionResult GetBeatmap(string fileMd5)
        {
            var hash = _cache.Get().CacheBeatmaps.Where(bm => bm.FileMd5 == fileMd5).Select(bm => bm.Hash).FirstOrDefault();

            if (hash == null)
            {
                foreach (var map in _contextFactory.Get().Beatmaps.Where(bm => bm.FileMd5 == fileMd5))
                {
                    var fileInfo = _downloader.Download(map);

                    map.FileMd5 = _cache.Get()
                                  .CacheBeatmaps
                                  .Where(cmap => cmap.Hash == fileInfo.Hash)
                                  .Select(cmap => cmap.FileMd5)
                                  .FirstOrDefault();
                }
                //return NotFound("not found");
            }

            var info = new osu.Game.IO.FileInfo {
                Hash = hash
            };

            return(File(_fileStorage.GetStream(info.StoragePath), "application/octet-stream", hash));
        }
コード例 #2
0
        public ActionResult GetBeatmap(string mapFile)
        {
            DogStatsd.Increment("osu.beatmap.download");
            var hash = _cache.Get()
                       .CacheBeatmaps
                       .Where(bm => bm.FileMd5 == mapFile || bm.File == mapFile)
                       .Select(bm => bm.Hash)
                       .FirstOrDefault();

            osu.Game.IO.FileInfo info = null;
            if (hash == null)
            {
                lock (_dbContextLock)
                {
                    foreach (var map in _dbContext.Beatmaps.Where(bm => bm.FileMd5 == mapFile || bm.File == mapFile))
                    {
                        var(fileInfo, pFileMd5) = _downloader.Download(map);

                        map.FileMd5 = pFileMd5;
                        info        = fileInfo;
                    }

                    if (info == null)
                    {
                        var(fileInfo, _) = _downloader.Download(mapFile);

                        info = fileInfo;
                    }
                }
            }
            else
            {
                info = new osu.Game.IO.FileInfo {
                    Hash = hash
                }
            };

            if (info == null)
            {
                return(NotFound("Beatmap not Found!"));
            }

            return(File(_fileStorage.GetStream(info.StoragePath), "application/octet-stream", hash));
        }