Monday, 15 September 2014

Configurable / dynamic parameters



I want to build something like a pipeline, where I can put commands (converters, readers, writers...) together, like a linear workflow and connect them by the given parameters of the commands. Everything should be serializable and a clean xml is mandatory, because graphical editor is not planned in the first step, so xml is edited (with a generated schema and intellisense support in VS this is no pain).


Sample:



<DataCommand name="AboFileReader">
<connection>
<parameter name="filename" direction="in" type="string">
<parameter name="tabledata" direction="out" type="DataTable">
</connection>
</DataCommand>
<DataCommand name="TrimConverter">
<connection>
<param name="tabledata" direction="in" type="DataTable" >
<param name="tabledata" direction="out" type="DataTable" >
</connection>
</DataCommand>
<DataCommand name="AboDataConverter">
<connection>
<param name="tabledata" direction="in" type="DataTable" >
<param name="tabledata" direction="out" type="DataTable" >
</connection>
</DataCommand>
<DataCommand name="AboSqlWriter">
<connection>
<param name="tabledata" direction="in" type="DataTable" >
</connection>
</DataCommand>


Three different ways I can do it come to my mind and all of them have pros and cons and i don´t know which to choose.


First I thought 1. is the way to go, but hten I came up with solution 3. because it gives a clean xml and is native serializable. For the next step (a editor) binding to GUI should be easy and a propertygrid doing reflection is not my first choice (reflection is always ugly), having a collection of parameters can easily be bound to the GUI.


Perhaps a combination of 1 and 3 is the way to go, to collect all parameters in a collection on startup?


1. Data-Annotations



[Parameter(Direction = "In", Description="...")]
public string FileName {get; set;}

[Parameter(Direction = "Out", Description="...")]
public DataTable Table {get; set;}


Pros: + native parameters are exposed + intellisense when coding


Cons: - native serializing? - ugly xml?


2. Windows Workflow Foundation Style



public InParameter<string> FileName {get; set;}

public OutParameter<DataTable> Table {get; set;}


Pros: + intellisense when coding + parameters are exposed + serializing works


Cons: - ugly xml?


3. Collection filled in constructor



ObservableCollection<Parameter> Parameters {get; set;}

public Init()
{
Parameters.Add( new Parameter() { Name="FileName", Type = typeOf(string), Direction="In", Description="..." } );
Parameters.Add( new Parameter() { Name="Table", Type = typeOf(DataTable), Direction="Out", Description="..." } );
}


Pros: + serializing works + clean xml


Cons: - parameters are exposed in sourcecode - no intellisense when coding


What is your experience and what is the way to go?


No comments:

Post a Comment