Beispiel #1
0
        /// <summary>
        /// Delete a beatmap from the manager.
        /// Is a no-op for already deleted beatmaps.
        /// </summary>
        /// <param name="beatmapSet">The beatmap set to delete.</param>
        public void Delete(BeatmapSetInfo beatmapSet)
        {
            lock (importContext)
            {
                var context = importContext.Value;

                using (var transaction = context.BeginTransaction())
                {
                    context.ChangeTracker.AutoDetectChangesEnabled = false;

                    // re-fetch the beatmap set on the import context.
                    beatmapSet = context.BeatmapSetInfo.Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == beatmapSet.ID);

                    // create local stores so we can isolate and thread safely, and share a context/transaction.
                    var iFiles    = new FileStore(() => context, storage);
                    var iBeatmaps = createBeatmapStore(() => context);

                    if (iBeatmaps.Delete(beatmapSet))
                    {
                        if (!beatmapSet.Protected)
                        {
                            iFiles.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
                        }
                    }

                    context.ChangeTracker.AutoDetectChangesEnabled = true;
                    context.SaveChanges(transaction);
                }
            }
        }
Beispiel #2
0
 void rollback()
 {
     if (!Delete(item))
     {
         // We may have not yet added the model to the underlying table, but should still clean up files.
         LogForModel(item, "Dereferencing files for incomplete import.");
         Files.Dereference(item.Files.Select(f => f.FileInfo).ToArray());
     }
 }
Beispiel #3
0
        /// <summary>
        /// Delete a beatmap from the manager.
        /// Is a no-op for already deleted beatmaps.
        /// </summary>
        /// <param name="beatmapSet">The beatmap set to delete.</param>
        public void Delete(BeatmapSetInfo beatmapSet)
        {
            if (!beatmaps.Delete(beatmapSet))
            {
                return;
            }

            if (!beatmapSet.Protected)
            {
                files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Delete an item from the manager.
        /// Is a no-op for already deleted items.
        /// </summary>
        /// <param name="item">The item to delete.</param>
        public void Delete(TModel item)
        {
            using (ContextFactory.GetForWrite())
            {
                // re-fetch the model on the import context.
                var foundModel = queryModel().Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == item.ID);

                if (foundModel.DeletePending)
                {
                    return;
                }

                if (ModelStore.Delete(foundModel))
                {
                    Files.Dereference(foundModel.Files.Select(f => f.FileInfo).ToArray());
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Delete a beatmap from the manager.
        /// Is a no-op for already deleted beatmaps.
        /// </summary>
        /// <param name="beatmapSet">The beatmap set to delete.</param>
        public void Delete(BeatmapSetInfo beatmapSet)
        {
            using (var usage = contextFactory.GetForWrite())
            {
                var context = usage.Context;

                context.ChangeTracker.AutoDetectChangesEnabled = false;

                // re-fetch the beatmap set on the import context.
                beatmapSet = context.BeatmapSetInfo.Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == beatmapSet.ID);

                if (beatmaps.Delete(beatmapSet))
                {
                    if (!beatmapSet.Protected)
                    {
                        files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
                    }
                }

                context.ChangeTracker.AutoDetectChangesEnabled = true;
            }
        }
        /// <summary>
        /// Delete an item from the manager.
        /// Is a no-op for already deleted items.
        /// </summary>
        /// <param name="item">The item to delete.</param>
        public void Delete(TModel item)
        {
            using (var usage = ContextFactory.GetForWrite())
            {
                var context = usage.Context;

                context.ChangeTracker.AutoDetectChangesEnabled = false;

                // re-fetch the model on the import context.
                var foundModel = queryModel().Include(s => s.Files).ThenInclude(f => f.FileInfo).First(s => s.ID == item.ID);

                if (foundModel.DeletePending)
                {
                    return;
                }

                if (ModelStore.Delete(foundModel))
                {
                    Files.Dereference(foundModel.Files.Select(f => f.FileInfo).ToArray());
                }

                context.ChangeTracker.AutoDetectChangesEnabled = true;
            }
        }