コード例 #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();
 }
コード例 #2
0
        public static void WikiWebRequest(string url, object ctx, object udata)
        {
            byte[] msg;
            stCoCServerConfig.CoCServerConfigData.Configuration conf = udata as stCoCServerConfig.CoCServerConfigData.Configuration;
            HttpListenerContext context = ctx as HttpListenerContext;

            if (
                (udata == null) ||
                (conf.HttpSrv == null)
                )
            {
                context.Response.Abort();
                return;
            }
            if (conf.HtmlTemplate == null)
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    String.Empty,
                    context
                    );
                return;
            }
            try
            {
                if ((msg = CoCWebSrv.WebWikiRouteTree(url, conf)) == null)
                {
                    throw new ArgumentException("Create Wiki page error");
                }
            }
            catch (Exception e)
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    e.Message,
                    context
                    );
                return;
            }
            try
            {
                if (context.Response.StatusCode == (int)HttpStatusCode.OK)
                {
                    context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "max-age=2629000, public");
                }
                else
                {
                    context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "no-cache");
                }
                context.Response.AddHeader(conf.HttpSrv.httpContentType, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeHtml));
                context.Response.ContentLength64 = msg.Length;
                context.Response.OutputStream.Write(msg, 0, msg.Length);
                context.Response.OutputStream.Close();
            }
