Skip to content

Commit 3ab3d2c

Browse files
authored
Merge pull request #42 from jdunkerley/streaming
IOutputHelper interface and factory
2 parents 4c5dc12 + 90bc05d commit 3ab3d2c

21 files changed

+199
-71
lines changed

AlteryxAddIns.Framework/AlteryxAddIns.Framework.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="ConfigWithIncomingConnection.cs" />
7575
<Compile Include="ConnectionState.cs" />
7676
<Compile Include="Factories\InputPropertyFactory.cs" />
77+
<Compile Include="Factories\OutputHelperFactory.cs" />
7778
<Compile Include="Factories\RecordCopierFactory.cs" />
7879
<Compile Include="FieldBaseHelpers.cs" />
7980
<Compile Include="FieldDescription.cs" />
@@ -83,6 +84,7 @@
8384
<Compile Include="ConfigWindows\InputFieldTypeConverter.cs" />
8485
<Compile Include="InputProperty.cs" />
8586
<Compile Include="Interfaces\IInputPropertyFactory.cs" />
87+
<Compile Include="Interfaces\IOutputHelperFactory.cs" />
8688
<Compile Include="Interfaces\IRecordCopier.cs" />
8789
<Compile Include="Interfaces\IRecordCopierFactory.cs" />
8890
<Compile Include="Interfaces\ProgressUpdatedEventArgs.cs" />
@@ -91,6 +93,7 @@
9193
<Compile Include="Interfaces\RecordPushedEventHandler.cs" />
9294
<Compile Include="Interfaces\SuccessEventArgs.cs" />
9395
<Compile Include="Interfaces\SuccessEventHandler.cs" />
96+
<Compile Include="Interfaces\IOutputHelper.cs" />
9497
<Compile Include="OutputHelper.cs" />
9598
<Compile Include="OutputType.cs" />
9699
<Compile Include="OutputTypeHelpers.cs" />

