private void SetOutput(IFormFlowWebRenderingService formFlowWebRenderingService, string text) { Control output = new LiteralControl("<pre>" + HttpUtility.HtmlEncode(text) + "</pre>"); formFlowWebRenderingService.SetNewPageOutput(output); }
private static void BaseEventHandler(string consoleId, string elementProviderName, FlowToken flowToken, FormFlowUiDefinition formFlowUiCommand, FlowControllerServicesContainer servicesContainer, Dictionary <IFormEventIdentifier, FormFlowEventHandler> eventHandlers, IFormEventIdentifier localScopeEventIdentifier, FlowControllerServicesContainer formServicesContainer) { FormTreeCompiler activeFormTreeCompiler = CurrentFormTreeCompiler; Dictionary <string, object> activeInnerFormBindings = CurrentInnerFormBindings; FormFlowEventHandler handler = eventHandlers[localScopeEventIdentifier]; Dictionary <string, Exception> bindingErrors = activeFormTreeCompiler.SaveAndValidateControlProperties(); FormTreeCompiler activeCustomToolbarFormTreeCompiler = CurrentCustomToolbarFormTreeCompiler; if (activeCustomToolbarFormTreeCompiler != null) { var toolbarBindingErrors = activeCustomToolbarFormTreeCompiler.SaveAndValidateControlProperties(); foreach (var pair in toolbarBindingErrors) { bindingErrors.Add(pair.Key, pair.Value); } } formServicesContainer.AddService(new BindingValidationService(bindingErrors)); handler.Invoke(flowToken, activeInnerFormBindings, formServicesContainer); if (formServicesContainer.GetService <IManagementConsoleMessageService>().CloseCurrentViewRequested) { ViewTransitionHelper.HandleCloseCurrentView(formFlowUiCommand.UiContainerType); return; } var formFlowService = formServicesContainer.GetService <IFormFlowRenderingService>(); bool replacePageOutput = (formServicesContainer.GetService <IFormFlowWebRenderingService>().NewPageOutput != null); bool rerenderView = formFlowService.RerenderViewRequested; if (formFlowService.BindingPathedMessages != null) { ShowFieldMessages(CurrentControlTreeRoot, formFlowService.BindingPathedMessages, CurrentControlContainer, servicesContainer); } List <bool> boolCounterList = new List <bool> { replacePageOutput, rerenderView }; if (boolCounterList.Count(f => f) > 1) { StringBuilder sb = new StringBuilder("Flow returned conflicting directives for post handling:\n"); if (replacePageOutput) { sb.AppendLine(" - Replace page output with new web control."); } if (rerenderView) { sb.AppendLine(" - Rerender view."); } throw new InvalidOperationException(sb.ToString()); } if (rerenderView) { Log.LogVerbose("FormFlowRendering", "Re-render requested"); IFlowUiDefinition newFlowUiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken, servicesContainer); if (!(newFlowUiDefinition is FlowUiDefinitionBase)) { throw new NotImplementedException("Unable to handle transitions to ui definition of type " + newFlowUiDefinition.GetType()); } ViewTransitionHelper.HandleRerender(consoleId, elementProviderName, flowToken, formFlowUiCommand, (FlowUiDefinitionBase)newFlowUiDefinition, servicesContainer); } if (replacePageOutput) { Log.LogVerbose("FormFlowRendering", "Replace pageoutput requested"); IFormFlowWebRenderingService webRenderingService = formServicesContainer.GetService <IFormFlowWebRenderingService>(); Control newPageOutput = webRenderingService.NewPageOutput; foreach (Control control in GetNestedControls(newPageOutput).Where(f => f is ScriptManager).ToList()) { control.Parent.Controls.Remove(control); } Page currentPage = HttpContext.Current.Handler as Page; HtmlHead newHeadControl = GetNestedControls(newPageOutput).FirstOrDefault(f => f is HtmlHead) as HtmlHead; HtmlHead oldHeadControl = currentPage.Header; ControlCollection headContainer = null; bool headersHasToBeSwitched = newHeadControl != null && oldHeadControl != null; if (headersHasToBeSwitched) { headContainer = newHeadControl.Parent.Controls; headContainer.Remove(newHeadControl); } currentPage.Controls.Clear(); if (string.IsNullOrEmpty(webRenderingService.NewPageMimeType)) { currentPage.Response.ContentType = "text/html"; } else { currentPage.Response.ContentType = webRenderingService.NewPageMimeType; } currentPage.Controls.Add(newPageOutput); if (headersHasToBeSwitched) { oldHeadControl.Controls.Clear(); oldHeadControl.InnerHtml = ""; oldHeadControl.InnerText = ""; if (newHeadControl.ID != null) { oldHeadControl.ID = newHeadControl.ID; } oldHeadControl.Title = newHeadControl.Title; headContainer.AddAt(0, oldHeadControl); foreach (Control c in newHeadControl.Controls.Cast <Control>().ToList()) { oldHeadControl.Controls.Add(c); } } } }
private void editCodeActivity_Preview_ExecuteCode(object sender, EventArgs e) { IInlineFunction functionInfo = this.GetBinding <IInlineFunction>("Function"); string code = this.GetBinding <string>("FunctionCode"); List <string> selectedAssemblies = this.GetBinding <List <string> >("SelectedAssemblies"); StringInlineFunctionCreateMethodErrorHandler handler = new StringInlineFunctionCreateMethodErrorHandler(); MethodInfo methodInfo = InlineFunctionHelper.Create(functionInfo, code, handler, selectedAssemblies); FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); IFormFlowWebRenderingService formFlowWebRenderingService = serviceContainer.GetService <IFormFlowWebRenderingService>(); if (handler.HasErrors) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrWhiteSpace(handler.MissingContainerType)) { AddFormattedTextBlock(sb, handler.MissingContainerType); } if (!string.IsNullOrWhiteSpace(handler.NamespaceMismatch)) { AddFormattedTextBlock(sb, handler.NamespaceMismatch); } if (!string.IsNullOrWhiteSpace(handler.MissionMethod)) { AddFormattedTextBlock(sb, handler.MissionMethod); } if (handler.LoadingException != null) { AddFormattedTextBlock(sb, handler.LoadingException.ToString()); } foreach (Tuple <int, string, string> compileError in handler.CompileErrors) { AddFormattedTextBlock(sb, "{0} : {1} : {2}".FormatWith(compileError.Item1, compileError.Item2, compileError.Item3)); } formFlowWebRenderingService.SetNewPageOutput(new LiteralControl(sb.ToString())); return; } List <ManagedParameterDefinition> parameters = this.GetBinding <List <ManagedParameterDefinition> >("Parameters"); List <object> parameterValues = new List <object>(); bool parameterErrors = false; StringBuilder parameterErrorMessages = new StringBuilder(); foreach (ParameterInfo parameterInfo in methodInfo.GetParameters()) { ManagedParameterDefinition parameter = parameters.FirstOrDefault(f => f.Name == parameterInfo.Name); if (parameter == null) { string message = string.Format(GetText("CSharpInlineFunction.MissingParameterDefinition"), parameterInfo.Name); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else if (parameter.Type != parameterInfo.ParameterType) { string message = string.Format(GetText("CSharpInlineFunction.WrongParameterTestValueType"), parameterInfo.Name, parameterInfo.ParameterType, parameter.Type); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else { string previewValueFunctionMarkup = (string.IsNullOrEmpty(parameter.TestValueFunctionMarkup) ? parameter.DefaultValueFunctionMarkup : parameter.TestValueFunctionMarkup); if (string.IsNullOrEmpty(previewValueFunctionMarkup)) { string message = string.Format(GetText("CSharpInlineFunction.MissingParameterTestOrDefaultValue"), parameterInfo.Name, parameterInfo.ParameterType, parameter.Type); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else { try { BaseRuntimeTreeNode treeNode = FunctionFacade.BuildTree(XElement.Parse(previewValueFunctionMarkup)); object value = treeNode.GetValue(); object typedValue = ValueTypeConverter.Convert(value, parameter.Type); parameterValues.Add(typedValue); } catch (Exception ex) { string message = string.Format("Error setting '{0}'. {1}", parameterInfo.Name, ex.Message); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } } } } if (parameterErrors) { formFlowWebRenderingService.SetNewPageOutput(new LiteralControl(parameterErrorMessages.ToString())); return; } CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; try { Guid pageId; if (this.GetBinding <object>("PageId") == null) { pageId = Guid.Empty; } else { pageId = this.GetBinding <Guid>("PageId"); } string dataScopeName = this.GetBinding <string>("PageDataScopeName"); string cultureName = this.GetBinding <string>("ActiveCultureName"); CultureInfo cultureInfo = null; if (cultureName != null) { cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); } using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = cultureInfo; IPage page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault(); if (page != null) { PageRenderer.CurrentPage = page; } object result = methodInfo.Invoke(null, parameterValues.ToArray()); string resultString; try { resultString = PrettyPrinter.Print(result); } catch (Exception ex) { throw new TargetInvocationException(ex); } SetOutput(formFlowWebRenderingService, resultString); } } catch (TargetInvocationException ex) { SetOutput(formFlowWebRenderingService, ex.InnerException.ToString()); } finally { Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; } }
private void editCodeActivity_Preview_ExecuteCode(object sender, EventArgs e) { Guid pageId; if (this.GetBinding <object>("PageId") == null) { pageId = Guid.Empty; } else { pageId = this.GetBinding <Guid>("PageId"); } string dataScopeName = this.GetBinding <string>("PageDataScopeName"); string cultureName = this.GetBinding <string>("ActiveCultureName"); // Setting debug page IPage oldPage = PageRenderer.CurrentPage; IPage page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault(); if (page != null) { PageRenderer.CurrentPage = page; } // Setting debug culture CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; CultureInfo cultureInfo = null; if (cultureName != null) { cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); } if (cultureInfo != null) { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; } List <NamedFunctionCall> namedFunctionCalls = GetBinding <List <NamedFunctionCall> >("FunctionCalls"); StringBuilder output = new StringBuilder(); foreach (NamedFunctionCall namedFunctionCall in namedFunctionCalls) { output.AppendLine(namedFunctionCall.FunctionCall.GetCompositeName() + " result:"); object functionResult; try { // Setting debug data scope using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { functionResult = namedFunctionCall.FunctionCall.GetValue(); } } catch (Exception ex) { StringBuilder sb = new StringBuilder(); while (ex != null) { sb.AppendLine(ex.ToString()); ex = ex.InnerException; } functionResult = sb.ToString(); } output.AppendLine(PrettyPrinter.Print(functionResult)); output.AppendLine(); } // Restore culture Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; // Page should not be restored FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); IFormFlowWebRenderingService formFlowWebRenderingService = serviceContainer.GetService <IFormFlowWebRenderingService>(); Control outputControl = new LiteralControl("<pre>" + HttpUtility.HtmlEncode(output) + "</pre>"); formFlowWebRenderingService.SetNewPageOutput(outputControl); }