#if DEBUG
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Wiki"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
#else
            catch (Exception)
            {
#endif
                context.Response.Abort();
                return;
            }

            context.Response.Close();
            return;

            /*
             * ///////
             * //////// Go this!
             * //////
             * string[] urlPart = url.Split('/');
             *
             * if (
             *  (urlPart.Length < 5) ||
             *  (
             *    (!urlPart[2].All(char.IsDigit)) ||
             *    (!urlPart[3].All(char.IsDigit)) ||
             *    (!urlPart[4].All(char.IsDigit))
             *  )
             * )
             * {
             *  DateTime cdate = DateTime.Now.AddDays(-1);
             *  urlPart = new string[] {
             *      "",
             *      "",
             *      cdate.ToString("yyyy"),
             *      cdate.ToString("MM"),
             *      cdate.ToString("dd")
             *  };
             * }
             * try
             * {
             *  cacheid = @"irc" + urlPart[4] + urlPart[3] + urlPart[2];
             *
             *  if (
             *      (!conf.Opt.WEBCacheEnable.bval) ||
             *      (!stCore.stCache.GetCacheObject<byte[]>(cacheid, out msg))
             *     )
             *  {
             *      filePath = conf.LogDump.GetFilePath(urlPart[4], urlPart[3], urlPart[2]);
             *
             *      if (!File.Exists(filePath))
             *      {
             *          string title = string.Format(
             *              Properties.Resources.httpLogNotFound,
             *              urlPart[2],
             *              urlPart[3],
             *              urlPart[4]
             *          );
             *          msg = Encoding.UTF8.GetBytes(
             *                  conf.HtmlTemplate.Render(
             *                      new
             *                      {
             *                          LANG = conf.Opt.SYSLANGConsole.value.ToLower(),
             *                          TITLE = title,
             *                          INSERTHTMLDATA = title,
             *                          TOPMENU = string.Format(
             *                              Properties.Resources.ircLogArchive,
             *                              conf.Opt.IRCChannel.value
             *                          ),
             *                          DATE = DateTime.Now.ToString(),
             *                          GENERATOR = conf.HttpSrv.wUserAgent,
             *                          DATEY = urlPart[2],
             *                          DATEM = urlPart[3],
             *                          DATED = urlPart[4]
             *                      },
             *                      "IrcLogTemplate.html",
             *                      filePath
             *                  )
             *          );
             *          context.Response.StatusCode = ((conf.Opt.WEBFrontEndEnable.bval) ? (int)HttpStatusCode.OK : (int)HttpStatusCode.NotFound);
             *      }
             *      else
             *      {
             *          msg = Encoding.UTF8.GetBytes(
             *                  conf.HtmlTemplate.Render(
             *                      new
             *                      {
             *                          LANG = conf.Opt.SYSLANGConsole.value.ToLower(),
             *                          TITLE = string.Format(
             *                              Properties.Resources.httpDateLogTitle,
             *                              urlPart[2],
             *                              urlPart[3],
             *                              urlPart[4]
             *                          ),
             *                          TOPMENU = string.Format(
             *                              Properties.Resources.ircLogArchive,
             *                              conf.Opt.IRCChannel.value
             *                          ),
             *                          DATE = DateTime.Now.ToString(),
             *                          GENERATOR = conf.HttpSrv.wUserAgent,
             *                          DATEY = urlPart[2],
             *                          DATEM = urlPart[3],
             *                          DATED = urlPart[4]
             *                      },
             *                      "IrcLogTemplate.html",
             *                      filePath
             *                  )
             *          );
             *          if (conf.Opt.WEBCacheEnable.bval)
             *          {
             *              stCore.stCache.SetCacheObject<byte[]>(cacheid, msg, DateTime.Now.AddHours(6));
             *          }
             *          context.Response.StatusCode = (int)HttpStatusCode.OK;
             *      }
             *  }
             *  else
             *  {
             *      context.Response.StatusCode = (int)HttpStatusCode.OK;
             #if DEBUG_isCached
             *      stConsole.WriteHeader("IRC LOG content is cached: " + cacheid + " : " + msg.Length.ToString());
             #endif
             *  }
             * }
             * catch (Exception e)
             * {
             *  CoCWebSrv._ErrorHtmlDefault(
             *      conf,
             *      HttpStatusCode.InternalServerError,
             *      e.Message,
             *      context
             *  );
             *  return;
             * }
             * try
             * {
             *  if (context.Response.StatusCode == (int)HttpStatusCode.OK)
             *  {
             *      context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "max-age=2629000, public");
             *  }
             *  else
             *  {
             *      context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "no-cache");
             *  }
             *  context.Response.AddHeader(conf.HttpSrv.httpContentType, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeHtml));
             *  context.Response.ContentLength64 = msg.Length;
             *  context.Response.OutputStream.Write(msg, 0, msg.Length);
             *  context.Response.OutputStream.Close();
             * }
             #if DEBUG
             * catch (Exception e)
             * {
             *  conf.ILog.LogError("[Template Web Request]: " + e.GetType().Name + " -> " + e.Message);
             #else
             * catch (Exception)
             * {
             #endif
             *  context.Response.Abort();
             *  return;
             * }
             * context.Response.Close();
             */
        }
