using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ORiN2.ManagedCAO; namespace Tester { public partial class WorkSpaceForm : Form { private CCaoEngine Engine { get; set; } public WorkSpaceForm() { InitializeComponent(); this.Engine = new CCaoEngine(); } private void btnAdd_Click(object sender, EventArgs e) { var optStr = GetParams().ToString(); CCaoController ctrl; try { ctrl = this.Engine.Workspaces[0].AddController("IoTPlatform", "CaoProv.FUJITSU.IoTPlatform", null, optStr); } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var ctrlForm = new ControllerForm(ctrl)) { ctrlForm.ShowDialog(this); } if (ctrl != null) { this.Engine.Workspaces[0].Controllers.Remove(ctrl.Name); ctrl = null; } } private void WorkSpace_FormClosed(object sender, FormClosedEventArgs e) { this.Engine.Dispose(); this.Engine = null; } private ParamModel GetParams() { return new ParamModel() { BaseURL = txtBaseURL.Text, TenantID = txtTenantID.Text, AccessCode = txtAccessCode.Text, APIVersion = txtVersion.Text, Timeout = txtTimeout.Text }; } private class ParamModel { public string BaseURL { get; set; } public string TenantID { get; set; } public string AccessCode { get; set; } public string APIVersion { get; set; } public string Timeout { get; set; } public override string ToString() { var str = string.Format("BaseURL={0},TenantID={1},AccessCode={2}", this.BaseURL, this.TenantID, this.AccessCode); if (!string.IsNullOrEmpty(APIVersion)) { str += string.Format(",APIVersion={0}", this.APIVersion); } if (!string.IsNullOrEmpty(Timeout)) { str += string.Format(",Timeout={0}", this.Timeout); } return str; } } } }