diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs index f96018400d..e4c27ddeca 100644 --- a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs +++ b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/AddInlineFunctionWorkflow.cs @@ -9,6 +9,7 @@ using Composite.Data.Types; using Composite.Functions.Inline; using Composite.Functions.ManagedParameters; +using Composite.C1Console.Users; namespace Composite.Workflows.Plugins.Elements.ElementProviders.MethodBasedFunctionProviderElementProvider @@ -28,6 +29,7 @@ private void initializeCodeActivity_InitBindings_ExecuteCode(object sender, Even { IInlineFunction function = DataFacade.BuildNew(); function.Id = Guid.NewGuid(); + function.Namespace = UserSettings.LastSpecifiedNamespace; this.Bindings.Add("NewFunction", function); @@ -123,6 +125,7 @@ private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs private static string _cleanTemplate = @"using System; +using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Composite.Data; @@ -142,6 +145,7 @@ namespace {0} private static string _parameterTemplate = @"using System; +using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Composite.Data; @@ -161,6 +165,7 @@ namespace {0} private static string _dataConnectionTemplate = @"using System; +using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Composite.Data; diff --git a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs index dc049aae5f..c2672bae58 100644 --- a/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs +++ b/Composite.Workflows/Plugins/Elements/ElementProviders/MethodBasedFunctionProviderElementProvider/EditInlineFunctionWorkflow.cs @@ -25,6 +25,10 @@ using Composite.Functions; using Composite.Functions.Inline; using Composite.Functions.ManagedParameters; +using Composite.Core.WebClient.Renderings.Page; +using Composite.C1Console.Users; +using System.Globalization; +using System.Threading; namespace Composite.Workflows.Plugins.Elements.ElementProviders.MethodBasedFunctionProviderElementProvider @@ -45,6 +49,35 @@ private void initializeCodeActivity_InitBindings_ExecuteCode(object sender, Even IInlineFunction functionInfo = this.GetDataItemFromEntityToken(); this.Bindings.Add("Function", functionInfo); + + List> pages = PageStructureInfo.PageListInDocumentOrder().ToList(); + if (pages.Count > 0) + { + this.Bindings.Add("PageId", pages.First().Key); + } + else + { + this.Bindings.Add("PageId", Guid.Empty); + } + + this.Bindings.Add("PageList", pages); + + + if (UserSettings.ActiveLocaleCultureInfo != null) + { + List> activeCulturesDictionary = UserSettings.ActiveLocaleCultureInfos.Select(f => new KeyValuePair(f.Name, StringResourceSystemFacade.GetString("Composite.Cultures", f.Name))).ToList(); + this.Bindings.Add("ActiveCultureName", UserSettings.ActiveLocaleCultureInfo.Name); + this.Bindings.Add("ActiveCulturesList", activeCulturesDictionary); + } + + this.Bindings.Add("PageDataScopeName", DataScopeIdentifier.AdministratedName); + this.Bindings.Add("PageDataScopeList", new Dictionary + { + { DataScopeIdentifier.AdministratedName, StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "EditInlineFunctionWorkflow.AdminitrativeScope.Label") }, + { DataScopeIdentifier.PublicName, StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "EditInlineFunctionWorkflow.PublicScope.Label") } + }); + + this.Bindings.Add("FunctionCode", functionInfo.GetFunctionCode()); List assemblies = new List(); @@ -224,10 +257,50 @@ private void editCodeActivity_Preview_ExecuteCode(object sender, EventArgs e) return; } - object result = methodInfo.Invoke(null, parameterValues.ToArray()); + CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; + CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; - Control output = new LiteralControl("
" + HttpUtility.HtmlEncode(result.ToString()) + "
"); - formFlowWebRenderingService.SetNewPageOutput(output); + try + { + Guid pageId = this.GetBinding("PageId"); + string dataScopeName = this.GetBinding("PageDataScopeName"); + string cultureName = this.GetBinding("ActiveCultureName"); + CultureInfo cultureInfo = null; + if (cultureName != null) + { + cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); + } + + using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) + { + Thread.CurrentThread.CurrentCulture = cultureInfo; + Thread.CurrentThread.CurrentUICulture = cultureInfo; + + IPage page = DataFacade.GetData(f => f.Id == pageId).FirstOrDefault(); + if (page != null) + { + PageRenderer.CurrentPage = page; + } + + object result = methodInfo.Invoke(null, parameterValues.ToArray()); + + Control output = new LiteralControl("
" + HttpUtility.HtmlEncode(result.ToString()) + "
"); + formFlowWebRenderingService.SetNewPageOutput(output); + + Thread.CurrentThread.CurrentCulture = oldCurrentCulture; + Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; + } + } + catch (TargetInvocationException ex) + { + Control output = new LiteralControl("
" + HttpUtility.HtmlEncode(ex.InnerException.ToString()) + "
"); + formFlowWebRenderingService.SetNewPageOutput(output); + } + finally + { + Thread.CurrentThread.CurrentCulture = oldCurrentCulture; + Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; + } } } diff --git a/Website/Composite/content/forms/Administrative/InlineFunctionEditFunction.xml b/Website/Composite/content/forms/Administrative/InlineFunctionEditFunction.xml index a1c8cc53c5..4248f0a478 100644 --- a/Website/Composite/content/forms/Administrative/InlineFunctionEditFunction.xml +++ b/Website/Composite/content/forms/Administrative/InlineFunctionEditFunction.xml @@ -2,6 +2,13 @@ + + + + + + + @@ -19,28 +26,66 @@ - - - - - - + + + + + + + - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Website/Composite/localization/Composite.Plugins.MethodBasedFunctionProviderElementProvider.en-us.xml b/Website/Composite/localization/Composite.Plugins.MethodBasedFunctionProviderElementProvider.en-us.xml index 1a91a528bf..b0b8d3c8fb 100644 --- a/Website/Composite/localization/Composite.Plugins.MethodBasedFunctionProviderElementProvider.en-us.xml +++ b/Website/Composite/localization/Composite.Plugins.MethodBasedFunctionProviderElementProvider.en-us.xml @@ -68,11 +68,22 @@ + + + + + + + + + + +