In this example, we will set up a custom Data transfer source(Reader)
You can inherit from DataTableReader class and need to override GetDataTable method.
This example SourceCustomParameters contains a path to the XML file which will be loaded into the DataTable.
using Centralpoint.Web;
using System;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;
namespace Centralpoint.Master
{
namespace Custom.Maximus_DataTransfer
{
public class CustomReader : DataTransferV.DataTableReader
{
protected DataTable _mainTable { get; set; }
public CustomReader(DataTransfer dataTransfer)
: base(dataTransfer)
{
}
protected override DataTable GetDataTable(bool includeData)
{
string sourceFile = this.DataTransfer.Attributes.Get("SourceCustomParameters");
HttpContext.Current.Trace.Warn("Trace_Warn", $"sourceFile: {sourceFile}");
if (String.IsNullOrWhiteSpace(sourceFile) || !File.Exists(sourceFile)) return new DataTable();
DataTable _mainTableName = new DataTable();
try
{
XDocument xml = XDocument.Load(sourceFile);
var system = from systemData in xml.Elements()
select new
{
Row = from attrib in xml.Descendants("row")
select new
{
Colum = from col in attrib.Descendants("col")
select new
{
Name = col.Attribute("name").Value,
Type = col.Attribute("type").Value,
Value = col.Value
},
Category = from at in attrib.Elements("categories")
select new
{
taxonomyCode = at.Element("category").Value
},
Attachments = from att in attrib.Elements("attachments").Elements("attmnt")
select new
{
fileName = att.Element("file_name").Value
},
}
};
foreach (var val in system)
{
foreach (var attrib in val.Row)
{
DataRow row = _mainTableName.NewRow();
StringBuilder attachments = new StringBuilder();
if (!_mainTableName.Columns.Contains("Attachments")) _mainTableName.Columns.Add("Attachments", typeof(String));
foreach (var att in attrib.Attachments)
{
if (attachments.Length > 0) attachments.Append(", ");
// HttpContext.Current.Trace.Warn("attmnt", $"{att.fileName}");
attachments.Append(att.fileName);
}
if (attachments.Length > 0)
row["Attachments"] = attachments.ToString();
foreach (var cat in attrib.Category)
{
HttpContext.Current.Trace.Warn("cat.taxonomyCode", $"{cat.taxonomyCode}");
if (!_mainTableName.Columns.Contains("Category")) _mainTableName.Columns.Add("Category", typeof(String));
row["Category"] = cat.taxonomyCode;
}
foreach (var column in attrib.Colum)
{
HttpContext.Current.Trace.Warn("column.Name", $"{column.Name}");
if (!_mainTableName.Columns.Contains(column.Name)) _mainTableName.Columns.Add(column.Name, typeof(String));
row[column.Name] = column.Value;
}
_mainTableName.Rows.Add(row);
}
}
}
catch (Exception ex)
{
HttpContext.Current.Trace.Warn("Maximus.GetDataTable", $"{ex.Message}. {ex.StackTrace}");
}
HttpContext.Current.Trace.Warn("Trace_Warn", $"3 . {_mainTableName.Rows.Count}");
return _mainTableName;
}
}
}
}
Keywords: Data Transfer, Data Transfer Source, Data Table
Related CodeSamples Records