This is an example of how to set up a custom Data Transfer CpScripting File. Each Script will be a separate file and doesn't require the setup of a call in the ExecuteCustom method.
You would need to create a se_ParseVersionNumber.cs file
This file needs to be in the Master /Root/App_Code/Custom directory.
This example retrieves a value from the source column and uses Regex to parse that value.
using Centralpoint.Web;
using System;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
namespace Centralpoint.Master
{
public partial class DataTransferCpScripting
{
[CpScript("se_ParseVersionNumber")]
public static string se_ParseVersionNumber(DataTransferCpScripting scripting, NameValueCollection collection)
{
string returnValue = "";
try
{
string defaultValue = Scripting.CollectionValue(collection, "defaultValue");
string systemName = collection["name"];
if (String.IsNullOrWhiteSpace(systemName)) systemName = "Title";
string value;
if (Scripting.CollectionValue(collection, "useDefaultValueOnUpdates").Equals("true", StringComparison.CurrentCultureIgnoreCase) && scripting.DataTransfer.Writer.IsUpdate)
value = scripting.DefaultValue();
else
value = String.IsNullOrEmpty(systemName) ? String.Empty : scripting.Column(systemName, defaultValue);
string location = collection["Location"];
if (String.IsNullOrWhiteSpace(location)) location = "1";
//1 = before, 2 = after
/*
>> FOUN(match)
310 USM Installation Manual for SVR23A v1.0 $1 = 310 USM Installation Manual for SVR23A $2 = v1.0
817 5G NR SVR21D P1 QCI133 Enable MOP v2.0
>> NOT FOUND(no match)
RF4461D-13A.stp, AT1K04 28GHz Outdoor AU Beambook-type30 (H50 V100 ) ComOn Etilt0 Env.vex
*/
//MatchCollection matches = Regex.Matches(value, "(.+?)(v[ ]{0,1}[0-9]{1,2}.[0-9]{1,2})(.*)", RegexOptions.IgnoreCase);
MatchCollection matches = Regex.Matches(value, "(.+?)(v[ ]{0,1}[0-9]{1,2}.[0-9]{1,2})(.*)");
string titleBefore = "";
string versionNumber = "";
string titleAfterVersionNumber = "";
if (matches.Count > 0)
{
//310 USM Installation Manual for SVR23A v1.0
Match match = matches[0];
titleBefore = match.Groups[1].Value; // $1 = 310 USM Installation Manual for SVR23A
versionNumber = match.Groups[2].Value; // $2 = v1.0
titleAfterVersionNumber = match.Groups[3].Value; //anything after (v.*)
returnValue = location.Equals("1") ? titleBefore.Trim() : $"{versionNumber.Trim()} {titleAfterVersionNumber.Trim()}";
}
else
returnValue = location.Equals("1") ? value : "";
}
catch (Exception ex)
{
scripting.DataTransfer.Status = $"se_ParseVersionNumber:Exception: {ex.Message}. {ex.StackTrace}";
}
return returnValue;
}
}
}
Keywords: Data Transfer, Data Transfer CpScripting
Related CodeSamples Records