Пример #1
0
        void FormatCalendarAsHtml(string args)
        {
            var bot     = new GameBot.Bot("roller", "roller");
            var results = bot.FindEvents(args);

            string yearlast   = "";
            string seasonlast = "";
            string weeklast   = "";
            string daylast    = "";
            string taglast    = "";

            StringBuilder b = new StringBuilder();

            b.AppendLine("<html>");
            b.AppendFormat("<head><title>Calendar</title></head>");
            b.AppendLine("<body>");
            b.AppendLine("<style>tr {vertical-align:text-top;} </style>");
            b.AppendLine("<center>");
            b.AppendLine("<table style=\"font-family: arial, sans-serif; font-size:8pt; max-width:800px;\">");

            if (results == null || results.Count == 0)
            {
                WriteSimpleOutput(String.Format("Events for '{0}' not found", args));
                return;
            }

            foreach (var p in results)
            {
                var    v = p.val;
                string date;
                string desc;
                string mm, dd, year;
                string tag, x;

                GameHost.Worker.Parse2(v, out date, out desc);
                GameHost.Worker.Parse3Ex(date, out mm, out dd, out year, "/");
                GameHost.Worker.Parse2Ex(desc, out tag, out x, ":");

                if (x == "")
                {
                    desc = tag;
                    tag  = "";
                }
                else
                {
                    desc = x;
                }

                int m = 0;
                int d = 0;
                Int32.TryParse(mm, out m);
                Int32.TryParse(dd, out d);

                if (m < 1 || m > 6)
                {
                    continue;
                }
                if (d < 1 || d > 56)
                {
                    continue;
                }
                if (m == 6 && d > 14)
                {
                    continue;
                }

                string season = seasons[m - 1];
                string week   = m == 6 ? hweeks[(d - 1) / 7] : weeks[(d - 1) / 7];

                if (yearlast != year)
                {
                    if (yearlast != "")
                    {
                        b.AppendLine("<tr><td style=\"width:3em;\">&nbsp;</td></tr>");
                    }
                    b.AppendFormat("<tr style=\"text-align:center\"><td colspan=\"3\"><h1><a href=\"/calendar//{0}\">{0}</a><br></h1></td></tr>\r\n", year);
                    seasonlast = "";
                }

                if (seasonlast != season)
                {
                    if (seasonlast != "")
                    {
                        b.AppendLine("<tr><td>&nbsp;</td></tr>");
                    }
                    b.AppendFormat("<tr style=\"text-align:center\"><td colspan=\"3\"><h2><a href=\"/calendar/{0}/[0-9]+/{1}\">{2} Season</a><br></h2></td></tr>\r\n", m, year, season);
                    weeklast = "";
                }

                if (weeklast != week)
                {
                    b.AppendFormat("<tr><td colspan=\"2\"><h3>{0} Week<br></h3></td></tr>\r\n", week);
                    daylast = "";
                    taglast = "";
                }

                string day = m + "/" + d;

                string dprint = (day == daylast) ? "" : day;

                if (dprint != "")
                {
                    dprint = String.Format("<a href=\"/calendar/{0}/\">{0}</a>", dprint);
                }

                if (tag == taglast)
                {
                    b.AppendFormat("<tr><td style=\"text-align:right\">{0}</td><td style=\"text-align:right\">*</td><td>{1}</td></tr>\r\n", dprint, desc.Replace("<", "&lt;").Replace(">", "&gt;"));
                }
                else
                {
                    b.AppendFormat("<tr><td style=\"text-align:right\">{0}</td><td style=\"text-align:right\"><a href=\"/calendar/{1}:\">{1}:</a></td><td>{2}</td></tr>\r\n", dprint, tag, desc.Replace("<", "&lt;").Replace(">", "&gt;"));
                }

                seasonlast = season;
                yearlast   = year;
                weeklast   = week;
                daylast    = day;
                taglast    = tag;
            }
            b.AppendLine("</table>");
            b.AppendLine("</center>");
            b.AppendLine("</body>");
            b.AppendLine("</html>");

            WriteRawOutput(b.ToString());
        }
Пример #2
0
        void FormatCalendarChoicesHtml()
        {
            var bot     = new GameBot.Bot("roller", "roller");
            var results = bot.FindEvents(".");

            StringBuilder b = new StringBuilder();

            b.AppendLine("<html>");
            b.AppendFormat("<head><title>Calendar</title></head>");
            b.AppendLine("<body>");
            b.AppendLine("<center>");
            b.AppendLine("<div style=\"font-family: arial, sans-serif; font-size:8pt; max-width:800px;\">");
            b.AppendLine("<br>The following tags are in use in the events calendar:<br><br>");

            var dict = new Dictionary <string, int>();

            foreach (var r in results)
            {
                var v = r.val;

                string date;
                string desc;
                string mm, dd, year;
                string tag;
                string x;

                GameHost.Worker.Parse2(v, out date, out desc);
                GameHost.Worker.Parse3Ex(date, out mm, out dd, out year, "/");

                GameHost.Worker.Parse2Ex(desc, out tag, out x, ":");

                if (!dict.ContainsKey(year))
                {
                    dict[year] = 1;
                }

                if (tag.Length > 0 && x != null && x.Length > 0)
                {
                    if (!dict.ContainsKey(tag))
                    {
                        dict[tag] = 1;
                    }
                }
            }

            var tags = dict.Keys.ToList();

            tags.Sort();


            bool fFirst        = true;
            bool fFirstNonYear = true;

            foreach (var r in tags)
            {
                if (Char.IsDigit(r[0]))
                {
                    if (!fFirst)
                    {
                        b.Append("&nbsp; * &nbsp;");
                    }

                    b.AppendFormat("<a href=\"/calendar//{0}\">{0}</a> \r\n", r);
                }
                else
                {
                    if (fFirstNonYear)
                    {
                        fFirstNonYear = false;
                        b.AppendLine("<br><br>");
                    }
                    else
                    {
                        b.Append("&nbsp; * &nbsp;");
                    }

                    b.AppendFormat("<a href=\"/calendar/{0}:\">{0}</a> \r\n", r);
                }

                fFirst = false;
            }

            b.AppendLine("</div>");
            b.AppendLine("</center>");
            b.AppendLine("</body>");
            b.AppendLine("</html>");
            WriteRawOutput(b.ToString());
        }