コード例 #3
0
        public static void InformerWebRequest(string url, object ctx, object udata)
        {
            stCoCServerConfig.CoCServerConfigData.Configuration conf = udata as stCoCServerConfig.CoCServerConfigData.Configuration;
            HttpListenerContext context = ctx as HttpListenerContext;

            stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq reqtype = stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq.None;

            if (
                (udata == null) ||
                (conf.HttpSrv == null)
                )
            {
                context.Response.Abort();
                return;
            }
            if (
                (conf.Api == null) ||
                (!conf.Api.DBCheck())
                )
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    String.Empty,
                    context
                    );
                return;
            }

            Int32 idx = 0, resize = 2;

            byte[]   msg     = null;
            string[] urlPart = url.Split('/');
            urlPart = urlPart.Skip(1).Concat(urlPart.Take(1)).ToArray();
            Array.Resize(ref urlPart, urlPart.Length - 1);
            string memberId = "",
                   langid   = stNet.stWebServerUtil.HttpUtil.GetHttpPreferedLanguage(context.Request.UserLanguages);

            try
            {
                if (urlPart.Length < 3)
                {
                    throw new ArgumentOutOfRangeException();
                }
                if (!Int32.TryParse(urlPart[2], out idx))
                {
                    throw new ArgumentOutOfRangeException();
                }
                switch (urlPart[1])
                {
                case "info":
                case "clan":
                {
                    reqtype = stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq.Clan;
                    if (urlPart.Length != 4)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    break;
                }

                case "player":
                case "member":
                {
                    reqtype = stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq.Members;
                    if (urlPart.Length != 5)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    if (urlPart[3].Equals("random"))
                    {
                        urlPart[1] = urlPart[3];
                        resize     = 3;
                    }
                    else
                    {
                        if ((urlPart[3].Length > 12) || (urlPart[3].Length < 6))
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        urlPart[2] = urlPart[3];
                    }
                    memberId = urlPart[3];
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException();
                }
                }
                Array.Resize(ref urlPart, urlPart.Length - resize);
            }
            catch (Exception)
            {
                conf.HttpSrv.BadRequestRaw(conf.Api.InformerImageError(reqtype, langid), context, (int)HttpStatusCode.BadRequest, HttpUtil.MimeType.MimePng);
                return;
            }
            try
            {
                stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None;
                string query = string.Empty;
                try
                {
                    query = conf.Api.GetQueryString(urlPart, ref cReq, conf.Opt.SQLDBFilterMemberTag.collection, conf.ILog.LogError);
                    if (
                        (cReq == stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None) ||
                        (string.IsNullOrWhiteSpace(query))
                        )
                    {
                        throw new ArgumentNullException();
                    }
                }
                catch (Exception)
                {
                    throw new ArgumentException();
                }

#if DEBUG_PrintWebRequest
                stConsole.WriteHeader("InformerWebRequest -> URL: (" + url + ") Query: (" + query + ")");
#endif
                DataTable dt = conf.Api.QueryData(query);
                if ((dt == null) || (dt.Rows.Count == 0))
                {
                    throw new ArgumentNullException();
                }
#if DEBUG_PrintJson
                stConsole.WriteHeader("InformerWebRequest -> JSON: " + dt.ToJson(false, false));
#endif
#if DEBUG_PrintDataTable
                dt.DataTableToPrint();
#endif
                msg = conf.Api.InformerImageGet(dt.Rows[0], reqtype, idx, memberId, langid, conf.Opt.WEBCacheEnable.bval);

#if DEBUG_PrintImageInfo
                stConsole.WriteHeader("InformerWebRequest -> ImageInfo: " + msg.Length);
#endif
            }
            catch (Exception)
            {
                conf.HttpSrv.BadRequestRaw(
                    conf.Api.InformerImageError(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq.Auth, langid),
                    context,
                    (int)HttpStatusCode.InternalServerError,
                    HttpUtil.MimeType.MimePng
                    );
                return;
            }
            try
            {
#if DEBUG_NoCache
                context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "no-cache");
                context.Response.AddHeader(conf.HttpSrv.httpAccelBuffering, "no");
#else
                context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "max-age=" + conf.Api.UpdateNextSeconds.ToString() + ", public");
                context.Response.AddHeader(conf.HttpSrv.httpAccelBuffering, "yes");
                context.Response.AddHeader(conf.HttpSrv.httpLastModified, conf.Api.UpdateLastTime.ToString("R"));
#endif
                context.Response.AddHeader(conf.HttpSrv.httpContentType, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimePng));
                context.Response.AddHeader(conf.HttpSrv.httpAccessControlAllowOrigin, "*");
                context.Response.ContentLength64 = msg.Length;
                context.Response.OutputStream.Write(msg, 0, msg.Length);
                context.Response.OutputStream.Close();
            }
#if DEBUG
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Informer"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
#else
            catch (Exception)
            {
#endif
                context.Response.Abort();
                return;
            }
            context.Response.Close();
        }
