Exemple #1
0
 /// <summary>
 /// get Home location, Exception to load Home page default (html template)
 /// </summary>
 private static void _WikiGetHome(stDokuWiki.WikiEngine.WikiFile wiki, string namesspace)
 {
     if (CoCWebSrv._WikiGetTarget(WikiRequestType.None, namesspace) == WikiFileType.None)
     {
         throw new WikiErrorPageException(
                   ((namesspace.Contains(":")) ? namesspace : String.Empty)
                   );
     }
     throw new WikiErrorPageException();
 }
Exemple #2
0
        public static byte[] WebWikiRouteTree(string url, Configuration conf, WikiFileMeta wfm = null)
        {
            try
            {
                List <string> urlPart = url.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToList();

                // Uri part, folders array
                switch (urlPart.Count)
                {
                case 0:
                {
                    // root, get home page template
                    // return Exception WikiHomePageException
                    stCore.stConsole.WriteHeader("0: Count");
                    throw new WikiHomePageException();
                }

                case 1:
                {
                    // not complette request,
                    // only WikiRequestType is set?
                    switch (CoCWebSrv._WikiGetAction(urlPart[0]))
                    {
                    default:
                    case WikiRequestType.None:
                    {
                        // get Exception Home page default (html template)
                        // return Exception WikiHomePageException
                        stCore.stConsole.WriteHeader("1: WikiRequestType.None:0");
                        _WikiGetHome(conf.WikiEngine, urlPart[0]);
                        break;
                    }

                    case WikiRequestType.List:
                    {
                        // get page list default ?
                        // return Md format txt
                        stCore.stConsole.WriteHeader("1: WikiRequestType.List:0");
                        return(_WikiGetList(conf.WikiEngine, WikiFileType.FileReadMd, String.Empty));
                    }

                    case WikiRequestType.Find:
                    {
                        // get find page default ?
                        // return Md format txt
                        stCore.stConsole.WriteHeader("1: WikiRequestType.Find:0");
                        throw new WikiSearchException("search pattern is empty");
                    }
                    }
                    break;
                }

                case 2:
                {
                    // get List/Page/Media ?
                    WikiRequestType wrt = CoCWebSrv._WikiGetAction(urlPart[0]);
                    WikiFileType    wft = CoCWebSrv._WikiGetTarget(wrt, urlPart[1]);
                    switch (wrt)
                    {
                    default:
                    case WikiRequestType.Del:
                    case WikiRequestType.Put:
                    case WikiRequestType.None:
                    {
                        // get Exception Home page default (html template)
                        // return Exception WikiHomePageException
                        stCore.stConsole.WriteHeader("2: _WikiGetHome");
                        _WikiGetHome(
                            conf.WikiEngine,
                            ((wft == WikiFileType.None) ? urlPart[1] : String.Empty)
                            );
                        break;
                    }

                    case WikiRequestType.Find:
                    {
                        // get page list default ?
                        stCore.stConsole.WriteHeader("2: _WikiFindList");
                        if (
                            ((wft == WikiFileType.None) &&
                             (string.IsNullOrWhiteSpace(urlPart[1]))) ||
                            (wft != WikiFileType.None)
                            )
                        {
                            throw new WikiSearchException("search pattern is empty");
                        }
                        return(_WikiFindList(
                                   conf.WikiEngine,
                                   ((wft == WikiFileType.None) ? WikiFileType.FileReadMd : wft),
                                   urlPart[1]
                                   ));
                    }

                    case WikiRequestType.List:
                    {
                        // get page list default ?
                        stCore.stConsole.WriteHeader("2: _WikiGetList");
                        return(_WikiGetList(
                                   conf.WikiEngine,
                                   ((wft == WikiFileType.None) ? WikiFileType.FileReadMd : wft),
                                   ((wft == WikiFileType.None) ? urlPart[1] : String.Empty)
                                   ));
                    }

                    case WikiRequestType.Get:
                    {
                        // get page/media default ? eturn start page
                        stCore.stConsole.WriteHeader("2: _WikiGetFile");
                        return(_WikiGetFile(
                                   conf.WikiEngine,
                                   ((wft == WikiFileType.None) ? WikiFileType.FileReadMd : wft),
                                   ((wft == WikiFileType.None) ? urlPart[1] : String.Empty)
                                   ));
                    }
                    }
                    break;
                }

                case 3:
                {
                    WikiRequestType wrtAct    = CoCWebSrv._WikiGetAction(urlPart[0]);
                    WikiFileType    wrtTarget = CoCWebSrv._WikiGetTarget(wrtAct, urlPart[1]);

                    if (
                        (wrtAct == WikiRequestType.None) ||
                        (wrtTarget == WikiFileType.None) ||
                        (string.IsNullOrWhiteSpace(urlPart[2])) ||
                        (!urlPart[2].Contains(":"))
                        )
                    {
                        // error request param
                        // return Exception WikiHomePageException
                        _WikiGetHome(conf.WikiEngine, urlPart[2]);
                    }

                    List <string> wikiPart = urlPart[2].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries).ToList();

                    switch (wikiPart.Count)
                    {
                    case 0:
                    {
                        // WikiRequestType and WikiFileType is valid,
                        // namespace not found, return default
                        switch (wrtAct)
                        {
                        case WikiRequestType.Get:
                        {
                            return(_WikiGetFile(
                                       conf.WikiEngine,
                                       wrtTarget,
                                       String.Empty
                                       ));
                        }

                        case WikiRequestType.Find:
                        {
                            if (string.IsNullOrWhiteSpace(urlPart[2]))
                            {
                                throw new WikiSearchException("search pattern is empty");
                            }
                            return(_WikiFindList(
                                       conf.WikiEngine,
                                       wrtTarget,
                                       urlPart[2]
                                       ));
                        }

                        case WikiRequestType.List:
                        {
                            return(_WikiGetList(
                                       conf.WikiEngine,
                                       wrtTarget,
                                       String.Empty
                                       ));
                        }

                        case WikiRequestType.Put:
                        case WikiRequestType.Del:
                        {
                            throw new WikiErrorPageException(
                                      string.Format(
                                          "not update, name space {0} incorrected",
                                          urlPart[2]
                                          )
                                      );
                        }
                        }
                        break;
                    }

                    default:
                    {
                        // wikiPart.Count > 0
                        // namespace and page/file name
                        switch (wrtAct)
                        {
                        case WikiRequestType.Get:
                        {
                            stCore.stConsole.WriteHeader("3:default _WikiGetFile: " + urlPart[2]);
                            return(_WikiGetFile(conf.WikiEngine, wrtTarget, urlPart[2]));
                        }

                        case WikiRequestType.List:
                        {
                            stCore.stConsole.WriteHeader("3:default _WikiGetList: " + " : " + wrtTarget + " : " + urlPart[2]);
                            return(_WikiGetList(conf.WikiEngine, wrtTarget, urlPart[2]));
                        }

                        case WikiRequestType.Find:
                        {
                            stCore.stConsole.WriteHeader("3:default _WikiFindList: " + " : " + wrtTarget + " : " + urlPart[2] + " : " + wikiPart[(wikiPart.Count - 1)]);
                            int idx = (wikiPart.Count - 1);
                            if (
                                (idx < 0) ||
                                (string.IsNullOrWhiteSpace(wikiPart[idx]))
                                )
                            {
                                throw new WikiSearchException("search pattern is empty, index: " + idx);
                            }
                            return(_WikiFindList(
                                       conf.WikiEngine,
                                       wrtTarget,
                                       wikiPart[idx]
                                       ));
                        }

                        case WikiRequestType.Put:
                        case WikiRequestType.Del:
                        {
                            stCore.stConsole.WriteHeader("3:default _WikiPutFile: " + urlPart[2]);
                            if (wfm == null)
                            {
                                throw new WikiErrorPageException(
                                          string.Format(
                                              "meta data is empty, not change",
                                              urlPart[2]
                                              )
                                          );
                            }
                            if (!wfm.IsAuth)
                            {
                                throw new WikiAuthException(
                                          string.Format(
                                              "Auth error, file not change",
                                              urlPart[2]
                                              ),
                                          wfm
                                          );
                            }
                            return(_WikiPutFile(conf.WikiEngine, wrtTarget, urlPart[2], wfm));
                        }
                        }
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    _WikiGetHome(conf.WikiEngine, urlPart[0]);
                    break;
                }
                }
            }
            catch (WikiErrorPageException e)
            {
                // error page WikiErrorPageException
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Wiki Parser"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
                return(null);
            }
            catch (WikiHomePageException e)
            {
                // home page WikiHomePageException
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Wiki Parser"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
                return(null);
            }
#if DEBUG
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Wiki Parser"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
#else
            catch (Exception)
            {
#endif
                return(null);
            }
            return(null);
        }