private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { string markup; if (C1File.Exists(this.FilePath)) { markup = C1File.ReadAllText(this.FilePath); } else { // someone deleted the feature file, but that won't stop us! XhtmlDocument template = new XhtmlDocument(); template.Head.Add(""); template.Body.Add(""); markup = template.ToString(); } this.Bindings.Add("FeatureName", this.FeatureName); this.Bindings.Add("Markup", markup); if (Path.GetExtension(this.FilePath) == ".html") { this.documentFormActivity1.FormDefinitionFileName = @"\Administrative\PageTemplateFeature\EditVisual.xml"; } else { this.documentFormActivity1.FormDefinitionFileName = @"\Administrative\PageTemplateFeature\EditMarkup.xml"; } }
public static void SaveRenderingLayout(string formName, XhtmlDocument layout) { using (var writer = ResourceFacade.GetResourceWriter()) { var key = GetKey(formName); writer.AddResource(key, layout.ToString()); } }
private void stepFinalize_codeActivity_ExecuteCode(object sender, EventArgs e) { AddNewTreeRefresher updateTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken); IVisualFunction newFunction = this.GetBinding <IVisualFunction>("Function"); newFunction.MaximumItemsToList = 10; newFunction.OrderbyAscending = true; newFunction.OrderbyFieldName = (GetDataTypeDescriptor().LabelFieldName ?? GetDataTypeDescriptor().Fields.First().Name); XhtmlDocument defaultDocument = BuildDefaultDocument(newFunction); newFunction.XhtmlTemplate = defaultDocument.ToString(); updateTreeRefresher.PostRefreshMesseges(this.EntityToken); var createdFunction = DataFacade.AddNew <IVisualFunction>(newFunction); this.ExecuteWorklow(createdFunction.GetDataEntityToken(), typeof(EditVisualFunctionWorkflow)); }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken); XhtmlDocument templateDocument = GetTemplateDocumentFromBindings(); IVisualFunction function = this.GetBinding <IVisualFunction>("Function"); function.XhtmlTemplate = templateDocument.ToString(); DataFacade.Update(function); string functionFullName = string.Format("{0}.{1}", function.Namespace, function.Name); this.UpdateBinding("OriginalFullName", functionFullName); updateTreeRefresher.PostRefreshMesseges(function.GetDataEntityToken()); SetSaveStatus(true); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { string name = this.GetBinding <string>("Name"); string editorType = this.GetBinding <string>("EditorType"); string filename = PageTemplateFeatureFacade.GetNewPageTemplateFeaturePath(name, editorType); var template = new XhtmlDocument(); template.Head.Add(""); template.Body.Add(new XElement(Namespaces.Xhtml + "p", "")); C1File.WriteAllText(filename, template.ToString()); this.CloseCurrentView(); this.RefreshRootEntityToken(); this.ExecuteAction(PageTemplateFeatureEntityToken.BuildFeatureEntityToken(name), new WorkflowActionToken(typeof(EditPageTemplateFeatureWorkflow))); }
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); }
public void ProcessRequest(HttpContext context) { OutputCacheHelper.InitializeFullPageCaching(context); using (var renderingContext = RenderingContext.InitializeFromHttpContext()) { bool cachingEnabled = false; string cacheKey = null; DonutCacheEntry cacheEntry = null; bool consoleUserLoggedIn = Composite.C1Console.Security.UserValidationFacade.IsLoggedIn(); // "Donut caching" is enabled for logged in users, only if profiling is enabled as well. if (!renderingContext.CachingDisabled && (!consoleUserLoggedIn || renderingContext.ProfilingEnabled)) { cachingEnabled = OutputCacheHelper.TryGetCacheKey(context, out cacheKey); if (cachingEnabled) { using (Profiler.Measure("Cache lookup")) { cacheEntry = OutputCacheHelper.GetFromCache(context, cacheKey); } } } XDocument document; var functionContext = PageRenderer.GetPageRenderFunctionContextContainer(); bool allFunctionsExecuted = false; bool preventResponseCaching = false; if (cacheEntry != null) { document = cacheEntry.Document; foreach (var header in cacheEntry.OutputHeaders) { context.Response.Headers[header.Name] = header.Value; } // Making sure this response will not go to the output cache preventResponseCaching = true; } else { if (renderingContext.RunResponseHandlers()) { return; } var renderer = PageTemplateFacade.BuildPageRenderer(renderingContext.Page.TemplateId); var slimRenderer = (ISlimPageRenderer)renderer; using (Profiler.Measure($"{nameof(ISlimPageRenderer)}.Render")) { document = slimRenderer.Render(renderingContext.PageContentToRender, functionContext); } allFunctionsExecuted = PageRenderer.ExecuteCacheableFunctions(document.Root, functionContext); if (cachingEnabled && !allFunctionsExecuted && OutputCacheHelper.ResponseCacheable(context)) { preventResponseCaching = true; if (!functionContext.ExceptionsSuppressed) { using (Profiler.Measure("Adding to cache")) { OutputCacheHelper.AddToCache(context, cacheKey, new DonutCacheEntry(context, document)); } } } } if (!allFunctionsExecuted) { using (Profiler.Measure("Executing embedded functions")) { PageRenderer.ExecuteEmbeddedFunctions(document.Root, functionContext); } } using (Profiler.Measure("Resolving page fields")) { PageRenderer.ResolvePageFields(document, renderingContext.Page); } string xhtml; if (document.Root.Name == RenderingElementNames.Html) { var xhtmlDocument = new XhtmlDocument(document); PageRenderer.ProcessXhtmlDocument(xhtmlDocument, renderingContext.Page); PageRenderer.ProcessDocumentHead(xhtmlDocument); xhtml = xhtmlDocument.ToString(); } else { xhtml = document.ToString(); } if (renderingContext.PreRenderRedirectCheck()) { return; } xhtml = renderingContext.ConvertInternalLinks(xhtml); if (GlobalSettingsFacade.PrettifyPublicMarkup) { xhtml = renderingContext.FormatXhtml(xhtml); } var response = context.Response; if (preventResponseCaching) { context.Response.Cache.SetNoServerCaching(); } // Disabling ASP.NET cache if there's a logged-in user if (consoleUserLoggedIn) { context.Response.Cache.SetCacheability(HttpCacheability.NoCache); } // Inserting performance profiling information if (renderingContext.ProfilingEnabled) { xhtml = renderingContext.BuildProfilerReport(); response.ContentType = "text/xml"; } response.Write(xhtml); } }
public override void ExecuteResult(ControllerContext context) { string markup; using (TimerProfilerFacade.CreateTimerProfiler()) { var page = PageRenderer.CurrentPage; var markupBuilder = new StringBuilder(); var sw = new StringWriter(markupBuilder); var output = new HtmlTextWriter(sw); IView view; using (Profiler.Measure("Resolving view for template")) { view = FindView(context).View; } var viewContext = new ViewContext(context, view, ViewData, TempData, output); view.Render(viewContext, output); markup = markupBuilder.ToString(); var xml = XDocument.Parse(markup); var functionContext = PageRenderer.GetPageRenderFunctionContextContainer(); functionContext = new FunctionContextContainer(functionContext, new Dictionary <string, object> { { "viewContext", viewContext } }); using (Profiler.Measure("Executing embedded functions")) { PageRenderer.ExecuteEmbeddedFunctions(xml.Root, functionContext); } using (Profiler.Measure("Resolving pagefields")) { PageRenderer.ResolvePageFields(xml, page); } var document = new XhtmlDocument(xml); using (Profiler.Measure("Normalizing html")) { PageRenderer.NormalizeXhtmlDocument(document); } PageRenderer.ResolveRelativePaths(document); PageRenderer.AppendC1MetaTags(page, document); using (Profiler.Measure("Resolving localized strings")) { LocalizationParser.Parse(document); } markup = document.ToString(); using (Profiler.Measure("Changing 'internal' page urls to 'public'")) { markup = PageUrlHelper.ChangeRenderingPageUrlsToPublic(markup); } using (Profiler.Measure("Changing 'internal' media urls to 'public'")) { markup = MediaUrlHelper.ChangeInternalMediaUrlsToPublic(markup); } markup = _mvcContext.FormatXhtml(markup); } if (_mvcContext.ProfilingEnabled) { markup = _mvcContext.BuildProfilerReport(); context.HttpContext.Response.ContentType = "text/xml"; } context.HttpContext.Response.Write(markup); }