コード例 #4
0
        public static void SseWebRequest(string url, object ctx, object udata)
        {
            stCoCServerConfig.CoCServerConfigData.Configuration conf = udata as stCoCServerConfig.CoCServerConfigData.Configuration;
            HttpListenerContext context = ctx as HttpListenerContext;

            if (
                (udata == null) ||
                (conf.HttpSrv == null)
                )
            {
                context.Response.Abort();
                return;
            }

            string[] urlPart = url.Split('/');

            if (urlPart.Length < 3)
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.BadRequest,
                    Properties.Resources.fmtNotifyUrlError,
                    context
                    );
                return;
            }

            stCoCAPI.CoCAPI.CoCNotifyHost client = new stCoCAPI.CoCAPI.CoCNotifyHost()
            {
                Response  = context.Response,
                IpAddress = ((IPAddress)stNet.stWebServerUtil.HttpUtil.GetHttpClientIP(context.Request)).ToString(),
                Language  = stNet.stWebServerUtil.HttpUtil.GetHttpPreferedLanguage(context.Request.UserLanguages)
            };

            switch (urlPart[2])
            {
            case "sse":
            {
                if (
                    (conf.Api == null) ||
                    (!conf.Api.DBCheck())
                    )
                {
                    if (conf.Api.NotifySendSseStreamComplette(
                            client,
                            stCoCAPI.CoCAPI.CoCEnum.EventNotify.ServerError.ToString(),
                            HttpStatusCode.InternalServerError.ToString()
                            ))
                    {
                        context.Response.Close();
                    }
                    else
                    {
                        context.Response.Abort();
                    }
                    return;
                }
                if (!context.Request.KeepAlive)
                {
                    if (conf.Api.NotifySendSseStreamComplette(
                            client,
                            stCoCAPI.CoCAPI.CoCEnum.EventNotify.ServerError.ToString(),
                            stCoCAPI.CoCAPI.CoCEnum.EventNotify.NoKeepAlive.ToString() + " : " + DateTime.Now.ToString()
                            ))
                    {
                        context.Response.Close();
                    }
                    else
                    {
                        context.Response.Abort();
                    }
                    return;
                }
                conf.Api.NotifySseAdd(client);
                break;
            }

            case "json":
            {
                if (
                    (conf.Api == null) ||
                    (!conf.Api.DBCheck())
                    )
                {
                    conf.HttpSrv.BadRequestJson(stCoCAPI.CoCAPI.CoCEnum.EventNotify.ServerError.ToString(), context, (int)HttpStatusCode.InternalServerError);
                    return;
                }
                bool isfull = true;
                if (
                    (urlPart.Length > 3) &&
                    (urlPart[3].Equals("list"))
                    )
                {
                    isfull = false;
                }
                if (conf.Api.NotifySendJsonComplette(client, isfull))
                {
                    context.Response.Close();
                }
                else
                {
                    context.Response.Abort();
                }
                break;
            }

            case "xml":
            case "rss":
            {
                if (
                    (conf.Api == null) ||
                    (!conf.Api.DBCheck())
                    )
                {
                    conf.HttpSrv.BadRequestXml(stCoCAPI.CoCAPI.CoCEnum.EventNotify.ServerError.ToString(), context, (int)HttpStatusCode.InternalServerError);
                    return;
                }
                if (conf.Api.NotifySendRssComplette(client))
                {
                    context.Response.Close();
                }
                else
                {
                    context.Response.Abort();
                }
                break;
            }

            default:
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    Properties.Resources.fmtNotifyUrlError,
                    context
                    );
                break;
            }
            }
        }
