Пример #1
0
        private void TagImage(ITagManager tagManager)
        {
            foreach (var tagName in TagNames)
            {
                var tag = TagFacade.FindByTagName(tagName);

                if (tag == null)
                {
                    tag = new TagViewModel(Guid.NewGuid(), tagName);
                    TagFacade.Insert(tag);
                    tagManager.Tags.Add(tag);
                }

                _images = new List <ImageViewModel>();

                var pages = PageFacade.FindByBookId(_BookID);
                for (int i = 0; i < pages.Count(); ++i)
                {
                    var page = pages.ElementAt(i);
                    PageFacade.GetProperty(ref page);
                    _images.Add(page.Image);
                }

                ImageTagFacade.BatchInsert(tag, _images);

                foreach (var imageTag in _images.Select(i => new ImageTagViewModel(i.ID, tag)))
                {
                    tagManager.Chains.Add(imageTag);
                }
            }
        }
Пример #2
0
        public override void ConfigureTaskImplementation(AsyncTaskSequence sequence)
        {
            sequence.Add(new Task(() =>
            {
                if (TagFacade.Exists(TagName))
                {
                    _tag = TagFacade.FindByTagName(TagName);
                }
                else
                {
                    _tag = new TagViewModel(Guid.NewGuid(), TagName);
                    TagFacade.Insert(_tag);
                }
            }));

            sequence.Add(new Task(() =>
            {
                _images = new List <ImageViewModel>();
            }));

            foreach (var entry in Entries)
            {
                var book = entry as BookViewModel;
                if (book != null)
                {
                    _pages = PageFacade.FindByBookId(book.ID);

                    for (int i = 0; i < _pages.Count(); ++i)
                    {
                        var p = _pages.ElementAt(i);
                        sequence.Add(new Task(() =>
                        {
                            GetPropertyIfImageIsNull(ref p);
                            _images.Add(p.Image);
                        }));
                    }
                    sequence.Add(new Task(() =>
                    {
                        var newEntity = new BookTagViewModel(book, _tag);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }

                var page = entry as PageViewModel;
                if (page != null)
                {
                    sequence.Add(new Task(() =>
                    {
                        GetPropertyIfImageIsNull(ref page);
                        _images.Add(page.Image);
                    }));

                    sequence.Add(new Task(() =>
                    {
                        var newEntity = new BookTagViewModel(page.BookID, _tag.ID);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }

                var image = entry as ImageViewModel;
                if (image != null)
                {
                    sequence.Add(new Task(() =>
                    {
                        _images.Add(image);
                    }));

                    sequence.Add(new Task(() =>
                    {
                        var tempPage  = PageFacade.FindByImageId(image.ID);
                        var newEntity = new BookTagViewModel(tempPage.BookID, _tag.ID);
                        if (!BookTagFacade.Exists(newEntity))
                        {
                            BookTagFacade.Insert(newEntity);
                        }
                    }));
                    continue;
                }
            }

            sequence.Add(new Task(() =>
            {
                ImageTagFacade.BatchInsert(_tag, _images);
            }));

            sequence.Add(new Task(() =>
            {
                var chains = from x in _images
                             where TagManager.Value.Chains.Count(c => c.ImageID == x.ID && c.TagID == _tag.ID) == 0
                             select new ImageTagViewModel(x.ID, _tag);

                foreach (var chain in chains)
                {
                    TagManager.Value.Chains.Add(chain);
                }
            }));

            sequence.Add(new Task(() =>
            {
                if (!TagManager.Value.Tags.Contains(_tag))
                {
                    TagManager.Value.Tags.Add(_tag);
                }
            }));

            sequence.Add(new Task(() => TagManager.Value.SelectedEntityTags = TagManager.Value.GetCommonTags()));
            sequence.Add(new Task(() => TagManager.Value.ObserveSelectedEntityTags()));
        }
Пример #3
0
        public static List <Task> GenerateAddImageTagTasks(ITagManager tagManager, IEnumerable <EntryViewModel> entries, string tagName)
        {
            List <Task> tasks = new List <Task>();

            var ita = new ImageTagAdding();

            tasks.Add(new Task(() =>
            {
                if (TagFacade.Exists(tagName))
                {
                    ita._tag = TagFacade.FindByTagName(tagName);
                }
                else
                {
                    ita._tag = new TagViewModel(Guid.NewGuid(), tagName);
                    TagFacade.Insert(ita._tag);
                }
            }));

            tasks.Add(new Task(() =>
            {
                ita._images = new List <ImageViewModel>();
            }));

            foreach (var entry in entries)
            {
                var book = entry as BookViewModel;
                if (book != null)
                {
                    ita._pages = PageFacade.FindByBookId(book.ID);

                    for (int i = 0; i < ita._pages.Count(); ++i)
                    {
                        var p = ita._pages.ElementAt(i);
                        tasks.Add(new Task(() =>
                        {
                            GetPropertyIfImageIsNull(ref p);
                            ita._images.Add(p.Image);
                        }));
                    }
                    continue;
                }

                var page = entry as PageViewModel;
                if (page != null)
                {
                    tasks.Add(new Task(() =>
                    {
                        GetPropertyIfImageIsNull(ref page);
                        ita._images.Add(page.Image);
                    }));
                    continue;
                }

                var image = entry as ImageViewModel;
                if (image != null)
                {
                    tasks.Add(new Task(() =>
                    {
                        ita._images.Add(image);
                    }));
                    continue;
                }
            }

            tasks.Add(new Task(() =>
            {
                ImageTagFacade.BatchInsert(ita._tag, ita._images);
            }));

            tasks.Add(new Task(() =>
            {
                var chains = from x in ita._images
                             where tagManager.Chains.Count(c => c.ImageID == x.ID && c.TagID == ita._tag.ID) == 0
                             select new ImageTagViewModel(x.ID, ita._tag);

                foreach (var chain in chains)
                {
                    tagManager.Chains.Add(chain);
                }
            }));

            tasks.Add(new Task(() =>
            {
                if (!tagManager.Tags.Contains(ita._tag))
                {
                    tagManager.Tags.Add(ita._tag);
                }
            }));

            tasks.Add(new Task(() => tagManager.SelectedEntityTags = tagManager.GetCommonTags()));
            tasks.Add(new Task(() => tagManager.ObserveSelectedEntityTags()));

            return(tasks);
        }