예제 #1
0
        /// <summary>
        /// Import a beatmap from an <see cref="ArchiveReader"/>.
        /// </summary>
        /// <param name="archive">The beatmap to be imported.</param>
        public BeatmapSetInfo Import(ArchiveReader archive)
        {
            using (contextFactory.GetForWrite()) // used to share a context for full import. keep in mind this will block all writes.
            {
                // create a new set info (don't yet add to database)
                var beatmapSet = createBeatmapSetInfo(archive);

                // check if this beatmap has already been imported and exit early if so
                var existingHashMatch = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == beatmapSet.Hash);
                if (existingHashMatch != null)
                {
                    Undelete(existingHashMatch);
                    return(existingHashMatch);
                }

                // check if a set already exists with the same online id
                if (beatmapSet.OnlineBeatmapSetID != null)
                {
                    var existingOnlineId = beatmaps.BeatmapSets.FirstOrDefault(b => b.OnlineBeatmapSetID == beatmapSet.OnlineBeatmapSetID);
                    if (existingOnlineId != null)
                    {
                        Delete(existingOnlineId);
                        beatmaps.Cleanup(s => s.ID == existingOnlineId.ID);
                    }
                }

                beatmapSet.Files    = createFileInfos(archive, files);
                beatmapSet.Beatmaps = createBeatmapDifficulties(archive);

                // remove metadata from difficulties where it matches the set
                foreach (BeatmapInfo b in beatmapSet.Beatmaps)
                {
                    if (beatmapSet.Metadata.Equals(b.Metadata))
                    {
                        b.Metadata = null;
                    }
                }

                // import to beatmap store
                Import(beatmapSet);
                return(beatmapSet);
            }
        }
예제 #2
0
        public BeatmapManager(Storage storage, Func <OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
        {
            createContext = context;

            refreshImportContext();

            beatmaps = createBeatmapStore(context);
            files    = new FileStore(context, storage);

            this.storage  = files.Storage;
            this.rulesets = rulesets;
            this.api      = api;

            if (importHost != null)
            {
                ipc = new BeatmapIPCChannel(importHost, this);
            }

            beatmaps.Cleanup();
        }
예제 #3
0
        public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
        {
            this.contextFactory = contextFactory;

            beatmaps = new BeatmapStore(contextFactory);

            beatmaps.BeatmapSetAdded   += s => BeatmapSetAdded?.Invoke(s);
            beatmaps.BeatmapSetRemoved += s => BeatmapSetRemoved?.Invoke(s);
            beatmaps.BeatmapHidden     += b => BeatmapHidden?.Invoke(b);
            beatmaps.BeatmapRestored   += b => BeatmapRestored?.Invoke(b);

            files = new FileStore(contextFactory, storage);

            this.rulesets = rulesets;
            this.api      = api;

            if (importHost != null)
            {
                ipc = new BeatmapIPCChannel(importHost, this);
            }

            beatmaps.Cleanup();
        }
예제 #4
0
        public BeatmapManager(Storage storage, Func <OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
        {
            createContext = context;
            importContext = new Lazy <OsuDbContext>(() =>
            {
                var c = createContext();
                c.Database.AutoTransactionsEnabled = false;
                return(c);
            });

            beatmaps = createBeatmapStore(context);
            files    = new FileStore(context, storage);

            this.storage  = files.Storage;
            this.rulesets = rulesets;
            this.api      = api;

            if (importHost != null)
            {
                ipc = new BeatmapIPCChannel(importHost, this);
            }

            beatmaps.Cleanup();
        }