Пример #1
0
        string SendResponse(HttpListenerRequest request)
        {
            try
            {
                string[] urlParts = request.RawUrl.Split('/');
                string   lastPart = urlParts.Length > 0? urlParts[urlParts.Length - 1] : null;
                Holder   holder   = null;

                if (Leagues.Count == 1)
                {
                    holder = Leagues.First();
                }
                else if (urlParts.Length > 1)
                {
                    holder = Leagues.Find(x => x.Key == urlParts[1]);
                }

                if (request.RawUrl == "/")
                {
                    if (Leagues.Count == 1)
                    {
                        return(ReportPages.OverviewPage(holder, false, ReportPages.GameHyper, OutputFormat.Svg));
                    }
                    else
                    {
                        return(ReportPages.RootPage(Leagues));
                    }
                }
                else if (lastPart.EndsWith(".html"))
                {
                    return(HtmlResponse(request.RawUrl, lastPart, holder));
                }
                else
                {
                    return(RestResponse(request));
                }
            }
            catch (Exception ex)
            {
                return("<html><body>\n" + ex.Message + "\n<br/><br/>\n" + ex.StackTrace + "</body></html>");

                throw;
            }
        }
Пример #2
0
        /// <summary>Generate reports for the selected leagues, and write them to disk.</summary>
        public static void ExportReports(string path, bool includeSecret, List <Holder> selected, Progress progress = null)
        {
            if (path != null)
            {
                int    denominator = selected.Count * 4 + 1;
                double numerator   = 0.0;
                if (progress == null)
                {
                    progress = DummyProgress;
                }

                if (selected.Any())
                {
                    using (StreamWriter sw = File.CreateText(Path.Combine(path, "index." + selected[0].ReportTemplates.OutputFormat.ToExtension())))
                        sw.Write(ReportPages.RootPage(selected));
                }
                progress(++numerator / denominator, "Root page exported.");

                foreach (Holder holder in selected)
                {
                    Directory.CreateDirectory(Path.Combine(path, holder.Key));

                    using (StreamWriter sw = File.CreateText(Path.Combine(path, holder.Key, "index." + holder.ReportTemplates.OutputFormat.ToExtension())))
                        sw.Write(ReportPages.OverviewPage(holder, includeSecret, ReportPages.GameHyper, holder.ReportTemplates.OutputFormat));
                    progress(++numerator / denominator, "Overview page exported.");

                    ExportPlayers(holder, path);
                    progress(++numerator / denominator, "Players pages exported.");

                    foreach (LeagueTeam leagueTeam in holder.League.Teams)
                    {
                        using (StreamWriter sw = File.CreateText(Path.Combine(path, holder.Key, "team" + leagueTeam.TeamId.ToString("D2", CultureInfo.InvariantCulture) + "." + holder.ReportTemplates.OutputFormat.ToExtension())))
                            sw.Write(ReportPages.TeamPage(holder.League, includeSecret, leagueTeam, ReportPages.GameHyper, holder.ReportTemplates.OutputFormat));
                    }
                    progress(++numerator / denominator, "Team pages exported.");

                    ExportGames(holder, path);
                    progress(++numerator / denominator, "Games pages exported.");
                }
            }
        }
Пример #3
0
        /// <summary>Generate reports for the selected leagues, and write them to disk.</summary>
        public static void ExportReports(string path, bool includeSecret, List <Holder> selected, ShowProgress progress = null)
        {
            if (path != null)
            {
                Progress myProgress = new Progress()
                {
                    Denominator = selected.Count * 3 + 1, ShowProgress = progress
                };

                if (selected.Any())
                {
                    using (StreamWriter sw = File.CreateText(Path.Combine(path, "index." + selected[0].ReportTemplates.OutputFormat.ToExtension())))
                        sw.Write(ReportPages.RootPage(selected));
                }
                myProgress.Increment("Root page exported.");

                foreach (Holder holder in selected)
                {
                    Directory.CreateDirectory(Path.Combine(path, holder.Key));

                    using (StreamWriter sw = File.CreateText(Path.Combine(path, holder.Key, "index." + holder.ReportTemplates.OutputFormat.ToExtension())))
                        sw.Write(ReportPages.OverviewPage(holder, includeSecret, holder.ReportTemplates.OutputFormat));
                    myProgress.Increment(holder.League.Title + " Overview page exported.");

                    foreach (LeagueTeam leagueTeam in holder.League.Teams)
                    {
                        using (StreamWriter sw = File.CreateText(Path.Combine(path, holder.Key, "team" + leagueTeam.TeamId.ToString("D2", CultureInfo.InvariantCulture) + "." + holder.ReportTemplates.OutputFormat.ToExtension())))
                            sw.Write(ReportPages.TeamPage(holder.League, includeSecret, leagueTeam, holder.ReportTemplates.OutputFormat));
                        myProgress.Advance(1 / holder.League.Teams.Count, "Team " + leagueTeam.Name + " page exported.");
                    }
                    myProgress.Advance(0, "Team pages exported.");

                    ExportGames(holder, path, myProgress);
                    myProgress.Advance(0, "Games pages exported.");
                }
            }
        }