/// <summary> /// ToString method from <see cref="WikiEngine.WikiFolderInfo"/>WikiEngine.WikiFolderInfo to MarkDown /// Page/Media/Attic List /// </summary> /// <param name="wfi"><see cref="WikiEngine.WikiFolderInfo"/>WikiEngine.WikiFolderInfo input</param> /// <param name="sb">StringBuilder instance or null</param> /// <param name="type"><see cref="WikiEngine.WikiFileType"/>WikiEngine.WikiFileType, if this equals WikiFileType.FileReadAttic, return only date from attic</param> /// <returns>String or String.Empty</returns> public string ResourceListToMdString(WikiFolderInfo wfi, StringBuilder sb = null, WikiFileType type = WikiFileType.None) { Action act; WikiFileAction wfa = new WikiFileAction(sb); wfa.IsAllFiles = true; switch (type) { // Attic date and time list to Md string case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { act = (Action)(() => this._WikiFileActionRecursive(wfi, wfa, this._ActionAtticDateList)); break; } default: { act = (Action)(() => this._WikiFileActionRecursive(wfi, wfa, this._ActionResourceList)); break; } } string sOut = this._ToMd( (object)new Object(), act, wfa.IsSBuilder, wfa.SBuilder ); return(string.Format( Properties.ResourceWikiEngine.ListFormatPageStatistic, sOut, ((string.IsNullOrWhiteSpace(wfi.SearchPatern)) ? wfi.NameSpace : wfi.SearchPatern), wfa.ConutDirs, wfa.ConutFiles, Environment.NewLine )); }
internal void _ActionAtticDateList(WikiFileAction wfa) { if ( (wfa == null) || (wfa.FileInfo == null) ) { return; } switch (wfa.FileInfo.FileType) { case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { string FileNameUri, FileTimeStamp; FileNameUri = Path.GetFileNameWithoutExtension(wfa.FileInfo.FileName); FileNameUri = Path.GetFileNameWithoutExtension(FileNameUri); FileTimeStamp = Path.GetExtension(FileNameUri); DateTime TimeStamp = Util.DokuUtil.GetDateTimeFromUnixTimeStampString( FileTimeStamp.Substring(1, (FileTimeStamp.Length - 1)) ); wfa.SBuilder.AppendFormat( Properties.ResourceWikiEngine.ListFormatAtticDate, WikiFile.wikiLocalPath, WikiFile.wikiLocalAttic, wfa.NameSpace, FileNameUri, TimeStamp.ToString() ); break; } default: { return; } } }
internal void _ActionResourceList(WikiFileAction wfa) { if ( (wfa == null) || (wfa.FileInfo == null) ) { return; } bool isNewNameSpace = ((string.IsNullOrWhiteSpace(wfa.LastNameSpace)) ? true : ((wfa.LastNameSpace.Equals(wfa.NameSpace)) ? false : true) ); if (isNewNameSpace) { wfa.LastNameSpace = wfa.NameSpace; wfa.SBuilder.AppendFormat( Properties.ResourceWikiEngine.ListFormatNameSpace, WikiFile.wikiLocalPath, DokuUtil.WikiFileTypeToString(wfa.FileInfo.FileType), wfa.NameSpace, ((string.IsNullOrWhiteSpace(wfa.NameSpace)) ? Properties.ResourceWikiEngine.txtHomePageTitle : wfa.NameSpace ), Environment.NewLine ); } switch (wfa.FileInfo.FileType) { case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { string FileNameUri, FileNameTxt, FileTimeStamp; FileNameUri = Path.GetFileNameWithoutExtension(wfa.FileInfo.FileName); FileNameUri = Path.GetFileNameWithoutExtension(FileNameUri); FileNameTxt = Path.GetFileNameWithoutExtension(FileNameUri); FileTimeStamp = Path.GetExtension(FileNameUri); DateTime TimeStamp = Util.DokuUtil.GetDateTimeFromUnixTimeStampString( FileTimeStamp.Substring(1, (FileTimeStamp.Length - 1)) ); wfa.SBuilder.AppendFormat( Properties.ResourceWikiEngine.ListFormatAttic, WikiFile.wikiLocalPath, WikiFile.wikiLocalAttic, wfa.NameSpace, FileNameUri, FileNameTxt, TimeStamp.ToString(), Environment.NewLine ); break; } case WikiFileType.FileReadMd: case WikiFileType.FileWriteMd: { wfa.SBuilder.AppendFormat( Properties.ResourceWikiEngine.ListFormatPage, WikiFile.wikiLocalPath, WikiFile.wikiLocalPage, wfa.NameSpace, wfa.FileInfo.FileName, wfa.FileInfo.TimeWrite.ToShortDateString(), Environment.NewLine ); break; } case WikiFileType.FileReadBinary: case WikiFileType.FileWriteBinary: { wfa.SBuilder.AppendFormat( Properties.ResourceWikiEngine.ListFormatMedia, WikiFile.wikiLocalPath, WikiFile.wikiLocalMedia, wfa.NameSpace, wfa.FileInfo.FileName, Path.GetFileNameWithoutExtension(wfa.FileInfo.FileName), wfa.FileInfo.FileExt, wfa.FileInfo.TimeWrite.ToShortDateString(), Environment.NewLine ); break; } default: { return; } } }
/// <summary> /// Recursive Action, use in: /// <see cref="_SetFileLock(WikiEngine.WikiData, bool)"/> /// </summary> /// <param name="wfi"><see cref="WikiEngine.WikiFolderInfo"/></param> /// <param name="wfa"><see cref="WikiEngine.WikiFileAction"/></param> /// <param name="act">Action<WikiEngine.WikiFileAction></param> /// <returns>Bolean</returns> internal bool _WikiFileActionRecursive( WikiFolderInfo wfi, WikiFileAction wfa, Action <WikiFileAction> act ) { bool isUpdate = false; if ( (act == null) || (wfa == null) || (wfi == null) ) { return(false); } if (wfi.Files.Count > 0) { wfa.ConutFile = 0; wfa.NameSpace = wfi.NameSpace; wfa.ConutFiles += wfi.Files.Count; wfi.Files.ForEach(o => { if ( (wfa.IsAllFiles) || (o.FileName.Equals(wfa.Search)) ) { wfa.FileInfo = o; wfa.ConutFile++; act(wfa); isUpdate = true; if (!wfa.IsAllFiles) { return; } } }); if ( (!wfa.IsAllFiles) && (isUpdate) ) { return(isUpdate); } } if (wfi.Dirs.Count > 0) { wfa.ConutDirs += wfi.Dirs.Count; foreach (KeyValuePair <string, WikiFolderInfo> item in wfi.Dirs) { wfa.Key = ((string)item.Key); bool ret = _WikiFileActionRecursive( ((WikiFolderInfo)item.Value), wfa, act ); isUpdate = ((isUpdate) ? isUpdate : ret); } } return(isUpdate); }