public async Task <SubmissionIdentifier> Submit(SubmissionOptions options) { string url = ApiBaseUrl + $"?access_token={this.apiAccessToken}"; string jsonData = this.jsonUtils.Serialize(options); return(await this.requester.PostJsonAsync <SubmissionIdentifier>(url, jsonData)); }
public async Task ReportCountIsControlledBySubmissionOptions(SectorTypes testSector, int testEditableReportCount) { // Arrange var testConfig = new SubmissionOptions { EditableReportCount = testEditableReportCount }; var testOrg = new Organisation { OrganisationId = 1, SectorType = testSector }; var testUserOrg = new UserOrganisation { Organisation = testOrg }; DateTime testSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(testOrg.SectorType); var mockService = new Mock <SubmissionPresenter>( mockDataRepo.Object, mockScopeBL.Object, null, mockDraftFileBL.Object, MoqHelpers.CreateIOptionsSnapshotMock(testConfig)); // Call the real functions unless overridden mockService.CallBase = true; // Act SubmissionPresenter testService = mockService.Object; List <ReportInfoModel> actualResults = await testService.GetAllEditableReportsAsync(testUserOrg, testSnapshotDate); // Assert Assert.AreEqual( testEditableReportCount, actualResults.Count, $"Expected editable report count to be {testEditableReportCount}"); }
public ShortForm(string name) { var controls = new List <IControl> { new Control { IsRequired = true, Label = "First name", Type = ControlType.TextBox, Name = "FirstName", ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Validation = new List <IControlValidation> { new MinimumLengthControlValidation { HasValue = true, ValidationRule = "minlength", ValidationValue = "3", ValidationErrorMessage = "too short" }, new MaximumLengthControlValidation { HasValue = true, ValidationRule = "maxlength", ValidationValue = "5", ValidationErrorMessage = "too long" } } }, new Control { IsRequired = true, Label = "Email address", Type = ControlType.Email, Name = "EmailAddress", ExplanationText = "explanation about putting your email in this field", Tooltip = "a tool tip saying what is an email", Validation = new List <IControlValidation> { new EmailControlValidation { HasValue = true, ValidationRule = "email", ValidationErrorMessage = "not valid email" } } }, //new Control //{ // IsRequired = true, Label = "Pick a date", Type = ControlType.Calendar, Name = "DatePick" //}, new Control { IsRequired = true, Label = "Enter a Uk Postcode", Type = ControlType.TextBox, Name = "UkPostcode", ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Validation = new List <IControlValidation> { new RegularExpressionControlValidation { HasValue = true, ValidationRule = "regular-expression", ValidationValue = "(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$", ValidationErrorMessage = "not right" } } } }; var submissionOptions = new SubmissionOptions { DisplayText = "thanks for submitting" }; Name = name; SubmitText = "Submit"; SubmissionOptions = submissionOptions; Controls = controls; }
public IForm Create(BizFormInfo info) { if (info == null) { return(new Form()); } var autoresponder = new Autoresponder { Sender = info.FormConfirmationSendFromEmail, Subject = info.FormConfirmationEmailSubject, Template = info.FormConfirmationTemplate }; var notification = new Notification { Sender = info.FormSendFromEmail, Recipients = info.FormSendToEmail, Subject = info.FormEmailSubject, Template = info.FormEmailTemplate, AttachUploadedDocuments = info.FormEmailAttachUploadedDocs }; var submissionOptions = new SubmissionOptions { DisplayText = info.FormDisplayText, ClearAfterSave = info.FormClearAfterSave, RedirectUrl = info.FormRedirectToUrl }; var hasAutoResponder = !String.IsNullOrWhiteSpace(autoresponder.Sender); var hasNotificationEmail = !String.IsNullOrWhiteSpace(notification.Sender) && !String.IsNullOrWhiteSpace(notification.Recipients); var form = new Form { Name = info.FormName, SubmitText = !string.IsNullOrEmpty(info.FormSubmitButtonText) ? info.FormSubmitButtonText : "Save", Autoresponder = hasAutoResponder ? autoresponder : null, Notification = hasNotificationEmail ? notification : null, SubmissionOptions = submissionOptions }; foreach (var controlInfo in info.Form.GetFields(true, false)) { var control = _controlFactory.Create(controlInfo); if (control == null) { continue; } form.Controls.Add(control); } return(form); }
public async Task <IEnumerable <SubmissionIdentifier> > ExecuteTests(string sourceCode, Language language, IEnumerable <string> inputs) { var identifiers = new List <SubmissionIdentifier>(); foreach (var testInput in inputs) { var option = new SubmissionOptions { Input = testInput, Language = language, SourceCode = sourceCode }; identifiers.Add(await this.engine.Submit(option)); } return(identifiers); }
public ActionResult Submit() { // Variables. var tempGuid = default(Guid); var keys = Request.Form.AllKeys; var fileKeys = Request.Files.AllKeys; var formId = Guid.Parse(Request["FormId"]); var pageId = NumberUtility.AttemptParseInt(Request["PageId"]); var pageNode = pageId.HasValue ? Umbraco.TypedContent(pageId.Value) : null; var pageUrl = pageNode?.Url; var pageName = pageNode?.Name; // Get values. var values = keys .Where(x => Guid.TryParse(x, out tempGuid)) .Select(x => { var fieldValue = Request.Form.GetValues(x); return(new FieldSubmission { FieldId = Guid.Parse(x), FieldValues = fieldValue }); }) .ToList(); // Get file values. var fileValues = fileKeys .Where(x => Guid.TryParse(x, out tempGuid)) .Select(x => { // Variables. var fileValue = Request.Files.Get(x); // Extract file data: http://stackoverflow.com/a/16030326/2052963 var reader = new BinaryReader(fileValue.InputStream); var fileData = reader.ReadBytes((int)fileValue.InputStream.Length); var filename = fileValue.FileName; // Return file field submission. return(new FileFieldSubmission() { FieldId = Guid.Parse(x), FileData = fileData, FileName = filename }); }) .ToList(); // Payload. var payload = new[] { new PayloadSubmission() { Name = "URL", Value = pageUrl }, new PayloadSubmission() { Name = "Page Name", Value = pageName } }.Where(x => !string.IsNullOrWhiteSpace(x.Value)); // Submit form. var context = new FormRequestContext() { CurrentPage = pageNode, HttpContext = HttpContext, Services = Services, UmbracoContext = UmbracoContext, UmbracoHelper = Umbraco }; var options = new SubmissionOptions() { Validate = Config.EnableServerSideValidation }; var result = Submissions.SubmitForm(formId, values, fileValues, payload, options, context); // Return result. return(Json(new { Success = result.Success })); }
/// <summary> /// Submits a form. /// </summary> /// <param name="formId"> /// The ID of the form to submit. /// </param> /// <param name="data"> /// The form data to submit. /// </param> /// <param name="files"> /// The file data to submit. /// </param> /// <param name="payload"> /// Extra data related to the submission. /// </param> /// <param name="options"> /// The options for this submission. /// </param> /// <param name="context"> /// The contextual information for the form request. /// </param> /// <returns> /// The result of the submission. /// </returns> public SubmissionResult SubmitForm(Guid formId, IEnumerable <FieldSubmission> data, IEnumerable <FileFieldSubmission> files, IEnumerable <PayloadSubmission> payload, SubmissionOptions options, FormRequestContext context) { // Is the form ID valid? var form = Forms.Retrieve(formId); if (form == null) { return(new SubmissionResult() { Success = false }); } // Create submission context. var submissionContext = new FormSubmissionContext() { Files = files, Data = data, Form = form, Payload = payload, CurrentPage = context.CurrentPage, HttpContext = context.HttpContext, Services = context.Services, UmbracoContext = context.UmbracoContext, UmbracoHelper = context.UmbracoHelper, SubmissionId = Guid.NewGuid(), ExtraContext = new Dictionary <string, object>(), SubmissionCancelled = false }; // Invoke submitting event (gives listeners a chance to change the submission). Submitting?.Invoke(submissionContext); // Fail the form submission if SubmissionCancelled is true. if (submissionContext.SubmissionCancelled) { return(new SubmissionResult() { Success = false }); } // Validate against native field validations. foreach (var field in form.Fields) { var fieldId = field.Id; var value = data.Where(x => x.FieldId == fieldId) .SelectMany(x => x.FieldValues); if (!field.IsValid(value)) { return(new SubmissionResult() { Success = false }); } } // Validate? if (options.Validate) { var valuesById = data.GroupBy(x => x.FieldId).Select(x => new { Id = x.Key, Values = x.SelectMany(y => y.FieldValues).ToList() }).ToDictionary(x => x.Id, x => x.Values); var filesById = files.GroupBy(x => x.FieldId).Select(x => new { Id = x.Key, Values = x.Select(y => y).ToList() }).ToDictionary(x => x.Id, x => x.Values); foreach (var field in form.Fields) { var validations = field.Validations .Select(x => Validations.Retrieve(x)) .ToList(); if (!validations.Any()) { continue; } var validationContext = new ValidationContext() { Field = field, Form = form }; foreach (var validation in validations) { var dataValues = valuesById.ContainsKey(field.Id) ? valuesById[field.Id] : new List <string>(); var fileValues = filesById.ContainsKey(field.Id) ? filesById[field.Id] : new List <FileFieldSubmission>(); var isValid = validation .IsValueValid(dataValues, fileValues, validationContext); if (!isValid) { return(new SubmissionResult() { Success = false }); } } } } // Prepare the form handlers. // This occurs on the current thread in case the handler needs information // only available in the current thread. var enabledHandlers = form.Handlers .Where(x => x.Enabled) .ToArray(); try { foreach (var handler in enabledHandlers) { handler.PrepareHandleForm(submissionContext); } } catch (Exception ex) { Logger.Error <Submissions_Instance>(ex, PreHandlerError); return(new SubmissionResult() { Success = false }); } // Initiate form handlers on a new thread (they may take some time to complete). var task = new Task(() => { foreach (var handler in enabledHandlers) { handler.HandleForm(submissionContext); } }); task.ContinueWith(FormHandlersExceptionHandler, TaskContinuationOptions.OnlyOnFaulted); task.Start(); // Return success. return(new SubmissionResult() { Success = true }); }
public LongForm(string name) { var controls = new List <IControl> { new Control { IsRequired = true, Label = "Upload an image", Type = ControlType.UploadFile, Name = "ImageUpload", ExplanationText = "explanation about this field", Tooltip = "only image file extensions for now" }, new Control { IsRequired = true, Label = "First name", Type = ControlType.TextBox, Name = "FirstName", ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Validation = new List <IControlValidation> { new MinimumLengthControlValidation { HasValue = true, ValidationRule = "minlength", ValidationValue = "3", ValidationErrorMessage = "too short" }, new MaximumLengthControlValidation { HasValue = true, ValidationRule = "maxlength", ValidationValue = "5", ValidationErrorMessage = "too long" } } }, new Control { IsRequired = true, Label = "Enter a Uk Postcode", Type = ControlType.TextBox, Name = "UkPostcode", ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Validation = new List <IControlValidation> { new RegularExpressionControlValidation { HasValue = true, ValidationRule = "regular-expression", ValidationValue = "(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$", ValidationErrorMessage = "not right" } } }, new Control { IsRequired = true, Label = "Surname", Type = ControlType.TextBox, Name = "Surname", Validation = new List <IControlValidation> { new MaximumLengthControlValidation { HasValue = true, ValidationRule = "maxlength", ValidationValue = "9", ValidationErrorMessage = "too long" } } }, new Control { IsRequired = true, Label = "Email address", Type = ControlType.Email, Name = "EmailAddress", ExplanationText = "explanation about putting your email in this field", Tooltip = "a tool tip saying what is an email", Validation = new List <IControlValidation> { new EmailControlValidation { HasValue = true, ValidationRule = "email", ValidationErrorMessage = "not valid email" } } }, new Control { IsRequired = true, Label = "This is a checkbox", Type = ControlType.CheckBox, Name = "CheckYes", ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", DefaultValue = "Yes", DefaultValues = new Dictionary <string, bool> { { "Yes", true } } }, new Control { IsRequired = true, ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Label = "Radio button options", Type = ControlType.RadioButton, Name = "Shop", DefaultValue = "Daily\r\nWeekly\r\nFornightly\r\nMonthly", DefaultValues = new Dictionary <string, bool> { { "Daily", true }, { "Weekly", false }, { "Monthly", false } } }, new Control { IsRequired = true, ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Label = "Multiple choices", Type = ControlType.MultipleChoice, Name = "Where", DefaultValue = "Buses|Radio", DefaultValues = new Dictionary <string, bool> { { "Buses", true }, { "Posters", false }, { "Heart Radio", true } } }, new Control { IsRequired = true, ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Label = "Drop Down List", Type = ControlType.DropDownList, Name = "Show", DefaultValue = " \r\nYes\r\nNo", DefaultValues = new Dictionary <string, bool> { { " ", false }, { "Yes", true }, { "No", false } } }, new Control { IsRequired = true, ExplanationText = "explanation about this field", Tooltip = "a tool tip saying what goes here", Label = "Radio button opt in", Type = ControlType.RadioButton, Name = "Optin", DefaultValue = "Yes", DefaultValues = new Dictionary <string, bool> { { "Yes", true }, { "No", true } } } }; var submissionOptions = new SubmissionOptions { DisplayText = "thanks for submitting" }; Name = name; SubmitText = "Submit"; SubmissionOptions = submissionOptions; Controls = controls; }
public ActionResult Submit() { // Variables. var tempGuid = default(Guid); var keys = Request.Form.AllKeys; var fileKeys = Request.Files.AllKeys; var formId = Guid.Parse(Request["FormId"]); var pageId = NumberUtility.AttemptParseInt(Request["PageId"]); var pageNode = pageId.HasValue ? Umbraco.TypedContent(pageId.Value) : null; var pageUrl = pageNode?.Url; var pageName = pageNode?.Name; // Get values. var values = keys .Where(x => Guid.TryParse(x, out tempGuid)) .Select(x => { var fieldValue = Request.Form.GetValues(x); return new FieldSubmission { FieldId = Guid.Parse(x), FieldValues = fieldValue }; }) .ToList(); // Get file values. var fileValues = fileKeys .Where(x => Guid.TryParse(x, out tempGuid)) .Select(x => { // Variables. var fileValue = Request.Files.Get(x); // Extract file data: http://stackoverflow.com/a/16030326/2052963 var reader = new BinaryReader(fileValue.InputStream); var fileData = reader.ReadBytes((int)fileValue.InputStream.Length); var filename = fileValue.FileName; // Return file field submission. return new FileFieldSubmission() { FieldId = Guid.Parse(x), FileData = fileData, FileName = filename }; }) .ToList(); // Payload. var payload = new[] { new PayloadSubmission() { Name = "URL", Value = pageUrl }, new PayloadSubmission() { Name = "Page Name", Value = pageName } }.Where(x => !string.IsNullOrWhiteSpace(x.Value)); // Submit form. var context = new FormRequestContext() { CurrentPage = pageNode, HttpContext = HttpContext, Services = Services, UmbracoContext = UmbracoContext, UmbracoHelper = Umbraco }; var options = new SubmissionOptions() { Validate = Config.EnableServerSideValidation }; var result = Submissions.SubmitForm(formId, values, fileValues, payload, options, context); // Return result. return Json(new { Success = result.Success }); }
/// <summary> /// Submits a form. /// </summary> /// <param name="formId"> /// The ID of the form to submit. /// </param> /// <param name="data"> /// The form data to submit. /// </param> /// <param name="options"> /// The options for this submission. /// </param> /// <returns> /// The result of the submission. /// </returns> public static SubmissionResult SubmitForm(Guid formId, IEnumerable <FieldSubmission> data, SubmissionOptions options) { // Is the form ID valid? var form = Forms.Retrieve(formId); if (form == null) { return(new SubmissionResult() { Success = false }); } // Validate? if (options.Validate) { var valuesById = data.GroupBy(x => x.FieldId).Select(x => new { Id = x.Key, Values = x.SelectMany(y => y.FieldValues).ToList() }).ToDictionary(x => x.Id, x => x.Values); foreach (var field in form.Fields) { var validations = field.Validations.Select(x => Validations.Retrieve(x)).ToList(); foreach (var validation in validations) { //TODO: var validationResult = validation.Validate(form, field, valuesById); } } } // Initiate form handlers on a new thread (they may take some time to complete). var t = new Thread(() => { try { foreach (var handler in form.Handlers) { handler.HandleForm(form, data); } } catch (Exception ex) { LogHelper.Error <Submissions_Instance>(HandlerError, ex); } }); t.IsBackground = true; t.Start(); // Return success. return(new SubmissionResult() { Success = true }); }
/// <summary> /// Submits a form. /// </summary> /// <param name="formId"> /// The ID of the form to submit. /// </param> /// <param name="data"> /// The form data to submit. /// </param> /// <param name="files"> /// The file data to submit. /// </param> /// <param name="payload"> /// Extra data related to the submission. /// </param> /// <param name="options"> /// The options for this submission. /// </param> /// <param name="context"> /// The contextual information for the form request. /// </param> /// <returns> /// The result of the submission. /// </returns> public static SubmissionResult SubmitForm(Guid formId, IEnumerable <FieldSubmission> data, IEnumerable <FileFieldSubmission> files, IEnumerable <PayloadSubmission> payload, SubmissionOptions options, FormRequestContext context) { // Is the form ID valid? var form = Forms.Retrieve(formId); if (form == null) { return(new SubmissionResult() { Success = false }); } // Create submission context. var submissionContext = new FormSubmissionContext() { Files = files, Data = data, Form = form, Payload = payload, CurrentPage = context.CurrentPage, HttpContext = context.HttpContext, Services = context.Services, UmbracoContext = context.UmbracoContext, UmbracoHelper = context.UmbracoHelper, SubmissionId = Guid.NewGuid(), ExtraContext = new Dictionary <string, object>() }; // Invoke submitting event (gives listeners a chance to change the submission). Submitting?.Invoke(submissionContext); // Validate? if (options.Validate) { var valuesById = data.GroupBy(x => x.FieldId).Select(x => new { Id = x.Key, Values = x.SelectMany(y => y.FieldValues).ToList() }).ToDictionary(x => x.Id, x => x.Values); foreach (var field in form.Fields) { var validations = field.Validations.Select(x => Validations.Retrieve(x)).ToList(); foreach (var validation in validations) { //TODO: var validationResult = validation.Validate(form, field, valuesById); } } } // Prepare the form handlers. // This occurs on the current thread in case the handler needs information // only available in the current thread. try { foreach (var handler in form.Handlers) { handler.PrepareHandleForm(submissionContext); } } catch (Exception ex) { LogHelper.Error <Submissions_Instance>(PreHandlerError, ex); return(new SubmissionResult() { Success = false }); } // Initiate form handlers on a new thread (they may take some time to complete). var t = new Thread(() => { try { foreach (var handler in form.Handlers) { handler.HandleForm(submissionContext); } } catch (Exception ex) { LogHelper.Error <Submissions_Instance>(HandlerError, ex); } }); t.IsBackground = true; t.Start(); // Return success. return(new SubmissionResult() { Success = true }); }
public Task <IQuantumMachineJob> SubmitAsync <TIn, TOut>( EntryPointInfo <TIn, TOut> entryPoint, TIn argument, SubmissionOptions options) => Task.FromResult <IQuantumMachineJob>(new ExampleJob());
public Task <IQuantumMachineJob> SubmitAsync( Stream qir, string entryPoint, IReadOnlyList <Argument> arguments, SubmissionOptions options) => Task.FromResult <IQuantumMachineJob>(new ExampleJob());