/// <summary> /// ToString method from <see cref="WikiEngine.WikiData"/>WikiEngine.WikiData to MarkDown /// </summary> /// <param name="wd">Data in WikiEngine.WikiData format</param> /// <param name="isPageInfo">Bolean print Page information before</param> /// <param name="sb">StringBuilder instance or null</param> /// <returns>String or String.Empty</returns> public string PageToMdString(WikiData wd, bool isPageInfo = false, StringBuilder sb = null) { bool IsSBuilder = this._CheckStringBuilder(ref sb); return(this._ToMd( (object)wd, (Action)(() => this._ActionPageSource(wd, sb, isPageInfo)), IsSBuilder, sb )); }
/// <summary> /// Constructor WikiFileAction /// </summary> /// <param name="wd">class WikiData</param> /// <param name="status">set status</param> public WikiFileAction(WikiData wd, bool status = false) : this(wd, status, null) { if ( (wd == null) || (string.IsNullOrWhiteSpace(wd.FileName)) ) { throw new WikiEngineInternalStructErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorGetResource, Properties.ResourceWikiEngine.txtErrorSearchEmpty, this.GetType().Name ) ); } }
private void _ActionPageSource(WikiData wd, StringBuilder sb, bool isPageInfo) { if ( (wd.FileContent == null) || (wd.FileContent.Length == 0) ) { sb.AppendFormat( Properties.ResourceWikiEngine.PageToMdError2, Environment.NewLine, wd.NameSpace, wd.FileName, wd.FileExt ); return; } if ( (wd.FileType != WikiEngine.WikiFileType.FileReadMd) && (wd.FileType != WikiEngine.WikiFileType.FileWriteMd) ) { sb.AppendFormat( Properties.ResourceWikiEngine.PageToMdError3, Environment.NewLine, wd.NameSpace, wd.FileName, wd.FileExt ); return; } if (isPageInfo) { sb.AppendFormat( Properties.ResourceWikiEngine.PageToMdError4, Environment.NewLine, wd.NameSpace, wd.FileName, wd.FileExt, wd.FilePath, Encoding.UTF8.GetString(wd.FileContent) ); } else { sb.Append(Encoding.UTF8.GetString(wd.FileContent)); } }
/// <summary> /// Constructor WikiFileAction /// </summary> /// <param name="wd">class WikiData</param> /// <param name="status">set status</param> /// <param name="sb">String Builder instance</param> public WikiFileAction(WikiData wd, bool status = false, StringBuilder sb = null) { Key = String.Empty; Status = status; IsAllFiles = false; LastNameSpace = String.Empty; ConutNameSpace = ConutFile = ConutDirs = ConutFiles = 0; if (wd == null) { Search = String.Empty; NameSpace = ":"; } else { Search = wd.FileName; NameSpace = ((string.IsNullOrWhiteSpace(wd.NameSpace)) ? ":" : wd.NameSpace); } IsSBuilder = (sb != null); SBuilder = sb; }
/// <summary> /// put page/media /// </summary> private byte[] _WikiPutFile(WikiFileType wft, string namesspace, WikiFileMeta wfm = null) { try { WikiData wd = null; WikiFileParse wfp = null; if (wfm == null) { throw new WikiEnginePutException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wft.ToString() ) ); } if ((wfp = (WikiFileParse)this._WikiFilesParse( wft, namesspace, null, null, true )) == null) { throw new WikiEngineInternalNameSpaceErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wft.ToString() ) ); } if ((wfp.IsNameSpaceValid) && (!wfp.IsNameSpaceOnly)) { switch (wfp.FolderType) { case WikiFileType.FileWriteMd: case WikiFileType.FileWriteBinary: { break; } case WikiFileType.FileWriteAttic: case WikiFileType.FileWriteMeta: { throw new WikiEngineNotImplementPageException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } default: case WikiFileType.FileReadMd: case WikiFileType.FileReadMeta: case WikiFileType.FileReadAttic: case WikiFileType.FileReadBinary: { throw new WikiEngineInternalFileTypeException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTreePut, MethodBase.GetCurrentMethod().Name, wfp.FolderType.ToString(), namesspace ) ); } } } else { throw new WikiEngineInternalNameSpaceErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTreeNameSpace, MethodBase.GetCurrentMethod().Name, wfp.FolderType.ToString(), namesspace ) ); } if ( ((wd = this._PutFile(wfp, null, wfm)) == null) || (wd.FileContent == null) || (wd.FileContent.Length == 0) ) { throw new WikiEngineInternalSearchEmptyException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } return(wd.FileContent); } catch (Exception e) { throw e; } }
/// <summary> /// get page/media/attic/meta /// </summary> private byte[] _WikiGetFile(WikiFileType wft, string namesspace) { try { WikiData wd = null; WikiFileParse wfp = null; if ((wfp = (WikiFileParse)this._WikiFilesParse( wft, namesspace, null, null, true )) == null) { throw new WikiEngineInternalNameSpaceErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wft.ToString() ) ); } switch (wfp.FolderType) { default: case WikiFileType.FileReadMd: case WikiFileType.FileWriteMd: case WikiFileType.FileReadBinary: case WikiFileType.FileWriteBinary: { wd = this._GetFile(wfp); break; } case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { wd = this._GetFileFromAttic(wfp); break; } case WikiFileType.FileReadMeta: { return(Encoding.UTF8.GetBytes( this.MetaListToMdString( this._GetFileMeta(wfp) ) )); } case WikiFileType.FileWriteMeta: { throw new WikiEngineNotImplementPageException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } } if ( (wd == null) || (wd.FileContent == null) || (wd.FileContent.Length == 0) ) { throw new WikiEngineInternalSearchEmptyException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } return(wd.FileContent); } catch (Exception e) { throw e; } }