Exemple #1
0
        public IActionResult Index(SourceCode sourceCode)
        {
            GenerateDataModel model = new GenerateDataModel();

            model.Source = sourceCode.Source;

            // todo: make not hacky
            sourceCode.Accessor        = _accessor;
            sourceCode.LibraryExporter = _exporter;

            var compileResult = sourceCode.Compile();

            if (!compileResult.IsValid)
            {
                model.HasCompileErrors = true;
                model.CompileErrors    = compileResult.Errors;

                HttpContext.Session.Remove(RandomObjectsSessionKey);
            }
            else
            {
                model.RandomObjects = sourceCode.GenerateData(10);
                model.PropertyNames = model.RandomObjects.First().Keys;

                HttpContext.Session.SetString(RandomObjectsSessionKey, JsonConvert.SerializeObject(model.RandomObjects));
            }

            return(View(model));
        }
Exemple #2
0
        public IActionResult Index()
        {
            GenerateDataModel model = new GenerateDataModel();

            model.Source =
                @"public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
    public string EmailAddress { get; set; }
    //Add your own properties here
}";
            return(View(model));
        }
Exemple #3
0
        public static void WriteFile(GenerateDataModel model)
        {
            var fileContent = JsonConvert.SerializeObject(model, Formatting.Indented);

            File.WriteAllText(AnswerFile, fileContent);
        }