Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using PX.Data;
using PX.DataSync;
using PX.DataSync.ACH;
using PX.Api;
namespace PX.DataSync
{
public class MyACHProvider : ACHProvider, IPXSYProvider
{
public override string ProviderName
{
get
{
return PX.Data.PXMessages.Localize("My ACH Provider");
}
}
protected override void InitialiseProxy(byte[] data)
{
InitialiseMySchemaFile();
}
protected override void InitialiseSchema()
{
InitialiseMySchemaFile();
}
protected void InitialiseMySchemaFile()
{
this.schemaFile = GetFile(GetParameter(SCHEMA_PARAMETER));
if (schemaFile == null) throw new PXException(Messages.FileNotFound, GetParameter(SCHEMA_PARAMETER));
MySchemaBuilder builder = new MySchemaBuilder(new MemoryStream(schemaFile.BinData, false), GetEncoding());
schema = builder.ParceSchema();
}
}
public class MySchemaBuilder : SchemaBuilder
{
public MySchemaBuilder(Stream stream, Encoding encoding)
: base(stream, encoding)
{
fieldBuilder = new MyFieldBuilder();
}
}
public class MyFieldBuilder : PX.DataSync.ACH.FieldBuilder
{
#region Constants
public const String TOTAL_COUNT_TWO_BASED_FLAG = "TotalCountPlusTwo";
#endregion
protected override FieldInfo CreateField(String fieldName, String[] settings)
{
if (fieldName.StartsWith(FORMULA_SEPARATOR.ToString()))
{
String s = fieldName.TrimStart(FORMULA_SEPARATOR);
if (s == TOTAL_COUNT_TWO_BASED_FLAG) return CreateTotalCountTwoBasedRegistrator(fieldName);
}
return base.CreateField(fieldName, settings);
}
protected virtual TotalCountTwoBasedField CreateTotalCountTwoBasedRegistrator(String name)
{
TotalCountTwoBasedField field = new TotalCountTwoBasedField(name);
return field;
}
}
#region FieldInfo
public class TotalCountTwoBasedField : SurogateField, IResetableField
{
private Int32 _count;
public TotalCountTwoBasedField(String name)
: base(name)
{
FillOnEnd = true;
}
public virtual void Reset()
{
_count = default(Int32);
}
public override string GetValue(FillContext context, InstanceInfo instance, IEnumerable<String> values)
{
_count++;
return (_count + 2).ToString(System.Globalization.CultureInfo.InvariantCulture);
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.