Skip to content

Commit

Permalink
Adding debug setting for inline C# functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IngvarKofoed committed Sep 20, 2010
1 parent aa3c44f commit 60dcb8c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,7 @@ private void initializeCodeActivity_InitBindings_ExecuteCode(object sender, Even
{
IInlineFunction function = DataFacade.BuildNew<IInlineFunction>();
function.Id = Guid.NewGuid();
function.Namespace = UserSettings.LastSpecifiedNamespace;

this.Bindings.Add("NewFunction", function);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +49,35 @@ private void initializeCodeActivity_InitBindings_ExecuteCode(object sender, Even
IInlineFunction functionInfo = this.GetDataItemFromEntityToken<IInlineFunction>();

this.Bindings.Add("Function", functionInfo);

List<KeyValuePair<Guid, string>> 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<KeyValuePair<string, string>> activeCulturesDictionary = UserSettings.ActiveLocaleCultureInfos.Select(f => new KeyValuePair<string, string>(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<string, string>
{
{ 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<KeyValuePair> assemblies = new List<KeyValuePair>();
Expand Down Expand Up @@ -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("<pre>" + HttpUtility.HtmlEncode(result.ToString()) + "</pre>");
formFlowWebRenderingService.SetNewPageOutput(output);
try
{
Guid 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 = cultureInfo;
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());

Control output = new LiteralControl("<pre>" + HttpUtility.HtmlEncode(result.ToString()) + "</pre>");
formFlowWebRenderingService.SetNewPageOutput(output);

Thread.CurrentThread.CurrentCulture = oldCurrentCulture;
Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture;
}
}
catch (TargetInvocationException ex)
{
Control output = new LiteralControl("<pre>" + HttpUtility.HtmlEncode(ex.InnerException.ToString()) + "</pre>");
formFlowWebRenderingService.SetNewPageOutput(output);
}
finally
{
Thread.CurrentThread.CurrentCulture = oldCurrentCulture;
Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<cms:formdefinition xmlns="http://www.composite.net/ns/management/bindingforms/std.ui.controls.lib/1.0" xmlns:f="http://www.composite.net/ns/management/bindingforms/std.function.lib/1.0" xmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0" xmlns:internal="http://www.composite.net/ns/management/bindingforms/internal.ui.controls.lib/1.0">
<cms:bindings>
<cms:binding name="Function" type="Composite.Data.Types.IInlineFunction, Composite" />

<cms:binding name="PageId" type="System.Guid" />
<cms:binding name="PageDataScopeName" type="System.String" optional="true"/>
<cms:binding name="PageDataScopeList" type="System.Collections.IEnumerable" optional="true"/>
<cms:binding name="ActiveCultureName" type="System.String" optional="true"/>
<cms:binding name="ActiveCulturesList" type="System.Collections.IEnumerable" optional="true"/>

<cms:binding name="FunctionCode" type="System.String" />
<cms:binding name="Assemblies" type="System.Collections.IEnumerable" />
<cms:binding name="SelectedAssemblies" type="System.Collections.IEnumerable" />
Expand All @@ -19,28 +26,66 @@

<TabPanels PreSelectedIndex="1">

<FieldGroup Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.FieldGroup.Label}">
<TextBox Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodName.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodName.Help}">
<TextBox.Text>
<cms:bind source="Function.Name" />
</TextBox.Text>
</TextBox>
<PlaceHolder Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.FieldGroup.Label}">
<FieldGroup Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.FieldGroup.Label}">
<TextBox Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodName.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodName.Help}">
<TextBox.Text>
<cms:bind source="Function.Name" />
</TextBox.Text>
</TextBox>

<TextBox Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodNamespace.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodNamespace.Help}">
<TextBox.Text>
<cms:bind source="Function.Namespace" />
</TextBox.Text>
</TextBox>
<TextBox Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodNamespace.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodNamespace.Help}">
<TextBox.Text>
<cms:bind source="Function.Namespace" />
</TextBox.Text>
</TextBox>

