private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { Type selectedMetaDataType = this.GetBinding <Type>(SelectedTypeBindingName); DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(selectedMetaDataType.GetImmutableTypeId()); PageMetaDataDescription dataAssociationVisabilityRule = this.GetBinding <PageMetaDataDescription>(DataAssociationVisabilityDescriptionBindingName); Guid metaDataContainerId = this.GetBinding <Guid>(SelectedContainerBindingName); string metaDataDefinitionName = this.GetBinding <string>(FieldGroupNameBindingName); string metaDataDefinitionLabel = this.GetBinding <string>(FieldGroupLabelBindingName); IData newDataTemplate = null; if (IsAnyPagesAffected()) { DataTypeDescriptorFormsHelper helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor); GeneratedTypesHelper generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor); helper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames); newDataTemplate = DataFacade.BuildNew(selectedMetaDataType); helper.BindingsToObject(this.Bindings, newDataTemplate); } using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope()) { IPage page = GetCurrentPage(); page.AddMetaDataDefinition(metaDataDefinitionName, metaDataDefinitionLabel, selectedMetaDataType.GetImmutableTypeId(), metaDataContainerId, dataAssociationVisabilityRule.StartLevel, dataAssociationVisabilityRule.Levels); if (newDataTemplate != null) { page.AddNewMetaDataToExistingPages(metaDataDefinitionName, newDataTemplate); } transactionScope.Complete(); } ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher(); parentTreeRefresher.PostRefreshMesseges(this.EntityToken); }
public static bool SubmitForm(ParameterList parameters, string captchaText) { try { _compiler.SaveControlProperties(); } catch (Exception) { } webUiControl.InitializeViewState(); Dictionary <string, string> errorMessages = formHelper.BindingsToObject(bindings, newData); DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(newData.DataSourceId.InterfaceType); foreach (var property in newData.DataSourceId.InterfaceType.GetProperties()) { if (property.PropertyType == typeof(string) && (string)property.GetValue(newData, null) == string.Empty) { property.SetValue(newData, null, null); } } ValidationResults validationResults = ValidationFacade.Validate(newData.DataSourceId.InterfaceType, newData); var isValid = true; var useCaptcha = parameters.GetParameter <bool>("UseCaptcha"); if (useCaptcha) { var Session = HttpContext.Current.Session; if (Session["FormsRendererCaptcha"] == null || !Captcha.IsValid(captchaText, Session["FormsRendererCaptcha"].ToString())) { ErrorSummary.AddError(StringResourceSystemFacade.GetString("Composite.Forms.Renderer", "Composite.Forms.Captcha.CaptchaText.error")); isValid = false; } } if (validationResults.IsValid == false) { isValid = false; Dictionary <string, string> errorSummary = new Dictionary <string, string>(); foreach (ValidationResult result in validationResults) { var label = result.Key; var help = result.Message; try { label = dataTypeDescriptor.Fields[result.Key].FormRenderingProfile.Label; help = dataTypeDescriptor.Fields[result.Key].FormRenderingProfile.HelpText; //if no HelpText specified - use standard C1 error if (help == string.Empty) { help = result.Message; } string error = GetLocalized(label) + ": " + GetLocalized(help); if (!errorSummary.ContainsValue(error)) { errorSummary.Add(errorSummary.Count().ToString(), error); } } catch { } } // add errors to ErrorSummary foreach (var dict in errorSummary) { ErrorSummary.AddError(dict.Value); } } //TODO: Looks like rudimentary code related to old C1 errros with binding? if (errorMessages != null) { isValid = false; foreach (var kvp in errorMessages) { var label = kvp.Key; try { label = dataTypeDescriptor.Fields[kvp.Key].FormRenderingProfile.Label; } catch { } ErrorSummary.AddError(GetLocalized(label) + ": " + GetLocalized(kvp.Value)); } } if (isValid) { using (new DataScope(DataScopeIdentifier.Administrated)) { IPublishControlled publishControlled = newData as IPublishControlled; if (publishControlled != null) { publishControlled.PublicationStatus = GenericPublishProcessController.Draft; } DataFacade.AddNew(newData); using (var datascope = new FormsRendererDataScope(newData)) { var formEmailHeaders = parameters.GetParameter("Email") as IEnumerable <FormEmail>; if (formEmailHeaders != null) { foreach (var formEmail in formEmailHeaders) { ParameterFacade.ResolveProperties(formEmail); var inputXml = GetXElement(newData); var body = new XhtmlDocument(); body.AppendDocument(formEmail.Body); if (formEmail.AppendFormData) { var formData = new XDocument(); var xslTransform = new XslCompiledTransform(); xslTransform.LoadFromPath(FormsRendererLocalPath + "Xslt/MailBody.xslt"); using (var writer = formData.CreateWriter()) { xslTransform.Transform(inputXml.CreateReader(), writer); } body.AppendDocument(formData); } Reflection.CallStaticMethod <object>("Composite.Core.WebClient.Renderings.Page.PageRenderer", "NormalizeXhtmlDocument", body); var mailMessage = new MailMessage(); try { mailMessage.From = new MailAddress(formEmail.From); } catch (Exception e) { LoggingService.LogError(string.Format("Mail sending(From: '{0}')", formEmail.From), e.Message); continue; } try { mailMessage.To.Add(formEmail.To); } catch (Exception e) { LoggingService.LogError(string.Format("Mail sending(To: '{0}')", formEmail.To), e.Message); continue; } if (!string.IsNullOrEmpty(formEmail.Cc)) { try { mailMessage.CC.Add(formEmail.Cc); } catch (Exception e) { LoggingService.LogError(string.Format("Mail sending(Cc: '{0}')", formEmail.Cc), e.Message); } } try { mailMessage.Subject = formEmail.Subject; mailMessage.IsBodyHtml = true; mailMessage.Body = body.ToString(); new SmtpClient().Send(mailMessage); } catch (Exception e) { throw new InvalidOperationException("Unable to send mail. Please ensure that web.config has correct /configuration/system.net/mailSettings: " + e.Message); } } } } } } return(isValid); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope()) { List <Guid> oldPageIds = GetOldAffectedPageIds(); List <Guid> newPageIds = GetNewAffectedPageIds(); Pair <string, Type> metaDataPair = this.GetBinding <Pair <string, Type> >("SelectedMetaDataDefinition"); Guid newMetaDataContainerId = this.GetBinding <Guid>("SelectedMetaDataContainer"); string newLabel = this.GetBinding <string>("Label"); int startLevel = this.GetBinding <int>("SelectedStartDisplay"); int levels = this.GetBinding <int>("SelectedInheritDisplay"); PageMetaDataFacade.UpdateDefinition(GetCurrentPageId(), metaDataPair.First, newLabel, startLevel, levels, newMetaDataContainerId); IEnumerable <Guid> oldPageIdsToRemove = oldPageIds.Except(newPageIds); foreach (Guid id in oldPageIdsToRemove) { IPage page = Composite.Data.PageManager.GetPageById(id); bool otherDefinitionExists = page.GetAllowedMetaDataDefinitions().Where(f => f.Name == metaDataPair.First).Any(); if (otherDefinitionExists) { continue; } using (new DataScope(DataScopeIdentifier.Public)) { IData dataToDelete = page.GetMetaData(metaDataPair.First, metaDataPair.Second); if (dataToDelete != null) { DataFacade.Delete(dataToDelete); } } using (new DataScope(DataScopeIdentifier.Administrated)) { IData dataToDelete = page.GetMetaData(metaDataPair.First, metaDataPair.Second); if (dataToDelete != null) { DataFacade.Delete(dataToDelete); } } } IData newDataTemplate = null; if (this.BindingExist("NewDataTemplate")) { newDataTemplate = this.GetBinding <IData>("NewDataTemplate"); DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(metaDataPair.Second.GetImmutableTypeId()); DataTypeDescriptorFormsHelper helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor); helper.BindingsToObject(this.Bindings, newDataTemplate); } IEnumerable <Guid> newPageIdsToAdd = newPageIds.Except(oldPageIds); foreach (Guid id in newPageIdsToAdd) { IPage page = Composite.Data.PageManager.GetPageById(id); page.AddNewMetaDataToExistingPage(metaDataPair.First, metaDataPair.Second, newDataTemplate); } transactionScope.Complete(); } }
/// <summary> /// Binds form values to a data item and sends messages to client to display validation messages. /// </summary> /// <param name="helper">Form binding helper</param> /// <param name="data">An IData instance</param> /// <returns>True, if there were no binding/validation errors</returns> protected bool BindAndValidate(DataTypeDescriptorFormsHelper helper, IData data) { Dictionary <string, string> errorMessages = helper.BindingsToObject(this.Bindings, data); ValidationResults validationResults = ValidationFacade.Validate(data.DataSourceId.InterfaceType, data); bool isValid = true; if (!validationResults.IsValid) { foreach (ValidationResult result in validationResults) { if (!result.Key.IsNullOrEmpty()) { this.ShowFieldMessage(result.Key, result.Message); } else { this.ShowMessage(DialogType.Error, "Validation error", result.Message); } isValid = false; } } // Checking that required strings are not empty var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType); foreach (var fieldName in dataTypeDescriptor.Fields .Where(f => !f.IsNullable && f.InstanceType == typeof(string) && !(f.Inherited && f.Name == "FieldName")) // Skipping validation for inherited IPageMetaData.FieldName .Select(f => f.Name)) { string bindingName = (helper.BindingNamesPrefix ?? "").Replace('.', '_') + fieldName; if (validationResults.Any(r => r.Key == bindingName)) { continue; } object fieldValue = this.Bindings[bindingName]; if (fieldValue is string && (fieldValue as string) == string.Empty && !helper.BindingIsOptional(bindingName)) { this.ShowFieldMessage(bindingName, LocalizationFiles.Composite_Management.Validation_RequiredField); isValid = false; } } if (errorMessages != null) { isValid = false; foreach (var kvp in errorMessages) { this.ShowFieldMessage(kvp.Key, kvp.Value); } } return(isValid); }