Exemplo n.º 1
0
        static string MakeCSVfromTemplate()
        {
            // check if in correct state
            if (templateName == null || currTmpl == null ||
                templateType != TemplateType.CSV)
            {
                return(null);
            }

            StreamWriter outfile = null;
            string       oldDir  = Directory.GetCurrentDirectory();

            try {
                ITmplBlock tmplDoc = currTmpl.ParseBlock();
                tmplDoc.Out();
                // we export CSVs also to pdfs directory. historically inconsistent.
                string workingDir = Path.Combine(oldDir, "pdfs");
                //Directory.SetCurrentDirectory(workingDir);
                string csvFile = Path.Combine(workingDir, templateName + ".csv");
                outfile = new StreamWriter(csvFile);
                outfile.Write(tmplDoc.BlockString);
                outfile.Close();
                return(csvFile);
            }
            finally {
                if (outfile != null)
                {
                    outfile.Close();
                }
                templateName = null;
                currTmpl     = null;
            }
        }
Exemplo n.º 2
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            TreeModel model = treeDebaters.Model;
            TreeIter  iter;

            if (model.GetIterFirst(out iter))
            {
                try {
                    ITemplate  tmpl         = MiscHelpers.GetTemplate("debaters", type);
                    ITmplBlock tmplDebaters = tmpl.ParseBlock("DEBATERS");
                    int        n            = 0;
                    do
                    {
                        n++;
                        TreeIter        storeIter = ConvertModelIterToStoreIter(iter);
                        EditableDebater d         = (EditableDebater)store.GetValue(storeIter, 0);
                        tmplDebaters.Assign("NUM", n.ToString());
                        tmplDebaters.Assign("NAME", d.Name.ToString());
                        tmplDebaters.Assign("CLUB", d.Club.ToString());
                        tmplDebaters.Assign("AGE", d.Age.ToString());
                        tmplDebaters.Assign("ROLE", EscapeString(d.Role.ToString(), type));
                        tmplDebaters.Assign("BLACKLIST", EscapeString(d.BlackList.ToString(), type));
                        tmplDebaters.Assign("WHITELIST", EscapeString(d.WhiteList.ToString(), type));
                        tmplDebaters.Assign("EXTRAINFO", EscapeString(d.ExtraInfo.ToString(), type));
                        tmplDebaters.Out();
                    }while(model.IterNext(ref iter));
                    MiscHelpers.AskShowTemplate(this,
                                                "Debaters successfully generated, see " +
                                                "pdfs/debaters.(pdf|csv)",
                                                MiscHelpers.MakeExportFromTemplate()
                                                );
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not export Debaters: " + ex.Message, MessageType.Error);
                }
            }
        }
