/// <summary> /// Get file information from FS from string /// </summary> /// <param name="wft">type enum <see cref="WikiEngine.WikiFileType"/>WikiEngine.WikiFileType</param> /// <param name="namesspace">wiki namespace include ':'</param> /// <param name="file">page/media name (serch patern string)</param> /// <returns><see cref="WikiEngine.WikiFileInfo"/>WikiEngine.WikiFileInfo</returns> internal WikiFileInfo _WikiFileGetFileInfo(WikiFileType wft, string namesspace, string file) { try { WikiFileParse wfp = new WikiFileParse(wft, true, namesspace, file); if ((wfp = this.__WikiFilesParse(wfp)) == null) { throw new WikiEngineInternalSearchErrorException(namesspace + file); } return(this.__WikiFileGetFileInfoSelect(wfp)); } catch (Exception e) { throw e; } }
/// <summary> /// internal Uri/Namespace parse /// </summary> /// <param name="wft">type enum <see cref="WikiEngine.WikiFileType"/>WikiEngine.WikiFileType</param> /// <param name="namesspace">wiki namespace include ':'</param> /// <param name="file">page/media name (serch patern string)</param> /// <param name="atticid">Attic ID (Unix Timestamp, Int32)</param> /// <param name="strong">Bolean, search one is true, search all is false</param> /// <param name="iswrite">Bolean, flag to write resource</param> /// <returns><see cref="WikiEngine.WikiFile.WikiFileParse"/>WikiEngine.WikiFile.WikiFileParse</returns> internal WikiFileParse _WikiFilesParse(WikiFileType wft, string namesspace, string file, string atticid = null, bool strong = false, bool iswrite = false) { try { WikiFileParse wfp = new WikiFileParse(wft, strong, namesspace, file, atticid, iswrite); if ((wfp = this.__WikiFilesParse(wfp)) == null) { throw new WikiEngineInternalSearchErrorException(namesspace + file); } return(wfp); } catch (Exception e) { throw e; } }
/// <summary> /// Meta append path to specific locations /// part of __WikiFilesParse /// </summary> /// <param name="checkNs"></param> /// <param name="checkFn"></param> /// <param name="wfp"></param> /// <param name="app"></param> internal void __WikiFilesParseMetaExtension(ref WikiFileParse wfp, bool checkNs, bool checkFn, string app) { try { if (checkFn) { wfp.SearchPatern = ___WikiFilesParseMetaExtension(wfp.SearchPatern, app); } else if (checkNs) { wfp.NameSpacePatern = ___WikiFilesParseMetaExtension(wfp.NameSpacePatern, app); } } catch (Exception e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } }
/// <summary> /// Get file information from FS from WikiEngine.WikiFileParse internal class /// </summary> /// <param name="wfp">internal class <see cref="WikiEngine.WikiFile.WikiFileParse"/>WikiEngine.WikiFile.WikiFileParse</param> /// <returns><see cref="WikiEngine.WikiFileInfo"/>WikiEngine.WikiFileInfo</returns> internal WikiFileInfo _WikiFileGetFileInfo(WikiFileParse wfp) { try { if (wfp == null) { throw new WikiEngineInternalNameSpaceErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorWikiFileParse, MethodBase.GetCurrentMethod().Name ) ); } return(this.__WikiFileGetFileInfoSelect(wfp)); } catch (Exception e) { throw e; } }
/// <summary> /// internal find Namespace /// </summary> /// <param name="wfp"><see cref="WikiFile.WikiFileParse"/>WikiFile.WikiFileParse data</param> /// <returns><see cref="WikiEngine.WikiFolderInfo"/>WikiEngine.WikiFolderInfo</returns> internal WikiFolderInfo __WikiFilesFindNamespace(WikiFileParse wfp) { WikiFolderInfo wfi = null; try { if (this._taskFilesList.Status == TaskStatus.Running) { this._taskFilesList.Wait(); if (this._taskFilesList.Exception != null) { throw this._taskFilesList.Exception; } } if (this._lockFs.TryEnterReadLock((this._isOnstart) ? waitReadFsOnStart : waitReadFsOnProcess)) { try { if ( (this._wikiFSDict == null) || (this._wikiFSDict.Count == 0) ) { throw new WikiEngineInternalSearchErrorException("FS base is empty"); } if ((wfi = this._wikiFSDict.Where(o => o.Key.Equals(DokuUtil.WikiFileTypeToString(wfp.FolderType))) .Select(o => { return((WikiFolderInfo)o.Value); }) .FirstOrDefault <WikiFolderInfo>()) == null) { throw new WikiEngineInternalSearchErrorException(); } if ( (wfp.UriPart == null) || (wfp.UriPart.Count == 0) ) { throw new WikiEngineInternalSearchOkException(); } int i = 0, count = ((wfp.IsNameSpaceOnly) ? wfp.UriPart.Count : (wfp.UriPart.Count - 1)); wfp.UriPart.ForEach(fpart => { if (i == count) { return; } if ((wfi = this.__WikiFilesFindNamespaceFolder(wfi, fpart)) == null) { return; } i++; }); if (wfi != null) { wfi.SearchPatern = ((wfp.IsNameSpaceOnly) ? String.Empty : wfp.UriPart[count]); throw new WikiEngineInternalSearchOkException(); } else { throw new WikiEngineInternalSearchErrorException(); } } finally { try { this._lockFs.ExitReadLock(); } catch (LockRecursionException e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } catch (SynchronizationLockException e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } } } throw new WikiEngineInternalSearchErrorException(); } catch (WikiEngineInternalSearchOkException) { return(wfi); } catch (WikiEngineInternalSearchErrorException) { return(null); } catch (Exception e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(null); } }
/// <summary> /// internal Wiki find files /// </summary> /// <param name="wfp"><see cref="WikiFile.WikiFileParse"/>WikiFile.WikiFileParse data</param> /// <returns>WikiFolderInfo data</returns> internal WikiFolderInfo __WikiFilesFindFiles(WikiFileParse wfp) { WikiFolderInfo wfi = null, wfo = null; string key = String.Empty; try { if (this._taskFilesList.Status == TaskStatus.Running) { this._taskFilesList.Wait(); if (this._taskFilesList.Exception != null) { throw new WikiEngineInternalSearchErrorException(this._taskFilesList.Exception.Message); } } if (this._lockFs.TryEnterReadLock((this._isOnstart) ? waitReadFsOnStart : waitReadFsOnProcess)) { try { if ( (this._wikiFSDict == null) || (this._wikiFSDict.Count == 0) ) { throw new WikiEngineInternalSearchErrorException("FS base is empty"); } key = DokuUtil.WikiFileTypeToString(wfp.FolderType); if ((wfi = this._wikiFSDict.Where(o => o.Key.Equals(key)) .Select(o => { return((WikiFolderInfo)o.Value); }) .FirstOrDefault <WikiFolderInfo>()) == null) { throw new WikiEngineInternalSearchEmptyException(); } if ( (wfp.UriPart != null) && (wfp.UriPart.Count > 0) ) { wfp.UriPart.ForEach(fpart => { if ((wfi = this.__WikiFilesFindNamespaceFolder(wfi, fpart)) == null) { return; } key = fpart; }); } if (wfi == null) { throw new WikiEngineInternalSearchEmptyException(); } wfo = new WikiFolderInfo(); wfo.SearchPatern = wfp.SearchPatern; wfo.SearchStrong = wfp.IsStrongSearch; if (this.__WikiFilesFindNamespaceFiles(ref wfo, wfi, key)) { throw new WikiEngineInternalSearchOkException(); } throw new WikiEngineInternalSearchEmptyException(); } finally { try { this._lockFs.ExitReadLock(); } catch (LockRecursionException e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } catch (SynchronizationLockException e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } } } throw new WikiEngineInternalSearchEmptyException(); } catch (WikiEngineInternalSearchOkException) { // Cache write result if (this._isCacheEnable) { _WikiFileCacheWrite(wfo, wfp.CacheId); } // return(wfo); } catch (WikiEngineInternalSearchEmptyException) { return(null); } catch (WikiEngineInternalSearchErrorException e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(null); } catch (Exception e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(null); } }
/// <summary> /// Attic append path to specific locations /// part of __WikiFilesParse /// </summary> /// <param name="wfp"></param> /// <param name="checkNs"></param> /// <param name="checkFn"></param> /// <param name="app"></param> internal void __WikiFilesParseAtticExtension(ref WikiFileParse wfp, bool checkNs, bool checkFn, string app) { try { // Test: // wfp.AtticId = "123456789"; // wfp.NameSpacePatern = "clan:xyz007.123456789.jpg"; // wfp.NameSpacePatern = "clan:xyz007.123456789"; // wfp.NameSpacePatern = "clan:xyz007.jpg"; // wfp.NameSpacePatern = "clan:xyz007"; int t, pos = 0; string sdate = String.Empty, sext = String.Empty; bool isAtticId = !string.IsNullOrWhiteSpace(wfp.AtticId); string[] part = ((checkFn) ? wfp.SearchPatern : wfp.NameSpacePatern) .Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); switch (part.Length) { case 1: { if (!isAtticId) { throw new WikiEngineInternalCacheExceptionAtticException(); } sext = mdExtension; sdate = wfp.AtticId; break; } case 2: { if (Int32.TryParse(part[1], out t)) { sext = mdExtension; sdate = part[1]; pos += part[1].Length + 1; } else if (!isAtticId) { throw new WikiEngineInternalCacheExceptionAtticException(); } else { sext = part[1]; pos += part[1].Length + 1; sdate = wfp.AtticId; } break; } case 3: { if (Int32.TryParse(part[1], out t)) { sdate = part[1]; pos += part[1].Length + 1; } else if (!isAtticId) { throw new WikiEngineInternalCacheExceptionAtticException(); } else { sdate = wfp.AtticId; } sext = part[2]; pos += part[2].Length + 1; break; } default: { throw new WikiEngineInternalCacheExceptionAtticException(); } } if (checkFn) { wfp.SearchPatern = string.Format( Properties.ResourceWikiEngine.fmtFailAtticFormat, wfp.SearchPatern.Substring(0, (wfp.SearchPatern.Length - pos)), sdate, sext, app ); } else if (checkNs) { wfp.NameSpacePatern = string.Format( Properties.ResourceWikiEngine.fmtFailAtticFormat, wfp.NameSpacePatern.Substring(0, (wfp.NameSpacePatern.Length - pos)), sdate, sext, app ); } } catch (WikiEngineInternalCacheExceptionAtticException) { WikiEngineInternalCacheExceptionAtticException ex = new WikiEngineInternalCacheExceptionAtticException( string.Format( Properties.ResourceWikiEngine.fmtErrorAtticIdEmpty, ((checkFn) ? wfp.SearchPatern : ((checkNs) ? wfp.NameSpacePatern : "none.." ) ) ) ); this.Fire_ProcessError(new WikiErrorEventArgs(ex, MethodBase.GetCurrentMethod().Name)); } catch (Exception e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); } }
/// <summary> /// internal Uri/Namespace parse /// </summary> /// <param name="wfp"></param> /// <returns><see cref="WikiFile.WikiFileParse"/>WikiFile.WikiFileParse</returns> internal WikiFileParse __WikiFilesParse(WikiFileParse wfp) { try { bool checkNs = !string.IsNullOrWhiteSpace(wfp.NameSpacePatern), checkFn = !string.IsNullOrWhiteSpace(wfp.SearchPatern); if ((!checkNs) && (!checkFn)) { throw new WikiEngineInternalNameSpaceErrorException( ((checkNs) ? wfp.NameSpacePatern : "") + ((checkFn) ? wfp.SearchPatern : "") ); } else if ((checkNs) && (!checkFn)) { if (!wfp.IsNameSpaceValid) { wfp.SearchPatern = wfp.NameSpacePatern; wfp.NameSpacePatern = ":"; checkNs = !checkNs; checkFn = !checkFn; } } else if ((!checkNs) && (checkFn)) { if (!wfp.IsSearchPaternValid) { wfp.NameSpacePatern = wfp.SearchPatern; wfp.SearchPatern = String.Empty; checkNs = !checkNs; checkFn = !checkFn; } } if (checkNs) { WikiFileType dwft = DokuUtil.WikiFileStringToDefaultType(wfp.NameSpacePatern, wfp.IsWriteOperation); switch (dwft) { case WikiFileType.None: case WikiFileType.FileUnknown: { switch (wfp.FolderType) { case WikiFileType.None: case WikiFileType.FileUnknown: { throw new WikiEngineInternalFileTypeException( ((checkNs) ? wfp.NameSpacePatern : "") + ((checkFn) ? wfp.SearchPatern : "") ); } default: { break; } } break; } case WikiFileType.NameSpace: { /* * // strong check files * if (!checkFn) * { * throw new WikiEngineInternalNameSpaceErrorException( * ((checkFn) ? wfp.SearchPatern : "") * ); * } */ break; } default: { switch (wfp.FolderType) { case WikiFileType.None: case WikiFileType.FileUnknown: { wfp.FolderType = dwft; break; } default: { break; } } break; } } } switch (wfp.FolderType) { case WikiFileType.None: case WikiFileType.FileUnknown: { throw new WikiEngineInternalFileTypeException( ((checkNs) ? wfp.NameSpacePatern : "") + ((checkFn) ? wfp.SearchPatern : "") ); } case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { this.__WikiFilesParseAtticExtension(ref wfp, checkNs, checkFn, atticExtension); break; } case WikiFileType.FileReadMeta: case WikiFileType.FileWriteMeta: { this.__WikiFilesParseMetaExtension(ref wfp, checkNs, checkFn, metaExtension); break; } default: { break; } } // Cache read request wfp.CacheId = ((this._isCacheEnable) ? _WikiFileCacheId( wfp.FolderType, string.Concat( ((checkNs) ? wfp.NameSpacePatern : "-"), (((!checkNs) && (checkFn)) ? wfp.SearchPatern : "-") ) ) : String.Empty ); if ((this._isCacheEnable) && ((wfp.FolderInfo = _WikiFileCacheRead(wfp.CacheId)) != null)) { return(wfp); } // End Cache if ((wfp.UriPart = wfp.NameSpacePatern .Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries) .ToList <string>()) == null) { throw new WikiEngineInternalSearchOkException(); } if ( (!checkFn) && (wfp.UriPart.Count > 1) ) { wfp.SearchPatern = wfp.UriPart[(wfp.UriPart.Count - 1)]; wfp.UriPart.RemoveAt(wfp.UriPart.Count - 1); } return(wfp); } catch (WikiEngineInternalSearchOkException) { return(null); } catch (Exception e) { this.Fire_ProcessError(new WikiErrorEventArgs(e, MethodBase.GetCurrentMethod().Name)); return(null); } }
/// <summary> /// part from _WikiFileGetFileInfo(WikiFileParse) internal method /// </summary> /// <param name="wfp">internal class <see cref="WikiEngine.WikiFile.WikiFileParse"/>WikiEngine.WikiFile.WikiFileParse</param> /// <returns><see cref="WikiEngine.WikiFileInfo"/>WikiEngine.WikiFileInfo</returns> internal WikiFileInfo __WikiFileGetFileInfoSelect(WikiFileParse wfp) { WikiFileInfo wfo = null; WikiFolderInfo wfi = null; try { if (wfp.FolderInfo != null) { wfi = wfp.FolderInfo; } else { if ((wfi = this.__WikiFilesFindFiles(wfp)) == null) { throw new WikiEngineInternalSearchEmptyException( string.Format( Properties.ResourceWikiEngine.mdErrorSearchEmpty, wfp.NameSpacePatern, wfp.SearchPatern, wfp.FolderType ) ); } } if (wfi.Dirs.Count != 1) { string exceptMessage = string.Format( "Directory count: {0} '{1}{2}'", wfi.Dirs.Count, wfp.NameSpacePatern, wfp.SearchPatern ); if (wfi.Dirs.Count == 0) { throw new WikiEngineInternalSearchEmptyException(exceptMessage); } throw new WikiEngineInternalSearchManyResultException(exceptMessage); } if ((wfo = wfi.Dirs .ElementAtOrDefault <KeyValuePair <string, WikiFolderInfo> >(0) .Value .Files .FirstOrDefault <WikiFileInfo>()) == null) { throw new WikiEngineInternalSearchEmptyException( string.Format( Properties.ResourceWikiEngine.mdErrorSearchEmpty, wfp.NameSpacePatern, wfp.SearchPatern, wfp.FolderType ) ); } return(wfo); } catch (Exception e) { throw e; } }
/// <summary> /// find pages list /// </summary> private byte[] _WikiFindList(WikiFileType wft, string namesspace) { WikiFileParse wfp = null; WikiFolderInfo wfi = null; try { if ((wfp = (WikiFileParse)this._WikiFilesParse( wft, namesspace, null, null, false )) == null) { throw new WikiEngineInternalNameSpaceErrorException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wft.ToString() ) ); } switch (wfp.FolderType) { case WikiFileType.FileReadMd: case WikiFileType.FileWriteMd: case WikiFileType.FileReadBinary: case WikiFileType.FileWriteBinary: case WikiFileType.FileReadAttic: case WikiFileType.FileWriteAttic: { if ((wfi = (WikiFolderInfo)this._FindFiles(wfp)) == null) { throw new WikiEngineInternalSearchEmptyException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } break; } default: { throw new WikiEngineNotImplementPageException( string.Format( Properties.ResourceWikiEngine.fmtErrorMapTree, MethodBase.GetCurrentMethod().Name, namesspace, wfp.FolderType.ToString() ) ); } } return(Encoding.UTF8.GetBytes( this.ResourceListToMdString(wfi, null, wfp.FolderType) )); } catch (Exception e) { throw e; } }
/// <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; } }