private static void WriteTemplate(string sourceFilePath, SubmitFormTemplate <WMColumnTemplate> template, WrapperKind wrapperKind, string targetDirectory)
        {
            var    className = Path.GetFileNameWithoutExtension(sourceFilePath);
            string wrapperCode;

            switch (wrapperKind)
            {
            case WrapperKind.TemplateWrapper:
                className  += "TemplateWrapper";
                wrapperCode = TemplateWrapperBuilder.BuildClass(className, template);
                break;

            case WrapperKind.ValuesWrapper:
                className  += "ValuesWrapper";
                wrapperCode = ValuesWrapperBuilder.BuildClass(className, template);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(wrapperKind), wrapperKind, null);
            }

            File.WriteAllText(
                Path.Combine(targetDirectory, Path.ChangeExtension(className, "cs")),
                wrapperCode, Encoding.UTF8);
        }
Example #2
0
        public void ApplyTemplate <TColumnTemplate>(SubmitFormTemplate <TColumnTemplate> template,
                                                    Dictionary <string, object> values = null)
            where TColumnTemplate : class, IShapeColumnTemplate
        {
            if (null == template)
            {
                throw new ArgumentNullException(nameof(template));
            }

            Reset();

            _templateName          = template.TemplateName;
            _templateBaseDirectory = template.BaseDirectory;

            Text = template.Text ?? throw new BadTemplateException("null == template.Text");

            foreach (var stepTemplate in template.Steps)
            {
                if (null == stepTemplate.TunableShape)
                {
                    throw new BadTemplateException("null == stepTemplate.TunableShape");
                }

                var tunableShape = new TunableShape
                {
                    Top    = 0,
                    Left   = 0,
                    Margin = new Padding(0, 0, 0, 0)
                };

                tunableShape.ApplyTemplate(stepTemplate.TunableShape);

                tunableShape.ServiceCommand += (sender, args) =>
                {
                    ServiceCommand?.Invoke(sender, args);
                };

                _steps.Add(new Step(tunableShape, stepTemplate.ActionText));
            }

            ApplyShape(values);

            previousButton.Visible = false;
        }
        public static SubmitForm BuildSubmitForm(ExtensionManager extensionManager, SubmitFormTemplate <WMColumnTemplate> template,
                                                 Dictionary <string, object> values = null)
        {
            if (null == extensionManager)
            {
                throw new ArgumentNullException(nameof(extensionManager));
            }

            if (null == template)
            {
                throw new ArgumentNullException(nameof(template));
            }

            var submitForm = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(extensionManager, submitForm);

            submitForm.ApplyTemplate(template, values);

            return(submitForm);
        }
