The Sample program demonstrates the main functionality of the OTX-Runtime API. It can be used as a reference for the expected runtime behavior of the API and the source code below is like a reference guide about the proper programming of the API.
Code snippet of the OTX-Runtime API Sample Program.
10 using System.Collections.Generic;
11 using System.Diagnostics;
15 using System.Threading;
16 using System.Threading.Tasks;
17 using System.Windows.Forms;
20 namespace OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample
22 public partial class SampleForm : Form
24 private const int VALUE_STRING_MAX_LENGTH = 1024;
26 private UserSettings userSettings = UserSettings.Default;
29 private List<IRuntimeContext> runtimeContexts =
new List<IRuntimeContext>();
30 private Dictionary<IRuntimeContext, DateTime> runtimeContextsExecutionStartTime =
new Dictionary<IRuntimeContext, DateTime>();
32 private IProject project =
null;
33 private IPlayerProject playerProject =
null;
34 private IProcedure procedureToExecute =
null;
36 private TreeNode startupNode =
null;
38 private IRuntimeManager globalRuntimeManager =
null;
40 private HmiWindow hmiWindow;
42 private DateTime lastTime = DateTime.Now;
44 private DefaultCustomScreenImplementation customScreenImplementation;
45 private ContextVariableImplementation contextVariableImplementation;
47 private StateVariableImplementation stateVariableImplementation;
48 private DefaultMeasureImplementation measureImplementation;
49 private DefaultExternalServiceProviderImplementation serviceProviderImplementation;
51 private BasicScreenOutputImpl basicScreenOutputImpl;
52 private CustomScreenOutputImpl customScreenOutputImpl;
53 private LoggingOutputImpl loggingOutputImpl;
54 private ContextVariableOutputImpl contextVariableOutputImpl;
56 private StateVariableOutputImpl stateVariableOutputImpl;
57 private MeasureOutputImpl measureOutputImpl;
58 private I18nOutputImpl i18NOutputImpl;
59 private ExternalServiceProviderOutputImpl serviceProviderOutputImpl;
61 private SqlOutputImpl sqlOutputImpl;
62 private CommonDialogsOutputImpl commonDialogsOutputImpl;
64 private SampleForm creatorForm;
66 private string runtimeContextName;
67 private long procedureExecutionCount;
68 private long cyclicExecutionCount;
70 private static string fileVersion;
72 private static int defaultPollingTime = 500;
73 private static int defaultBatteryVoltageThreshold = 6000;
74 private bool useConnectionState =
false;
75 private bool? KL15State =
null;
78 private bool isLoadding =
false;
80 private ushort defaultDiagPort = SampleConstants.DEFAULT_DM_PORT;
81 private ushort defaultRuntimePort = SampleConstants.DEFAULT_RT_PORT;
82 private string defaultDiagPipeName = SampleConstants.DEFAULT_DM_PIPE_NAME;
83 private string defaultRuntimePipeName = SampleConstants.DEFAULT_RT_PIPE_NAME;
85 private readonly
object printTextLock =
new object();
86 private readonly
object eventListenerLock =
new object();
88 private bool cyclicExecuteAsyncIsProcessing =
false;
89 private System.Windows.Forms.Timer webServerTimer =
new System.Windows.Forms.Timer();
91 public static bool isAcceptEmptyLicenseValue;
95 fileVersion = RuntimeConfig.Instance.Version;
96 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
98 isAcceptEmptyLicenseValue = licenseKeyFromOTForOTPLicense.Equals(
"") ? false :
true;
100 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
102 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
106 String licenseKey = Setting.UserSettings.Default.LicenseKey;
107 licenseKey = LicensingUtil.Decrypt(licenseKey);
108 if (LicensingUtil.CheckLicenseKeyFormat(licenseKey))
110 LicenseManager.SetLicenseKey(licenseKey);
114 MessageBox.Show(
"There is an invalid license key format. Please set your new key in license box.",
"Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
119 public SampleForm(
string title = SampleConstants.MAIN_INSTANCE_NAME, SampleForm creatorForm =
null)
121 this.ShowInTaskbar =
false;
123 this.creatorForm = creatorForm;
125 this.webServerTimer.Interval = 1000;
126 this.webServerTimer.Enabled =
true;
127 this.webServerTimer.Tick += WebServerTimer_Tick;
129 InitializeComponent();
131 PrintText(
"Application started");
134 private void SampleForm_Load(
object sender, EventArgs e)
136 PrintText(
"Start Initialization...");
139 InitializeSampleDefaultValues();
140 this.UpdateWebServerButton();
142 if (this.creatorForm !=
null)
144 this.checkBoxStartAllParents.Visible =
true;
145 this.checkBoxStartAllParents.Checked = this.creatorForm.checkBoxStartAllParents.Checked;
148 SetRuntimeContextName();
149 SetTitle(this.title);
150 SetLocation(this.creatorForm);
152 this.toolTip1.SetToolTip(labelProcedureExecutionTimes,
"Total procedure execution time.");
153 this.toolTip1.SetToolTip(textBoxTimeout,
"Timeout for procedure execution in milliseconds. The default value 0 means without timeout.");
154 this.toolTip1.SetToolTip(checkBoxUseConnectionState,
"Use expected connection state during procedure execution.");
155 this.toolTip1.SetToolTip(labelBatteryState,
"State of the battery (KL 30)");
156 this.toolTip1.SetToolTip(checkBoxIgnition,
"Expected ignition (KL 15) state during procedure execution");
157 this.toolTip1.SetToolTip(labelIgnitionState,
"State of the ignition (KL 15)");
158 this.toolTip1.SetToolTip(buttonCheckBatteryIgnition,
"Check current battery (KL30) and ignition (KL15) state.");
159 this.toolTip1.SetToolTip(textBoxPollingTime,
"Time in milliseconds between the next check of the connection state during the procedure execution (Polling). The default value is 500 ms.");
160 this.toolTip1.SetToolTip(textBoxVoltageThreshold,
"Voltage threshold in millivolt from which the battery voltage, see GetBatteryVoltage is enough for KL30 = On. The default value is 6000 mV.");
162 PrintText(
"... Initialization finished.");
163 this.ShowInTaskbar =
true;
166 private void SampleForm_Shown(
object sender, EventArgs e)
168 this.cbFilePath.SelectionLength = 0;
171 private void SetRuntimeContextName()
173 if (this.creatorForm !=
null && !String.IsNullOrEmpty(
this.creatorForm.runtimeContextName))
175 System.Text.RegularExpressions.Match regExpMatch = System.Text.RegularExpressions.Regex.Match(this.creatorForm.runtimeContextName,
@"\d*$");
177 if (
int.TryParse(regExpMatch.Value, out number))
180 this.textBoxRuntimeContextName.Text = this.creatorForm.runtimeContextName.Substring(0, regExpMatch.Index) + number.ToString();
185 private void SetTitle(
string title)
187 if (String.IsNullOrWhiteSpace(title))
188 title = SampleConstants.MAIN_INSTANCE_NAME;
190 bool runningAsAdmin = System.Security.Principal.WindowsIdentity.GetCurrent().Owner.IsWellKnown(System.Security.Principal.WellKnownSidType.BuiltinAdministratorsSid);
192 this.Text = String.Format(
193 "emotive OTX-Runtime API for DotNet - Reference Application - Version {0} - {1} Bit - {2} - Thread-ID {3}{4}",
195 Environment.Is64BitProcess ?
"64" :
"32",
197 Thread.CurrentThread.ManagedThreadId,
198 runningAsAdmin ?
" - Administrator" :
string.Empty
201 if (!String.IsNullOrEmpty(
this.cbFilePath.Text))
202 this.Text = this.Text +
" - " + Path.GetFileName(this.cbFilePath.Text);
204 if (!String.IsNullOrEmpty(
this.runtimeContextName))
205 this.Text = this.Text +
" - " + this.runtimeContextName;
208 private const int FORM_OFFSET = 25;
210 private void SetLocation(SampleForm creatorForm)
212 if (creatorForm !=
null)
214 int xOffset = FORM_OFFSET;
215 int yOffset = FORM_OFFSET;
217 if (creatorForm.creatorForm !=
null)
219 xOffset = creatorForm.Location.X - creatorForm.creatorForm.Location.X;
220 yOffset = creatorForm.Location.Y - creatorForm.creatorForm.Location.Y;
223 this.Location =
new Point(creatorForm.Location.X + xOffset, creatorForm.Location.Y + yOffset);
224 this.Size = creatorForm.Size;
228 private void CreateCustomImpl()
230 CreateDefaultCustomImpl();
231 CreateOutputWindowCustomImpl();
234 private void CreateDefaultCustomImpl()
236 PrintText(
"Create default custom implementation");
238 customScreenImplementation =
new DefaultCustomScreenImplementation();
239 customScreenImplementation.KeyDown += CustomScreenImplementation_KeyDown;
241 contextVariableImplementation =
new ContextVariableImplementation();
242 contextVariableImplementation.ContextVariableRead += ContextVariableRead;
244 stateVariableImplementation =
new StateVariableImplementation();
245 stateVariableImplementation.StateVariableValueChanged += StateVariableValueChanged;
247 measureImplementation =
new DefaultMeasureImplementation();
248 serviceProviderImplementation =
new DefaultExternalServiceProviderImplementation();
251 private void CreateOutputWindowCustomImpl()
253 PrintText(
"Create output window custom implementation");
255 basicScreenOutputImpl =
new BasicScreenOutputImpl();
256 customScreenOutputImpl =
new CustomScreenOutputImpl();
257 loggingOutputImpl =
new LoggingOutputImpl();
258 contextVariableOutputImpl =
new ContextVariableOutputImpl();
260 stateVariableOutputImpl =
new StateVariableOutputImpl();
261 measureOutputImpl =
new MeasureOutputImpl();
262 i18NOutputImpl =
new I18nOutputImpl();
263 serviceProviderOutputImpl =
new ExternalServiceProviderOutputImpl();
265 sqlOutputImpl =
new SqlOutputImpl();
266 commonDialogsOutputImpl =
new CommonDialogsOutputImpl();
268 basicScreenOutputImpl.LogEvent += PrintText;
269 customScreenOutputImpl.LogEvent += PrintText;
270 loggingOutputImpl.LogEvent += PrintText;
271 contextVariableOutputImpl.LogEvent += PrintText;
273 stateVariableOutputImpl.LogEvent += PrintText;
274 measureOutputImpl.LogEvent += PrintText;
275 i18NOutputImpl.LogEvent += PrintText;
276 serviceProviderOutputImpl.LogEvent += PrintText;
278 sqlOutputImpl.LogEvent += PrintText;
279 commonDialogsOutputImpl.LogEvent += PrintText;
282 private void InitializeSampleDefaultValues()
284 PrintText(
"Initialize default values");
286 this.comboBoxTraceLevel.Items.AddRange(Enum.GetNames(typeof(TraceLevels)));
289 treeViewOtxProject.ImageList = imageList1;
291 textBoxRtPortPipe.Name = SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME;
292 textBoxDiagPortPipe.Name = SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME;
296 this.EnableConnectionState();
299 private void LoadSetting()
301 SaveSettingUtil.Reload();
304 cbFilePath.Text = userSettings.Ptx_Ppx_Directory;
305 cbFilePath.Text = userSettings.Ptx_Ppx_Directory;
306 if (!String.IsNullOrEmpty(userSettings.Ptx_Ppx_DirectoryList))
308 this.cbFilePath.Items.AddRange(userSettings.Ptx_Ppx_DirectoryList.Split(
';'));
310 AddComboBoxFileOrPath(this.cbFilePath);
314 SetupTraceFileMaxCountAndSize();
317 SetupDefaultPortAndPipeName();
319 SetupCustomImplType();
321 SetupWindowLocation();
323 checkBoxAsyncExecution.Checked = userSettings.Asynchron;
324 checkBoxCyclicExecution.Checked = userSettings.Cyclic;
325 checkBoxCyclicReload.Checked = userSettings.CyclicReload;
326 checkBoxNewRuntimeManager.Checked = userSettings.NewRunTimeManager;
327 checkBoxAdd2Output.Checked = userSettings.AddMessageToOutput;
328 checkBoxStartAllParents.Checked = userSettings.StartAllParents;
331 checkBoxUseConnectionState.Checked = userSettings.ConnectionState;
332 checkBoxIgnition.CheckState = userSettings.Ignition == 1 ? CheckState.Checked : (userSettings.Ignition == 0 ? CheckState.Unchecked : CheckState.Indeterminate);
334 SetupVoltageThreshold();
336 this.textBoxRuntimeContextName.Text = userSettings.RuntimeContextName.ToString();
338 catch (System.Exception e)
340 PrintText(e.Message);
341 userSettings.Reset();
345 bool isPathChanging =
false;
346 private void AddComboBoxFileOrPath(ComboBox comboBox)
348 if (comboBox !=
null && !isPathChanging)
350 isPathChanging =
true;
352 string path = comboBox.Text;
354 if (Directory.Exists(path) || File.Exists(path))
356 while (comboBox.Items.Contains(path))
358 comboBox.Items.Remove(path);
361 while (comboBox.Items.Contains(path.TrimEnd(
new char[] {
'/',
'\\' })))
363 comboBox.Items.Remove(path.TrimEnd(
new char[] {
'/',
'\\' }));
366 path = path.TrimEnd(
new char[] {
'/',
'\\' });
368 comboBox.Items.Insert(0, path);
369 comboBox.Text = path;
370 comboBox.SelectAll();
373 isPathChanging =
false;
377 private void SetupTraceFileMaxCountAndSize()
379 textBoxTraceFileMaxCount.Text = userSettings.TraceFileMaxCount.ToString();
380 textBoxTraceFileMaxSize.Text = userSettings.TraceFileMaxSize.ToString();
383 private void SetupDefaultPortAndPipeName()
385 defaultDiagPort = userSettings.DiagManagerPort;
386 defaultRuntimePort = userSettings.RuntimePort;
388 defaultDiagPipeName = userSettings.DiagManagerPipeName;
389 defaultRuntimePipeName = userSettings.RuntimePipeName;
391 IpcTypes ipcTypes = IpcTypes.SOCKET;
392 Enum.TryParse<IpcTypes>(userSettings.IpcType, out ipcTypes);
394 if (comboBoxIpcType.Items.Count == 0)
396 comboBoxIpcType.Items.Add(IpcTypes.SOCKET);
397 comboBoxIpcType.Items.Add(IpcTypes.PIPE);
400 comboBoxIpcType.SelectedItem = ipcTypes;
403 private void SetupTraceLevel()
405 RuntimeConfig.Instance.TraceLevel = userSettings.TraceLevels;
406 comboBoxTraceLevel.SelectedItem = RuntimeConfig.Instance.TraceLevel.ToString();
409 private void SetupTraceFolder()
411 if (userSettings.TracingDirectory !=
string.Empty)
412 RuntimeConfig.Instance.TraceFolder = userSettings.TracingDirectory;
414 textBoxTraceFolder.Text = RuntimeConfig.Instance.TraceFolder;
417 private void SetupCustomImplType()
419 if (userSettings.CustomImplTypes == CustomImplTypes.OutputImpl)
421 radioButtonOuputWindow.Checked =
true;
423 else if (userSettings.CustomImplTypes == CustomImplTypes.NoCustom)
425 radioButtonNoCustomImplementation.Checked =
true;
429 radioButtonDefaultImplementation.Checked =
true;
433 private void SetupWindowSize()
435 int width = userSettings.WindowWidth;
436 int height = userSettings.WindowHeight;
437 this.Size =
new Size(width, height);
440 private void SetupWindowLocation()
442 int locationX = userSettings.WindowLocationX;
443 int locationY = userSettings.WindowLocationY;
444 Point location =
new Point(locationX, locationY);
446 if (CheckFormIsInBound(location))
448 this.Location = location;
452 this.CenterToScreen();
455 private bool CheckFormIsInBound(Point location)
459 Screen formContainScreens = Screen.AllScreens.Where(screen => screen.Bounds.Contains(location) ==
true).FirstOrDefault();
461 return formContainScreens !=
null;
463 catch (System.Exception)
469 private void SetupTimeOut()
471 string timeOutString = userSettings.TimeOut.ToString();
472 this.textBoxTimeout.Text = timeOutString;
475 private void SetupPollingTime()
477 string pollingTimeString = userSettings.PollingTime.ToString();
478 this.textBoxPollingTime.Text = pollingTimeString;
481 private void SetupVoltageThreshold()
483 string voltageThreshold = userSettings.VoltageThreshold.ToString();
484 this.textBoxVoltageThreshold.Text = voltageThreshold;
487 private void comboBoxIpcType_SelectedValueChanged(
object sender, EventArgs e)
490 textBoxDiagPortPipe.TextChanged -= textBoxPortPipe_TextChanged;
491 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
495 case IpcTypes.SOCKET:
497 portPipeLabel.Text =
"Runner / DiagManager Ports";
499 textBoxDiagPortPipe.Text = defaultDiagPort.ToString();
500 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
502 textBoxRtPortPipe.Text = defaultRuntimePort.ToString();
507 portPipeLabel.Text =
"Runner / DiagManager Pipes";
509 textBoxDiagPortPipe.Text = defaultDiagPipeName;
510 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
512 textBoxRtPortPipe.Text = defaultRuntimePipeName;
520 private void textBoxPortPipe_TextChanged(
object sender, EventArgs e)
522 PrintText(
"Create RuntimeManager...");
526 this.globalRuntimeManager = CreateRuntimeManager();
528 catch (System.Exception ex)
530 switch ((sender as TextBox).Name)
532 case SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME:
534 PrintText(String.Format(
"Invalid Otx Runtime {0}", IpcPortPipeString()));
537 case SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME:
539 PrintText(String.Format(
"Invalid Diag Manager {0}", IpcPortPipeString()));
547 PrintText(
"No RuntimeManager created");
550 if (this.globalRuntimeManager ==
null)
552 PrintText(
"RuntimeManager is null.");
556 private IRuntimeManager CreateRuntimeManager()
558 IRuntimeManager runtimeManager =
null;
562 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
564 case IpcTypes.SOCKET:
566 runtimeManager = CreateSocketRuntimeManager();
572 runtimeManager = CreatePipeRuntimeManager();
577 PrintText($
"... {ipcType} RuntimeManager created (MinBinVersion: {RuntimeConfig.Instance.MinBinVersion})");
579 InitializeRuntimeEvents(runtimeManager);
580 SetCustomImplementation(runtimeManager);
582 catch (InvalidLicenseException ex)
585 PrintText(
"... No RuntimeManager created.");
587 return runtimeManager;
590 return runtimeManager;
593 private string IpcPortPipeString()
595 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
597 case IpcTypes.SOCKET:
598 return SampleConstants.PORT_STRING;
600 return SampleConstants.PIPE_STRING;
607 private IRuntimeManager CreateSocketRuntimeManager()
609 ushort rtPort = Convert.ToUInt16(textBoxRtPortPipe.Text);
613 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort);
617 ushort diagPort = Convert.ToUInt16(textBoxDiagPortPipe.Text);
618 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort, diagPort);
622 private IRuntimeManager CreatePipeRuntimeManager()
626 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text);
630 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text, textBoxDiagPortPipe.Text);
634 private bool NoDiag()
636 return String.IsNullOrWhiteSpace(textBoxDiagPortPipe.Text);
639 private void InitializeRuntimeEvents(IRuntimeManager runtimeManager)
641 if (runtimeManager ==
null)
644 runtimeManager.ProcedurePending -= ProcedurePending;
645 runtimeManager.ProcedureStarted -= ProcedureStarted;
646 runtimeManager.ProcedurePaused -= ProcedurePaused;
647 runtimeManager.ProcedureContinued -= ProcedureContinued;
648 runtimeManager.ProcedureFinished -= ProcedureFinished;
649 runtimeManager.ProcedureAborted -= ProcedureAborted;
650 runtimeManager.ProcedureStopped -= ProcedureStopped;
651 runtimeManager.ProcedureTimeout -= ProcedureTimeout;
652 runtimeManager.DiagConnectionStateChanged -= DiagConnectionStateChanged;
653 runtimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
655 runtimeManager.ProcedurePending += ProcedurePending;
656 runtimeManager.ProcedureStarted += ProcedureStarted;
657 runtimeManager.ProcedurePaused += ProcedurePaused;
658 runtimeManager.ProcedureContinued += ProcedureContinued;
659 runtimeManager.ProcedureFinished += ProcedureFinished;
660 runtimeManager.ProcedureAborted += ProcedureAborted;
661 runtimeManager.ProcedureStopped += ProcedureStopped;
662 runtimeManager.ProcedureTimeout += ProcedureTimeout;
663 runtimeManager.DiagConnectionStateChanged += DiagConnectionStateChanged;
664 runtimeManager.InOutParameterValueChanged += InOutParameterValueChanged;
666 PrintText(
"Initialization of runtime events finished");
669 private void radioButtonCustomImpl_CheckedChanged(
object sender =
null, System.EventArgs e =
null)
671 if (this.globalRuntimeManager ==
null)
674 if (sender !=
null && (sender as RadioButton).Checked ==
false)
677 this.SetCustomImplementation(this.globalRuntimeManager);
680 private void SetCustomImplementation(IRuntimeManager runtimeManager)
682 if (runtimeManager ==
null)
685 var currentCustomImpl = GetCurrentCustomImpl();
687 switch (currentCustomImpl)
689 case CustomImplTypes.OutputImpl:
691 SetOutputWindowImplementation(runtimeManager);
694 case CustomImplTypes.DefaultCustomImpl:
696 SetDefaultCustomImplementation(runtimeManager);
699 case CustomImplTypes.NoCustom:
701 RemoveCustomImplementation(runtimeManager);
708 if (currentCustomImpl != CustomImplTypes.None)
710 PrintText(
"Set up custom implementation finished");
714 private CustomImplTypes GetCurrentCustomImpl()
716 if (radioButtonOuputWindow.Checked)
717 return CustomImplTypes.OutputImpl;
718 else if (radioButtonDefaultImplementation.Checked)
719 return CustomImplTypes.DefaultCustomImpl;
720 else if (radioButtonNoCustomImplementation.Checked)
721 return CustomImplTypes.NoCustom;
723 return CustomImplTypes.None;
726 private void SetOutputWindowImplementation(IRuntimeManager runtimeManager)
728 if (runtimeManager ==
null)
731 runtimeManager.SetCustomImplementation(basicScreenOutputImpl);
732 runtimeManager.SetCustomImplementation(customScreenOutputImpl);
733 runtimeManager.SetCustomImplementation(loggingOutputImpl);
734 runtimeManager.SetCustomImplementation(contextVariableOutputImpl);
736 runtimeManager.SetCustomImplementation(stateVariableOutputImpl);
737 runtimeManager.SetCustomImplementation(measureOutputImpl);
738 runtimeManager.SetCustomImplementation(i18NOutputImpl);
739 runtimeManager.SetCustomImplementation(serviceProviderOutputImpl);
741 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
742 runtimeManager.SetCustomImplementation(commonDialogsOutputImpl);
745 private void SetDefaultCustomImplementation(IRuntimeManager runtimeManager)
747 if (runtimeManager ==
null)
750 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
751 runtimeManager.SetCustomImplementation(customScreenImplementation);
752 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
753 runtimeManager.SetCustomImplementation(contextVariableImplementation);
755 runtimeManager.SetCustomImplementation(stateVariableImplementation);
756 runtimeManager.SetCustomImplementation(measureImplementation);
757 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
758 runtimeManager.SetCustomImplementation(serviceProviderImplementation);
760 runtimeManager.SetCustomImplementation(sqlOutputImpl);
761 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
764 private void RemoveCustomImplementation(IRuntimeManager runtimeManager)
766 if (runtimeManager ==
null)
769 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
770 runtimeManager.SetCustomImplementation((ICustomScreenImplementation)
null);
771 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
772 runtimeManager.SetCustomImplementation((IContextVariableImplementation)
null);
774 runtimeManager.SetCustomImplementation((IStateVariableImplementation)
null);
775 runtimeManager.SetCustomImplementation((IMeasureImplementation)
null);
776 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
777 runtimeManager.SetCustomImplementation((IExternalServiceProviderImplementation)
null);
779 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
780 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
783 private void ProcedurePending(IRuntimeContext context)
787 Invoke(
new MethodInvoker(delegate ()
789 ProcedurePending(context);
794 lock (eventListenerLock)
796 this.PrintText(
string.Format(
"Event ProcedurePending occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
797 UpdateExecutionState(context);
798 ShowConnectionStateMessage(context);
802 private void ProcedureStarted(IRuntimeContext context)
806 Invoke(
new MethodInvoker(delegate ()
808 ProcedureStarted(context);
813 lock (eventListenerLock)
815 this.PrintText(
string.Format(
"Event ProcedureStarted occurred - {0} - ExecutionState = {1} - RuntimeId = {2} - ProcessId = {3}", context.Procedure.FullName, context.ExecutionState.ToString(), context.RuntimeId, context.ProcessId));
816 UpdateExecutionState(context);
820 private void ProcedurePaused(IRuntimeContext context, ExecutionStateChangeReason reason)
824 Invoke(
new MethodInvoker(delegate ()
826 ProcedurePaused(context, reason);
831 lock (eventListenerLock)
833 this.PrintText(
string.Format(
"Event ProcedurePaused occurred - {0} - ExecutionState = {1} - ExecutionStateChangeReason = {2}", context.Procedure.FullName, context.ExecutionState.ToString(), reason.ToString()));
834 UpdateExecutionState(context, reason);
837 ShowConnectionStateMessage(context);
842 private void ProcedureContinued(IRuntimeContext context)
846 Invoke(
new MethodInvoker(delegate ()
848 ProcedureContinued(context);
853 lock (eventListenerLock)
855 this.PrintText(
string.Format(
"Event ProcedureContinued occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
856 UpdateExecutionState(context);
860 private void ProcedureStopped(IRuntimeContext context)
864 Invoke(
new MethodInvoker(delegate ()
866 ProcedureStopped(context);
871 lock (eventListenerLock)
873 this.PrintText(
string.Format(
"Event ProcedureStopped occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
874 UpdateExecutionState(context);
878 private void ProcedureTimeout(IRuntimeContext context)
882 Invoke(
new MethodInvoker(delegate ()
884 ProcedureTimeout(context);
889 lock (eventListenerLock)
891 cyclicExecuteAsyncIsProcessing =
false;
892 this.PrintText(
string.Format(
"Event ProcedureTimeout occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
893 UpdateExecutionState(context);
897 private void DiagConnectionStateChanged(ClampState batteryState, ClampState ignitionState)
901 Invoke(
new MethodInvoker(delegate ()
903 DiagConnectionStateChanged(batteryState, ignitionState);
908 lock (eventListenerLock)
910 this.PrintText(
string.Format(
"Event DiagConnectionStateChanged occurred - BatteryState = {0}, IgnitionState = {1}", batteryState.ToString(), ignitionState.ToString()));
911 System.Media.SystemSounds.Beep.Play();
913 SetBatteryIgnitionState(batteryState, ignitionState);
918 private void ProcedureFinished(IRuntimeContext context)
922 Invoke(
new MethodInvoker(delegate ()
924 ProcedureFinished(context);
929 lock (eventListenerLock)
931 IProcedureParameter procedureParameter;
932 string procedureName = context.Procedure.FullName;
933 string parameterOuput;
935 for (
int i = 0; i < context.Procedure.Parameters.Count(); i++)
937 procedureParameter = context.Procedure.Parameters.ElementAt(i);
938 parameterOuput =
"Parameter Changed - " + procedureParameter.Name +
"(" + procedureParameter.DataType +
") = ";
940 if (procedureParameter.Value !=
null)
942 parameterOuput += ShortenedValueString(procedureParameter);
946 parameterOuput +=
null;
949 this.PrintText(parameterOuput);
952 UpdateGridviewParameter(context.Procedure);
954 this.PrintText(
string.Format(
"ProcedureFinished({0}) ExecutionState({1}) - Execution duration {2} - Running time {3} - Used memory {4})",
955 context.Procedure.FullName,
956 context.ExecutionState.ToString(),
957 (DateTime.Now -
this.runtimeContextsExecutionStartTime[context]).ToString(
"mm':'ss','fff"),
958 TimeSpan.FromMilliseconds(context.ExecutionTime).ToString(
"mm':'ss','fff"),
959 string.Format(
"{0:0,0} kB", context.ProcessMemory / 1024))
962 UpdateExecutionState(context);
964 cyclicExecuteAsyncIsProcessing =
false;
968 private void ProcedureAborted(IRuntimeContext context)
972 Invoke(
new MethodInvoker(delegate ()
974 ProcedureAborted(context);
979 this.PrintText(
string.Format(
"ProcedureAborted({0}) ExecutionState({1})", context.Procedure.FullName, context.ExecutionState.ToString()));
981 if (context.HasRuntimeException)
983 PrintException(context.RuntimeException,
"Reason: API ");
986 if (context.HasOtxException)
988 PrintException(context.OtxException,
"Reason: OTX ");
990 cyclicExecuteAsyncIsProcessing =
false;
991 UpdateExecutionState(context);
994 private void UpdateExecutionState(IRuntimeContext context, ExecutionStateChangeReason? reason =
null)
998 switch (context.ExecutionState)
1002 this.procedureExecutionCount++;
1004 AddRuntimeContext(context);
1005 DisplayProcedureExecutionState(context);
1007 this.buttonExecuteMain.Enabled = checkBoxAsyncExecution.Checked;
1008 this.buttonExecuteSelectedProcedure.Enabled = checkBoxAsyncExecution.Checked;
1010 UpdateExecutionStateButtons(
true);
1011 UpdatePauseButton(
true);
1017 this.procedureExecutionCount--;
1020 DisplayProcedureExecutionState(context);
1029 DisplayProcedureExecutionState(context);
1030 UpdateExecutionStateButtons(
true);
1031 UpdatePauseButton(
true,
false);
1037 this.procedureExecutionCount--;
1039 RemoveRuntimeContext(context);
1040 DisplayProcedureExecutionState(context);
1042 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
1043 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
1045 UpdateExecutionStateButtons(
false);
1046 UpdatePauseButton(
true,
false);
1048 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1049 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1055 this.procedureExecutionCount--;
1057 RemoveRuntimeContext(context);
1058 DisplayProcedureExecutionState(context);
1060 this.buttonExecuteMain.Enabled =
true;
1061 this.buttonExecuteSelectedProcedure.Enabled =
true;
1063 UpdateExecutionStateButtons(
false);
1064 UpdatePauseButton(
true,
false);
1066 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1067 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1073 this.procedureExecutionCount--;
1075 RemoveRuntimeContext(context);
1076 DisplayProcedureExecutionState(context);
1078 this.buttonExecuteMain.Enabled =
true;
1079 this.buttonExecuteSelectedProcedure.Enabled =
true;
1081 UpdateExecutionStateButtons(
false);
1082 UpdatePauseButton(
true,
false);
1084 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1085 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1090 System.Media.SystemSounds.Hand.Play();
1092 this.procedureExecutionCount--;
1094 RemoveRuntimeContext(context);
1095 DisplayProcedureExecutionState(context);
1097 this.buttonExecuteMain.Enabled =
true;
1098 this.buttonExecuteSelectedProcedure.Enabled =
true;
1100 UpdateExecutionStateButtons(
false);
1101 UpdatePauseButton(
true,
false);
1103 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1104 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1109 StartStopUpdateGuiTimer();
1113 private void StartStopUpdateGuiTimer()
1115 if (this.procedureExecutionCount <= 0)
1117 this.updateGuiTimer.Enabled =
false;
1118 this.labelSeparator1.Visible =
false;
1119 this.labelProcedureExecutionTimes.Visible =
false;
1121 else if (!this.updateGuiTimer.Enabled)
1123 this.updateGuiTimer.Enabled =
true;
1127 private void updateGuiTimer_Tick(
object sender, EventArgs e)
1129 DisplayProcedureExecutionTimes();
1132 private void DisplayProcedureExecutionTimes()
1134 string text =
string.Empty;
1136 if (this.runtimeContextsExecutionStartTime.Count > 0)
1138 foreach (var item
in this.runtimeContextsExecutionStartTime)
1140 var duration = DateTime.Now - item.Value;
1141 text +=
string.Format(
"{0}: {1} | ", item.Key.Procedure.Name, duration.ToString(
"mm':'ss"));
1143 text = text.TrimEnd(
new char[] {
' ',
'|' });
1146 this.labelProcedureExecutionTimes.Text = text;
1147 this.labelSeparator1.Visible =
true;
1148 this.labelProcedureExecutionTimes.Visible =
true;
1151 private void InOutParameterValueChanged(IRuntimeContext context, IProcedureInOutParameter parameter)
1155 Invoke(
new MethodInvoker(delegate ()
1157 InOutParameterValueChanged(context, parameter);
1162 lock (eventListenerLock)
1166 string valueStr = ShortenedValueString(parameter);
1167 string message = String.Format(
"Parameter '{0}' new value = {1}", parameter.Name, valueStr);
1169 UpdateGridviewParameter(parameter);
1171 catch (InvalidCastException ex)
1173 PrintText(ex.Message);
1178 private static string ShortenedValueString(IProcedureParameter parameter)
1182 var valueStr = ValueConverter.Value2String(parameter.Value);
1183 if (valueStr.Length > VALUE_STRING_MAX_LENGTH)
1184 return valueStr.Substring(0, VALUE_STRING_MAX_LENGTH) +
"...";
1191 return string.Empty;
1194 private void UpdatePauseButton(
bool pauseAvailable,
bool enabled =
true)
1196 this.buttonPause.Enabled = enabled;
1197 this.buttonPause.Checked = !pauseAvailable;
1198 this.buttonPause.Image = pauseAvailable
1199 ? global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Pause
1200 : global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Continue;
1203 private void UpdateExecutionStateButtons(
bool wasExecuted)
1205 if (this.useConnectionState)
1207 this.labelTimeout.Enabled = !wasExecuted;
1208 this.textBoxTimeout.Enabled = !wasExecuted;
1209 this.checkBoxUseConnectionState.Enabled = !wasExecuted;
1210 this.labelExpectedState.Enabled = !wasExecuted;
1211 this.checkBoxIgnition.Enabled = !wasExecuted;
1212 this.labelPollingTime.Enabled = !wasExecuted;
1213 this.textBoxPollingTime.Enabled = !wasExecuted;
1214 this.labelVoltageThreshold.Enabled = !wasExecuted;
1215 this.textBoxVoltageThreshold.Enabled = !wasExecuted;
1220 if (checkBoxAsyncExecution.Checked ==
false)
1222 this.buttonExecuteMain.Enabled =
false;
1223 this.buttonExecuteSelectedProcedure.Enabled =
false;
1226 this.buttonStop.Enabled =
true;
1230 if (project !=
null && project.MainProcedure !=
null)
1232 this.buttonExecuteMain.Enabled =
true;
1235 this.buttonExecuteSelectedProcedure.Enabled =
true;
1237 this.buttonStop.Enabled =
false;
1241 private void DisplayProcedureExecutionState(IRuntimeContext context,
string errorMessage =
"")
1243 if (
string.IsNullOrEmpty(errorMessage))
1245 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Info16;
1247 if (this.procedureExecutionCount <= 0)
1249 this.procedureExecutionCount = 0;
1252 this.labelProcedureExecutionState.Text =
"Execution is paused, click \"Continue\"...";
1256 this.labelProcedureExecutionState.Text =
"Select a procedure and click \"Start\"...";
1259 else if (this.procedureExecutionCount == 1)
1261 this.labelProcedureExecutionState.Text =
"1 Procedure is running";
1265 this.labelProcedureExecutionState.Text =
string.Format(
"{0} Procedures are running", this.procedureExecutionCount);
1270 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Error16;
1271 this.labelProcedureExecutionState.Text = errorMessage;
1274 private void SyncWithParent(
object parentControl,
object control =
null,
bool newThread =
false)
1276 if (parentControl !=
null)
1278 if (this.creatorForm !=
null && this.checkBoxStartAllParents.Checked)
1280 if (parentControl is Button)
1284 ThreadPool.QueueUserWorkItem(state => ParentButtonClick(parentControl as Button));
1288 ParentButtonClick(parentControl as Button);
1291 else if (parentControl is TextBox && control !=
null)
1293 string text = (control as TextBox).Text;
1296 ThreadPool.QueueUserWorkItem(state => ParentTextBoxSetText(parentControl as TextBox, text));
1300 ParentTextBoxSetText(parentControl as TextBox, text);
1303 else if (parentControl is CheckBox && control !=
null)
1305 CheckState checkState = (control as CheckBox).CheckState;
1308 ThreadPool.QueueUserWorkItem(state => ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState));
1312 ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState);
1315 else if (parentControl is ComboBox && control !=
null)
1317 int index = (control as ComboBox).SelectedIndex;
1320 ThreadPool.QueueUserWorkItem(state => ParentComboBoxSetIndex(parentControl as ComboBox, index));
1324 ParentComboBoxSetIndex(parentControl as ComboBox, index);
1327 else if (parentControl is NumericUpDown && control !=
null)
1329 int value = decimal.ToInt32((control as NumericUpDown).Value);
1331 ThreadPool.QueueUserWorkItem(state => ParentNumericUpDownSetValue(parentControl as NumericUpDown, value));
1333 ParentNumericUpDownSetValue(parentControl as NumericUpDown, value);
1339 private void ParentButtonClick(Button button)
1341 if (button.InvokeRequired)
1343 this.creatorForm.Invoke(
new Action(() => button.PerformClick()));
1347 button.PerformClick();
1351 private void ParentTextBoxSetText(TextBox textBox,
string text)
1353 if (textBox.InvokeRequired)
1355 this.creatorForm.Invoke(
new Action(() => textBox.Text = text));
1359 textBox.Text = text;
1363 private void ParentCheckBoxSetCheckState(CheckBox checkBox, CheckState checkState)
1365 if (checkBox.InvokeRequired)
1367 this.creatorForm.Invoke(
new Action(() => checkBox.CheckState = checkState));
1371 checkBox.CheckState = checkState;
1375 private void ParentComboBoxSetIndex(ComboBox comboBox,
int index)
1377 if (comboBox.InvokeRequired)
1379 this.creatorForm.Invoke(
new Action(() => comboBox.SelectedIndex = index));
1383 comboBox.SelectedIndex = index;
1387 private void buttonBrowseTraceFolder_Click(
object sender, EventArgs e)
1389 folderBrowserDialog1.SelectedPath = this.textBoxTraceFolder.Text;
1390 folderBrowserDialog1.ShowNewFolderButton =
true;
1392 DialogResult result = folderBrowserDialog1.ShowDialog();
1393 if (result == DialogResult.OK)
1395 this.textBoxTraceFolder.Text = folderBrowserDialog1.SelectedPath;
1399 private void buttonOpenTraceFolder_Click(
object sender, EventArgs e)
1401 string path = this.textBoxTraceFolder.Text;
1402 if (Directory.Exists(path))
1404 Process.Start(path);
1409 private void textBoxTraceFolder_TextChanged(
object sender, EventArgs e)
1411 if (this.globalRuntimeManager ==
null)
1414 string path = this.textBoxTraceFolder.Text;
1416 if (path != RuntimeConfig.Instance.TraceFolder)
1418 if (Directory.Exists(path))
1420 RuntimeConfig.Instance.TraceFolder = textBoxTraceFolder.Text;
1421 this.buttonOpenTraceFolder.Enabled =
true;
1423 PrintText(
"Set trace folder to " + RuntimeConfig.Instance.TraceFolder);
1427 this.buttonOpenTraceFolder.Enabled =
false;
1432 this.buttonOpenTraceFolder.Enabled =
true;
1435 SyncWithParent(this.creatorForm?.textBoxTraceFolder, this.textBoxTraceFolder);
1439 private void comboBoxTraceLevel_SelectedValueChanged(
object sender, EventArgs e)
1441 if (this.globalRuntimeManager ==
null)
1444 var traceLevel = (
TraceLevels)comboBoxTraceLevel.SelectedIndex;
1445 if (traceLevel == RuntimeConfig.Instance.TraceLevel)
1448 RuntimeConfig.Instance.TraceLevel = traceLevel;
1449 PrintText(
"Updated trace level");
1452 private void buttonBrowseFile_Click(
object sender, EventArgs e)
1454 DialogResult result = openFileDialog1.ShowDialog();
1455 if (result == DialogResult.OK)
1457 cbFilePath.Text = openFileDialog1.FileName;
1459 this.buttonReload.PerformClick();
1463 private void cbFilePath_TextChanged(
object sender, EventArgs e)
1465 AddComboBoxFileOrPath(cbFilePath);
1467 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1469 buttonReload.Enabled =
false;
1473 buttonReload.Enabled =
true;
1476 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1479 private void cbFilePath_SelectedValueChanged(
object sender, EventArgs e)
1481 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1483 buttonReload.Enabled =
false;
1487 buttonReload.Enabled =
true;
1488 this.buttonReload.PerformClick();
1491 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1494 private void buttonReload_Click(
object sender, EventArgs e)
1496 this.LoadContextFile(this.globalRuntimeManager);
1498 SyncWithParent(this.creatorForm?.buttonReload);
1501 private void LoadContextFile(IRuntimeManager runtimeManager)
1503 PrintText(
"Load '" + cbFilePath.Text +
"'...");
1505 if (runtimeManager ==
null)
1507 PrintText(
"... No RuntimeManager exists!");
1511 if (String.IsNullOrWhiteSpace(cbFilePath.Text.Trim()))
1513 PrintText(
"... wrong file name.");
1517 SetTitle(this.title);
1522 this.isLoadding =
true;
1523 this.playerProject =
null;
1524 this.project =
null;
1525 this.contextVariableImplementation.ResetAllValues();
1526 this.stateVariableImplementation.ResetAllValues();
1529 if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ptx"))
1531 this.project = LoadPtx(runtimeManager);
1533 if (this.project !=
null)
1535 PrintText(
"... Project '" + project.Name +
"' successfully loaded.");
1537 ClearCustomImplemetationCaches();
1539 this.LoadPackage(this.project);
1541 ReadSettings(this.project.Settings);
1543 this.isLoadding =
false;
1547 else if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ppx"))
1549 this.playerProject = LoadPpx(runtimeManager);
1551 if (this.playerProject !=
null)
1553 ClearCustomImplemetationCaches();
1555 PrintText(
"... Player '" + playerProject.Name +
"' successfully loaded.");
1557 foreach (IProject item
in this.playerProject.Projects)
1560 this.LoadPackage(item);
1563 ReadSettings(this.playerProject.Settings);
1565 this.isLoadding =
false;
1570 catch (System.Exception ex)
1575 this.isLoadding =
false;
1578 private void ClearSampleGUI()
1580 this.treeViewOtxProject.Nodes.Clear();
1581 this.gridViewParameter.Rows.Clear();
1582 this.gridViewContext.Rows.Clear();
1583 this.gridViewState.Rows.Clear();
1584 this.gridViewSettings.Rows.Clear();
1587 private void ClearCustomImplemetationCaches()
1589 if (this.contextVariableImplementation !=
null)
1590 this.contextVariableImplementation.ResetAllValues();
1592 if (this.contextVariableOutputImpl !=
null)
1593 this.contextVariableOutputImpl.ResetAllValues();
1595 if (this.stateVariableImplementation !=
null)
1596 this.stateVariableImplementation.ResetAllValues();
1602 private IProject LoadPtx(IRuntimeManager runtimeManager)
1604 IProject project =
null;
1606 if (runtimeManager.IsProtected(cbFilePath.Text))
1608 project = runtimeManager.LoadPtx(cbFilePath.Text, txtPassword.Text.Trim());
1612 project = runtimeManager.LoadPtx(cbFilePath.Text);
1615 if (project.MainProcedure !=
null)
1617 buttonExecuteMain.Enabled =
true;
1624 private IPlayerProject LoadPpx(IRuntimeManager runtimeManager)
1626 IPlayerProject playerProject =
null;
1628 if (runtimeManager.IsProtected(cbFilePath.Text))
1630 playerProject = runtimeManager.LoadPpx(cbFilePath.Text, txtPassword.Text.Trim());
1634 playerProject = runtimeManager.LoadPpx(cbFilePath.Text);
1637 return playerProject;
1641 private void LoadPackage(IProject project)
1643 PrintText(
"Browse project...");
1645 IPackage[] packages = project.Packages;
1646 if (packages ==
null)
1648 IDocument document = project.StartupDocument;
1649 this.treeViewOtxProject.Nodes.Add(CreateDocumentNode(document));
1653 string treeNodeText = project.Name;
1654 if (!String.IsNullOrWhiteSpace(project.Version))
1655 treeNodeText = String.Format(
"{0} ({1})", treeNodeText, project.Version);
1657 TreeNode root =
new TreeNode(treeNodeText);
1658 root.ImageKey = root.SelectedImageKey =
"ODFProject.bmp";
1659 foreach (IPackage pack
in packages)
1661 root.Nodes.Add(this.CreatePackageNode(pack));
1664 this.treeViewOtxProject.Nodes.Add(root);
1667 this.treeViewOtxProject.Enabled = this.gridViewParameter.Enabled =
true;
1668 this.treeViewOtxProject.ExpandAll();
1669 this.treeViewOtxProject.SelectedNode = startupNode;
1670 this.treeViewOtxProject.Focus();
1672 PrintText(
"... project browsing finished.");
1676 private TreeNode CreateDocumentNode(IDocument doc)
1678 TreeNode documentNode =
new TreeNode(doc.Name);
1679 documentNode.Tag = doc;
1680 documentNode.ImageKey = documentNode.SelectedImageKey =
"DocumentOTX16.bmp";
1683 documentNode.Text +=
" (StartUp)";
1686 foreach (IProcedure p
in doc.Procedures)
1688 TreeNode procedureNode = CreateProcedureNode(p);
1689 documentNode.Nodes.Add(procedureNode);
1690 if (doc.IsStartup && p.Name ==
"main")
1692 startupNode = procedureNode;
1693 buttonExecuteMain.Enabled =
true;
1695 else if (startupNode ==
null)
1697 startupNode = procedureNode;
1701 return documentNode;
1705 private TreeNode CreateProcedureNode(IProcedure procedure)
1707 if (checkBoxCyclicReload.Checked &&
1708 procedureToExecute !=
null &&
1709 procedureToExecute.FullName == procedure.FullName)
1711 procedureToExecute = procedure;
1714 TreeNode procedureNode =
new TreeNode(procedure.Name);
1715 procedureNode.ImageKey = procedureNode.SelectedImageKey =
"Procedure.bmp";
1716 procedureNode.Tag = procedure;
1717 return procedureNode;
1721 private TreeNode CreatePackageNode(IPackage pack)
1723 TreeNode packageNode =
new TreeNode(pack.Name);
1724 packageNode.Tag = pack;
1725 packageNode.ImageKey = packageNode.SelectedImageKey =
"Package.bmp";
1727 List<IDocument> documents = pack.Documents.ToList();
1728 foreach (IDocument doc
in documents)
1730 packageNode.Nodes.Add(CreateDocumentNode(doc));
1733 foreach (IPackage package
in pack.Packages)
1735 packageNode.Nodes.Add(this.CreatePackageNode(package));
1742 private void gridView_CellValueChanged(
object sender, DataGridViewCellEventArgs e)
1744 DataGridView gridView = sender as DataGridView;
1747 if (gridView == this.gridViewParameter)
1749 columnName = dataGridViewTextBoxColumnValue.Name;
1751 else if (gridView == this.gridViewContext)
1753 columnName = dataGridViewTextBoxColumnContextValue.Name;
1760 if (!this.isLoadding && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == columnName &&
1762 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewCheckBoxCell ||
1763 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewComboBoxCell
1768 this.Validate(
false);
1773 void gridViewParameter_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1775 DataGridView gridView = sender as DataGridView;
1776 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name)
1778 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1779 if (parameter.Value !=
null)
1781 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnValue.Name].Value = ConvertValue2String(parameter.Value);
1782 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDetails.Name].Value = GetDetails(parameter.Value);
1789 void gridViewParameter_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1791 DataGridView gridView = sender as DataGridView;
1792 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 &&
1793 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name &&
1794 !gridView.Rows[e.RowIndex].ReadOnly &&
1795 e.FormattedValue !=
null)
1797 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1798 if (e.FormattedValue.ToString() == ValueConverter.Value2String(parameter.Value) || e.FormattedValue.ToString() == ConvertValue2String(parameter.Value))
1803 object value =
null;
1807 value = ValueConverter.String2Value(e.FormattedValue.ToString(), parameter.DataType);
1809 catch (System.Exception ex)
1822 System.Media.SystemSounds.Exclamation.Play();
1826 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDataType.Name].ErrorText =
string.Empty;
1827 if (parameter is IProcedureInParameter)
1828 (parameter as IProcedureInParameter).Value = value;
1829 else if (parameter is IProcedureInOutParameter)
1830 (parameter as IProcedureInOutParameter).Value = value;
1841 void gridViewContextVariable_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1843 DataGridView gridView = sender as DataGridView;
1844 if (!this.isLoadding && gridView !=
null &&
1846 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name)
1848 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1849 if (gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag !=
null)
1851 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1852 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1858 void gridViewContextVariable_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1860 DataGridView gridView = sender as DataGridView;
1861 if (!this.isLoadding && gridView !=
null &&
1863 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name &&
1864 !gridView.Rows[e.RowIndex].ReadOnly &&
1865 e.FormattedValue !=
null)
1867 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1868 if (e.FormattedValue.ToString() == ValueConverter.Value2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag) || e.FormattedValue.ToString() == ConvertValue2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag))
1873 object value =
null;
1877 value = ValueConverter.String2Value(e.FormattedValue.ToString(), context.DataType);
1879 catch (System.Exception ex)
1892 System.Media.SystemSounds.Exclamation.Play();
1898 string fullNameContextVariable = context.Document.FullName +
'.' + context.Name;
1899 this.contextVariableImplementation.SetValue(fullNameContextVariable, value);
1900 this.contextVariableOutputImpl.SetValue(fullNameContextVariable, value);
1901 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = value;
1902 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDataType.Name].ErrorText =
string.Empty;
1913 private void treeViewOtxProject_AfterSelect(
object sender, TreeViewEventArgs e)
1915 TreeNode node = e.Node;
1919 this.gridViewParameter.Rows.Clear();
1920 this.gridViewContext.Rows.Clear();
1921 this.gridViewState.Rows.Clear();
1923 if (node.Tag is IProcedure)
1925 IProcedure procedure = node.Tag as IProcedure;
1926 ClearCustomImplemetationCaches();
1927 UpdateGridview(procedure);
1929 buttonExecuteSelectedProcedure.Enabled =
true;
1930 this.project = GetProject(procedure);
1935 buttonExecuteSelectedProcedure.Enabled =
false;
1939 private IProject GetProject(IProcedure procedure)
1941 if (procedure !=
null)
1943 IPackage
package = procedure.Document.Package;
1944 if (package !=
null)
1946 while (package.Parent !=
null)
1948 package = package.Parent;
1951 return package.Project;
1957 private void treeViewOtxProject_DrawNode(
object sender, DrawTreeNodeEventArgs e)
1959 e.DrawDefault =
true;
1963 private void buttonReadSettings_Click(
object sender, EventArgs e)
1965 Dictionary<string, string> settings =
null;
1966 if (this.playerProject !=
null)
1968 settings = this.playerProject.Settings;
1970 else if (this.project !=
null)
1972 settings = this.project.Settings;
1974 ReadSettings(settings);
1977 private void ReadSettings(Dictionary<string, string> settings)
1979 if (settings !=
null)
1981 PrintText(
"Read settings");
1983 gridViewSettings.Rows.Clear();
1985 foreach (KeyValuePair<string, string> setting
in settings)
1987 object[] values =
new object[] { setting.Key, setting.Value };
1988 this.gridViewSettings.Rows.Add(values);
1994 private void buttonWriteSettings_Click(
object sender, EventArgs e)
1997 string valueSetting;
1998 int selectedSettingPosition = 0;
1999 Dictionary<string, string> newSettings =
new Dictionary<string, string>();
2001 if (this.gridViewSettings.SelectedRows.Count != 0)
2003 selectedSettingPosition = this.gridViewSettings.SelectedRows[0].Index;
2008 if (project !=
null || playerProject !=
null)
2010 foreach (DataGridViewRow row
in this.gridViewSettings.Rows)
2012 nameSetting = row.Cells[this.dataGridViewTextBoxColumnSettingName.Name].Value.ToString();
2013 valueSetting = row.Cells[this.dataGridViewTextBoxColumnSettingValue.Name].Value?.ToString();
2015 newSettings.Add(nameSetting, valueSetting);
2018 if (playerProject !=
null)
2020 playerProject.Settings = newSettings;
2021 ReadSettings(playerProject.Settings);
2025 project.Settings = newSettings;
2026 ReadSettings(project.Settings);
2029 this.gridViewSettings.Rows[selectedSettingPosition].Selected =
true;
2030 this.gridViewSettings.Rows[selectedSettingPosition].Cells[dataGridViewTextBoxColumnSettingValue.Name].Selected =
true;
2032 PrintText(
"Write settings finished");
2035 catch (System.Exception ex)
2041 private void checkBoxCyclicExecution_CheckedChanged(
object sender, EventArgs e)
2043 this.checkBoxCyclicReload.Enabled = this.checkBoxNewRuntimeManager.Enabled = this.checkBoxCyclicExecution.Checked;
2045 if (!this.checkBoxCyclicExecution.Checked)
2047 this.checkBoxCyclicReload.Checked = this.checkBoxNewRuntimeManager.Checked =
false;
2050 SyncWithParent(this.creatorForm?.checkBoxCyclicExecution, this.checkBoxCyclicExecution);
2053 private void checkBoxAsyncExecution_CheckedChanged(
object sender, EventArgs e)
2055 SyncWithParent(this.creatorForm?.checkBoxAsyncExecution, this.checkBoxAsyncExecution);
2058 private void checkBoxNewRuntimeManager_CheckedChanged(
object sender, EventArgs e)
2060 if (this.checkBoxNewRuntimeManager.Checked)
2062 this.checkBoxCyclicReload.Checked =
true;
2065 SyncWithParent(this.creatorForm?.checkBoxNewRuntimeManager, this.checkBoxNewRuntimeManager);
2068 private void checkBoxCyclicReload_CheckedChanged(
object sender, EventArgs e)
2070 SyncWithParent(this.creatorForm?.checkBoxCyclicReload, this.checkBoxCyclicReload);
2074 private void buttonExecuteSelectedProcedure_Click(
object sender, EventArgs e)
2078 if (treeViewOtxProject.SelectedNode !=
null && treeViewOtxProject.SelectedNode.Tag is IProcedure)
2080 IDocument document = treeViewOtxProject.SelectedNode.Parent.Tag as IDocument;
2081 List<string> listItemsReviewed =
new List<string>();
2083 this.procedureToExecute = treeViewOtxProject.SelectedNode.Tag as IProcedure;
2084 this.ExecuteProcedure();
2088 PrintText(
"Please select Procedure to execute");
2092 catch (System.Exception ex)
2097 SyncWithParent(this.creatorForm?.buttonExecuteSelectedProcedure,
null,
true);
2102 private void buttonExecuteMain_Click(
object sender, EventArgs e)
2106 if (project !=
null)
2108 treeViewOtxProject.SelectedNode = startupNode;
2109 this.procedureToExecute = project.MainProcedure;
2110 this.ExecuteProcedure();
2114 PrintText(
"There is no project has been loaded. Please reload the project");
2117 catch (System.Exception ex)
2122 SyncWithParent(this.creatorForm?.buttonExecuteMain,
null,
true);
2126 private async
void ExecuteProcedure()
2128 PrintText(
"Start procedure execution...");
2130 if (checkBoxAsyncExecution.Checked ==
false)
2132 this.buttonExecuteMain.Enabled =
false;
2133 this.buttonExecuteSelectedProcedure.Enabled =
false;
2138 if (this.globalRuntimeManager !=
null && procedureToExecute !=
null)
2140 this.buttonStop.Enabled =
true;
2142 CheckBatteryIgnitionState(this.globalRuntimeManager);
2144 if (checkBoxCyclicExecution.Checked)
2146 ThreadPool.QueueUserWorkItem(state => DoCyclic());
2151 if (checkBoxAsyncExecution.Checked)
2153 this.globalRuntimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2157 await Task.Run(() => this.globalRuntimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text)));
2163 PrintText(
"RuntimeManager is null or no Procedure is selected to run.");
2166 catch (System.Exception ex)
2170 UpdateButtonStateAfterThrowException();
2174 private void UpdateButtonStateAfterThrowException()
2176 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
2177 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
2179 UpdateExecutionStateButtons(
false);
2180 UpdatePauseButton(
true,
false);
2182 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
2183 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
2187 private void DoCyclic()
2189 DateTime startTime = DateTime.Now;
2194 while (checkBoxCyclicExecution.Checked)
2196 IRuntimeManager runtimeManager =
null;
2197 IRuntimeContext runtimeContext =
null;
2200 this.cyclicExecutionCount++;
2202 if (this.checkBoxNewRuntimeManager.Checked)
2204 runtimeManager = CreateRuntimeManager();
2208 runtimeManager = this.globalRuntimeManager;
2211 CheckCyclicReloadOrNewRuntimeManager(runtimeManager);
2213 cyclicExecuteAsyncIsProcessing =
true;
2214 CheckBatteryIgnitionState(this.globalRuntimeManager);
2216 if (this.checkBoxAsyncExecution.Checked)
2218 runtimeContext = runtimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2219 if (runtimeContext !=
null)
2222 Application.DoEvents();
2228 runtimeContext = runtimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2233 this.cyclicExecutionCount = 0;
2238 catch (System.Exception ex)
2242 UpdateButtonStateAfterThrowException();
2246 Invoke(
new MethodInvoker(delegate ()
2248 if (this.checkBoxNewRuntimeManager.Checked)
2250 LoadContextFile(this.globalRuntimeManager);
2254 PrintText(
"Cyclic execution finished");
2256 var duration = DateTime.Now - startTime;
2257 string text = String.Format(
"Execution Statistics: Duration {0} (hh:mm:ss) with {1} cycles and {2:0} ms per cycle", duration.ToString(
@"hh\:mm\:ss"), cyclic, duration.TotalMilliseconds / cyclic);
2259 this.cyclicExecutionCount -= cyclic;
2260 if (this.cyclicExecutionCount < 0)
2262 this.cyclicExecutionCount = 0;
2265 if (this.checkBoxAdd2Output.Checked)
2271 MessageBox.Show(text);
2274 private void WaitCyclicExecuteAsyncIsProcessing()
2276 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2279 while (cyclicExecuteAsyncIsProcessing)
2282 Application.DoEvents();
2288 private void CheckCyclicReloadOrNewRuntimeManager(IRuntimeManager runtimeMgr,
bool waitCyclic =
true)
2292 WaitCyclicExecuteAsyncIsProcessing();
2297 Invoke(
new MethodInvoker(delegate ()
2299 CheckCyclicReloadOrNewRuntimeManager(runtimeMgr,
false);
2304 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2306 LoadContextFile(runtimeMgr);
2309 if (this.checkBoxCyclicExecution.Checked)
2311 this.checkBoxCyclicExecution.Text =
"Cyclic (" + this.cyclicExecutionCount +
")";
2315 this.checkBoxCyclicExecution.Text =
"Cyclic";
2320 private void buttonStop_Click(
object sender, EventArgs e)
2322 if (this.globalRuntimeManager !=
null)
2324 PrintText(String.Format(
"Try to stop all running procedures..."));
2325 this.globalRuntimeManager.StopAll();
2326 this.procedureExecutionCount = 0;
2330 this.checkBoxCyclicExecution.Checked =
false;
2332 SyncWithParent(this.creatorForm?.buttonStop);
2335 private void PrintException(System.Exception ex,
string additionalText =
"")
2337 PrintText(String.Format(
"!!! {2}{0}: {1}", ex.GetType().Name, ex.Message, additionalText));
2338 System.Media.SystemSounds.Hand.Play();
2341 private void PrintText(
string text)
2345 this.Invoke(
new Action(() => PrintText(text)));
2349 if (!this.checkBoxAdd2Output.Checked)
2355 lock (printTextLock)
2357 if (this.listBoxOuput.Items.Count >= 10000)
2359 buttonClearOutput_Click(
null,
null);
2362 string prefixString = GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime();
2363 string itemToAdd = prefixString + text +
"\t\t";
2365 this.listBoxOuput.Items.Add(itemToAdd);
2366 this.listBoxOuput.SelectedItems.Clear();
2367 this.listBoxOuput.TopIndex = listBoxOuput.Items.Count - 1;
2369 if (this.listBoxOuput.Items.Count >= 7500)
2371 this.labelOutputOverflow.Visible =
true;
2376 Application.DoEvents();
2380 private string GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime()
2382 DateTime now = DateTime.Now;
2383 var duration = now - this.lastTime;
2385 this.lastTime = now;
2387 string timeDurationString = String.Format(
"{0:HH:mm:ss.fff} {1,6:#,##0} ms ", now, duration.TotalMilliseconds);
2388 return timeDurationString;
2391 private void buttonCopyRow_Click(
object sender, EventArgs e)
2393 if (this.listBoxOuput.SelectedItems !=
null)
2395 string text =
string.Empty;
2396 foreach (
string row
in this.listBoxOuput.SelectedItems)
2398 text += row.Trim(
'\t') +
"\n";
2401 Clipboard.SetText(text);
2405 private void buttonClearOutput_Click(
object sender, EventArgs e)
2407 this.listBoxOuput.Items.Clear();
2408 this.labelOutputOverflow.Visible =
false;
2409 this.buttonCopyRow.Enabled =
false;
2413 private void UpdateGridview(IProcedure procedure)
2415 if (procedure ==
null ||
2416 procedure.Parameters ==
null)
2421 UpdateGridviewParameter(procedure);
2423 IDocument document = procedure.Document;
2424 if (document !=
null)
2426 List<string> listItemsReviewed =
new List<string>();
2427 UpdateGridViewContextVariable(document,
false, listItemsReviewed);
2429 listItemsReviewed.Clear();
2430 UpdateGridViewStateVariable(document,
false, listItemsReviewed);
2434 private void UpdateGridviewParameter(IProcedure procedure)
2436 foreach (IProcedureParameter param
in procedure.Parameters)
2438 UpdateGridviewParameter(param);
2443 private void UpdateGridviewParameter(IProcedureParameter parameter)
2445 if (parameter ==
null)
2450 bool bValueWasSet =
false;
2453 string collumnName = dataGridViewTextBoxColumnName.Name;
2454 string collumnValue = dataGridViewTextBoxColumnValue.Name;
2455 string collumnDetails = dataGridViewTextBoxColumnDetails.Name;
2456 foreach (DataGridViewRow row
in this.gridViewParameter.Rows)
2458 if (row.Cells[collumnName].Value.Equals(parameter.Name))
2462 if (parameter.Value !=
null)
2464 row.Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2467 catch (System.Exception ex)
2469 row.Cells[collumnValue].ErrorText = ex.Message;
2472 bValueWasSet =
true;
2480 string direction = parameter is IProcedureInParameter ?
"In" : (parameter is IProcedureInOutParameter ?
"InOut" :
"Out");
2481 object[] values =
new object[] { parameter.Name, direction, parameter.DataType };
2482 int index = this.gridViewParameter.Rows.Add(values);
2484 this.gridViewParameter.Rows[index].Tag = parameter;
2486 this.gridViewParameter.Rows[index].ReadOnly = parameter is IProcedureOutParameter || parameter.InitValue ==
null;
2488 if (parameter.DataType.Equals(
"Boolean"))
2490 gridViewParameter.Rows[index].Cells[collumnValue] =
new DataGridViewCheckBoxCell();
2491 DataGridViewCheckBoxCell cell = gridViewParameter.Rows[index].Cells[collumnValue] as DataGridViewCheckBoxCell;
2492 cell.Value = ConvertValue2String(parameter.Value);
2498 if (parameter.Value !=
null)
2500 gridViewParameter.Rows[index].Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2503 catch (System.Exception ex)
2505 gridViewParameter.Rows[index].Cells[collumnValue].ErrorText = ex.Message;
2509 gridViewParameter.Rows[index].Cells[collumnDetails].Value = GetDetails(parameter.Value);
2513 private string ConvertValue2String(
object value)
2517 return string.Empty;
2520 return ValueConverter.Value2String(value);
2523 private string GetDetails(
object value)
2527 return string.Empty;
2530 if (value is TranslationKey translationKey)
2532 if (!
string.IsNullOrEmpty(translationKey.TextIdMappingName))
2534 return string.Format(
"MappingName: {0}", translationKey.TextIdMappingName);
2537 else if (value is EnumerationElement enumerationElement)
2539 if (enumerationElement.TranslationKey !=
null)
2541 if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId) && !
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextIdMappingName))
2543 return string.Format(
"TextId: {0}, MappingName: {1}", enumerationElement.TranslationKey.TextId, enumerationElement.TranslationKey.TextIdMappingName);
2545 else if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId))
2547 return string.Format(
"TextId: {0}", enumerationElement.TranslationKey.TextId);
2550 return string.Format(
"MappingName: {0}", enumerationElement.TranslationKey.TextIdMappingName);
2554 return string.Empty;
2558 private void UpdateGridViewContextVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2560 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2561 if (listItemsReviewed.Contains(@
namespace))
2566 listItemsReviewed.Add(@
namespace);
2567 foreach (IContextVariable contextVariable
in document.ContextVariables)
2569 if (contextVariable ==
null)
2574 bool bValueWasSet =
false;
2577 foreach (DataGridViewRow row
in this.gridViewContext.Rows)
2579 if (row.Cells[
this.dataGridViewTextBoxColumnContextName.Name].Value !=
null && row.Cells[
this.dataGridViewTextBoxColumnContextName.Name].Value.Equals(withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + contextVariable.Name) : contextVariable.Name))
2581 if (radioButtonDefaultImplementation.Checked)
2583 object contextVariableValue = this.contextVariableImplementation.GetValue(
null, contextVariable,
null);
2584 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariableValue !=
null ? ConvertValue2String(contextVariableValue) : null;
2588 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariable.InitValue !=
null ? ConvertValue2String(contextVariable.InitValue) : null;
2591 bValueWasSet =
true;
2599 object[] values =
null;
2600 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + contextVariable.Name) : contextVariable.Name, contextVariable.DataType };
2601 int index = this.gridViewContext.Rows.Add(values);
2603 object contextVariableValue = contextVariable.InitValue;
2605 this.gridViewContext.Rows[index].Tag = contextVariable;
2606 this.gridViewContext.Rows[index].ReadOnly = contextVariable.InitValue ==
null;
2607 this.gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = contextVariable.InitValue;
2608 if (contextVariable.DataType.Equals(
"Boolean"))
2610 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] =
new DataGridViewCheckBoxCell();
2611 DataGridViewCheckBoxCell cell = gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] as DataGridViewCheckBoxCell;
2612 cell.Value = ConvertValue2String(contextVariableValue);
2618 if (contextVariableValue !=
null)
2620 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(contextVariableValue);
2624 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value =
null;
2627 catch (System.Exception ex)
2629 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].ErrorText = ex.Message;
2633 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(contextVariableValue);
2639 foreach (IDocument importDoc
in document.Imports)
2641 UpdateGridViewContextVariable(importDoc,
true, listItemsReviewed);
2644 catch (System.Exception ex)
2651 private void StateVariableValueChanged(IStateVariable stateVariable,
object value)
2653 if (this.InvokeRequired)
2655 this.Invoke(
new Action(() => StateVariableValueChanged(stateVariable, value)));
2659 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2660 stateVariable.MappingName,
2661 (stateVariable.MappingIndex > -1 ?
"[" + stateVariable.MappingIndex +
"]" : String.Empty));
2662 string strValue =
"null";
2665 strValue = ValueConverter.Value2String(value);
2671 string outputLog = String.Format(
"StateVariableChanged({0} {1}.{2}{3} = {4})",
2672 stateVariable.DataType,
2673 stateVariable.Document.FullName,
2677 PrintText(outputLog);
2678 UpdateGridViewStateVariable(stateVariable);
2681 private void ContextVariableRead(IContextVariable contextVariable,
object value)
2683 if (this.InvokeRequired)
2685 this.Invoke(
new Action(() => ContextVariableRead(contextVariable, value)));
2689 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2690 contextVariable.MappingName,
2691 (contextVariable.MappingIndex > -1 ?
"[" + contextVariable.MappingIndex +
"]" : String.Empty));
2692 string strValue =
"null";
2695 strValue = ValueConverter.Value2String(value);
2700 string outputLog = String.Format(
"ContextVariableRead({0} {1}.{2}{3} = {4})",
2701 contextVariable.DataType,
2702 contextVariable.Document.FullName,
2703 contextVariable.Name,
2707 PrintText(outputLog);
2710 private void UpdateGridViewStateVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2712 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2713 if (listItemsReviewed.Contains(@
namespace))
2718 listItemsReviewed.Add(@
namespace);
2719 foreach (IStateVariable stateVariable
in document.StateVariables)
2721 object[] values =
null;
2722 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + stateVariable.Name) : stateVariable.Name, stateVariable.DataType };
2723 int index = this.gridViewState.Rows.Add(values);
2725 this.gridViewState.Rows[index].Tag = stateVariable;
2727 if (stateVariable.DataType.Equals(
"Boolean"))
2729 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] =
new DataGridViewCheckBoxCell();
2730 DataGridViewCheckBoxCell cell = gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] as DataGridViewCheckBoxCell;
2731 cell.Value = ConvertValue2String(stateVariable.InitValue);
2737 if (stateVariable.InitValue !=
null)
2739 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariable.InitValue);
2742 catch (System.Exception ex)
2744 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2748 if (stateVariable.InitValue !=
null)
2750 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariable.InitValue);
2756 foreach (IDocument importDoc
in document.Imports)
2758 UpdateGridViewStateVariable(importDoc,
true, listItemsReviewed);
2761 catch (System.Exception ex)
2769 private void UpdateGridViewStateVariable(IStateVariable stateVar)
2771 if (stateVar ==
null)
2777 foreach (DataGridViewRow row
in this.gridViewState.Rows)
2779 if (row.Cells[
this.dataGridViewTextBoxColumnStateName.Name].Value !=
null && row.Tag == stateVar)
2781 object stateVariableValue =
null;
2783 if (radioButtonDefaultImplementation.Checked)
2784 stateVariableValue = this.stateVariableImplementation.GetValue(stateVar);
2786 stateVariableValue = stateVar.InitValue;
2788 if (stateVariableValue !=
null)
2792 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariableValue);
2794 catch (System.Exception ex)
2796 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2799 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariableValue);
2803 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value =
null;
2804 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value =
string.Empty;
2810 Application.DoEvents();
2813 private void buttonNewInstance_Click(
object sender, EventArgs e)
2815 Form form =
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this);
2819 private void buttonNewInstanceNewThread_Click(
object sender, EventArgs e)
2821 Thread thread =
new Thread(
new ThreadStart(NewInstanceInThread));
2822 thread.SetApartmentState(ApartmentState.STA);
2826 private void NewInstanceInThread()
2828 Application.Run(
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this));
2831 private void buttonHmi_Click(
object sender, EventArgs e)
2833 if (this.buttonHmi.Checked)
2835 hmiWindow =
new HmiWindow();
2836 hmiWindow.FormClosing += HmiWindow_FormClosing;
2837 hmiWindow.SizeChanged += HmiWindow_SizeChanged;
2838 hmiWindow.Activated += HmiWindow_Activated;
2841 hmiWindow.Size =
new Size(userSettings.HmiWindowWidth, userSettings.HmiWindowHeight);
2842 hmiWindow.Location =
new Point(this.Location.X +
this.Size.Width,
this.Location.Y);
2843 if (this.creatorForm !=
null && this.creatorForm.hmiWindow !=
null)
2845 this.hmiWindow.Size = this.creatorForm.hmiWindow.Size;
2848 hmiWindow.BringToFront();
2850 customScreenImplementation.HmiScreenContainer = this.hmiWindow.HmiControl;
2852 else if (this.hmiWindow !=
null)
2854 this.hmiWindow.Close();
2857 SyncWithParent(this.creatorForm?.buttonHmi, this.buttonHmi);
2860 private void HmiWindow_FormClosing(
object sender, FormClosingEventArgs e)
2862 customScreenImplementation.HmiScreenContainer =
null;
2863 this.hmiWindow =
null;
2865 this.buttonHmi.Checked =
false;
2868 private void HmiWindow_Activated(
object sender, EventArgs e)
2870 if (customScreenImplementation !=
null)
2872 customScreenImplementation.ActivateHmiScreen();
2876 private void HmiWindow_SizeChanged(
object sender, EventArgs e)
2878 userSettings.HmiWindowWidth = this.hmiWindow.Width;
2879 userSettings.HmiWindowHeight = this.hmiWindow.Height;
2881 if (customScreenImplementation !=
null)
2883 customScreenImplementation.RefreshHmiScreen();
2887 private void CustomScreenImplementation_KeyDown(Runtime.Api.Custom.KeyEventArgs e)
2889 string key =
"Unknown";
2890 if (e is WpfKeyEventArgs)
2892 WpfKeyEventArgs wpfArgs = e as WpfKeyEventArgs;
2893 key = wpfArgs.Key.ToString();
2894 if (wpfArgs.ModifierKey == System.Windows.Input.ModifierKeys.Alt &&
2895 wpfArgs.Key == System.Windows.Input.Key.F4)
2899 else if (wpfArgs.Key == System.Windows.Input.Key.F10 || wpfArgs.Key == System.Windows.Input.Key.LeftAlt || wpfArgs.Key == System.Windows.Input.Key.RightAlt)
2904 else if (e is FormKeyEventArgs)
2906 FormKeyEventArgs formArgs = e as FormKeyEventArgs;
2907 if (formArgs.ModifierKey == Keys.Alt &&
2908 formArgs.Key == Keys.F4)
2912 else if (formArgs.Key == Keys.F10 || formArgs.Key == Keys.Alt)
2916 key = formArgs.Key.ToString();
2919 this.PrintText(
"CustomScreenImplementation_KeyDown(" + key +
")");
2923 private void SampleForm_FormClosing(
object sender, FormClosingEventArgs e)
2926 if (this.globalRuntimeManager !=
null)
2928 this.globalRuntimeManager.StopAll();
2929 this.globalRuntimeManager.ProcedurePending -= ProcedurePending;
2930 this.globalRuntimeManager.ProcedureStarted -= ProcedureStarted;
2931 this.globalRuntimeManager.ProcedurePaused -= ProcedurePaused;
2932 this.globalRuntimeManager.ProcedureContinued -= ProcedureContinued;
2933 this.globalRuntimeManager.ProcedureFinished -= ProcedureFinished;
2934 this.globalRuntimeManager.ProcedureStopped -= ProcedureStopped;
2935 this.globalRuntimeManager.ProcedureAborted -= ProcedureAborted;
2936 this.globalRuntimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
2939 this.stateVariableImplementation.StateVariableValueChanged -= StateVariableValueChanged;
2941 basicScreenOutputImpl.LogEvent -= PrintText;
2942 customScreenOutputImpl.LogEvent -= PrintText;
2943 loggingOutputImpl.LogEvent -= PrintText;
2944 contextVariableOutputImpl.LogEvent -= PrintText;
2946 stateVariableOutputImpl.LogEvent -= PrintText;
2947 measureOutputImpl.LogEvent -= PrintText;
2948 i18NOutputImpl.LogEvent -= PrintText;
2949 serviceProviderOutputImpl.LogEvent -= PrintText;
2951 sqlOutputImpl.LogEvent -= PrintText;
2952 commonDialogsOutputImpl.LogEvent -= PrintText;
2957 private void SaveSettings()
2959 if (this.creatorForm ==
null)
2962 userSettings.Ptx_Ppx_Directory = cbFilePath.Text.Trim();
2963 userSettings.Ptx_Ppx_DirectoryList =
string.Join(
";", this.cbFilePath.Items.Cast<Object>().Select(item => item.ToString()).ToArray());
2965 userSettings.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text.Trim());
2966 userSettings.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text.Trim());
2967 userSettings.TraceLevels = RuntimeConfig.Instance.TraceLevel;
2968 userSettings.TracingDirectory = textBoxTraceFolder.Text.Trim();
2970 userSettings.WindowWidth = this.Size.Width;
2971 userSettings.WindowHeight = this.Size.Height;
2972 userSettings.WindowLocationX = this.Location.X;
2973 userSettings.WindowLocationY = this.Location.Y;
2974 userSettings.CustomImplTypes = GetCurrentCustomImpl();
2975 SaveSocketPortOrPipeName();
2977 userSettings.Asynchron = checkBoxAsyncExecution.Checked;
2978 userSettings.Cyclic = checkBoxCyclicExecution.Checked;
2979 userSettings.CyclicReload = checkBoxCyclicReload.Checked;
2980 userSettings.NewRunTimeManager = checkBoxNewRuntimeManager.Checked;
2981 userSettings.AddMessageToOutput = checkBoxAdd2Output.Checked;
2982 userSettings.StartAllParents = checkBoxStartAllParents.Checked;
2984 userSettings.TimeOut = (ulong)Convert.ToInt32(
this.textBoxTimeout.Text.Trim());
2985 userSettings.ConnectionState = checkBoxUseConnectionState.Checked;
2986 userSettings.Ignition = checkBoxIgnition.CheckState == CheckState.Checked ? 1 : (checkBoxIgnition.CheckState == CheckState.Unchecked ? 0 : -1);
2987 userSettings.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text.Trim());
2988 userSettings.VoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text.Trim());
2990 userSettings.RuntimeContextName = this.textBoxRuntimeContextName.Text.Trim();
2992 SaveSettingUtil.Save();
2996 private void SaveSocketPortOrPipeName()
2998 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
3002 case IpcTypes.SOCKET:
3006 userSettings.DiagManagerPort = Convert.ToUInt16(textBoxDiagPortPipe.Text.Trim());
3007 userSettings.RuntimePort = Convert.ToUInt16(textBoxRtPortPipe.Text.Trim());
3008 userSettings.IpcType = IpcTypes.SOCKET.ToString();
3010 catch (System.Exception)
3012 userSettings.DiagManagerPort = SampleConstants.DEFAULT_DM_PORT;
3013 userSettings.RuntimePort = SampleConstants.DEFAULT_RT_PORT;
3020 string diagManagerPipeName = textBoxDiagPortPipe.Text.Trim();
3021 string runtimePipeName = textBoxRtPortPipe.Text.Trim();
3023 userSettings.DiagManagerPipeName = (diagManagerPipeName !=
string.Empty) ? diagManagerPipeName : SampleConstants.DEFAULT_DM_PIPE_NAME;
3024 userSettings.RuntimePipeName = (runtimePipeName !=
string.Empty) ? runtimePipeName : SampleConstants.DEFAULT_RT_PIPE_NAME;
3025 userSettings.IpcType = IpcTypes.PIPE.ToString();
3034 private void textBoxRuntimeContextName_TextChanged(
object sender, EventArgs e)
3036 this.runtimeContextName = this.textBoxRuntimeContextName.Text = this.textBoxRuntimeContextName.Text.Trim();
3037 SetTitle(this.title);
3040 private void listBoxOuput_SelectedIndexChanged(
object sender, EventArgs e)
3042 this.buttonCopyRow.Enabled = this.listBoxOuput.SelectedItems.Count > 0;
3045 private void buttonPause_Click(
object sender, EventArgs e)
3047 lock (this.runtimeContexts)
3049 if (this.buttonPause.Checked)
3051 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3055 runtimeContext.Pause();
3061 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3065 runtimeContext.Continue();
3071 SyncWithParent(this.creatorForm?.buttonPause, this.buttonPause);
3074 private void AddRuntimeContext(IRuntimeContext context)
3076 lock (this.runtimeContexts)
3078 if (!this.runtimeContexts.Contains(context))
3080 this.runtimeContexts.Add(context);
3083 if (!runtimeContextsExecutionStartTime.ContainsKey(context))
3085 runtimeContextsExecutionStartTime.Add(context, DateTime.Now);
3090 private void RemoveRuntimeContext(IRuntimeContext context)
3092 lock (this.runtimeContexts)
3094 if (this.runtimeContexts.Contains(context))
3096 this.runtimeContexts.Remove(context);
3099 if (runtimeContextsExecutionStartTime.ContainsKey(context))
3101 runtimeContextsExecutionStartTime.Remove(context);
3106 private bool IsPauseEnabled()
3108 lock (this.runtimeContexts)
3110 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3122 private bool IsContinueEnable()
3124 lock (this.runtimeContexts)
3126 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3138 private void SetExpectedState()
3140 if (this.useConnectionState)
3142 if (this.KL15State ==
null)
3146 else if (this.KL15State.Value)
3161 private void checkBoxUseConnectionState_CheckedChanged(
object sender, EventArgs e)
3163 this.useConnectionState = this.checkBoxUseConnectionState.Checked;
3164 this.EnableConnectionState();
3165 this.SetExpectedState();
3167 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
3168 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
3170 SyncWithParent(this.creatorForm?.checkBoxUseConnectionState, this.checkBoxUseConnectionState);
3173 private void CheckBoxKL15_CheckStateChanged(
object sender, System.EventArgs e)
3175 switch (this.checkBoxIgnition.CheckState)
3177 case CheckState.Checked:
3178 this.KL15State =
true;
3180 case CheckState.Unchecked:
3181 this.KL15State =
false;
3184 this.KL15State =
null;
3188 this.SetExpectedState();
3190 SyncWithParent(this.creatorForm?.checkBoxIgnition, this.checkBoxIgnition);
3193 private void EnableConnectionState()
3195 this.labelExpectedState.Enabled = this.useConnectionState;
3196 this.labelBatteryState.Enabled = this.useConnectionState;
3197 this.checkBoxIgnition.Enabled = this.useConnectionState;
3198 this.labelPollingTime.Enabled = this.useConnectionState;
3199 this.textBoxPollingTime.Enabled = this.useConnectionState;
3200 this.labelVoltageThreshold.Enabled = this.useConnectionState;
3201 this.textBoxVoltageThreshold.Enabled = this.useConnectionState;
3202 this.buttonCheckBatteryIgnition.Enabled = this.useConnectionState;
3205 private void buttonCheckBatteryIgnition_Click(
object sender, EventArgs e)
3207 CheckBatteryIgnitionState(this.globalRuntimeManager);
3209 SyncWithParent(this.creatorForm?.buttonCheckBatteryIgnition, this.buttonCheckBatteryIgnition);
3212 private void textBoxPollingTime_TextChanged(
object sender, EventArgs e)
3216 if (Convert.ToInt32(
this.textBoxPollingTime.Text) <= 0)
3218 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3223 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3226 SyncWithParent(this.creatorForm?.textBoxPollingTime, this.textBoxPollingTime);
3229 private void textBoxBatteryVoltageThreshold_TextChanged(
object sender, EventArgs e)
3233 if (Convert.ToInt32(
this.textBoxVoltageThreshold.Text) <= 0)
3235 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3240 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3243 SyncWithParent(this.creatorForm?.textBoxVoltageThreshold, this.textBoxVoltageThreshold);
3246 private void CheckBatteryIgnitionState(IRuntimeManager runtimeManager)
3248 if (this.useConnectionState)
3250 runtimeManager.DiagConnectionState.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text);
3251 runtimeManager.DiagConnectionState.BatteryVoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text);
3252 ClampState batteryState = runtimeManager.DiagConnectionState.BatteryState;
3253 ClampState ignitionState = runtimeManager.DiagConnectionState.IgnitionState;
3255 SetBatteryIgnitionState(batteryState, ignitionState);
3257 PrintText(
"Check DiagConnection State - BatteryState = " + batteryState.ToString() +
", IgnitionState = " + ignitionState.ToString());
3261 private void SetBatteryIgnitionState(ClampState batteryState, ClampState ignitionState)
3263 switch (batteryState)
3266 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryNotAvailable16;
3269 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOff16;
3272 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOn16;
3276 switch (ignitionState)
3279 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionNotAvailable16;
3282 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOff16;
3285 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOn16;
3290 private void ShowConnectionStateMessage(IRuntimeContext runtimeContext)
3292 if (runtimeContext !=
null)
3294 System.Media.SystemSounds.Beep.Play();
3296 switch (this.expectedConnectionState)
3299 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3300 this.PrintText(
"-- Not expected connection state: Either it is not possible to communicate with the VCI or the battery is not connected. Please connect it! --");
3301 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3304 this.PrintText(
"------------------------------------------------------------------------------------");
3305 this.PrintText(
"-- Not expected connection state: The ignition must be OFF. Please switch it OFF! --");
3306 this.PrintText(
"------------------------------------------------------------------------------------");
3309 this.PrintText(
"----------------------------------------------------------------------------------");
3310 this.PrintText(
"-- Not expected connection state: The ignition must be ON. Please switch it ON! --");
3311 this.PrintText(
"----------------------------------------------------------------------------------");
3319 private void checkBoxAdd2Output_CheckedChanged(
object sender, EventArgs e)
3321 SyncWithParent(this.creatorForm?.checkBoxAdd2Output, this.checkBoxAdd2Output);
3324 private void ParentNumericUpDownSetValue(NumericUpDown numericUpDown,
int value)
3326 var action =
new Action(() => numericUpDown.Value = value);
3327 if (numericUpDown.InvokeRequired)
3328 this.creatorForm.Invoke(action);
3333 private void comboBoxTraceLevel_SelectedIndexChanged(
object sender, EventArgs e)
3335 SyncWithParent(this.creatorForm?.comboBoxTraceLevel, this.comboBoxTraceLevel);
3337 private void txtPassword_TextChanged(
object sender, EventArgs e)
3339 SyncWithParent(this.creatorForm?.txtPassword, this.txtPassword);
3342 private void textBoxTimeout_TextChanged(
object sender, EventArgs e)
3344 SyncWithParent(this.creatorForm?.textBoxTimeout, this.textBoxTimeout);
3347 private void textBoxTraceFileMaxSize_TextChanged(
object sender, EventArgs e)
3349 if (globalRuntimeManager ==
null)
3352 PrintText(
"Set TraceFileMaxSize to " + this.textBoxTraceFileMaxSize.Text);
3356 RuntimeConfig.Instance.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text);
3357 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxSize, this.textBoxTraceFileMaxSize);
3360 catch (System.Exception ex)
3363 this.textBoxTraceFileMaxSize.Text = RuntimeConfig.Instance.TraceFileMaxSize.ToString();
3367 private void textBoxTraceFileMaxCount_TextChanged(
object sender, EventArgs e)
3369 if (globalRuntimeManager ==
null)
3372 PrintText(
"Set TraceFileMaxCount to " + this.textBoxTraceFileMaxCount.Text);
3376 RuntimeConfig.Instance.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text);
3377 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxCount, this.textBoxTraceFileMaxCount);
3379 catch (System.Exception ex)
3382 this.textBoxTraceFileMaxCount.Text = RuntimeConfig.Instance.TraceFileMaxCount.ToString();
3386 private void WebServerTimer_Tick(
object sender, EventArgs e)
3388 this.UpdateWebServerButton();
3391 int isStartWebSever = -1;
3392 private void UpdateWebServerButton()
3394 if (this.InvokeRequired)
3396 this.Invoke(
new Action(() => UpdateWebServerButton()));
3400 if (customScreenImplementation ==
null)
3402 this.buttonStartStopWebServer.Enabled =
false;
3406 this.buttonStartStopWebServer.Enabled =
true;
3407 if (DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3409 if (isStartWebSever == 1)
3414 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StopWebServer;
3415 isStartWebSever = 1;
3419 if (isStartWebSever == 0)
3424 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StartWebServer;
3425 isStartWebSever = 0;
3429 private void buttonStartStopWebServer_Click(
object sender, EventArgs e)
3431 if (this.InvokeRequired)
3433 this.Invoke(
new Action(() => buttonStartStopWebServer_Click(sender, e)));
3437 if (customScreenImplementation ==
null)
3442 if (!DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3444 customScreenImplementation.StartHtmlWebServer();
3448 customScreenImplementation.StopHtmlWebServer();
3452 private void buttonLicense_Click(
object sender, EventArgs e)
3454 LicenseForm licenseForm =
new LicenseForm(
this);
3455 licenseForm.ShowDialog(
this);
3458 public void ReloadRuntimeManager()
3462 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
3463 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
3465 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
3468 this.globalRuntimeManager = CreateRuntimeManager();
3472 catch (System.Exception ex)
3475 PrintText(
"No RuntimeManager created");
Namespace containing all interfaces for custom implementations
Definition: IBasicScreenImplementation.cs:7
Namespace which contains all supported data types
Definition: BlackBox.cs:5
Namespace containing exceptions
Definition: ConnectionStateException.cs:7
Namespace containing all objects related to licensing
Definition: IpcLicenseCheckerBase.cs:10
Namespace for browsing at OTX data structure.
Definition: IContextVariable.cs:5
Namespace containing main entries: IProject and IPlayerProject.
Definition: IPlayerProject.cs:5
Namespace containing the programming interface for browsing and execution of OTX procedures in own ap...
Definition: ApiConstants.cs:5
ExecutionStateChangeReason
Reason, why a procedure execution state was changed, e.g. Paused or Running
Definition: ExecutionStateChangeReason.cs:13
ClampState
Contains the state of a clamp
Definition: ClampState.cs:13
ExecutionState
Contains the state of the runtime context.
Definition: ExecutionState.cs:7
ExpectedState
Contains the expected state of the diagnostic connection
Definition: ExpectedState.cs:13
Namespace containing all objects for browsing and execution of OTX procedures
Definition: ApiConstants.cs:5
Namespace containing all objects which are standardized according to ISO 13209 (OTX)
Namespace containing all objects related to testing inside automotive industry