Пример #1
0
 public void RemoveImage(Thumbnail thumb)
 {
     Images.Remove(thumb);
 }
Пример #2
0
 public void AddImage(Thumbnail thumb)
 {
     Images.Add(thumb);
 }
Пример #3
0
 public void RemoveImageData(Category category, Thumbnail thumb)
 {
     category.RemoveImage(thumb);
     dataManager.RemoveImage(thumb, category.Title);
 }
Пример #4
0
 public void AddImageFirst(Thumbnail thumb)
 {
     Images.Insert(0, thumb);
 }
Пример #5
0
        void GetCategoriesFromData(Action callback)
        {
            var thread = new Thread(() =>
            {
                var files  = Directory.GetFiles(folderPath, "*.png");
                var sorted = files.Select(x => new KeyValuePair <string, FileInfo>(x, new FileInfo(x))).ToList();
                sorted.Sort((KeyValuePair <string, FileInfo> a, KeyValuePair <string, FileInfo> b) => b.Value.LastWriteTime.CompareTo(a.Value.LastWriteTime));

                if (files.Length > 0)
                {
                    uiContext.Post((x) => ProgressMax.Value = files.Length, null);
                }

                var newCategories = new Dictionary <string, Category>();
                var undefined     = new Category(Category.DEFAULT_CATEGORY_NAME);
                newCategories.Add(Category.DEFAULT_CATEGORY_NAME, undefined);
                var dataCategories = dataManager.GetCategories();

                int count = 0;
                foreach (var file in sorted)
                {
                    if (stopThread)
                    {
                        break;
                    }

                    bool found = false;
                    var thumb  = new Thumbnail(file.Key, file.Value.LastWriteTime, file.Value.Length);

                    foreach (var category in dataCategories)
                    {
                        if (found)
                        {
                            break;
                        }

                        if (!newCategories.TryGetValue(category.categoryName, out Category currentCategory))
                        {
                            currentCategory = new Category(category.categoryName);
                            newCategories.Add(currentCategory.Title, currentCategory);
                        }

                        foreach (var card in category.cards)
                        {
                            if (found)
                            {
                                break;
                            }

                            if (Path.Combine(folderPath, card) == file.Key)
                            {
                                currentCategory.AddImage(thumb);
                                found = true;
                            }
                        }
                    }

                    if (!found)
                    {
                        undefined.AddImage(thumb);
                    }

                    ++count;
                    uiContext.Post((x) => ProgressVal.Value = count, null);
                }

                if (!stopThread)
                {
                    uiContext.Post((x) =>
                    {
                        foreach (var cat in newCategories)
                        {
                            Categories.Add(cat.Key, cat.Value);
                        }

                        callback();
                    }, null);
                }

                stopThread = false;
            });

            thread.IsBackground = true;
            thread.Start();
        }