Example #4
0
        public static string BuildClass(string className, SubmitFormTemplate <WMColumnTemplate> submitFormTemplate)
        {
            if (null == className)
            {
                throw new ArgumentNullException(nameof(className));
            }

            if (null == submitFormTemplate)
            {
                throw new ArgumentNullException(nameof(submitFormTemplate));
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("using System;");
            stringBuilder.AppendLine("using System.Collections.Generic;");

            stringBuilder.AppendLine("");

            stringBuilder.AppendLine("namespace WMBusinessTools.Extensions.StronglyTypedWrappers");
            stringBuilder.AppendLine("{");

            bool onlyOneStep = 1 == submitFormTemplate.Steps.Count;

            stringBuilder.AppendLine("internal sealed class " + className + (onlyOneStep ? ": StronglyTypedValuesWrapper" : ""));
            stringBuilder.AppendLine("{");

            int stepNumber = 1;

            foreach (var submitFormTemplateStep in submitFormTemplate.Steps)
            {
                var innerClassName  = "Step" + stepNumber;
                var constructorName = innerClassName;

                if (!onlyOneStep)
                {
                    stringBuilder.AppendLine("public sealed class " + innerClassName + ": StronglyTypedValuesWrapper");
                    stringBuilder.AppendLine("{");
                }
                else
                {
                    constructorName = className;
                }

                int controlNumber = 1;

                foreach (var tunableShapeColumn in submitFormTemplateStep.TunableShape.Columns)
                {
                    controlNumber = ProcessColumn(stringBuilder, tunableShapeColumn.Controls, controlNumber);
                }

                stringBuilder.AppendLine();

                stringBuilder.AppendLine("public " + constructorName + "()");
                stringBuilder.AppendLine("{");
                stringBuilder.AppendLine("}");

                stringBuilder.AppendLine("public " + constructorName + "(List<object> values)");
                stringBuilder.AppendLine("{");
                stringBuilder.AppendLine("if (null == values)");
                stringBuilder.AppendLine("throw new ArgumentNullException(nameof(values));");
                stringBuilder.AppendLine("ApplyOutcomeValues(values);");
                stringBuilder.AppendLine("}");

                if (!onlyOneStep)
                {
                    stringBuilder.AppendLine("}");
                }

                stepNumber++;
            }

            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("}");

            return(stringBuilder.ToString());
        }
 public Step2(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[1])
 {
 }
 public CreatePurseFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
Example #7
0
        public static string BuildClass(string className, SubmitFormTemplate <WMColumnTemplate> submitFormTemplate)
        {
            if (null == className)
            {
                throw new ArgumentNullException(nameof(className));
            }

            if (null == submitFormTemplate)
            {
                throw new ArgumentNullException(nameof(submitFormTemplate));
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("using Xml2WinForms.Templates;");
            stringBuilder.AppendLine("using WMBusinessTools.Extensions.Templates.Controls;");

            stringBuilder.AppendLine("");

            stringBuilder.AppendLine("namespace WMBusinessTools.Extensions.StronglyTypedWrappers");
            stringBuilder.AppendLine("{");

            bool onlyOneStep = 1 == submitFormTemplate.Steps.Count;

            stringBuilder.AppendLine("internal sealed class " + className + (onlyOneStep ? ": StronglyTypedTemplateWrapper" : ""));
            stringBuilder.AppendLine("{");

            int stepNumber = 1;

            foreach (var submitFormTemplateStep in submitFormTemplate.Steps)
            {
                var innerClassName  = "Step" + stepNumber;
                var constructorName = innerClassName;

                if (!onlyOneStep)
                {
                    stringBuilder.AppendLine("public sealed class " + innerClassName + ": StronglyTypedTemplateWrapper");
                    stringBuilder.AppendLine("{");
                }
                else
                {
                    constructorName = className;
                }

                int controlNumber = 1;

                foreach (var tunableShapeColumn in submitFormTemplateStep.TunableShape.Columns)
                {
                    var сontrolTemplates = new List <ControlTemplate>();

                    foreach (var controlTemplate in tunableShapeColumn.Controls)
                    {
                        сontrolTemplates.AddRange(SelectControlTemplates(controlTemplate));
                    }

                    foreach (var controlTemplate in сontrolTemplates)
                    {
                        controlNumber = ProcessColumn(stringBuilder, controlTemplate, controlNumber);
                        controlNumber++;
                    }
                }

                stringBuilder.AppendLine();

                stringBuilder.AppendLine("public " + constructorName + "(SubmitFormTemplate<WMColumnTemplate> template)");
                stringBuilder.AppendLine(":base(template.Steps[" + (stepNumber - 1) + "])");
                stringBuilder.AppendLine("{");
                stringBuilder.AppendLine("}");

                if (!onlyOneStep)
                {
                    stringBuilder.AppendLine("}");
                }

                stepNumber++;
            }

            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("}");

            return(stringBuilder.ToString());
        }
        public static SubmitFormTemplate <WMColumnTemplate> LoadSubmitFormTemplate(string filePath)
        {
            if (null == filePath)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            // SubmitFormTemplate
            var result = TryLoadSubmitFormTemplate(() =>
                                                   Utils.TemplateLoader.LoadTemplateFromJsonFile <SubmitFormTemplate <WMColumnTemplate> >(filePath));

            if (null != result)
            {
                return(result);
            }

            // TunableShapeTemplate
            result = TryLoadSubmitFormTemplate(() =>
            {
                var tunableShapeTemplate = Utils.TemplateLoader
                                           .LoadTemplateFromJsonFile <TunableShapeTemplate <WMColumnTemplate> >(filePath);

                var stepTemplates = new List <StepTemplate <WMColumnTemplate> >
                {
                    new StepTemplate <WMColumnTemplate>(tunableShapeTemplate, "action")
                };

                var submitFormTemplate = new SubmitFormTemplate <WMColumnTemplate>("text");
                submitFormTemplate.Steps.AddRange(stepTemplates);

                return(submitFormTemplate);
            });

            if (null != result)
            {
                return(result);
            }

            // FilterFormTemplate
            result = TryLoadSubmitFormTemplate(() =>
            {
                var filterFormTemplate = Utils.TemplateLoader
                                         .LoadTemplateFromJsonFile <FilterFormTemplate <WMColumnTemplate> >(filePath);

                var tunableShapeTemplate =
                    new TunableShapeTemplate <WMColumnTemplate>();
                tunableShapeTemplate.Columns.Add(filterFormTemplate.FilterScreen.Column);

                var stepTemplates = new List <StepTemplate <WMColumnTemplate> >
                {
                    new StepTemplate <WMColumnTemplate>(tunableShapeTemplate, "action")
                };

                var submitFormTemplate = new SubmitFormTemplate <WMColumnTemplate>("text");
                submitFormTemplate.Steps.AddRange(stepTemplates);

                return(submitFormTemplate);
            });

            return(result);
        }
 public RejectInvoiceFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
 public CreateOutgoingInvoiceFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
 public DbSettingsFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
Example #12
0
 public MoneybackFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
 public SendMessageToDeveloperFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
Example #14
0
 public FinishProtectionFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
 public SendSmsFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }
 public RedeemPaymerFormTemplateWrapper(SubmitFormTemplate <WMColumnTemplate> template)
     : base(template.Steps[0])
 {
 }