コード例 #5
0
        public static void FileWebRequest(string url, object ctx, object udata)
        {
            stCoCServerConfig.CoCServerConfigData.Configuration conf = udata as stCoCServerConfig.CoCServerConfigData.Configuration;
            HttpListenerContext context = ctx as HttpListenerContext;

            if (
                (udata == null) ||
                (conf.HttpSrv == null)
                )
            {
                context.Response.Abort();
                return;
            }

            byte[] msg      = null;
            long   msgsize  = 0;
            string modify   = String.Empty;
            string filePath = conf.Opt.SYSROOTPath.value;

            if (url.Contains("?"))
            {
                string [] urlPart = url.Split('?');
                if ((urlPart.Length == 0) || (string.IsNullOrWhiteSpace(urlPart[0])))
                {
                    CoCWebSrv._ErrorHtmlDefault(
                        conf,
                        HttpStatusCode.BadRequest,
                        String.Empty,
                        context
                        );
                    return;
                }
                url = urlPart[0];
            }

            foreach (string part in url.Split('/'))
            {
                if (part.Equals(".."))
                {
                    CoCWebSrv._ErrorHtmlDefault(
                        conf,
                        HttpStatusCode.BadRequest,
                        String.Empty,
                        context
                        );
                    return;
                }
                filePath = Path.Combine(filePath, part);
            }
            if (!File.Exists(filePath))
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.NotFound,
                    HttpStatusCode.NotFound.ToString() + @" path: '<b>" + url + @"</b>'",
                    context
                    );
                return;
            }
            try
            {
                msg = File.ReadAllBytes(filePath);
                switch (context.Request.HttpMethod)
                {
                case "HEAD":
                {
                    FileInfo fi = new FileInfo(filePath);
                    modify = fi.LastWriteTimeUtc.ToLongDateString();
                    break;
                }

                case "GET":
                {
                    msg     = File.ReadAllBytes(filePath);
                    msgsize = msg.Length;
                    modify  = File.GetLastWriteTimeUtc(filePath).ToLongDateString();
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException(Properties.Resources.httpMethodNotSupport);
                }
                }
            }
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, ""),
                        e.GetType().Name,
                        e.Message
                        )
                    );
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    e.Message,
                    context
                    );
                return;
            }
            try
            {
                context.Response.AddHeader(conf.HttpSrv.httpContentType, HttpUtil.GetMimeType(url));
                context.Response.AddHeader(conf.HttpSrv.httpContentDisposition,
                                           string.Format(
                                               Properties.Settings.Default.setHttpContentDisposition,
                                               Path.GetFileName(filePath)
                                               )
                                           );
                context.Response.AddHeader(conf.HttpSrv.httpLastModified, modify);
                context.Response.ContentLength64 = msgsize;
                context.Response.OutputStream.Write(msg, 0, msg.Length);
                context.Response.OutputStream.Close();
            }
#if DEBUG
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "File"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
#else
            catch (Exception)
            {
#endif
                context.Response.Abort();
                return;
            }
            context.Response.Close();
        }
