Esempio n. 1
0
        public static ForestNode <DirectoryInfoCache> ForestWithSync(DirectoryInfo cur)
        {
            var dic = DirectoryInfoCache.CreateRoot(cur);

            dic.SyncAllToFileSystem();
            return(Forest(dic));
        }
Esempio n. 2
0
        private DirectoryInfoCache SaveToCache(DirectoryInfo di)
        {
            var diCache = new DirectoryInfoCache(this, di);

            _children.Add(diCache);
            return(diCache);
        }
Esempio n. 3
0
        private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi)
        {
            var baseDic = new DirectoryInfoCache(null, baseDi);

            baseDic.PossiblyMoveFromOutside = true;
            return(baseDic);
        }
Esempio n. 4
0
        internal virtual void MoveTo(DirectoryInfoCache from, FileInfo target, string destRelative)
        {
            var destDIC = EnsureSubdirectory(from, destRelative);

            WriteBlack(destDIC.FullName);
            SafeMoveTo(from, target, destDIC);
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 // do not contain top.
 internal void WriteGrayBetween(DirectoryInfoCache top, DirectoryInfoCache bottom)
 {
     while (bottom != top)
     {
         WriteGray(bottom.FullName);
         bottom = bottom.Parent;
     }
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
            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";
            }
Esempio n. 10
0
 public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item)
 {
     Parent = parent;
     if (parent != null)
         InterestedFilePattern = parent.InterestedFilePattern;
     PossiblyMoveFromOutside = false;
     Item = item;
     _fullName = NormalizedFullName(item.FullName);
     FileCount = 0;
 }
Esempio n. 11
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;
 }
Esempio n. 12
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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item)
 {
     Parent = parent;
     if (parent != null)
     {
         InterestedFilePattern = parent.InterestedFilePattern;
     }
     PossiblyMoveFromOutside = false;
     Item      = item;
     _fullName = NormalizedFullName(item.FullName);
     FileCount = 0;
 }
Esempio n. 15
0
        public void StartSplit()
        {
            Abort   = false;
            Current = StartDirectory;
            var root = DirectoryInfoCache.Forest(StartDirectory);

            _walker = root.Walker;

            _dirty.Clear();
            WriteBlack(StartDirectory.FullName);

            SyncDirectoryInfoCacheToFileSystem();
        }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
        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>();
        }
Esempio n. 18
0
        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();
            }
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        // 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;
                }
            }
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
 // 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;
         }
     }
 }
Esempio n. 23
0
 private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi)
 {
     var baseDic = new DirectoryInfoCache(null, baseDi);
     baseDic.PossiblyMoveFromOutside = true;
     return baseDic;
 }
Esempio n. 24
0
 // do not contain top.
 internal void WriteGrayBetween(DirectoryInfoCache top, DirectoryInfoCache bottom)
 {
     while (bottom != top)
     {
         WriteGray(bottom.FullName);
         bottom = bottom.Parent;
     }
 }
Esempio n. 25
0
 internal void MoveToDirect(DirectoryInfoCache from, FileInfo file, DirectoryInfoCache dest)
 {
     WriteBlack(dest.FullName);
     WriteGrayBetween(from, dest.Parent);
     SafeMoveTo(from, file, dest);
 }
Esempio n. 26
0
 private SplitFolder CreateSplitFolderForEnglish(DirectoryInfoCache root, DirectoryInfoCache c)
 {
     return CreateSplitFolder(root, c, new EnglishTactics());
 }
Esempio n. 27
0
 SplitFolder CreateSplitFolder(DirectoryInfoCache baseDIC, DirectoryInfoCache curDIC, ISplitTactics tactics)
 {
     var sf = new SplitFolder(baseDIC, tactics);
     sf.Current = curDIC;
     return sf;
 }
Esempio n. 28
0
 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;
 }
Esempio n. 29
0
 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;
 }
Esempio n. 30
0
        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();
            }
        }
Esempio n. 31
0
 DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub)
 {
     return(parent.EnsureSubdirectory(relativeSub));
 }
Esempio n. 32
0
        private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result)
        {
            SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese));

            return(sf);
        }
Esempio n. 33
0
 internal void MoveToDirect(DirectoryInfoCache from, FileInfo file, DirectoryInfoCache dest)
 {
     WriteBlack(dest.FullName);
     WriteGrayBetween(from, dest.Parent);
     SafeMoveTo(from, file, dest);
 }
Esempio n. 34
0
 DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub)
 {
     return parent.EnsureSubdirectory(relativeSub);
 }
Esempio n. 35
0
 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;
 }
Esempio n. 36
0
        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>();
        }
Esempio n. 37
0
 private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result)
 {
     SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese));
     return sf;
 }
Esempio n. 38
0
 private DirectoryInfoCache CreateDIC(DirectoryInfoCache baseDIC, string path)
 {
     var dic = CreateDIC(path);
     SetupDICParent(baseDIC, dic);
     return dic;
 }
Esempio n. 39
0
 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;
 }
Esempio n. 40
0
 internal virtual void MoveTo(DirectoryInfoCache from, FileInfo target, string destRelative)
 {
     var destDIC = EnsureSubdirectory(from, destRelative);
     WriteBlack(destDIC.FullName);
     SafeMoveTo(from, target, destDIC);
 }
Esempio n. 41
0
        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();
        }
Esempio n. 42
0
 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);
 }
Esempio n. 43
0
 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";
 }
Esempio n. 44
0
 private DirectoryInfoCache SaveToCache(DirectoryInfo di)
 {
     var diCache = new DirectoryInfoCache(this, di);
     _children.Add(diCache);
     return diCache;
 }