public static ForestNode <DirectoryInfoCache> ForestWithSync(DirectoryInfo cur) { var dic = DirectoryInfoCache.CreateRoot(cur); dic.SyncAllToFileSystem(); return(Forest(dic)); }
private DirectoryInfoCache SaveToCache(DirectoryInfo di) { var diCache = new DirectoryInfoCache(this, di); _children.Add(diCache); return(diCache); }
private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi) { var baseDic = new DirectoryInfoCache(null, baseDi); baseDic.PossiblyMoveFromOutside = true; return(baseDic); }
internal virtual void MoveTo(DirectoryInfoCache from, FileInfo target, string destRelative) { var destDIC = EnsureSubdirectory(from, destRelative); WriteBlack(destDIC.FullName); SafeMoveTo(from, target, destDIC); }
public void MoveTo(FileInfo target, DirectoryInfoCache to, string newName) { // Debug.Assert(Array.Exists(Item.GetFiles(InterestedFilePattern), (x) => x == target)); RawMoveTo(target, to.FullName, newName); to.AddFileCount(1); AddFileCount(-1); }
public static Dumper CreateHtmlGenerater(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter) { DumpAction htmlAction = DumpAction.CreateHtmlGeneraterAction(bzipPath, result.Item); var dumper = new Dumper(bzipPath, htmlAction, counter); SplitFolder sf = CreateSplitFolder(isJapanese, result); PostCreate(dumper, isJapanese, sf); return dumper; }
// do not contain top. internal void WriteGrayBetween(DirectoryInfoCache top, DirectoryInfoCache bottom) { while (bottom != top) { WriteGray(bottom.FullName); bottom = bottom.Parent; } }
public static Dumper CreateHtmlGenerater(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter) { DumpAction htmlAction = DumpAction.CreateHtmlGeneraterAction(bzipPath, result.Item); var dumper = new Dumper(bzipPath, htmlAction, counter); SplitFolder sf = CreateSplitFolder(isJapanese, result); PostCreate(dumper, isJapanese, sf); return(dumper); }
public ArchiveTask(DirectoryInfoCache workDir, Action <IEnumerable <FileInfo>, string> archive, string extension) { Archive = archive; var node = DirectoryInfoCache.Forest(workDir); _walker = node.Walker; Extension = extension; SourceExtension = ".html"; }
public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item) { Parent = parent; if (parent != null) InterestedFilePattern = parent.InterestedFilePattern; PossiblyMoveFromOutside = false; Item = item; _fullName = NormalizedFullName(item.FullName); FileCount = 0; }
public static Dumper CreateRawDumper(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter) { DumpAction rawDump = DumpAction.CreateRawDumpAction(bzipPath, result.Item); Dumper dumper = new Dumper(bzipPath, rawDump, counter); SplitFolder sf = CreateSplitFolder(isJapanese, result); // not DRY! sf.InterestedFilePattern = "*.wiki"; PostCreate(dumper, isJapanese, sf); return dumper; }
public static Dumper CreateRawDumper(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter) { DumpAction rawDump = DumpAction.CreateRawDumpAction(bzipPath, result.Item); Dumper dumper = new Dumper(bzipPath, rawDump, counter); SplitFolder sf = CreateSplitFolder(isJapanese, result); // not DRY! sf.InterestedFilePattern = "*.wiki"; PostCreate(dumper, isJapanese, sf); return(dumper); }
public static ForestNode <DirectoryInfoCache> Forest(DirectoryInfoCache dic) { ForestNode <DirectoryInfoCache> root = new ForestNode <DirectoryInfoCache>(ForestNode <DirectoryInfoCache> .Edge.Leading, dic, (x, i) => x.GetChild(i), (x) => x.Parent, (x) => x.ChildrenLength, (x) => x.ChildIndex, (x, y) => x.FullName == y.FullName); return(root); }
public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item) { Parent = parent; if (parent != null) { InterestedFilePattern = parent.InterestedFilePattern; } PossiblyMoveFromOutside = false; Item = item; _fullName = NormalizedFullName(item.FullName); FileCount = 0; }
public void StartSplit() { Abort = false; Current = StartDirectory; var root = DirectoryInfoCache.Forest(StartDirectory); _walker = root.Walker; _dirty.Clear(); WriteBlack(StartDirectory.FullName); SyncDirectoryInfoCacheToFileSystem(); }
public override bool Equals(object other) { if (other == null) { return(((object)this) == null); } if (other is DirectoryInfoCache) { DirectoryInfoCache dic = other as DirectoryInfoCache; return(_fullName == dic.FullName); } return(false); }
public SplitFolder(DirectoryInfoCache baseDi, ISplitTactics tactics) { _splitDictInit = true; Base = baseDi; Abort = false; _tactics = tactics; Current = Base; StartDirectory = Current; MaxFileNum = WikipediaConv.Properties.Settings.Default.OneFolderMaxFileNum; _dirty = new Dictionary <string, Dirtiness>(); }
public void SyncAllToFileSystem() { Debug.Assert(this.Parent == null); var walker = DirectoryInfoCache.Forest(this).Walker; while (walker.HasNext) { walker.MoveNext(); var node = walker.Current; if (node.CurrentEdge == ForestNode <DirectoryInfoCache> .Edge.Trailing) { continue; } node.Element.SyncToFileSystem(); } }
DirectoryInfoCache GetWorkingDirectory(string bzipPath, string dirName, string interestedFilePattern) { if (_workingDir != null) { return(_workingDir); } var parent = new FileInfo(bzipPath).Directory; DirectoryInfo di = new DirectoryInfo(Path.Combine(parent.FullName, dirName)); if (!di.Exists) { di.Create(); } _workingDir = DirectoryInfoCache.CreateRoot(di); _workingDir.InterestedFilePattern = interestedFilePattern; _workingDir.SyncAllToFileSystem(); return(_workingDir); }
// rename if name is dup private static void SafeMoveTo(DirectoryInfoCache from, FileInfo target, DirectoryInfoCache destDIC) { var newName = target.Name; for (int i = 0; i < 10; i++) { try { from.MoveTo(target, destDIC, newName); return; } catch (IOException) { var fname = Path.GetFileNameWithoutExtension(newName); var extension = Path.GetExtension(newName); fname += 'X'; newName = fname + extension; } } }
private bool SortToSubdirectories() { bool moveSomething = false; foreach (var file in FileEnum) { DirectoryInfoCache dest = GetDest(file); if (dest != null) { moveSomething = true; MoveToDirect(Current, file, dest); } else { var destRelative = GetOneMatchedSubdirectoryRelativePath(file); if (!String.IsNullOrEmpty(destRelative)) { moveSomething = true; MoveTo(Current, file, destRelative); } } } return(moveSomething); }
private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi) { var baseDic = new DirectoryInfoCache(null, baseDi); baseDic.PossiblyMoveFromOutside = true; return baseDic; }
internal void MoveToDirect(DirectoryInfoCache from, FileInfo file, DirectoryInfoCache dest) { WriteBlack(dest.FullName); WriteGrayBetween(from, dest.Parent); SafeMoveTo(from, file, dest); }
private SplitFolder CreateSplitFolderForEnglish(DirectoryInfoCache root, DirectoryInfoCache c) { return CreateSplitFolder(root, c, new EnglishTactics()); }
SplitFolder CreateSplitFolder(DirectoryInfoCache baseDIC, DirectoryInfoCache curDIC, ISplitTactics tactics) { var sf = new SplitFolder(baseDIC, tactics); sf.Current = curDIC; return sf; }
private static DirectoryInfoCache SetupDICParent(DirectoryInfoCache baseDIC, DirectoryInfoCache cur) { while (baseDIC != cur) { var parentCand = new DirectoryInfoCache(null, cur.Item.Parent); if (baseDIC.FullName == parentCand.FullName) parentCand = baseDIC; cur.Parent = parentCand; cur.Parent.Children.Add(cur); cur = cur.Parent; } return cur; }
DirectoryInfoCache GetWorkingDirectory(string bzipPath, string dirName, string interestedFilePattern) { if (_workingDir != null) return _workingDir; var parent = new FileInfo(bzipPath).Directory; DirectoryInfo di = new DirectoryInfo(Path.Combine(parent.FullName, dirName)); if (!di.Exists) { di.Create(); } _workingDir = DirectoryInfoCache.CreateRoot(di); _workingDir.InterestedFilePattern = interestedFilePattern; _workingDir.SyncAllToFileSystem(); return _workingDir; }
private void DumpFileToArchive(string[] files, Action <IEnumerable <FileInfo>, string> archive, Func <string, bool, DirectoryInfoCache, PerfCounter, Dumper> createDumper, DirectoryInfoCache workingDir, string outputExtension, string sourceExtension) { if (EnableAutoLogging) { // use parent of pdf/epub folder. _counter.SetOutputFolder(workingDir.Item.Parent.FullName); } using (var uwAll = _counter.UsingWatch("All")) { foreach (string file in files) { bool isJapanese = IsJapanese(file); Dumper gen = createDumper(file, isJapanese, workingDir, _counter); gen.EnableAutoLogging = EnableAutoLogging; if (DialogResult.OK != new ProgressDialog(gen.LongTask, _counter).ShowDialog(this)) { // MessageBox.Show("generate html cancelled"); // tmp fall through. // return; } } using (var uwArchive = _counter.UsingWatch("Archive")) { ArchiveTask archiveTask = new ArchiveTask(workingDir, archive, outputExtension); archiveTask.SourceExtension = sourceExtension; if (DialogResult.OK != new ProgressDialog(archiveTask, _counter).ShowDialog(this)) { MessageBox.Show("generate epub cancelled"); return; } } } if (EnableAutoLogging) { _counter.DumpToLog(); } }
DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub) { return(parent.EnsureSubdirectory(relativeSub)); }
private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result) { SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese)); return(sf); }
DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub) { return parent.EnsureSubdirectory(relativeSub); }
SplitFolder CreateSplitFolder(DirectoryInfo baseDi, DirectoryInfo curDi) { var sf = new SplitFolder(baseDi); var cur = new DirectoryInfoCache(null, curDi); sf.Current = cur; // setup parent var baseDIC = sf.StartDirectory; cur = SetupDICParent(baseDIC, cur); Assert.AreEqual(sf.StartDirectory, cur); return sf; }
public SplitFolder(DirectoryInfoCache baseDi, ISplitTactics tactics) { _splitDictInit = true; Base = baseDi; Abort = false; _tactics = tactics; Current = Base; StartDirectory = Current; MaxFileNum = WikipediaConv.Properties.Settings.Default.OneFolderMaxFileNum; _dirty = new Dictionary<string, Dirtiness>(); }
private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result) { SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese)); return sf; }
private DirectoryInfoCache CreateDIC(DirectoryInfoCache baseDIC, string path) { var dic = CreateDIC(path); SetupDICParent(baseDIC, dic); return dic; }
public static ForestNode<DirectoryInfoCache> Forest(DirectoryInfoCache dic) { ForestNode<DirectoryInfoCache> root = new ForestNode<DirectoryInfoCache>(ForestNode<DirectoryInfoCache>.Edge.Leading, dic, (x, i) => x.GetChild(i), (x) => x.Parent, (x) => x.ChildrenLength, (x) => x.ChildIndex, (x, y) => x.FullName == y.FullName); return root; }
private void DumpFileToArchive(string[] files, Action<IEnumerable<FileInfo>, string> archive, Func<string, bool, DirectoryInfoCache, PerfCounter, Dumper> createDumper, DirectoryInfoCache workingDir, string outputExtension, string sourceExtension) { if (EnableAutoLogging) { // use parent of pdf/epub folder. _counter.SetOutputFolder(workingDir.Item.Parent.FullName); } using (var uwAll = _counter.UsingWatch("All")) { foreach (string file in files) { bool isJapanese = IsJapanese(file); Dumper gen = createDumper(file, isJapanese, workingDir, _counter); gen.EnableAutoLogging = EnableAutoLogging; if (DialogResult.OK != new ProgressDialog(gen.LongTask, _counter).ShowDialog(this)) { // MessageBox.Show("generate html cancelled"); // tmp fall through. // return; } } using (var uwArchive = _counter.UsingWatch("Archive")) { ArchiveTask archiveTask = new ArchiveTask(workingDir, archive, outputExtension); archiveTask.SourceExtension = sourceExtension; if (DialogResult.OK != new ProgressDialog(archiveTask, _counter).ShowDialog(this)) { MessageBox.Show("generate epub cancelled"); return; } } } if (EnableAutoLogging) _counter.DumpToLog(); }
public ArchiveTask(DirectoryInfoCache workDir, Action<IEnumerable<FileInfo>, string> archive, string extension) { Archive = archive; var node = DirectoryInfoCache.Forest(workDir); _walker = node.Walker; Extension = extension; SourceExtension = ".html"; }
private DirectoryInfoCache SaveToCache(DirectoryInfo di) { var diCache = new DirectoryInfoCache(this, di); _children.Add(diCache); return diCache; }