Пример #1
0
        public virtual async Task DeleteExportProfileAsync(ExportProfile profile, bool force = false)
        {
            Guard.NotNull(profile, nameof(profile));

            if (!force && profile.IsSystemProfile)
            {
                throw new SmartException(T("Admin.DataExchange.Export.CannotDeleteSystemProfile"));
            }

            await _db.LoadCollectionAsync(profile, x => x.Deployments);

            await _db.LoadReferenceAsync(profile, x => x.Task);

            var folder      = profile.GetExportDirectory();
            var deployments = profile.Deployments.Where(x => !x.IsTransientRecord()).ToList();

            if (profile.Deployments.Any())
            {
                _db.ExportDeployments.RemoveRange(deployments);
            }

            if (profile.Task != null)
            {
                _db.TaskDescriptors.Remove(profile.Task);
            }

            _db.ExportProfiles.Remove(profile);

            await _db.SaveChangesAsync();

            if (Directory.Exists(folder)) // TODO: (mg) (core) Use IDirectory.Exists
            {
                var fs = new LocalFileSystem(folder);

                // TODO: (mg) (core) find out how to correctly use LocalFileSystem.ClearDirectory.
                // RE: If profile.GetExportDirectory() returns IDirectory, just pass it to ClearDirectory().
                IDirectory whatever = null;
                fs.ClearDirectory(whatever, true, TimeSpan.Zero);
            }
        }