<TextArea Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodDescription.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodDescription.Help}">
<TextArea.Text>
<cms:bind source="Function.Description" />
</TextArea.Text>
</TextArea>
</FieldGroup>
<TextArea Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodDescription.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.MethodDescription.Help}">
<TextArea.Text>
<cms:bind source="Function.Description" />
</TextArea.Text>
</TextArea>

</FieldGroup>

<FieldGroup Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugFieldGroup.Label}">
<PageSelector Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugPage.Label}" Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugPage.Help}">
<PageSelector.Selected>
<cms:bind source="PageId"/>
</PageSelector.Selected>
</PageSelector>
<KeySelector OptionsKeyField="Key" OptionsLabelField="Value"
Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugPageDataScope.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugPageDataScope.Help}">
<KeySelector.Options>
<cms:read source="PageDataScopeList"/>
</KeySelector.Options>
<KeySelector.Selected>
<cms:bind source="PageDataScopeName"/>
</KeySelector.Selected>
</KeySelector>
<f:NullCheck>
<f:NullCheck.CheckValue>
<cms:read source="ActiveCultureName"/>
</f:NullCheck.CheckValue>
<f:NullCheck.WhenNotNull>
<KeySelector OptionsKeyField="Key" OptionsLabelField="Value"
Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugActiveLocale.Label}"
Help="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.DebugActiveLocale.Help}">
<KeySelector.Options>
<cms:read source="ActiveCulturesList"/>
</KeySelector.Options>
<KeySelector.Selected>
<cms:bind source="ActiveCultureName"/>
</KeySelector.Selected>
</KeySelector>
</f:NullCheck.WhenNotNull>
</f:NullCheck>
</FieldGroup>
</PlaceHolder>


<TextEditor Label="${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditInlineFunctionWorkflow.Code.Label}" MimeType="text/x-csharp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@
<string key="EditInlineFunctionWorkflow.MethodNamespace.Help" value="The namespace of the method you want to create" />
<string key="EditInlineFunctionWorkflow.MethodDescription.Label" value="Description" />
<string key="EditInlineFunctionWorkflow.MethodDescription.Help" value="A short description of the function" />
<string key="EditInlineFunctionWorkflow.DebugFieldGroup.Label" value="Debug" />
<string key="EditInlineFunctionWorkflow.DebugPage.Label" value="Page" />
<string key="EditInlineFunctionWorkflow.DebugPage.Help" value="When debugging, this page is used as current page" />
<string key="EditInlineFunctionWorkflow.DebugPageDataScope.Label" value="Data scope" />
<string key="EditInlineFunctionWorkflow.DebugPageDataScope.Help" value="When debugging, this is used as current data scope" />
<string key="EditInlineFunctionWorkflow.DebugActiveLocale.Label" value="Language" />
<string key="EditInlineFunctionWorkflow.DebugActiveLocale.Help" value="When debugging, this is used as the current language" />

<string key="EditInlineFunctionWorkflow.Code.Label" value="Source" />
<string key="EditInlineFunctionWorkflow.AssembliesFieldGroup.Label" value="Assembly References" />
<string key="EditInlineFunctionWorkflow.Preview.Label" value="Preview" />
<string key="EditInlineFunctionWorkflow.ParameterFieldGroup.Label" value="Input Parameters" />

<string key="EditInlineFunctionWorkflow.AdminitrativeScope.Label" value="Adminitrative" />
<string key="EditInlineFunctionWorkflow.PublicScope.Label" value="Public" />

<string key="InlineFunctionMethodTemplate.Clean" value="Empty method" />
<string key="InlineFunctionMethodTemplate.WithParameters" value="Method with parameters" />
<string key="InlineFunctionMethodTemplate.DataConnection" value="Method using data connection" />
Expand Down

0 comments on commit 60dcb8c

Please sign in to comment.