-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added project files and Post To Flow save action for WFFM
- Loading branch information
Alexander Doroshenko
committed
Dec 4, 2017
1 parent
7b1819a
commit 958342c
Showing
13 changed files
with
935 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27004.2006 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Flow", "Sitecore.Flow\Sitecore.Flow.csproj", "{6EC77305-BC8A-474E-A9F6-74C2ED3541A7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6EC77305-BC8A-474E-A9F6-74C2ED3541A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6EC77305-BC8A-474E-A9F6-74C2ED3541A7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6EC77305-BC8A-474E-A9F6-74C2ED3541A7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6EC77305-BC8A-474E-A9F6-74C2ED3541A7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {122F90E2-54B9-46D4-9D74-28032F877BC9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Sitecore.Data; | ||
using Sitecore.Diagnostics; | ||
using Sitecore.WFFM.Abstractions.Actions; | ||
using Sitecore.WFFM.Actions.Base; | ||
|
||
namespace Sitecore.Flow.Actions | ||
{ | ||
public class PostToFlow : WffmSaveAction | ||
{ | ||
public string TriggerAddress { get; set; } | ||
|
||
public override void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, | ||
params object[] data) | ||
{ | ||
Assert.ArgumentNotNull(adaptedFields, nameof(adaptedFields)); | ||
|
||
var fields = GetFieldsJson(adaptedFields); | ||
Task.Run(() => PostRequest(fields)); | ||
} | ||
|
||
private static string GetFieldsJson(AdaptedResultList adaptedFields) | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append("{"); | ||
var fieldDescriptors = new List<string>(); | ||
foreach (AdaptedControlResult adaptedField in adaptedFields) | ||
{ | ||
fieldDescriptors.Add(" \"" + adaptedField.FieldName + "\" : \"" + | ||
HttpUtility.JavaScriptStringEncode(adaptedField.Value) + "\" "); | ||
} | ||
|
||
sb.Append(fieldDescriptors.Aggregate((i, j) => i + "," + j)); | ||
sb.Append("}"); | ||
return sb.ToString(); | ||
} | ||
|
||
private void PostRequest(string json) | ||
{ | ||
try | ||
{ | ||
var httpWebRequest = (HttpWebRequest) WebRequest.Create(TriggerAddress); | ||
httpWebRequest.ContentType = "application/json"; | ||
httpWebRequest.Method = "POST"; | ||
|
||
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) | ||
{ | ||
streamWriter.Write(json); | ||
streamWriter.Flush(); | ||
streamWriter.Close(); | ||
} | ||
|
||
var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse(); | ||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) | ||
{ | ||
var result = streamReader.ReadToEnd(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error("PostToFlow: Action failed to execute", ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | ||
<sitecore> | ||
<wffm> | ||
<actions> | ||
<postToFlow type="Sitecore.Flow.Actions.PostToFlow, Sitecore.Flow"> | ||
</postToFlow> | ||
</actions> | ||
</wffm> | ||
</sitecore> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.WebPages; | ||
using RazorGenerator.Mvc; | ||
|
||
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(Sitecore.Flow.RazorGeneratorMvcStart), "Start")] | ||
|
||
namespace Sitecore.Flow { | ||
public static class RazorGeneratorMvcStart { | ||
public static void Start() { | ||
var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly) { | ||
UsePhysicalViewsIfNewer = HttpContext.Current.Request.IsLocal | ||
}; | ||
|
||
ViewEngines.Engines.Insert(0, engine); | ||
|
||
// StartPage lookups are done by WebPages. | ||
VirtualPathFactoryManager.RegisterVirtualPathFactory(engine); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Sitecore.Diagnostics; | ||
using Sitecore.Forms.Shell.UI.Controls; | ||
using Sitecore.Forms.Shell.UI.Dialogs; | ||
using Sitecore.WFFM.Abstractions.Dependencies; | ||
using Sitecore.WFFM.Abstractions.Shared; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Web; | ||
using System.Web.UI.WebControls; | ||
using Sitecore.Data; | ||
using Sitecore.Flow.Extensions; | ||
using Sitecore.Web.UI.HtmlControls; | ||
|
||
namespace Sitecore.Flow.Dialogs | ||
{ | ||
public class PostToFlowPage : EditorBase | ||
{ | ||
protected ControlledChecklist ConditionList; | ||
private readonly IResourceManager resourceManager; | ||
|
||
public const string TriggerAddressrKey = "TriggerAddress"; | ||
private const string FormFieldID = "{C9E1BF85-800A-4247-A3A3-C3F5DFBFD6AA}"; | ||
protected Edit TriggerAddress; | ||
protected TextBox FlowSchema; | ||
|
||
public string TriggerAddressValue | ||
{ | ||
get { return GetValueByKey(TriggerAddressrKey, string.Empty); } | ||
set { SetValue(TriggerAddressrKey, value); } | ||
} | ||
|
||
public PostToFlowPage() : this(DependenciesManager.ResourceManager) | ||
{ | ||
} | ||
|
||
public PostToFlowPage(IResourceManager resourceManager) | ||
{ | ||
Assert.IsNotNull(resourceManager, "resourceManager"); | ||
this.resourceManager = resourceManager; | ||
} | ||
|
||
protected override void OnLoad(EventArgs e) | ||
{ | ||
base.OnLoad(e); | ||
|
||
if (!Sitecore.Context.ClientPage.IsEvent) | ||
{ | ||
if (!string.IsNullOrEmpty(TriggerAddressValue)) | ||
{ | ||
TriggerAddress.Value = TriggerAddressValue; | ||
} | ||
|
||
var formId = Sitecore.Context.Request.QueryString["id"]; | ||
var fieldItems = Database.GetDatabase("master").GetItem(formId)?.Axes.GetDescendants() | ||
.Where(x => x.IsDerived(new ID(FormFieldID))).ToList(); | ||
|
||
if (fieldItems != null && fieldItems.Any()) | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append($@"{{ {Environment.NewLine} ""type"": ""object"",{Environment.NewLine} ""properties"": {{ "); | ||
|
||
var fieldDescriptors = new List<string>(); | ||
foreach (var field in fieldItems) | ||
{ | ||
fieldDescriptors.Add($"{Environment.NewLine} \"{HttpUtility.JavaScriptStringEncode(field.Name)}\": {{\"type\": \"string\"}}"); | ||
} | ||
|
||
sb.Append(fieldDescriptors.Aggregate((i, j) => i + "," + j)); | ||
sb.Append(Environment.NewLine + " } " + Environment.NewLine + "}"); | ||
FlowSchema.Text = sb.ToString(); | ||
} | ||
|
||
Localize(); | ||
} | ||
else | ||
{ | ||
TriggerAddress.Value = Sitecore.Web.WebUtil.GetFormValue("TriggerAddress"); | ||
} | ||
} | ||
|
||
protected override void SaveValues() | ||
{ | ||
TriggerAddressValue = TriggerAddress.Value; | ||
base.SaveValues(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Sitecore.Data; | ||
using Sitecore.Data.Items; | ||
using Sitecore.Data.Managers; | ||
|
||
namespace Sitecore.Flow.Extensions | ||
{ | ||
public static class ItemExtensions | ||
{ | ||
public static bool IsDerived(this Item item, ID templateId) | ||
{ | ||
if (item == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return !templateId.IsNull && item.IsDerived(item.Database.Templates[templateId]); | ||
} | ||
|
||
private static bool IsDerived(this Item item, Item templateItem) | ||
{ | ||
if (item == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (templateItem == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var itemTemplate = TemplateManager.GetTemplate(item); | ||
return itemTemplate != null && (itemTemplate.ID == templateItem.ID || itemTemplate.DescendsFrom(templateItem.ID)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Sitecore.Flow")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Alexander Doroshenko")] | ||
[assembly: AssemblyProduct("Sitecore.Flow")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("6ec77305-bc8a-474e-a9f6-74c2ed3541a7")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Revision and Build Numbers | ||
// by using the '*' as shown below: | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.