コード例 #1
0
        public TagRegisterItem(FileContent file)
        {
            FileContent = file;

            if (Regex.IsMatch(file.Name, RegexPattern1)) {
                SearchWord = Regex.Match(file.Name, RegexPattern1).Groups[1].Value;
            } else if (Regex.IsMatch(file.Name, RegexPattern2)) {
                SearchWord = Path.GetFileNameWithoutExtension(
                    Regex.Match(file.Name, RegexPattern2).Groups[1].Value);
            } else {
                SearchWord = Path.GetFileNameWithoutExtension(file.FullPath);
            }
        }
コード例 #2
0
        /// <summary>
        /// コンテンツ読み込み
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="option"></param>
        public void LoadContents(DirectoryNodeViewModel dir, SearchOption option = SearchOption.TopDirectoryOnly) {
            if (dir is RootNodeViewModel) return;

            // キャンセルトークン生成
            Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<CancellationTokenSource> Cancel");
            Logger("<CancellationTokenSource> Cancel");
            foreach (var source in tokenSources.Values) {
                source.Cancel(true);
            }
            if (!tokenSources.ContainsKey(dir.FullPath))
                tokenSources.Add(dir.FullPath, new CancellationTokenSource());

            // コンテンツ取得
            FileContents = new ObservableCollection<FileContent>();
            Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<LoadContents> " + dir.Name);
            Logger("<LoadContents> " + dir.Name);

            var entries = new DirectoryInfo(dir.FullPath).EnumerateFileSystemInfos("*", option)
                .Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden) && !f.Attributes.HasFlag(FileAttributes.System))
                .OrderBy(f => f.FullName)
                .OrderByDescending(f => f.Attributes.HasFlag(FileAttributes.Directory));

            // コンテンツロード
            if (tokenSources.ContainsKey(dir.FullPath)) {
                CancellationToken token = tokenSources[dir.FullPath].Token;

                foreach (var entry in entries) {
                    // 無視ファイルリスト照合
                    if (Properties.Settings.Default.IgnoreFiles.Cast<string>().Any(f => f == entry.Name))
                        continue;

                    FileContent content = new FileContent(entry, token) {
                        VirtualPath = dir.VirtualPath + "/" + entry.Name
                    };
                    content.LoadTag += (tag) => Logger("<LoadTag> " + entry.Name);
                    content.DirectoryOpened += (sender, vpath) => DirectoryOpened(sender, vpath);
                    content.Remove += (sender) => FileContents.Remove(sender as FileContent);
                    FileContents.Add(content);

                    //Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<LoadContens> Add " + entity.Name);
                }
                Logger("<LoadContents> Read Entries");

                //Thumbnails
                Task.Factory.StartNew(() => {
                    foreach (var content in FileContents.Where(a => !a.IsDirectory)) {
                        if (token.IsCancellationRequested) {
                            //Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<Cancellation Thumbnails> Cancellation Requested");
                            break;
                        }
                        Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<LoadThumbnails> " + content.Name);
                        Logger("<LoadThumbnails> " + content.Name);
                        content.LoadThumbnails();
                    }
                }, token).ContinueWith((a) => {
                    tokenSources[dir.FullPath].Dispose();
                    tokenSources.Remove(dir.FullPath);
                });
            }

            Debug.WriteLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff") + " " + "<LoadContents> Exit");
            Logger("<LoadContents> Exit " + dir.Name);

            CurrentDirectory = dir;
            Settings.Default.DefaultPath = dir.VirtualPath;
            Settings.Default.Save();
        }