 | SettingsObject Class |
An object that represents serializable settings that can also have GUI counterpart.
Use for Export Field Settings, Profile settings and User settings. Export Profile Settings
also utilize this class via
ExportSettingsBaseFIELDSETTINGSTYPE.
Inheritance Hierarchy Namespace: CTExtensions.ExportCore.ConfigAssembly: CTInterface (in CTInterface.dll) Version: 25.0
Syntaxpublic abstract class SettingsObject
Public MustInherit Class SettingsObject
The SettingsObject type exposes the following members.
Constructors | Name | Description |
---|
 | SettingsObject | Initializes a new instance of the SettingsObject class |
Top
Properties | Name | Description |
---|
 | Context |
Given context for this object if any. If the settings object supports context,
it must be initialized using InitWithContext(ICTExtension, ISettingsContext).
|
 | HasSerializedCustomData |
This flag tells whether custom data has been serialized
by overriding a CUSTOMTOOLS' core settings object. This is important to
check at overridden implementation of deserialization methods
to avoid attempts of deserializing content that is not even stored.
See also IsCustomized.
For implementation that do not override existing extensions, this can be ignored.
|
 | ParentExtension |
Parent Extension
|
 | Version |
Version of this object, automatically
included in serialization.
|
Top
Methods | Name | Description |
---|
 | CloneT |
Clone this object using serialization.
|
 | CopyTo |
Copy this object to target object.
|
 | CreateAdapter |
Provide GUI counterpart for this custom settings type.
It will be shown as Export Profile Field settings tab,
Profile Settings page or User Settings page depending
on which type param this object is from
ExportBaseFIELDSETTINGSTYPE, EXPORTSETTINGSTYPE, PROFILESETTINGSTYPE, USERSETTINGSTYPE.
|
 | CreateAdapters |
Provide GUI counterparts for this custom settings type.
They will be shown as multiple Export Profile Field settings tabs,
Profile Settings pages or User Settings pages depending
on which type param this object is from
ExportBaseFIELDSETTINGSTYPE, EXPORTSETTINGSTYPE, PROFILESETTINGSTYPE, USERSETTINGSTYPE.
You can override this function and set your implementation of CreateAdapter(ICTExtension) to return null,
if you wish to provide multiple GUI controls for interracting with this object.
|
 | Deserialize(Byte) |
Internally used for deserializing this object from store.
|
 | Deserialize(Stream) |
Deserialize your object from s. Do not otherwise
manipulate or modify e.g. Position.
It is highly recommended to use StreamExtensions for popping
base types from s.
Data must be deserialized in same order as is serialized at Serialize(Stream).
Make sure you deserialize according to Version variable and then set it
to correspond current object version. |
  | GetCurrentVersion |
Returns current version in format YYss where YY is major and ss is minor, e.g. 2401 for CT 2024 SP1.
|
 | Init |
Must be called immediately after this object is created as new or when reinitialization is needed before deserialization.
OR, you can call InitWithContext(ICTExtension, ISettingsContext) instead of this.
|
 | InitWithContext |
Called immediately after this object is created as new or when reinitialization is needed before deserialization.
Calls Init(ICTExtension) internally, but also sets Context as given.
|
 | IsCustomized |
This function is meant to be sealed -implemented by CUSTOMTOOLS core objects to define the base object type,
so it can be distinquished from script extended ones. This is needed for successful deserialization.
See also HasSerializedCustomData.
For implementation that do not override existing extensions, this can be ignored.
|
 | Serialize |
Internally used for serializing and storing this object.
|
 | Serialize(Stream) |