Exemplo n.º 3
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            try {
                ITemplate tmpl      = MiscHelpers.GetTemplate("ranking", type);
                string    separator = type == MiscHelpers.TemplateType.PDF ?
                                      "+" : "\",\"";
                ITmplBlock tmplTitle = tmpl.ParseBlock("TITLE");
                tmplTitle.Assign("V", Tournament.I.Title);
                tmplTitle.Out();

                ITmplBlock tmplTeams = tmpl.ParseBlock("TEAMS");
                int        pos       = 1;
                int        realPos   = 1;
                foreach (RankingDataItem item in teams)
                {
                    TeamData td = (TeamData)item.Data;
                    if (!(pos > 1 && teams[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplTeams.Assign("POS", realPos.ToString());
                    tmplTeams.Assign("NAME", td.TeamName);

                    List <int> speakerPos = new List <int>(3);
                    foreach (RoundDebater rd in td)
                    {
                        int realPos_ = 1;
                        for (int i = 0; i < speakers.Count; i++)
                        {
                            if (!(i > 0 && speakers[i - 1].TotalPoints == speakers[i].TotalPoints))
                            {
                                realPos_ = i + 1;
                            }
                            if (rd.Equals(speakers[i].Data))
                            {
                                speakerPos.Add(realPos_);
                            }
                        }
                    }
                    speakerPos.Sort();
                    ITmplBlock tmplSpeakerPos = tmpl.ParseBlock("SPEAKERPOS");
                    for (int i = 0; i < speakerPos.Count; i++)
                    {
                        tmplSpeakerPos.Assign("POS", speakerPos[i].ToString());
                        tmplSpeakerPos.Assign("SEP", i == speakerPos.Count - 1?"":separator);
                        tmplSpeakerPos.Out();
                    }


                    // we divide the avg by three to make it comparable to team position
                    tmplTeams.Assign("SPEAKERPOSAVG", item.AvgPoints < 0 ? "?" :
                                     OPDtabData.MiscHelpers.FmtDecimal(OPDtabData.MiscHelpers.CalcExactAverage(speakerPos) / 3)
                                     );

                    if (mBreakingTeams.Contains(pos - 1))
                    {
                        tmplTeams.Assign("BREAKMARK", "Break");
                    }
                    else
                    {
                        tmplTeams.Assign("BREAKMARK", "");
                    }
                    tmplTeams.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDTEAM");
                    int        nPoints            = 0;
                    if (item.RoundPoints.Count == 0)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.RoundPoints.Count; i++)
                        {
                            string[] PosToStr = new string[] { "G", "O", "F" };
                            tmplPointsPerRound.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.RoundPoints[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      PosToStr[(int)RoundResultData.PosToRoleType[item.RoundPositions[i]]]);
                            tmplPointsPerRound.Assign("SEP", i == item.RoundPoints.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplTeams.Out();
                    pos++;
                }

                ITmplBlock tmplSpeakers = tmpl.ParseBlock("SPEAKERS");
                pos     = 1;
                realPos = 1;
                foreach (RankingDataItem item in speakers)
                {
                    RoundDebater rd = (RoundDebater)item.Data;
                    if (!(pos > 1 && speakers[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplSpeakers.Assign("POS", realPos.ToString());
                    tmplSpeakers.Assign("NAME", rd.Name.FirstName + " " + rd.Name.LastName);
                    tmplSpeakers.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    if (mTeamSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Team");
                    }
                    else if (mFreeSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Tab");
                    }
                    else if (mBestSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Raum");
                    }
                    else
                    {
                        tmplSpeakers.Assign("BREAKMARK", "");
                    }
                    tmplSpeakers.Assign("TEAMNAME", rd.Role.TeamName);

                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDSPEAKER");
                    int        nPoints            = 0;
                    if (item.Points == null)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.Points.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS",
                                                      OPDtabData.MiscHelpers.DoubleToStr(item.Points[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      OPDtabData.MiscHelpers.IntToStr(item.RoundPositions[i] + 1));
                            tmplPointsPerRound.Assign("SEP", i == item.Points.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("POS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplSpeakers.Assign("AVERAGEPOINTS", item.AvgPoints < 0 ? "?" :
                                        OPDtabData.MiscHelpers.FmtDecimal(item.AvgPoints));
                    tmplSpeakers.Out();
                    pos++;
                }
                MiscHelpers.AskShowTemplate(this,
                                            "Ranking Export successfully generated, see pdfs/ranking.(pdf|csv).",
                                            MiscHelpers.MakeExportFromTemplate()
                                            );
            }
            catch (Exception ex) {
                MiscHelpers.ShowMessage(this, "Could not export Ranking: " + ex.Message, MessageType.Error);
            }
        }
Exemplo n.º 4
0
        public static string MakePDFfromTemplate(string prefix, bool runtwice)
        {
            // check if in correct state
            if (templateName == null || currTmpl == null ||
                templateType != TemplateType.PDF)
            {
                return(null);
            }

            StreamWriter outfile = null;
            string       oldDir  = Directory.GetCurrentDirectory();

            try {
                ITmplBlock tmplDoc = currTmpl.ParseBlock();
                tmplDoc.Out();
                string fileName = prefix == null ? templateName :
                                  prefix.Replace(" ", "_") + "-" + templateName;
                string workingDir = Path.Combine(oldDir, "pdfs");
                Directory.SetCurrentDirectory(workingDir);
                string latexFile = Path.Combine(workingDir, fileName + ".tex");
                outfile = new StreamWriter(latexFile);
                outfile.Write(tmplDoc.BlockString);
                outfile.Close();
                // run latex
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents = false;
                proc.StartInfo.FileName  = "pdflatex";
                proc.StartInfo.Arguments = "-interaction=nonstopmode \"" + latexFile + "\"";
                // two times
                proc.Start();
                proc.WaitForExit();
                if (runtwice)
                {
                    proc.Start();
                    proc.WaitForExit();
                }
                // cleanup
                foreach (string ext in new string[] { "aux", "log", "out", "nav", "toc", "snm" })
                {
                    string fN = Path.Combine(workingDir, fileName + "." + ext);
                    if (File.Exists(fN))
                    {
                        File.Delete(fN);
                    }
                }
                // also cleanup generated tex file?
                if (AppSettings.I.DeleteTexFile)
                {
                    string fN = Path.Combine(workingDir, fileName + ".tex");
                    if (File.Exists(fN))
                    {
                        File.Delete(fN);
                    }
                }
                return(Path.Combine(workingDir, fileName + ".pdf"));
            }
            finally {
                if (outfile != null)
                {
                    outfile.Close();
                }
                Directory.SetCurrentDirectory(oldDir);
                templateName = null;
                currTmpl     = null;
            }
        }