public static string CreateTestData(SurveyObject survey)
        {
            StringBuilder csharp = new StringBuilder();

            foreach (var page in survey.pages)
            {
                BuildPropertyData(csharp, page.elements.Where(e => Common._simpleTypeElements.Contains(e.type)).ToList(), page);
            }

            List <Element> survey_dynamic_elements = new List <Element>();

            foreach (var page in survey.pages)
            {
                Common.GetDynamicElements(survey_dynamic_elements, page.elements);
            }

            if (survey_dynamic_elements.Count > 0)
            {
                BuildDynamicPropertyData(csharp, survey_dynamic_elements);
            }

            return(csharp.ToString());
        }
        public static string CreateValidators(SurveyObject survey, string _namespace, string className, bool commentedOut)
        {
            _commentedOut = commentedOut;

            _surveyAllElements = new List <Element>();
            _calculatedValues  = survey.calculatedValues;

            foreach (var page in survey.pages)
            {
                Common.AddSurveyElement(_surveyAllElements, page, page.elements);
            }

            //  Get a list of dynamic properties, from the matrixdynamic and the paneldynamic.
            //  Then if there is such items, we create the classes validators
            List <Element> survey_dynamic_elements = new List <Element>();

            foreach (var page in survey.pages)
            {
                Common.GetDynamicElements(survey_dynamic_elements, page.elements);
            }

            StringBuilder csharp = new StringBuilder();

            csharp.AppendLine("using System.Collections.Generic;");
            csharp.AppendLine("using FluentValidation;");
            csharp.AppendLine("using System.Linq;");
            csharp.AppendLine("using ComplaintFormCore.Resources;");
            csharp.AppendLine("using ComplaintFormCore.Web_Apis.Models;");

            csharp.AppendLine();

            csharp.Append("namespace ");
            csharp.AppendLine(_namespace);
            csharp.AppendLine("{");

            //  STEP 1: Create the class(s) implementing AbstractValidator

            //  Create the main class validator
            csharp.Append("public partial class ");
            csharp.Append(className);
            csharp.Append("Validator: AbstractValidator<");
            csharp.Append(className);
            csharp.Append(">");
            csharp.AppendLine("{");

            //  constructor
            csharp.Append("public ");
            csharp.Append(className);
            csharp.Append("Validator(SharedLocalizer _localizer)");
            csharp.AppendLine("{");

            csharp.AppendLine("ValidatorOptions.Global.CascadeMode = CascadeMode.Continue;");
            csharp.AppendLine();

            foreach (var page in survey.pages)
            {
                //  We just don't want to deal with the non-html elements
                BuildPageValidator(csharp, page.elements.Where(e => e.type != "html").ToList(), page);
            }

            if (survey_dynamic_elements.Count > 0)
            {
                SetDynamicValidators(csharp, survey_dynamic_elements);
            }

            List <Element> survey_matrix_elements = new List <Element>();

            foreach (var page in survey.pages)
            {
                Common.GetMatrixElements(survey_matrix_elements, page.elements);
            }

            if (survey_matrix_elements.Count > 0)
            {
                csharp.AppendLine();
                BuildMatrixValidators(csharp, survey_matrix_elements);
            }

            csharp.AppendLine("}");             // end constructor

            //if (survey.calculatedValues != null)
            //{
            //	foreach (var methods in survey.calculatedValues)
            //	{
            //		BuildCalculatedValues(csharp, methods);
            //	}
            //}

            csharp.AppendLine("}");            // end main class
            csharp.AppendLine("}");            // end namespace

            return(csharp.ToString());
        }
Ejemplo n.º 3
0
        public static string CreateModel(SurveyObject survey, string @namespace, string className)
        {
            var builder = new ModelBuilder(survey);

            return(builder.GenerateModel(@namespace, className));
        }
Ejemplo n.º 4
0
 public SurveyParser(SurveyObject survey)
 {
     _survey = survey;
 }
Ejemplo n.º 5
0
 public ModelBuilder(SurveyObject survey)
 {
     _modelProperties = new SurveyParser(survey).GetProperties();
 }