AlteryxAddIns.Framework/BaseEngine.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace JDunkerley.AlteryxAddIns.Framework
1515
public abstract class BaseEngine<TConfig> : AlteryxRecordInfoNet.INetPlugin, IBaseEngine
1616
where TConfig : new()
1717
{
18+
private readonly IOutputHelperFactory _outputHelperFactory;
19+
1820
private readonly Dictionary<string, PropertyInfo> _inputs;
1921
private readonly Dictionary<string, PropertyInfo> _outputs;
2022

@@ -26,13 +28,20 @@ public abstract class BaseEngine<TConfig> : AlteryxRecordInfoNet.INetPlugin, IBa
2628
/// Initializes a new instance of the <see cref="BaseEngine{T}"/> class.
2729
/// </summary>
2830
/// <param name="recordCopierFactory">Factory to create copiers</param>
29-
protected BaseEngine(IRecordCopierFactory recordCopierFactory)
31+
/// <param name="outputHelperFactory">Factory to create output helpers</param>
32+
protected BaseEngine(IRecordCopierFactory recordCopierFactory, IOutputHelperFactory outputHelperFactory)
3033
{
3134
this.RecordCopierFactory = recordCopierFactory;
35+
this._outputHelperFactory = outputHelperFactory;
3236

3337
var type = this.GetType();
3438
this._inputs = type.GetProperties<AlteryxRecordInfoNet.IIncomingConnectionInterface>();
35-
this._outputs = type.GetProperties<OutputHelper>();
39+
this._outputs = type.GetProperties<IOutputHelper>();
40+
41+
if (this._outputHelperFactory == null && this._outputs.Count > 0)
42+
{
43+
throw new ArgumentNullException(nameof(outputHelperFactory), "Tool has an output but no factory has been provided.");
44+
}
3645
}
3746

3847
/// <summary>
@@ -88,7 +97,7 @@ public void PI_Init(int nToolId, AlteryxRecordInfoNet.EngineInterface engineInte
8897

8998
foreach (var kvp in this._outputs)
9099
{
91-
kvp.Value.SetValue(this, new OutputHelper(this, kvp.Key), null);
100+
kvp.Value.SetValue(this, this._outputHelperFactory.CreateOutputHelper(this, kvp.Key), null);
92101
}
93102

94103
this.OnInitCalled();

AlteryxAddIns.Framework/BaseTool.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/// <seealso cref="AlteryxGuiToolkit.Plugins.IPlugin" />
1818
public abstract class BaseTool<TConfig, TEngine>
1919
where TConfig : new()
20+
where TEngine : AlteryxRecordInfoNet.INetPlugin
2021
{
2122
private readonly Lazy<Image> _icon;
2223

6.18 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace JDunkerley.AlteryxAddIns.Framework.Factories
2+
{
3+
using Interfaces;
4+
5+
/// <summary>
6+
/// Factory For Creating <see cref="IOutputHelper"/> objects.
7+
/// </summary>
8+
public class OutputHelperFactory : IOutputHelperFactory
9+
{
10+
/// <summary>
11+
/// Creates a new instance of an <see cref="IOutputHelper"/>
12+
/// </summary>
13+
/// <param name="hostEngine">The host engine.</param>
14+
/// <param name="connectionName">Name of the outgoing connection.</param>
15+
/// <returns>A configured instance of an <see cref="IOutputHelper"/></returns>
16+
public IOutputHelper CreateOutputHelper(IBaseEngine hostEngine, string connectionName)
17+
=> new OutputHelper(hostEngine, connectionName);
18+
}
19+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace JDunkerley.AlteryxAddIns.Framework.Interfaces
2+
{
3+
using System.Xml;
4+
using AlteryxRecordInfoNet;
5+
6+
/// <summary>
7+
/// Interface Defining An Output Helper
8+
/// </summary>
9+
public interface IOutputHelper
10+
{
11+
/// <summary>
12+
/// Gets a reusable <see cref="Record"/> object
13+
/// </summary>
14+
Record Record { get; }
15+
16+
/// <summary>
17+
/// Gets the <see cref="RecordInfo"/> describing the Output records
18+
/// </summary>
19+
RecordInfo RecordInfo { get; }
20+
21+
/// <summary>
22+
/// Given a fieldName, gets the <see cref="FieldBase"/> for it
23+
/// </summary>
24+
/// <param name="fieldName">Name of field</param>
25+
/// <returns><see cref="FieldBase"/> representing the field</returns>
26+
FieldBase this[string fieldName] { get; }
27+
28+
/// <summary>
29+
/// Initializes the output stream.
30+
/// </summary>
31+
/// <param name="recordInfo">RecordInfo defining the fields and outputs of the connection.</param>
32+
/// <param name="sortConfig">Sort configuration to pass onto Alteryx.</param>
33+
/// <param name="oldConfig">XML configuration of the tool.</param>
34+
void Init(RecordInfo recordInfo, XmlElement sortConfig = null, XmlElement oldConfig = null);
35+
36+
/// <summary>
37+
/// Pushes a record to Alteryx to hand onto over tools.
38+
/// </summary>
39+
/// <param name="record">Record object to push to the stream.</param>
40+
/// <param name="close">Value indicating whether to close the connection after pushing the record.</param>
41+
/// <param name="updateCountMod">How often to update Row Count and Data</param>
42+
void Push(Record record, bool close = false, ulong updateCountMod = 250);
43+
44+
/// <summary>
45+
/// Update The Progress Of A Connection
46+
/// </summary>
47+
/// <param name="percentage">Percentage Progress from 0.0 to 1.0</param>
48+
/// <param name="setToolProgress">Set Tool Progress As Well</param>
49+
void UpdateProgress(double percentage, bool setToolProgress = false);
50+
51+
/// <summary>
52+
/// Tell Alteryx We Are Finished
53+
/// </summary>
54+
/// <param name="executionComplete">Tell Alteryx Tool Execution Is Complete</param>
55+
void Close(bool executionComplete = false);
56+
}
57+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace JDunkerley.AlteryxAddIns.Framework.Interfaces
2+
{
3+
/// <summary>
4+
/// Interface to decouple the construction of <see cref="IOutputHelper"/> objects from <see cref="BaseEngine{TConfig}"/>.
5+
/// </summary>
6+
public interface IOutputHelperFactory
7+
{
8+
/// <summary>
9+
/// Creates a new instance of an <see cref="IOutputHelper"/>
10+
/// </summary>
11+
/// <param name="hostEngine">The host engine.</param>
12+
/// <param name="connectionName">Name of the outgoing connection.</param>
13+
/// <returns>A configured instance of an <see cref="IOutputHelper"/></returns>
14+
IOutputHelper CreateOutputHelper(IBaseEngine hostEngine, string connectionName);
15+
}
16+
}

AlteryxAddIns.Framework/Interfaces/IRecordCopierFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace JDunkerley.AlteryxAddIns.Framework.Interfaces
22
{
33
/// <summary>
4-
/// Interface to decouple the construction of <see cref="IRecordCopier"/> objects from the engines.
4+
/// Interface to decouple the construction of <see cref="IRecordCopier"/> objects from <see cref="BaseEngine{TConfig}"/>.
55
/// </summary>
66
public interface IRecordCopierFactory
77
{

AlteryxAddIns.Framework/OutputHelper.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ namespace JDunkerley.AlteryxAddIns.Framework
55

66
using AlteryxRecordInfoNet;
77

8+
using Interfaces;
9+
810
/// <summary>
911
/// Output Helper Class
1012
/// </summary>
11-
public sealed class OutputHelper : IDisposable
13+
internal sealed class OutputHelper : IDisposable, IOutputHelper
1214
{
1315
private readonly IBaseEngine _hostEngine;
1416

@@ -70,7 +72,7 @@ public void AddConnection(OutgoingConnection connection)
7072
public void Init(RecordInfo recordInfo, XmlElement sortConfig = null, XmlElement oldConfig = null)
7173
{
7274
this.RecordInfo = recordInfo;
73-
this._lazyRecord = new Lazy<Record>(this.CreateRecord);
75+
this._lazyRecord = new Lazy<Record>(() => this.RecordInfo?.CreateRecord());
7476

7577
this._recordCount = 0;
7678
this._recordLength = 0;
@@ -79,12 +81,6 @@ public void Init(RecordInfo recordInfo, XmlElement sortConfig = null, XmlElement
7981
this._hostEngine.Engine.OutputMessage(this._hostEngine.NToolId, MessageStatus.STATUS_Info, $"Init called back on {this._connectionName}");
8082
}
8183

82-
/// <summary>
83-
/// Create A New Record (Can be reused)
84-
/// </summary>
85-
/// <returns>An empty record based off the RecordInfo.</returns>
86-
public Record CreateRecord() => this.RecordInfo?.CreateRecord();
87-
8884
/// <summary>
8985
/// Pushes a record to Alteryx to hand onto over tools.
9086
/// </summary>

AlteryxAddIns.Roslyn/AlteryxAddIns.Roslyn.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@
108108
</ProjectReference>
109109
</ItemGroup>
110110
<ItemGroup>
111-
<None Include="Install.bat" />
112-
<None Include="InstallRelease.bat">
111+
<None Include="Install.bat">
113112
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
114113
</None>
114+
<None Include="InstallRelease.bat" />
115115
<None Include="packages.config" />
116116
<None Include="Uninstall.bat">
117117
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -135,8 +135,8 @@
135135
<PropertyGroup>
136136
<PostBuildEvent>rmdir "$(SolutionDir)\Release\Roslyn" /s /q
137137
mkdir "$(SolutionDir)\Release\Roslyn"
138-
copy "$(TargetDir)\*.dll" "$(SolutionDir)\Release\Roslyn\"
139-
copy "$(TargetDir)\InstallRelease.bat" "$(SolutionDir)\Release\RoslynInstall.bat"
138+
copy "$(ProjectDir)\*.dll" "$(SolutionDir)\Release\Roslyn\"
139+
copy "$(ProjectDir)\InstallRelease.bat" "$(SolutionDir)\Release\RoslynInstall.bat"
140140
</PostBuildEvent>
141141
</PropertyGroup>
142142
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)