public ActionResult <ApiFightTextSimulationResult> PostHtml([FromBody] string xmlFight)
        {
            try
            {
                ApiFightTextSimulationResult res  = new ApiFightTextSimulationResult();
                FightSimulation       sim         = new FightSimulation(Program.World, xmlFight);
                StringWriter          log         = new StringWriter();
                StringWriter          html        = new StringWriter();
                FightSimulationResult fightResult = sim.Run(log);
                fightResult.WriteToHtml(html);
                log.Flush();
                html.Flush();
                res.Text = html.ToString();
                res.Log  = log.ToString();

                if (res.Log.Length > (1024 * 1024))
                {
                    res.Log = res.Log.Substring(0, (1024 * 1024)) + " ...";
                }

                return(res);
            }
            catch (Exception e)
            {
                return(StatusCode(400, e));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                WriteHelp();
                return;
            }



            string definition = File.ReadAllText(args[0]);
            string fight      = File.ReadAllText(args[1]);

            World        world     = new World(definition);
            StringWriter log       = new StringWriter();
            StringWriter outStream = new StringWriter();

            FightSimulation       simulation = new FightSimulation(world, fight);
            FightSimulationResult res        = simulation.Run(log);

            log.Flush();
            System.Console.WriteLine(log.ToString());


            string outFile = "out.";

            switch (args[2])
            {
            case "csv":
                outFile += "csv";
                res.WriteToCsv(outStream);
                break;

            case "html":
                outFile += "html";
                res.WriteToHtml(outStream);
                break;

            case "htmlchart":
                outFile += "htmlchart";
                res.WriteToHtmlChart(outStream);
                break;

            default:
                outFile = String.Empty;
                break;
            }
            if (!String.IsNullOrEmpty(outFile))
            {
                outStream.Flush();
                File.WriteAllText(outFile, outStream.ToString());
            }
        }