Пример #1
0
        /// <summary>
        /// Called at the end of the database Initialiser and used to repair and/or upgrade the database
        /// Note this method must contain re-runnable code as it executes at every app startup
        /// </summary>
        public void UpgradeContent()
        {
            foreach (var track in Tracks.Where(t => t.AlphamericTitle == null))
            {
                log.Warning($"track {track.Title} [T-{track.Id}] has no alphameric text");
                track.AlphamericTitle = track.Title.ToAlphaNumerics().ToLower();
            }
            foreach (var work in Works.Where(w => w.AlphamericName == null))
            {
                log.Warning($"work {work.Name} [W-{work.Id}] has no alphameric text");
                work.AlphamericName = work.Name.ToAlphaNumerics().ToLower();
            }
            foreach (var performance in Performances.Where(w => w.AlphamericPerformers == null))
            {
                log.Warning($"performance {performance.Performers} [P-{performance.Id}] has no alphameric text");
                performance.AlphamericPerformers = performance.Performers.ToAlphaNumerics().ToLower();
            }
            foreach (var composition in Compositions.Where(w => w.AlphamericName == null))
            {
                log.Warning($"composition {composition.Name} [C-{composition.Id}] has no alphameric text");
                composition.AlphamericName = composition.Name.ToAlphaNumerics().ToLower();
            }


            var toBeRemoved = TaskItems.Where(x => x.Type != TaskType.ResampleWork).ToList();

            toBeRemoved.AddRange(TaskItems.Where(x => x.Status == Core.TaskStatus.Finished || x.Status == Core.TaskStatus.Failed));
            TaskItems.RemoveRange(toBeRemoved);
            log.Information($"{toBeRemoved.Count()} task items removed");
            TaskItems.ToList().ForEach(x => x.Status = Core.TaskStatus.Pending);
            SaveChanges();
//#if DEBUG
//            var allItems = TaskItems.ToArray();
//            TaskItems.RemoveRange(allItems);
//            log.Warning($"{allItems.Count()} task items removed");
//#else
//            var staleTaskItemDate = DateTimeOffset.Now - TimeSpan.FromDays(5);
//            foreach (var item in TaskItems.Where(t => t.CreatedAt < staleTaskItemDate).ToArray())
//            {
//                switch(item.Status)
//                {
//                    case Core.TaskStatus.Finished:
//                        break;
//                    case Core.TaskStatus.Failed:
//                        log.Warning($"Task {item.Type} created on {item.CreatedAt.ToDefaultWithTime()} for {item.TaskString} failed - removed");
//                        break;
//                    default:
//                        log.Warning($"Task {item.Type} created on {item.CreatedAt.ToDefaultWithTime()} for {item.TaskString}, status {item.Status} - removed");
//                        break;
//                }
//                TaskItems.Remove(item);
//            }
//#endif
//            SaveChanges();
        }
        private void RemoveCompositions()
        {
            foreach (var child in Compositions.Where(x => x.IsChecked).ToList())
            {
                child.IsChecked = false;
                if (child.State == ItemState.Added)
                {
                    Compositions.Remove(child);
                }
                else
                {
                    child.State = ItemState.Removed;
                }
            }

            CompositionsView.Refresh();
            CheckItem();
        }
        private void Save()
        {
            var removed = Compositions.Where(x => x.State == ItemState.Removed).ToList();

            removed.ForEach(x => Compositions.Remove(x));

            var added = Compositions.Where(x => x.State == ItemState.Added).ToList();

            added.ForEach(x => x.State = ItemState.Unchanged);

            var updated = Compositions.Where(x => x.State == ItemState.Updated).ToList();

            updated.ForEach(x => x.State = ItemState.Unchanged);

            _providerFactory.CompositionsProvider.RemoveCompositions(removed);
            _providerFactory.CompositionsProvider.AddCompositions(added);
            _providerFactory.CompositionsProvider.UpdateCompositions(updated);

            _providerFactory.CompositionsProvider.SaveChanges();

            CheckItem();
        }
Пример #4
0
        public IEnumerable <ApplicationRelationshipDefinition> CollectionRelationships()
        {
            IEnumerable <ApplicationRelationshipDefinition> applicationAssociations = Associations.Where(a => a.Collection);
            IEnumerable <ApplicationRelationshipDefinition> applicationCompositions = Compositions.Where(a => a.Collection);

            return(applicationAssociations.Union(applicationCompositions));
        }