EventExtensionEXTTYPE Class |
Namespace: CTExtensions.ExportCore.EXTs
The EventExtensionEXTTYPE type exposes the following members.
Name | Description | |
---|---|---|
EventExtensionEXTTYPE |
Constructor
|
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\CTInterface.dll } // @AUTO-REFERENCE { [CT_INSTALL_PATH]\Interop.CTEngineLib.dll } // @AUTO-REFERENCE { [CT_INSTALL_PATH]\ATRControls2.dll } // @AUTO-REFERENCE { c:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Windows.Forms.dll } // @AUTO-REFERENCE { c:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Drawing.dll } using ATR.CT.CTInterface; using CTEngineLib; using CTExtensions.ExportCore.Config; /* SettingsObject, ControlAdapter, StreamExtensions, PropertyGridAdapter */ using CTExtensions.ExportCore.EXTs; /* EventExtension */ using CTExtensions.ExportCore.ExportBaseTypes; /* ERPExportBaseExtraOptsWithUserSettings */ using System.Windows.Forms; /* MyExportSettingsGUI */ using System.IO; /* Stream */ using ATRControls2; /* MyUserSettingsGUI (GenericLoginCtrl) */ using System.Collections.Generic; /* List */ using System; namespace CustomErpIntegrationDemo { // Object representing my custom settings (MyFieldStringData and MyFieldBoolData) // for Export Profile Fields of Export Profiles that are bound to my Erp Integration. public class MyExportFieldSettings : SettingsObject { // -- My data -- public string MyFieldStringData { get; set; } public bool MyFieldBoolData { get; set; } // -- -- -- -- // -- Serialization of my data protected override void Deserialize(Stream s) { MyFieldStringData = s.PopString(); MyFieldBoolData = s.PopBool(); } protected override void Serialize(Stream s) { s.PushString(MyFieldStringData); s.PushBool(MyFieldBoolData); } // -- -- -- -- // -- return GUI control capable of showing and modifying my data // when editing Export Profile Fields at Options. public override ControlAdapter CreateAdapter(ICTExtension parent) { // PropertyGridAdapter just utilizes System.Windows.Forms.PropertyGrid // to enable editing of data object values. It could be custom control too, // but this is a quick solution. return new PropertyGridAdapter<MyExportFieldSettings>(parent); } // -- -- -- -- } // Object representing my custom settings // for each individual CT user. public class MyUserSettings : SettingsObject { // -- My data -- public bool Enabled { get; set; } public string UserName { get; set; } public string PassWord { get; set; } // -- -- -- -- // -- Serialization of my data 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(); } // -- -- -- -- // -- return GUI control capable of showing and modifying my data // at User Options. public override ControlAdapter CreateAdapter(ICTExtension parent) { // Custom control "MyUserSettingsGUI" declared below return new MyUserSettingsGUI(parent); } // -- -- -- -- } // Custom control that accesses "MyUserSettings", shown as // an individual page at User Options public class MyUserSettingsGUI : ControlAdapter<MyUserSettings> { // Utilizing generic login control from ATRControls2 ATRControls2.WinForm.GenericLoginCtrl moCtrl; public MyUserSettingsGUI(ICTExtension parent) : base(parent) { // Load and configure the control. 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); } // -- Couple the data object values with GUI elements // back and forth. 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; } // -- -- -- -- } // Object representing my custom Export Profile specific settings. // Accessed from [...] button at Export Profile settings. // Internally, ExportSettingsBase holds also Export Profile Field // settings of our custom type (MyExportFieldSettings) public class MyExportSettings : ExportSettingsBase<MyExportFieldSettings> { // -- My data -- public string TargetCompany { get; set; } // -- -- -- -- // -- Serialization of my data protected override void Deserialize(Stream s) { base.Deserialize(s); // Important to remember base object serialization! TargetCompany = s.PopString(); } protected override void Serialize(Stream s) { base.Serialize(s); // Important to remember base object serialization! s.PushString(TargetCompany); } // -- -- -- -- // -- return GUI control capable of showing and modifying // TargetCompany Export Profile options. public override ControlAdapter CreateAdapter(ICTExtension extension) { return new MyExportSettingsGUI(extension); } } // GUI control that accesses "MyExportSettings", shown // with [...] button at Export Profile settings // Just a simple text box. 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); } // -- Couple the data object values with GUI elements // back and forth. public override void LoadFrom(MyExportSettings settings) { tb.Text = settings.TargetCompany; } public override void SaveTo(MyExportSettings settings) { settings.TargetCompany = tb.Text; } // -- -- -- -- } // Object representing my custom settings // in the scope of the current CT Profile public class MyProfileSettings : SettingsObject { // -- My data -- public string ConnectionString { get; set; } // -- -- -- -- // -- Serialization of my data protected override void Deserialize(Stream s) { ConnectionString = s.PopString(); } protected override void Serialize(Stream s) { s.PushString(ConnectionString); } // -- -- -- -- // -- return GUI control capable of showing and modifying my data // when visiting this integration's page at Profile Options public override ControlAdapter CreateAdapter(ICTExtension parent) { // PropertyGridAdapter just utilizes System.Windows.Forms.PropertyGrid // to enable editing of data object values. return new PropertyGridAdapter<MyProfileSettings>(parent); } // -- -- -- -- } // The actual Export script; the one that handles // all the Item/BOM export to the target system // utilizing the previously defined custom settings. // This demo also utilizes export xml to StructureItem, hence IStructureItemCreator public class MyExportEventsHandler : EventExtension<MyCustomErpIntegration>, IStructureItemCreator { // The main class of your integration. public MyCustomErpIntegration ParentExtension { get; private set; } // You always want to check at OnExportProfileSelected // if you should handle any of the events. // Only handle them if the typename of the Export Profile // matches the identifying name of your integration. public bool HandleEvents { get; private set; } public override void Init(MyCustomErpIntegration parent) { ParentExtension = parent; HandleEvents = false; } // -- The only and only place to subscribe for CTInterface Events // Everything subscribed at Hook MUST beunsubscribed at UnHook. public override void Hook(CTInterface oCTInterface) { oCTInterface.OnExportProfileSelected += OnExportProfileSelectedHandler; oCTInterface.OnStrExport += OnStrExportHandler; } public override void UnHook(CTInterface oCTInterface) { oCTInterface.OnExportProfileSelected -= OnExportProfileSelectedHandler; } // -- -- -- -- // -- IStructureItemCreator: This allows returning // a custom object type for export items. public StructureItem CreateStructureItemObject() { return new StructureItem(); // Just use the default object. } // -- -- -- -- // -- Event Handlers // An Export profile was loaded at Export private void OnExportProfileSelectedHandler(object sender, CTInterface.ExportProfileSelectedArgs e) { // Verify we want handle export events. HandleEvents = e.ExportProfile.Typename == ParentExtension.IdentifyingName(); } // Export has been invoked private void OnStrExportHandler(object sender, CTInterface.StrExportArgs e) { if (!HandleEvents) return; // Immediately stop if not my event. e.RetVal = true; // Cancel XML output. // Just as an extended example, this is a common way of // transforming export XML into something more dev-friendly StructureItem root = StructureItem.ParseStructureXml(this, e.Str); /* EXAMPLE ON HOW TO ACCESS CUSTOM SETTINGS */ // Profile level settings. MyProfileSettings currentProfileSettings = ParentExtension.GetProfileSettings(); var connectionString = currentProfileSettings.ConnectionString; // Get my custom user settings MyUserSettings currentUserSettings = ParentExtension.GetUserSettings(); var isEnabled = currentUserSettings.Enabled; var userName = currentUserSettings.UserName; var pwd = currentUserSettings.PassWord; // Get my custom export profile settings MyExportSettings currentExportSettings = ParentExtension.GetExportSettings((CTExportProfile)e.ExpProfile); var targetCompany = currentExportSettings.TargetCompany; // Get my custom export profile field settings from MyExportSettings object[] fields = (object[])e.ExpProfile.GetFields(); foreach (ICTExportProfileField field in fields) { MyExportFieldSettings fieldSetting = null; if (currentExportSettings.FieldSettings.TryGetValue(field.Label, out fieldSetting)) { // My Custom field settings of this export profile field. var myBool = fieldSetting.MyFieldBoolData; var myStr = fieldSetting.MyFieldStringData; } } /* -- -- -- -- */ } // -- -- -- -- } // THIS is the main class that ties it all together. In its simplicity, // it just defines the stong types for all custom objects and returns // the MyExportEventsHandler for the base class. // All data is stored using IdentifyingName, so changing it will // cause all previous data of this integration to be lost. // FriendlyName is shown all of the UI and messages related to this integration. public class MyCustomErpIntegration : ERPExportBaseExtraOptsWithUserAndProfileSettings<MyExportFieldSettings, MyExportSettings, MyUserSettings, MyProfileSettings> { public override string FriendlyName() { return "My Custom Integration"; // This is shown in the UI. } public override string IdentifyingName() { return "MY-CUSTOM-ERP-INTEGRATION-12345"; // Just something that is unique and constant. } public override List<EventExtension> GetEventExtensions() { return new List<EventExtension>() { new MyExportEventsHandler() }; } } }
CUSTOMTOOLS 2022 SP0