コード例 #6
0
        public static void TemplateWebRequest(string url, object ctx, object udata)
        {
            byte[] msg;
            string filePath, cacheid;

            stCoCServerConfig.CoCServerConfigData.Configuration conf = udata as stCoCServerConfig.CoCServerConfigData.Configuration;
            HttpListenerContext context = ctx as HttpListenerContext;

            if (
                (udata == null) ||
                (conf.HttpSrv == null)
                )
            {
                context.Response.Abort();
                return;
            }
            if (
                (conf.HtmlTemplate == null) ||
                (conf.LogDump == null)
                )
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    String.Empty,
                    context
                    );
                return;
            }

            string [] urlPart = url.Split('/');

            if (
                (urlPart.Length < 5) ||
                (
                    (!urlPart[2].All(char.IsDigit)) ||
                    (!urlPart[3].All(char.IsDigit)) ||
                    (!urlPart[4].All(char.IsDigit))
                )
                )
            {
                DateTime cdate = DateTime.Now.AddDays(-1);
                urlPart = new string[] {
                    "",
                    "",
                    cdate.ToString("yyyy"),
                    cdate.ToString("MM"),
                    cdate.ToString("dd")
                };
            }
            try
            {
                cacheid = @"irc" + urlPart[4] + urlPart[3] + urlPart[2];

                if (
                    (!conf.Opt.WEBCacheEnable.bval) ||
                    (!stCore.stCache.GetCacheObject <byte[]>(cacheid, out msg))
                    )
                {
                    filePath = conf.LogDump.GetFilePath(urlPart[4], urlPart[3], urlPart[2]);

                    if (!File.Exists(filePath))
                    {
                        string title = string.Format(
                            Properties.Resources.httpLogNotFound,
                            urlPart[2],
                            urlPart[3],
                            urlPart[4]
                            );
                        msg = Encoding.UTF8.GetBytes(
                            conf.HtmlTemplate.Render(
                                new
                        {
                            LANG           = conf.Opt.SYSLANGConsole.value.ToLower(),
                            TITLE          = title,
                            INSERTHTMLDATA = title,
                            TOPMENU        = string.Format(
                                Properties.Resources.ircLogArchive,
                                conf.Opt.IRCChannel.value
                                ),
                            DATE      = DateTime.Now.ToString(),
                            GENERATOR = conf.HttpSrv.wUserAgent,
                            DATEY     = urlPart[2],
                            DATEM     = urlPart[3],
                            DATED     = urlPart[4]
                        },
                                "IrcLogTemplate.html",
                                filePath
                                )
                            );
                        context.Response.StatusCode = ((conf.Opt.WEBFrontEndEnable.bval) ? (int)HttpStatusCode.OK : (int)HttpStatusCode.NotFound);
                    }
                    else
                    {
                        msg = Encoding.UTF8.GetBytes(
                            conf.HtmlTemplate.Render(
                                new
                        {
                            LANG  = conf.Opt.SYSLANGConsole.value.ToLower(),
                            TITLE = string.Format(
                                Properties.Resources.httpDateLogTitle,
                                urlPart[2],
                                urlPart[3],
                                urlPart[4]
                                ),
                            TOPMENU = string.Format(
                                Properties.Resources.ircLogArchive,
                                conf.Opt.IRCChannel.value
                                ),
                            DATE      = DateTime.Now.ToString(),
                            GENERATOR = conf.HttpSrv.wUserAgent,
                            DATEY     = urlPart[2],
                            DATEM     = urlPart[3],
                            DATED     = urlPart[4]
                        },
                                "IrcLogTemplate.html",
                                filePath
                                )
                            );
                        if (conf.Opt.WEBCacheEnable.bval)
                        {
                            stCore.stCache.SetCacheObject <byte[]>(cacheid, msg, DateTime.Now.AddHours(6));
                        }
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                    }
                }
                else
                {
                    context.Response.StatusCode = (int)HttpStatusCode.OK;
#if DEBUG_isCached
                    stConsole.WriteHeader("IRC LOG content is cached: " + cacheid + " : " + msg.Length.ToString());
#endif
                }
            }
            catch (Exception e)
            {
                CoCWebSrv._ErrorHtmlDefault(
                    conf,
                    HttpStatusCode.InternalServerError,
                    e.Message,
                    context
                    );
                return;
            }
            try
            {
                if (context.Response.StatusCode == (int)HttpStatusCode.OK)
                {
                    context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "max-age=2629000, public");
                }
                else
                {
                    context.Response.AddHeader(conf.HttpSrv.httpCacheControl, "no-cache");
                }
                context.Response.AddHeader(conf.HttpSrv.httpContentType, HttpUtil.GetMimeType("", HttpUtil.MimeType.MimeHtml));
                context.Response.ContentLength64 = msg.Length;
                context.Response.OutputStream.Write(msg, 0, msg.Length);
                context.Response.OutputStream.Close();
            }
#if DEBUG
            catch (Exception e)
            {
                conf.ILog.LogError(
                    string.Format(
                        Properties.Resources.fmtMainError,
                        string.Format(fmtClassName, "Template"),
                        e.GetType().Name,
                        e.Message
                        )
                    );
#else
            catch (Exception)
            {
#endif
                context.Response.Abort();
                return;
            }
            context.Response.Close();
        }
コード例 #7
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);
        }