Serialize your object to s. Do not otherwise
manipulate or modify e.g. Position.
It is highly recommended to use StreamExtensions for pushing
base types into s.
Data must be serialized in same order as is deserialized at Deserialize(Stream). |
Top
Example
This example shows how to utilize classes of
CTExtensions.ExportCore,
CTExtensions.ExportCore.Config,
CTExtensions.ExportCore.ExportBaseTypes and
CTExtensions.ExportCore.EXTs namespaces for creating
a custom Export ERP integration that supports custom data storing on CT Profile, current User, Export Profile and Export Profile Field levels,
as well as very powerful
GenericExportHandlerT, E, I for the actual export process.
Language: C#
Class name: MyCustomErpIntegration
using ATR.CT.CTInterface;
using CTEngineLib;
using CTExtensions.ExportCore.Config;
using CTExtensions.ExportCore.EXTs;
using CTExtensions.ExportCore.ExportBaseTypes;
using System.Windows.Forms;
using System.IO;
using ATRControls2;
using System.Collections.Generic;
using CTExtensions.ExportCore.ExportHandler;
using ATRControlsXLib;
using System.Linq;
namespace CustomErpIntegrationDemo
{
public class MyCustomErpIntegration : ERPExportBaseExtraOptsWithUserAndProfileSettings<MyExportFieldSettings, MyExportSettings, MyUserSettings, MyProfileSettings>
{
public override string FriendlyName()
{
return "My Custom Integration";
}
public override string IdentifyingName()
{
return "MY-CUSTOM-ERP-INTEGRATION-12345";
}
public override List<EventExtension> GetEventExtensions()
{
return new List<EventExtension>() { new MyExportHandler() };
}
protected override ExportTypeExt<MyExportSettings, MyExportFieldSettings> CreateExportType()
{
return new ExportWithFullPDMSupport();
}
public class ExportWithFullPDMSupport : ExportTypeExt<MyExportSettings, MyExportFieldSettings>
{
public override bool AllowUseInSWPDM()
{
return true;
}
public override bool SupportsSilentExecution()
{
return true;
}
}
}
public class MyExportHandler : GenericExportHandler<MyCustomErpIntegration, MyExportItem, MyRowItemizer>
{
protected override void ManipulateExportDataBeforeItemization(ICTExportProfile profile, ICTExportProfileData data, string conf, bool bLastConfiguration)
{
MyExportSettings exportsettings = (GetParent() as MyCustomErpIntegration).GetExportSettings(profile as CTExportProfile);
foreach (var fieldSettings in exportsettings.FieldSettings)
{
string field = fieldSettings.Key;
MyExportFieldSettings settings = fieldSettings.Value;
if (settings.MyFieldBoolData)
{
for (int i = 0; i < data.Rows; i++)
data.SetValue(i, field, data.GetValueByName(field, i).ToUpper());
}
}
}
protected override void GetAdditionalColumnsSetup(IListViewEx oList, string configuration, out Dictionary<string, bool> oColsToAdd, out List<string> oColsToHide)
{
oColsToAdd = null;
oColsToHide = null;
oColsToAdd = new Dictionary<string, bool>() { { "Item Status", true } };
}
protected override void UpdateItemsPreFilling(List<MyExportItem> items)
{
MyExportSettings exportsettings = (GetParent() as MyCustomErpIntegration).GetExportSettings(moExportProfile as CTExportProfile);
MyUserSettings userSettings = (GetParent() as MyCustomErpIntegration).GetUserSettings();
MyProfileSettings profileSettings = (GetParent() as MyCustomErpIntegration).GetProfileSettings();
if (CurrentExportCase == ExportCase.SOLIDWORKS)
{
Log("This goes to %TEMP%\\MY-CUSTOM-ERP-INTEGRATION-12345.log");
}
else if (CurrentExportCase == ExportCase.PDM)
{
Log("This goes to Task Details");
}
else if (CurrentExportCase == ExportCase.SOLIDWORKS_Silent)
{
Log("This goes to Task Details and the operation is silent.");
}
if (items.Count > 0)
{
items.First().RowColorController.ClearColors();
items.First().SetValue("Item Status", "EXISTING");
items.First().RowColorController.SetFieldBGColor("Item Status", ExportItemColorController.COLOR_WHITE);
items.First().WillGetItemNumberAfterExport = false;
}
foreach (var item in items.Skip(1))
{
item.RowColorController.ClearColors();
item.SetValue("Item Status", "NEW");
item.RowColorController.SetFieldBGColor("Item Status", ExportItemColorController.COLOR_NEW);
item.WillGetItemNumberAfterExport = true;
}
if (items.Count > 0)
{
var ghostItem = items.First().AddGhostItem<MyExportItem>("Item '12345' in target ERP");
ghostItem.SetQuantityIn(items.First(), 1);
ghostItem.SetValue("Item Status", "Exists in ERP but not in CAD");
ghostItem.RowColorController.SetRowFGColor(ExportItemColorController.COLOR_GHOST);
}
}
protected override bool Export(List<MyExportItem> items)
{
MyExportSettings exportsettings = (GetParent() as MyCustomErpIntegration).GetExportSettings(moExportProfile as CTExportProfile);
MyUserSettings userSettings = (GetParent() as MyCustomErpIntegration).GetUserSettings();
MyProfileSettings profileSettings = (GetParent() as MyCustomErpIntegration).GetProfileSettings();
foreach (var item in items.Where(x => x.WillGetItemNumberAfterExport))
{
item.WillGetItemNumberAfterExport = false;
}
foreach (var item in items)
{
if (Itemizer.GetRowType(item.DataRows.First().Item1) == RowItemizer.RowType.Ghost)
continue;
item.RowColorController.ClearColors();
item.SetValue("Item Status", "OK");
item.RowColorController.SetFieldBGColor("Item Status", ExportItemColorController.COLOR_WHITE);
}
return true;
}
protected override bool SecondPhaseExport(List<MyExportItem> items)
{
return true;
}
}
public class MyExportItem : ExportItem
{
public bool WillGetItemNumberAfterExport { get; set; }
public MyExportItem()
{
WillGetItemNumberAfterExport = false;
}
public override bool RequiresWriteBack()
{
return base.RequiresWriteBack() || WillGetItemNumberAfterExport;
}
}
public class MyRowItemizer : RowItemizer
{
}
public class MyExportFieldSettings : SettingsObject
{
public string MyFieldStringData { get; set; }
public bool MyFieldBoolData { get; set; }
protected override void Deserialize(Stream s)
{
MyFieldStringData = s.PopString();
MyFieldBoolData = s.PopBool();
}
protected override void Serialize(Stream s)
{
s.PushString(MyFieldStringData);
s.PushBool(MyFieldBoolData);
}
public override ControlAdapter CreateAdapter(ICTExtension parent)
{
return new PropertyGridAdapter<MyExportFieldSettings>(parent);
}
}
public class MyUserSettings : SettingsObject
{
public bool Enabled { get; set; }
public string UserName { get; set; }
public string PassWord { get; set; }
protected override void Serialize(Stream s)
{
s.PushBool(Enabled);
s.PushString(UserName);
s.PushString(PassWord);
}
protected override void Deserialize(Stream s)
{
Enabled = s.PopBool();
UserName = s.PopString();
PassWord = s.PopString();
}
public override ControlAdapter CreateAdapter(ICTExtension parent)
{
return new MyUserSettingsGUI(parent);
}
}
public class MyUserSettingsGUI : ControlAdapter<MyUserSettings>
{
ATRControls2.WinForm.GenericLoginCtrl moCtrl;
public MyUserSettingsGUI(ICTExtension parent) : base(parent)
{
moCtrl = new ATRControls2.WinForm.GenericLoginCtrl();
moCtrl.BackColor = System.Drawing.Color.White;
moCtrl.ShowEnableCheck(true);
moCtrl.ShowUsernameField(true);
moCtrl.ShowPasswordField(true);
moCtrl.ShowDatabaseField(false);
moCtrl.ShowTestConnectionButton(false);
moCtrl.ShowCommunicationPointField(false);
moCtrl.Dock = System.Windows.Forms.DockStyle.Fill;
Controls.Add(moCtrl);
}
public override void LoadFrom(MyUserSettings settings)
{
moCtrl.LoginEnabled = settings.Enabled;
moCtrl.Username = settings.UserName;
moCtrl.Password = settings.PassWord;
}
public override void SaveTo(MyUserSettings settings)
{
settings.Enabled = moCtrl.LoginEnabled;
settings.UserName = moCtrl.Username;
settings.PassWord = moCtrl.Password;
}
}
public class MyExportSettings : ExportSettingsBase<MyExportFieldSettings>
{
public string TargetCompany { get; set; }
protected override void Deserialize(Stream s)
{
base.Deserialize(s);
TargetCompany = s.PopString();
}
protected override void Serialize(Stream s)
{
base.Serialize(s);
s.PushString(TargetCompany);
}
public override ControlAdapter CreateAdapter(ICTExtension extension)
{
return new MyExportSettingsGUI(extension);
}
}
public class MyExportSettingsGUI : ControlAdapter<MyExportSettings>
{
System.Windows.Forms.TextBox tb;
public MyExportSettingsGUI(ICTExtension ext) : base(ext)
{
tb = new System.Windows.Forms.TextBox();
tb.Dock = System.Windows.Forms.DockStyle.Top;
Controls.Add(tb);
}
public override void LoadFrom(MyExportSettings settings)
{
tb.Text = settings.TargetCompany;
}
public override void SaveTo(MyExportSettings settings)
{
settings.TargetCompany = tb.Text;
}
}
public class MyProfileSettings : SettingsObject
{
public string ConnectionString { get; set; }
protected override void Deserialize(Stream s)
{
ConnectionString = s.PopString();
}
protected override void Serialize(Stream s)
{
s.PushString(ConnectionString);
}
public override ControlAdapter CreateAdapter(ICTExtension parent)
{
return new PropertyGridAdapter<MyProfileSettings>(parent);
}
}
}
Revision HistoryDate | Version | Description |
---|
- | 2022 SP0 | First Release |
- | 2024 SP0 |
Extended with Context that can be initilized using InitWithContext(ICTExtension, ISettingsContext), to given
this object some arbitrary context; e.g. if this object is infact a serializable sub-object of another SettingsObject.
|
- | 2024 SP1 |
Extended with HasSerializedCustomData, IsCustomized and GetCurrentVersion.
Also improved serialization routine to better accomondate cases when core settings are extended with scripts.
|
- | 2025 SP1 |
- Extended with CreateAdapters(ICTExtension) that allows objects to provide multiple controls for editing settings stored in this object.
- Default implementation of IsCustomized now returns true instead of false. This is because
script extensions seldom remember to override this, but built-in SettingsObjects must.
|
See Also