Example #1
0
        /// <summary>ベースフォルダが指定されている場合、ベースフォルダを検索し、登録されていないデータを新たに登録します</summary>
        /// <param name="baseFolderPath">ベースフォルダリスト</param>
        /// <exception cref="DirectoryNotFoundException">ベースフォルダが存在しない。または指定されていない</exception>
        public static void SyncBaseFolder(string baseFolderPath)
        {
            shelf = shelf.ReadJson(baseFolderPath);
            Array.ForEach(shelf.Books.ToArray(), b => b.Status = AnalyzeResult.NotRunning);
            foreach (var b in shelf.Books.Where(b => sortedbooks.ContainsKey(b.Hash)))
            {
                sortedbooks.Add(b.Hash, b);
            }

            // ファイルの検索と除外処理
            var syncPaths = new HashSet <string>(shelf.Books.Select(b => b.FilePath.ToLower()).OrderBy(v => v));
            IEnumerable <string> files = GetAllFiles(baseFolderPath, "*").AsParallel();

            files = files.Where(f => extensions.Contains(Path.GetExtension(f).ToLower()));
            var count = files.Count();

            files = files.Where(f => !syncPaths.Contains(f.ToLower()));
            Console.WriteLine($"ファイル>書籍ファイル総数:{count},新規・変更数:{files.Count()}");

            foreach (var filePath in files)
            {
                var book = new BookModel(filePath);
                book = CheckHash(book);
                Console.WriteLine($"{LabelAttributeUtils.GetLabelName(book.Status)}>{book.FilePath}");
            }

            var books = shelf.Books.Where(b => b.Status == AnalyzeResult.NotRunning);

            foreach (var book in books)
            {
                if (!book.FileExists())
                {
                    book.Status = AnalyzeResult.FileNotFound;
                    Console.WriteLine($"{LabelAttributeUtils.GetLabelName(book.Status)}>{book.FilePath}");
                }
            }

            shelf.WriteJson();
        }
Example #2
0
        /// <summary>ラベル編集完了イベント</summary>
        /// <param name="sender">発生元オブジェクト</param>
        /// <param name="e">イベント情報</param>
        private void SelectListView_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(e.Label))
            {
                e.CancelEdit = true;
                return;
            }

            try
            {
                var target = (ListView)sender;

                var filePath = target.Items[e.Item].SubItems[1].Text;
                var shelf    = new ShelfModel().ReadJson(filePath);
                shelf.Title = e.Label;
                shelf.WriteJson();
                this.ShowBooksList();
            }
            catch
            {
                MessageBox.Show(this, "変更できませんでした。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.CancelEdit = true;
            }
        }