public Tree LoadTreeFromDom(string treeId, XDocument document) { string xslFilename = Path.Combine(TreeDefinitionsFolder, XslFilename); var fileInfo = new C1FileInfo(xslFilename); // The default xslt transformation does no changes and it's xsl file has size of 358 bytes, skipping this file saves up to 0.5 second on site startup if (fileInfo.Exists && fileInfo.Length != 358) { try { var newDocument = new XDocument(); using (XmlWriter xmlWriter = newDocument.CreateWriter()) { var xslTransform = new XslCompiledTransform(); xslTransform.LoadFromPath(xslFilename); xslTransform.Transform(document.CreateReader(), xmlWriter); } document = newDocument; } catch (Exception ex) { Log.LogCritical("TreeFacade", "Failed to apply xslt on the tree {0} with the following exception", treeId); Log.LogCritical("TreeFacade", ex); } } return(Load(treeId, document)); }
private XDocument TransformMarkup(XElement inputRoot) { var newTree = new XDocument(); using (XmlWriter writer = newTree.CreateWriter()) { var xslTransformer = new XslCompiledTransform(); xslTransformer.LoadFromPath(this.MapPath(XsltFileName)); xslTransformer.Transform(inputRoot.CreateReader(), writer); } return(newTree); }
private XDocument TransformMarkup(XElement inputRoot) { var newTree = new XDocument(); using (XmlWriter writer = newTree.CreateWriter()) { var xslTransformer = new XslCompiledTransform(); xslTransformer.LoadFromPath(this.MapPath(XsltFileName)); xslTransformer.Transform(inputRoot.CreateReader(), writer); } return newTree; }
private XDocument TransformMarkup(XElement inputRoot) { XDocument newTree = new XDocument(); using (XmlWriter writer = newTree.CreateWriter()) { XslCompiledTransform xslTransformer = new XslCompiledTransform(); xslTransformer.LoadFromPath(this.MapPath("ViewUnpublishedItems.xslt")); xslTransformer.Transform(inputRoot.CreateReader(), writer); } return(newTree); }
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); }