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.
11 using System.Collections.Generic;
12 using System.Diagnostics;
16 using System.Threading;
17 using System.Threading.Tasks;
18 using System.Windows.Forms;
19 using Microsoft.Win32;
21 namespace OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample
23 public partial class SampleForm : Form
25 private const int VALUE_STRING_MAX_LENGTH = 1024;
27 private UserSettings userSettings = UserSettings.Default;
30 private List<IRuntimeContext> runtimeContexts =
new List<IRuntimeContext>();
31 private Dictionary<IRuntimeContext, DateTime> runtimeContextsExecutionStartTime =
new Dictionary<IRuntimeContext, DateTime>();
33 private IProject project =
null;
34 private IPlayerProject playerProject =
null;
35 private IProcedure procedureToExecute =
null;
37 private TreeNode startupNode =
null;
39 private IRuntimeManager globalRuntimeManager =
null;
41 private HmiWindow hmiWindow;
43 private DateTime lastTime = DateTime.Now;
45 private DefaultCustomScreenImplementation customScreenImplementation;
46 private ContextVariableImplementation contextVariableImplementation;
48 private StateVariableImplementation stateVariableImplementation;
49 private DefaultMeasureImplementation measureImplementation;
50 private DefaultExternalServiceProviderImplementation serviceProviderImplementation;
52 private BasicScreenOutputImpl basicScreenOutputImpl;
53 private CustomScreenOutputImpl customScreenOutputImpl;
54 private LoggingOutputImpl loggingOutputImpl;
55 private ContextVariableOutputImpl contextVariableOutputImpl;
57 private StateVariableOutputImpl stateVariableOutputImpl;
58 private MeasureOutputImpl measureOutputImpl;
59 private I18nOutputImpl i18NOutputImpl;
60 private ExternalServiceProviderOutputImpl serviceProviderOutputImpl;
62 private SqlOutputImpl sqlOutputImpl;
63 private CommonDialogsOutputImpl commonDialogsOutputImpl;
65 private SampleForm creatorForm;
67 private string runtimeContextName;
68 private long procedureExecutionCount;
69 private long cyclicExecutionCount;
71 private static string fileVersion;
73 private static int defaultPollingTime = 500;
74 private static int defaultBatteryVoltageThreshold = 6000;
75 private bool useConnectionState =
false;
76 private bool? KL15State =
null;
79 private bool isLoadding =
false;
81 private ushort defaultDiagPort = SampleConstants.DEFAULT_DM_PORT;
82 private ushort defaultRuntimePort = SampleConstants.DEFAULT_RT_PORT;
83 private string defaultDiagPipeName = SampleConstants.DEFAULT_DM_PIPE_NAME;
84 private string defaultRuntimePipeName = SampleConstants.DEFAULT_RT_PIPE_NAME;
86 private readonly
object printTextLock =
new object();
87 private readonly
object eventListenerLock =
new object();
89 private bool cyclicExecuteAsyncIsProcessing =
false;
90 private System.Windows.Forms.Timer webServerTimer =
new System.Windows.Forms.Timer();
92 public static bool isAcceptEmptyLicenseValue;
93 private static List<SampleForm> listForms =
new List<SampleForm>();
97 fileVersion = RuntimeConfig.Instance.Version;
98 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
100 isAcceptEmptyLicenseValue = licenseKeyFromOTForOTPLicense.Equals(
"") ? false :
true;
102 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
104 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
108 String licenseKey = Setting.UserSettings.Default.LicenseKey;
109 licenseKey = LicensingUtil.Decrypt(licenseKey);
110 if (LicensingUtil.CheckLicenseKeyFormat(licenseKey))
112 LicenseManager.SetLicenseKey(licenseKey);
116 MessageBox.Show(
"There is an invalid license key format. Please set your new key in license box.",
"Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
120 SystemEvents.DisplaySettingsChanged +=
new EventHandler(SystemEvents_DisplaySettingsChanged);
123 static void SystemEvents_DisplaySettingsChanged(
object sender, EventArgs e)
127 foreach (Form frm
in listForms)
131 if (frm.InvokeRequired)
133 frm.Invoke(
new Action(() => { frm.Refresh(); }));
146 public SampleForm(
string title = SampleConstants.MAIN_INSTANCE_NAME, SampleForm creatorForm =
null)
148 this.ShowInTaskbar =
false;
150 this.creatorForm = creatorForm;
152 this.webServerTimer.Interval = 1000;
153 this.webServerTimer.Enabled =
true;
154 this.webServerTimer.Tick += WebServerTimer_Tick;
156 InitializeComponent();
160 PrintText(
"Application started");
163 private void SampleForm_Load(
object sender, EventArgs e)
165 this.Visible =
false;
166 PrintText(
"Start Initialization...");
169 InitializeSampleDefaultValues();
170 this.UpdateWebServerButton();
172 if (this.creatorForm !=
null)
174 this.checkBoxStartAllParents.Visible =
true;
175 this.checkBoxStartAllParents.Checked = this.creatorForm.checkBoxStartAllParents.Checked;
178 SetRuntimeContextName();
179 SetTitle(this.title);
180 SetLocation(this.creatorForm);
182 this.toolTip1.SetToolTip(labelProcedureExecutionTimes,
"Total procedure execution time.");
183 this.toolTip1.SetToolTip(textBoxTimeout,
"Timeout for procedure execution in milliseconds. The default value 0 means without timeout.");
184 this.toolTip1.SetToolTip(checkBoxUseConnectionState,
"Use expected connection state during procedure execution.");
185 this.toolTip1.SetToolTip(labelBatteryState,
"State of the battery (KL 30)");
186 this.toolTip1.SetToolTip(checkBoxIgnition,
"Expected ignition (KL 15) state during procedure execution");
187 this.toolTip1.SetToolTip(labelIgnitionState,
"State of the ignition (KL 15)");
188 this.toolTip1.SetToolTip(buttonCheckBatteryIgnition,
"Check current battery (KL30) and ignition (KL15) state.");
189 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.");
190 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.");
192 LoadContextFile(globalRuntimeManager);
194 PrintText(
"... Initialization finished.");
195 this.ShowInTaskbar =
true;
198 private void SampleForm_Shown(
object sender, EventArgs e)
200 this.cbFilePath.SelectionLength = 0;
204 private void SetRuntimeContextName()
206 if (this.creatorForm !=
null && !String.IsNullOrEmpty(
this.creatorForm.runtimeContextName))
208 System.Text.RegularExpressions.Match regExpMatch = System.Text.RegularExpressions.Regex.Match(this.creatorForm.runtimeContextName,
@"\d*$");
210 if (
int.TryParse(regExpMatch.Value, out number))
213 this.textBoxRuntimeContextName.Text = this.creatorForm.runtimeContextName.Substring(0, regExpMatch.Index) + number.ToString();
218 private void SetTitle(
string title)
220 if (String.IsNullOrWhiteSpace(title))
221 title = SampleConstants.MAIN_INSTANCE_NAME;
223 bool runningAsAdmin = System.Security.Principal.WindowsIdentity.GetCurrent().Owner.IsWellKnown(System.Security.Principal.WellKnownSidType.BuiltinAdministratorsSid);
225 this.Text = String.Format(
226 "emotive OTX-Runtime API for DotNet - Reference Application - Version {0} - {1} Bit - {2} - Thread-ID {3}{4}",
228 Environment.Is64BitProcess ?
"64" :
"32",
230 Thread.CurrentThread.ManagedThreadId,
231 runningAsAdmin ?
" - Administrator" :
string.Empty
234 if (!String.IsNullOrEmpty(
this.cbFilePath.Text))
235 this.Text = this.Text +
" - " + Path.GetFileName(this.cbFilePath.Text);
237 if (!String.IsNullOrEmpty(
this.runtimeContextName))
238 this.Text = this.Text +
" - " + this.runtimeContextName;
241 private const int FORM_OFFSET = 25;
243 private void SetLocation(SampleForm creatorForm)
245 if (creatorForm !=
null)
247 int xOffset = FORM_OFFSET;
248 int yOffset = FORM_OFFSET;
250 if (creatorForm.creatorForm !=
null)
252 xOffset = creatorForm.Location.X - creatorForm.creatorForm.Location.X;
253 yOffset = creatorForm.Location.Y - creatorForm.creatorForm.Location.Y;
256 this.Location =
new Point(creatorForm.Location.X + xOffset, creatorForm.Location.Y + yOffset);
257 this.Size = creatorForm.Size;
261 private void CreateCustomImpl()
263 CreateDefaultCustomImpl();
264 CreateOutputWindowCustomImpl();
267 private void CreateDefaultCustomImpl()
269 PrintText(
"Create default custom implementation");
271 customScreenImplementation =
new DefaultCustomScreenImplementation();
272 customScreenImplementation.KeyDown += CustomScreenImplementation_KeyDown;
274 contextVariableImplementation =
new ContextVariableImplementation();
275 contextVariableImplementation.ContextVariableRead += ContextVariableRead;
277 stateVariableImplementation =
new StateVariableImplementation();
278 stateVariableImplementation.StateVariableValueChanged += StateVariableValueChanged;
280 measureImplementation =
new DefaultMeasureImplementation();
281 serviceProviderImplementation =
new DefaultExternalServiceProviderImplementation();
284 private void CreateOutputWindowCustomImpl()
286 PrintText(
"Create output window custom implementation");
288 basicScreenOutputImpl =
new BasicScreenOutputImpl();
289 customScreenOutputImpl =
new CustomScreenOutputImpl();
290 loggingOutputImpl =
new LoggingOutputImpl();
291 contextVariableOutputImpl =
new ContextVariableOutputImpl();
293 stateVariableOutputImpl =
new StateVariableOutputImpl();
294 measureOutputImpl =
new MeasureOutputImpl();
295 i18NOutputImpl =
new I18nOutputImpl();
296 serviceProviderOutputImpl =
new ExternalServiceProviderOutputImpl();
298 sqlOutputImpl =
new SqlOutputImpl();
299 commonDialogsOutputImpl =
new CommonDialogsOutputImpl();
301 basicScreenOutputImpl.LogEvent += PrintText;
302 customScreenOutputImpl.LogEvent += PrintText;
303 loggingOutputImpl.LogEvent += PrintText;
304 contextVariableOutputImpl.LogEvent += PrintText;
306 stateVariableOutputImpl.LogEvent += PrintText;
307 measureOutputImpl.LogEvent += PrintText;
308 i18NOutputImpl.LogEvent += PrintText;
309 serviceProviderOutputImpl.LogEvent += PrintText;
311 sqlOutputImpl.LogEvent += PrintText;
312 commonDialogsOutputImpl.LogEvent += PrintText;
315 private void InitializeSampleDefaultValues()
317 PrintText(
"Initialize default values");
319 this.comboBoxTraceLevel.Items.AddRange(Enum.GetNames(typeof(TraceLevels)));
322 treeViewOtxProject.ImageList = imageList1;
324 textBoxRtPortPipe.Name = SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME;
325 textBoxDiagPortPipe.Name = SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME;
329 this.EnableConnectionState();
332 private void LoadSetting()
334 SaveSettingUtil.Reload();
339 SetupTraceFileProfilerMaxCountAndSize();
342 SetupDefaultPortAndPipeName();
344 cbFilePath.Text = userSettings.Ptx_Ppx_Directory;
345 if (!String.IsNullOrEmpty(userSettings.Ptx_Ppx_DirectoryList))
347 this.cbFilePath.Items.AddRange(userSettings.Ptx_Ppx_DirectoryList.Split(
';'));
349 AddComboBoxFileOrPath(this.cbFilePath);
351 SetupCustomImplType();
353 SetupWindowLocation();
355 checkBoxAsyncExecution.Checked = userSettings.Asynchron;
356 checkBoxCyclicExecution.Checked = userSettings.Cyclic;
357 checkBoxCyclicReload.Checked = userSettings.CyclicReload;
358 checkBoxNewRuntimeManager.Checked = userSettings.NewRunTimeManager;
359 checkBoxAdd2Output.Checked = userSettings.AddMessageToOutput;
360 checkBoxStartAllParents.Checked = userSettings.StartAllParents;
363 checkBoxUseConnectionState.Checked = userSettings.ConnectionState;
364 checkBoxIgnition.CheckState = userSettings.Ignition == 1 ? CheckState.Checked : (userSettings.Ignition == 0 ? CheckState.Unchecked : CheckState.Indeterminate);
366 SetupVoltageThreshold();
369 this.textBoxRuntimeContextName.Text = userSettings.RuntimeContextName.ToString();
371 catch (System.Exception e)
373 PrintText(e.Message);
374 userSettings.Reset();
378 bool isPathChanging =
false;
379 private void AddComboBoxFileOrPath(ComboBox comboBox)
381 if (comboBox !=
null && !isPathChanging)
383 isPathChanging =
true;
385 string path = comboBox.Text;
387 if (Directory.Exists(path) || File.Exists(path))
389 while (comboBox.Items.Contains(path))
391 comboBox.Items.Remove(path);
394 while (comboBox.Items.Contains(path.TrimEnd(
new char[] {
'/',
'\\' })))
396 comboBox.Items.Remove(path.TrimEnd(
new char[] {
'/',
'\\' }));
399 path = path.TrimEnd(
new char[] {
'/',
'\\' });
401 comboBox.Items.Insert(0, path);
402 comboBox.Text = path;
403 comboBox.SelectAll();
406 isPathChanging =
false;
410 private void SetupTraceFileProfilerMaxCountAndSize()
414 RuntimeConfig.Instance.TraceFileMaxCount = userSettings.TraceFileMaxCount;
415 textBoxTraceFileMaxCount.Text = userSettings.TraceFileMaxCount.ToString();
417 catch (System.Exception e)
419 textBoxTraceFileMaxCount.Text = RuntimeConfig.Instance.TraceFileMaxCount.ToString();
424 RuntimeConfig.Instance.TraceFileMaxSize = userSettings.TraceFileMaxSize;
425 textBoxTraceFileMaxSize.Text = userSettings.TraceFileMaxSize.ToString();
427 catch (System.Exception e)
429 textBoxTraceFileMaxSize.Text = RuntimeConfig.Instance.TraceFileMaxSize.ToString();
434 RuntimeConfig.Instance.Profiling = userSettings.Profiling;
435 checkBoxProfiling.Checked = userSettings.Profiling;
437 catch (System.Exception e)
439 checkBoxProfiling.Checked = RuntimeConfig.Instance.Profiling;
444 RuntimeConfig.Instance.ProfilingMaxFileSize = userSettings.ProfilingMaxFileSize;
445 textBoxProfilingSize.Text = userSettings.ProfilingMaxFileSize.ToString();
447 catch (System.Exception e)
449 textBoxProfilingSize.Text = RuntimeConfig.Instance.ProfilingMaxFileSize.ToString();
453 private void SetupDefaultPortAndPipeName()
455 defaultDiagPort = userSettings.DiagManagerPort;
456 defaultRuntimePort = userSettings.RuntimePort;
458 defaultDiagPipeName = userSettings.DiagManagerPipeName;
459 defaultRuntimePipeName = userSettings.RuntimePipeName;
461 IpcTypes ipcTypes = IpcTypes.SOCKET;
462 Enum.TryParse<IpcTypes>(userSettings.IpcType, out ipcTypes);
464 if (comboBoxIpcType.Items.Count == 0)
466 comboBoxIpcType.Items.Add(IpcTypes.SOCKET);
467 comboBoxIpcType.Items.Add(IpcTypes.PIPE);
470 comboBoxIpcType.SelectedItem = ipcTypes;
473 private void SetupTraceLevel()
475 RuntimeConfig.Instance.TraceLevel = userSettings.TraceLevels;
476 comboBoxTraceLevel.SelectedItem = RuntimeConfig.Instance.TraceLevel.ToString();
479 private void SetupTraceFolder()
481 if (userSettings.TracingDirectory !=
string.Empty)
482 RuntimeConfig.Instance.TraceFolder = userSettings.TracingDirectory;
484 textBoxTraceFolder.Text = RuntimeConfig.Instance.TraceFolder;
487 private void SetupCustomImplType()
489 if (userSettings.CustomImplTypes == CustomImplTypes.OutputImpl)
491 radioButtonOuputWindow.Checked =
true;
493 else if (userSettings.CustomImplTypes == CustomImplTypes.NoCustom)
495 radioButtonNoCustomImplementation.Checked =
true;
499 radioButtonDefaultImplementation.Checked =
true;
503 private void SetupWindowSize()
505 int width = userSettings.WindowWidth;
506 int height = userSettings.WindowHeight;
507 this.Size =
new Size(width, height);
510 private void SetupWindowLocation()
512 int locationX = userSettings.WindowLocationX;
513 int locationY = userSettings.WindowLocationY;
514 Point location =
new Point(locationX, locationY);
516 if (CheckFormIsInBound(location))
518 this.Location = location;
522 this.CenterToScreen();
525 private bool CheckFormIsInBound(Point location)
529 Screen formContainScreens = Screen.AllScreens.Where(screen => screen.Bounds.Contains(location) ==
true).FirstOrDefault();
531 return formContainScreens !=
null;
533 catch (System.Exception)
539 private void SetupTimeOut()
541 string timeOutString = userSettings.TimeOut.ToString();
542 this.textBoxTimeout.Text = timeOutString;
545 private void SetupPollingTime()
547 string pollingTimeString = userSettings.PollingTime.ToString();
548 this.textBoxPollingTime.Text = pollingTimeString;
551 private void SetupVoltageThreshold()
553 string voltageThreshold = userSettings.VoltageThreshold.ToString();
554 this.textBoxVoltageThreshold.Text = voltageThreshold;
557 private void comboBoxIpcType_SelectedValueChanged(
object sender, EventArgs e)
560 textBoxDiagPortPipe.TextChanged -= textBoxPortPipe_TextChanged;
561 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
565 case IpcTypes.SOCKET:
567 portPipeLabel.Text =
"Runner / DiagManager Ports";
569 textBoxDiagPortPipe.Text = defaultDiagPort.ToString();
570 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
572 textBoxRtPortPipe.Text = defaultRuntimePort.ToString();
577 portPipeLabel.Text =
"Runner / DiagManager Pipes";
579 textBoxDiagPortPipe.Text = defaultDiagPipeName;
580 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
582 textBoxRtPortPipe.Text = defaultRuntimePipeName;
590 private void textBoxPortPipe_TextChanged(
object sender, EventArgs e)
592 PrintText(
"Create RuntimeManager...");
596 this.globalRuntimeManager = CreateRuntimeManager();
598 catch (System.Exception ex)
600 switch ((sender as TextBox).Name)
602 case SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME:
604 PrintText(String.Format(
"Invalid Otx Runtime {0}", IpcPortPipeString()));
607 case SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME:
609 PrintText(String.Format(
"Invalid Diag Manager {0}", IpcPortPipeString()));
617 PrintText(
"No RuntimeManager created");
620 if (this.globalRuntimeManager ==
null)
622 PrintText(
"RuntimeManager is null.");
626 private IRuntimeManager CreateRuntimeManager()
628 IRuntimeManager runtimeManager =
null;
632 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
634 case IpcTypes.SOCKET:
636 runtimeManager = CreateSocketRuntimeManager();
642 runtimeManager = CreatePipeRuntimeManager();
647 PrintText($
"... {ipcType} RuntimeManager created (MinBinVersion: {RuntimeConfig.Instance.MinBinVersion})");
649 InitializeRuntimeEvents(runtimeManager);
650 SetCustomImplementation(runtimeManager);
652 catch (InvalidLicenseException ex)
655 PrintText(
"... No RuntimeManager created.");
657 return runtimeManager;
660 return runtimeManager;
663 private string IpcPortPipeString()
665 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
667 case IpcTypes.SOCKET:
668 return SampleConstants.PORT_STRING;
670 return SampleConstants.PIPE_STRING;
677 private IRuntimeManager CreateSocketRuntimeManager()
679 ushort rtPort = Convert.ToUInt16(textBoxRtPortPipe.Text);
683 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort);
687 ushort diagPort = Convert.ToUInt16(textBoxDiagPortPipe.Text);
688 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort, diagPort);
692 private IRuntimeManager CreatePipeRuntimeManager()
696 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text);
700 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text, textBoxDiagPortPipe.Text);
704 private bool NoDiag()
706 return String.IsNullOrWhiteSpace(textBoxDiagPortPipe.Text);
709 private void InitializeRuntimeEvents(IRuntimeManager runtimeManager)
711 if (runtimeManager ==
null)
714 runtimeManager.ProcedurePending -= ProcedurePending;
715 runtimeManager.ProcedureStarted -= ProcedureStarted;
716 runtimeManager.ProcedurePaused -= ProcedurePaused;
717 runtimeManager.ProcedureContinued -= ProcedureContinued;
718 runtimeManager.ProcedureFinished -= ProcedureFinished;
719 runtimeManager.ProcedureAborted -= ProcedureAborted;
720 runtimeManager.ProcedureStopped -= ProcedureStopped;
721 runtimeManager.ProcedureTimeout -= ProcedureTimeout;
722 runtimeManager.DiagConnectionStateChanged -= DiagConnectionStateChanged;
723 runtimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
725 runtimeManager.ProcedurePending += ProcedurePending;
726 runtimeManager.ProcedureStarted += ProcedureStarted;
727 runtimeManager.ProcedurePaused += ProcedurePaused;
728 runtimeManager.ProcedureContinued += ProcedureContinued;
729 runtimeManager.ProcedureFinished += ProcedureFinished;
730 runtimeManager.ProcedureAborted += ProcedureAborted;
731 runtimeManager.ProcedureStopped += ProcedureStopped;
732 runtimeManager.ProcedureTimeout += ProcedureTimeout;
733 runtimeManager.DiagConnectionStateChanged += DiagConnectionStateChanged;
734 runtimeManager.InOutParameterValueChanged += InOutParameterValueChanged;
736 PrintText(
"Initialization of runtime events finished");
739 private void radioButtonCustomImpl_CheckedChanged(
object sender =
null, System.EventArgs e =
null)
741 if (this.globalRuntimeManager ==
null)
744 if (sender !=
null && (sender as RadioButton).Checked ==
false)
747 this.SetCustomImplementation(this.globalRuntimeManager);
750 private void SetCustomImplementation(IRuntimeManager runtimeManager)
752 if (runtimeManager ==
null)
755 var currentCustomImpl = GetCurrentCustomImpl();
757 switch (currentCustomImpl)
759 case CustomImplTypes.OutputImpl:
761 SetOutputWindowImplementation(runtimeManager);
764 case CustomImplTypes.DefaultCustomImpl:
766 SetDefaultCustomImplementation(runtimeManager);
769 case CustomImplTypes.NoCustom:
771 RemoveCustomImplementation(runtimeManager);
778 if (currentCustomImpl != CustomImplTypes.None)
780 PrintText(
"Set up custom implementation finished");
784 private CustomImplTypes GetCurrentCustomImpl()
786 if (radioButtonOuputWindow.Checked)
787 return CustomImplTypes.OutputImpl;
788 else if (radioButtonDefaultImplementation.Checked)
789 return CustomImplTypes.DefaultCustomImpl;
790 else if (radioButtonNoCustomImplementation.Checked)
791 return CustomImplTypes.NoCustom;
793 return CustomImplTypes.None;
796 private void SetOutputWindowImplementation(IRuntimeManager runtimeManager)
798 if (runtimeManager ==
null)
801 runtimeManager.SetCustomImplementation(basicScreenOutputImpl);
802 runtimeManager.SetCustomImplementation(customScreenOutputImpl);
803 runtimeManager.SetCustomImplementation(loggingOutputImpl);
804 runtimeManager.SetCustomImplementation(contextVariableOutputImpl);
806 runtimeManager.SetCustomImplementation(stateVariableOutputImpl);
807 runtimeManager.SetCustomImplementation(measureOutputImpl);
808 runtimeManager.SetCustomImplementation(i18NOutputImpl);
809 runtimeManager.SetCustomImplementation(serviceProviderOutputImpl);
811 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
812 runtimeManager.SetCustomImplementation(commonDialogsOutputImpl);
815 private void SetDefaultCustomImplementation(IRuntimeManager runtimeManager)
817 if (runtimeManager ==
null)
820 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
821 runtimeManager.SetCustomImplementation(customScreenImplementation);
822 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
823 runtimeManager.SetCustomImplementation(contextVariableImplementation);
825 runtimeManager.SetCustomImplementation(stateVariableImplementation);
826 runtimeManager.SetCustomImplementation(measureImplementation);
827 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
828 runtimeManager.SetCustomImplementation(serviceProviderImplementation);
830 runtimeManager.SetCustomImplementation(sqlOutputImpl);
831 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
834 private void RemoveCustomImplementation(IRuntimeManager runtimeManager)
836 if (runtimeManager ==
null)
839 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
840 runtimeManager.SetCustomImplementation((ICustomScreenImplementation)
null);
841 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
842 runtimeManager.SetCustomImplementation((IContextVariableImplementation)
null);
844 runtimeManager.SetCustomImplementation((IStateVariableImplementation)
null);
845 runtimeManager.SetCustomImplementation((IMeasureImplementation)
null);
846 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
847 runtimeManager.SetCustomImplementation((IExternalServiceProviderImplementation)
null);
849 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
850 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
853 private void ProcedurePending(IRuntimeContext context)
857 Invoke(
new MethodInvoker(delegate ()
859 ProcedurePending(context);
864 lock (eventListenerLock)
866 this.PrintText(
string.Format(
"Event ProcedurePending occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
867 UpdateExecutionState(context);
868 ShowConnectionStateMessage(context);
872 private void ProcedureStarted(IRuntimeContext context)
876 Invoke(
new MethodInvoker(delegate ()
878 ProcedureStarted(context);
883 lock (eventListenerLock)
885 this.PrintText(
string.Format(
"Event ProcedureStarted occurred - {0} - ExecutionState = {1} - RuntimeId = {2} - ProcessId = {3}", context.Procedure.FullName, context.ExecutionState.ToString(), context.RuntimeId, context.ProcessId));
886 UpdateExecutionState(context);
890 private void ProcedurePaused(IRuntimeContext context, ExecutionStateChangeReason reason)
894 Invoke(
new MethodInvoker(delegate ()
896 ProcedurePaused(context, reason);
901 lock (eventListenerLock)
903 this.PrintText(
string.Format(
"Event ProcedurePaused occurred - {0} - ExecutionState = {1} - ExecutionStateChangeReason = {2}", context.Procedure.FullName, context.ExecutionState.ToString(), reason.ToString()));
904 UpdateExecutionState(context, reason);
907 ShowConnectionStateMessage(context);
912 private void ProcedureContinued(IRuntimeContext context)
916 Invoke(
new MethodInvoker(delegate ()
918 ProcedureContinued(context);
923 lock (eventListenerLock)
925 this.PrintText(
string.Format(
"Event ProcedureContinued occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
926 UpdateExecutionState(context);
930 private void ProcedureStopped(IRuntimeContext context)
934 Invoke(
new MethodInvoker(delegate ()
936 ProcedureStopped(context);
941 lock (eventListenerLock)
943 this.PrintText(
string.Format(
"Event ProcedureStopped occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
944 UpdateExecutionState(context);
948 private void ProcedureTimeout(IRuntimeContext context)
952 Invoke(
new MethodInvoker(delegate ()
954 ProcedureTimeout(context);
959 lock (eventListenerLock)
961 cyclicExecuteAsyncIsProcessing =
false;
962 this.PrintText(
string.Format(
"Event ProcedureTimeout occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
963 UpdateExecutionState(context);
967 private void DiagConnectionStateChanged(ClampState batteryState, ClampState ignitionState)
971 Invoke(
new MethodInvoker(delegate ()
973 DiagConnectionStateChanged(batteryState, ignitionState);
978 lock (eventListenerLock)
980 this.PrintText(
string.Format(
"Event DiagConnectionStateChanged occurred - BatteryState = {0}, IgnitionState = {1}", batteryState.ToString(), ignitionState.ToString()));
981 System.Media.SystemSounds.Beep.Play();
983 SetBatteryIgnitionState(batteryState, ignitionState);
988 private void ProcedureFinished(IRuntimeContext context)
992 Invoke(
new MethodInvoker(delegate ()
994 ProcedureFinished(context);
999 lock (eventListenerLock)
1001 IProcedureParameter procedureParameter;
1002 string procedureName = context.Procedure.FullName;
1003 string parameterOuput;
1005 for (
int i = 0; i < context.Procedure.Parameters.Count(); i++)
1007 procedureParameter = context.Procedure.Parameters.ElementAt(i);
1008 parameterOuput =
"Parameter Changed - " + procedureParameter.Name +
"(" + procedureParameter.DataType +
") = ";
1010 if (procedureParameter.Value !=
null)
1012 parameterOuput += ShortenedValueString(procedureParameter);
1016 parameterOuput +=
null;
1019 this.PrintText(parameterOuput);
1022 UpdateGridviewParameter(context.Procedure);
1024 this.PrintText(
string.Format(
"ProcedureFinished({0}) ExecutionState({1}) - Execution duration {2} - Running time {3} - Used memory {4})",
1025 context.Procedure.FullName,
1026 context.ExecutionState.ToString(),
1027 (DateTime.Now -
this.runtimeContextsExecutionStartTime[context]).ToString(
"hh':'mm':'ss','fff"),
1028 TimeSpan.FromMilliseconds(context.ExecutionTime).ToString(
"hh':'mm':'ss','fff"),
1029 string.Format(
"{0:0,0} kB", context.ProcessMemory / 1024))
1032 UpdateExecutionState(context);
1034 cyclicExecuteAsyncIsProcessing =
false;
1038 private void ProcedureAborted(IRuntimeContext context)
1042 Invoke(
new MethodInvoker(delegate ()
1044 ProcedureAborted(context);
1049 this.PrintText(
string.Format(
"ProcedureAborted({0}) ExecutionState({1})", context.Procedure.FullName, context.ExecutionState.ToString()));
1051 if (context.HasRuntimeException)
1053 PrintException(context.RuntimeException,
"Reason: API ");
1056 if (context.HasOtxException)
1058 PrintException(context.OtxException,
"Reason: OTX ");
1060 cyclicExecuteAsyncIsProcessing =
false;
1061 UpdateExecutionState(context);
1064 private void UpdateExecutionState(IRuntimeContext context, ExecutionStateChangeReason? reason =
null)
1066 if (context !=
null)
1068 switch (context.ExecutionState)
1072 this.procedureExecutionCount++;
1074 AddRuntimeContext(context);
1075 DisplayProcedureExecutionState(context);
1077 this.buttonExecuteMain.Enabled = checkBoxAsyncExecution.Checked;
1078 this.buttonExecuteSelectedProcedure.Enabled = checkBoxAsyncExecution.Checked;
1080 UpdateExecutionStateButtons(
true);
1081 UpdatePauseButton(
true);
1087 this.procedureExecutionCount--;
1090 DisplayProcedureExecutionState(context);
1099 DisplayProcedureExecutionState(context);
1100 UpdateExecutionStateButtons(
true);
1101 UpdatePauseButton(
true,
false);
1107 this.procedureExecutionCount--;
1109 RemoveRuntimeContext(context);
1110 DisplayProcedureExecutionState(context);
1112 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
1113 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
1115 UpdateExecutionStateButtons(
false);
1116 UpdatePauseButton(
true,
false);
1118 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1119 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1125 this.procedureExecutionCount--;
1127 RemoveRuntimeContext(context);
1128 DisplayProcedureExecutionState(context);
1130 this.buttonExecuteMain.Enabled =
true;
1131 this.buttonExecuteSelectedProcedure.Enabled =
true;
1133 UpdateExecutionStateButtons(
false);
1134 UpdatePauseButton(
true,
false);
1136 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1137 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1143 this.procedureExecutionCount--;
1145 RemoveRuntimeContext(context);
1146 DisplayProcedureExecutionState(context);
1148 this.buttonExecuteMain.Enabled =
true;
1149 this.buttonExecuteSelectedProcedure.Enabled =
true;
1151 UpdateExecutionStateButtons(
false);
1152 UpdatePauseButton(
true,
false);
1154 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1155 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1160 System.Media.SystemSounds.Hand.Play();
1162 this.procedureExecutionCount--;
1164 RemoveRuntimeContext(context);
1165 DisplayProcedureExecutionState(context);
1167 this.buttonExecuteMain.Enabled =
true;
1168 this.buttonExecuteSelectedProcedure.Enabled =
true;
1170 UpdateExecutionStateButtons(
false);
1171 UpdatePauseButton(
true,
false);
1173 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1174 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1179 StartStopUpdateGuiTimer();
1183 private void StartStopUpdateGuiTimer()
1185 if (this.procedureExecutionCount <= 0)
1187 this.updateGuiTimer.Enabled =
false;
1188 this.labelSeparator1.Visible =
false;
1189 this.labelProcedureExecutionTimes.Visible =
false;
1191 else if (!this.updateGuiTimer.Enabled)
1193 this.updateGuiTimer.Enabled =
true;
1197 private void updateGuiTimer_Tick(
object sender, EventArgs e)
1199 DisplayProcedureExecutionTimes();
1202 private void DisplayProcedureExecutionTimes()
1204 string text =
string.Empty;
1206 if (this.runtimeContextsExecutionStartTime.Count > 0)
1208 foreach (var item
in this.runtimeContextsExecutionStartTime)
1210 var duration = DateTime.Now - item.Value;
1211 text +=
string.Format(
"{0}: {1} | ", item.Key.Procedure.Name, duration.ToString(
"hh':'mm':'ss"));
1213 text = text.TrimEnd(
new char[] {
' ',
'|' });
1216 this.labelProcedureExecutionTimes.Text = text;
1217 this.labelSeparator1.Visible =
true;
1218 this.labelProcedureExecutionTimes.Visible =
true;
1221 private void InOutParameterValueChanged(IRuntimeContext context, IProcedureInOutParameter parameter)
1225 Invoke(
new MethodInvoker(delegate ()
1227 InOutParameterValueChanged(context, parameter);
1232 lock (eventListenerLock)
1236 string valueStr = ShortenedValueString(parameter);
1237 string message = String.Format(
"Parameter '{0}' new value = {1}", parameter.Name, valueStr);
1239 UpdateGridviewParameter(parameter);
1241 catch (InvalidCastException ex)
1243 PrintText(ex.Message);
1248 private static string ShortenedValueString(IProcedureParameter parameter)
1252 var valueStr = ValueConverter.Value2String(parameter.Value);
1253 if (valueStr.Length > VALUE_STRING_MAX_LENGTH)
1254 return valueStr.Substring(0, VALUE_STRING_MAX_LENGTH) +
"...";
1261 return string.Empty;
1264 private void UpdatePauseButton(
bool pauseAvailable,
bool enabled =
true)
1266 this.buttonPause.Enabled = enabled;
1267 this.buttonPause.Checked = !pauseAvailable;
1268 this.buttonPause.Image = pauseAvailable
1269 ? global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Pause
1270 : global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Continue;
1273 private void UpdateExecutionStateButtons(
bool wasExecuted)
1275 if (this.useConnectionState)
1277 this.labelTimeout.Enabled = !wasExecuted;
1278 this.textBoxTimeout.Enabled = !wasExecuted;
1279 this.checkBoxUseConnectionState.Enabled = !wasExecuted;
1280 this.labelExpectedState.Enabled = !wasExecuted;
1281 this.checkBoxIgnition.Enabled = !wasExecuted;
1282 this.labelPollingTime.Enabled = !wasExecuted;
1283 this.textBoxPollingTime.Enabled = !wasExecuted;
1284 this.labelVoltageThreshold.Enabled = !wasExecuted;
1285 this.textBoxVoltageThreshold.Enabled = !wasExecuted;
1290 if (checkBoxAsyncExecution.Checked ==
false)
1292 this.buttonExecuteMain.Enabled =
false;
1293 this.buttonExecuteSelectedProcedure.Enabled =
false;
1296 this.buttonStop.Enabled =
true;
1300 if (project !=
null && project.MainProcedure !=
null)
1302 this.buttonExecuteMain.Enabled =
true;
1305 this.buttonExecuteSelectedProcedure.Enabled =
true;
1307 this.buttonStop.Enabled =
false;
1311 private void DisplayProcedureExecutionState(IRuntimeContext context,
string errorMessage =
"")
1313 if (
string.IsNullOrEmpty(errorMessage))
1315 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Info16;
1317 if (this.procedureExecutionCount <= 0)
1319 this.procedureExecutionCount = 0;
1322 this.labelProcedureExecutionState.Text =
"Execution is paused, click \"Continue\"...";
1326 this.labelProcedureExecutionState.Text =
"Select a procedure and click \"Start\"...";
1329 else if (this.procedureExecutionCount == 1)
1331 this.labelProcedureExecutionState.Text =
"1 Procedure is running";
1335 this.labelProcedureExecutionState.Text =
string.Format(
"{0} Procedures are running", this.procedureExecutionCount);
1340 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Error16;
1341 this.labelProcedureExecutionState.Text = errorMessage;
1344 private void SyncWithParent(
object parentControl,
object control =
null,
bool newThread =
false)
1346 if (parentControl !=
null)
1348 if (this.creatorForm !=
null && this.checkBoxStartAllParents.Checked)
1350 if (parentControl is Button)
1354 ThreadPool.QueueUserWorkItem(state => ParentButtonClick(parentControl as Button));
1358 ParentButtonClick(parentControl as Button);
1361 else if (parentControl is TextBox && control !=
null)
1363 string text = (control as TextBox).Text;
1366 ThreadPool.QueueUserWorkItem(state => ParentTextBoxSetText(parentControl as TextBox, text));
1370 ParentTextBoxSetText(parentControl as TextBox, text);
1373 else if (parentControl is CheckBox && control !=
null)
1375 CheckState checkState = (control as CheckBox).CheckState;
1378 ThreadPool.QueueUserWorkItem(state => ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState));
1382 ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState);
1385 else if (parentControl is ComboBox && control !=
null)
1387 int index = (control as ComboBox).SelectedIndex;
1390 ThreadPool.QueueUserWorkItem(state => ParentComboBoxSetIndex(parentControl as ComboBox, index));
1394 ParentComboBoxSetIndex(parentControl as ComboBox, index);
1397 else if (parentControl is NumericUpDown && control !=
null)
1399 int value = decimal.ToInt32((control as NumericUpDown).Value);
1401 ThreadPool.QueueUserWorkItem(state => ParentNumericUpDownSetValue(parentControl as NumericUpDown, value));
1403 ParentNumericUpDownSetValue(parentControl as NumericUpDown, value);
1409 private void ParentButtonClick(Button button)
1411 if (button.InvokeRequired)
1413 this.creatorForm.Invoke(
new Action(() => button.PerformClick()));
1417 button.PerformClick();
1421 private void ParentTextBoxSetText(TextBox textBox,
string text)
1423 if (textBox.InvokeRequired)
1425 this.creatorForm.Invoke(
new Action(() => textBox.Text = text));
1429 textBox.Text = text;
1433 private void ParentCheckBoxSetCheckState(CheckBox checkBox, CheckState checkState)
1435 if (checkBox.InvokeRequired)
1437 this.creatorForm.Invoke(
new Action(() => checkBox.CheckState = checkState));
1441 checkBox.CheckState = checkState;
1445 private void ParentComboBoxSetIndex(ComboBox comboBox,
int index)
1447 if (comboBox.InvokeRequired)
1449 this.creatorForm.Invoke(
new Action(() => comboBox.SelectedIndex = index));
1453 comboBox.SelectedIndex = index;
1457 private void buttonBrowseTraceFolder_Click(
object sender, EventArgs e)
1459 folderBrowserDialog1.SelectedPath = this.textBoxTraceFolder.Text;
1460 folderBrowserDialog1.ShowNewFolderButton =
true;
1462 DialogResult result = folderBrowserDialog1.ShowDialog();
1463 if (result == DialogResult.OK)
1465 this.textBoxTraceFolder.Text = folderBrowserDialog1.SelectedPath;
1469 private void buttonOpenTraceFolder_Click(
object sender, EventArgs e)
1471 string path = this.textBoxTraceFolder.Text;
1472 if (Directory.Exists(path))
1474 Process.Start(path);
1479 private void textBoxTraceFolder_TextChanged(
object sender, EventArgs e)
1481 if (this.globalRuntimeManager ==
null)
1484 string path = this.textBoxTraceFolder.Text;
1486 if (path != RuntimeConfig.Instance.TraceFolder)
1488 if (Directory.Exists(path))
1490 RuntimeConfig.Instance.TraceFolder = textBoxTraceFolder.Text;
1491 this.buttonOpenTraceFolder.Enabled =
true;
1493 PrintText(
"Set trace folder to " + RuntimeConfig.Instance.TraceFolder);
1497 this.buttonOpenTraceFolder.Enabled =
false;
1502 this.buttonOpenTraceFolder.Enabled =
true;
1505 SyncWithParent(this.creatorForm?.textBoxTraceFolder, this.textBoxTraceFolder);
1509 private void comboBoxTraceLevel_SelectedValueChanged(
object sender, EventArgs e)
1511 if (this.globalRuntimeManager ==
null)
1514 var traceLevel = (
TraceLevels)comboBoxTraceLevel.SelectedIndex;
1515 if (traceLevel == RuntimeConfig.Instance.TraceLevel)
1518 RuntimeConfig.Instance.TraceLevel = traceLevel;
1519 PrintText(
"Updated trace level");
1522 private void buttonBrowseFile_Click(
object sender, EventArgs e)
1524 DialogResult result = openFileDialog1.ShowDialog();
1525 if (result == DialogResult.OK)
1527 cbFilePath.Text = openFileDialog1.FileName;
1529 this.buttonReload.PerformClick();
1533 private void cbFilePath_TextChanged(
object sender, EventArgs e)
1535 AddComboBoxFileOrPath(cbFilePath);
1537 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1539 buttonReload.Enabled =
false;
1543 buttonReload.Enabled =
true;
1546 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1549 private void cbFilePath_SelectedValueChanged(
object sender, EventArgs e)
1551 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1553 buttonReload.Enabled =
false;
1557 buttonReload.Enabled =
true;
1558 if (isPathChanging ==
false)
1560 this.buttonReload.PerformClick();
1564 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1567 private void buttonReload_Click(
object sender, EventArgs e)
1569 this.LoadContextFile(this.globalRuntimeManager);
1571 SyncWithParent(this.creatorForm?.buttonReload);
1574 private void LoadContextFile(IRuntimeManager runtimeManager)
1576 PrintText(
"Load '" + cbFilePath.Text +
"'...");
1578 if (runtimeManager ==
null)
1580 PrintText(
"... No RuntimeManager exists!");
1584 if (String.IsNullOrWhiteSpace(cbFilePath.Text.Trim()))
1586 PrintText(
"... wrong file name.");
1590 SetTitle(this.title);
1595 this.isLoadding =
true;
1596 this.playerProject =
null;
1597 this.project =
null;
1598 this.contextVariableImplementation.ResetAllValues();
1599 this.stateVariableImplementation.ResetAllValues();
1602 if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ptx"))
1604 this.project = LoadPtx(runtimeManager);
1606 if (this.project !=
null)
1608 PrintText(
"... Project '" + project.Name +
"' successfully loaded.");
1610 ClearCustomImplemetationCaches();
1612 this.LoadPackage(this.project);
1614 ReadSettings(this.project.Settings);
1616 this.isLoadding =
false;
1620 else if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ppx"))
1622 this.playerProject = LoadPpx(runtimeManager);
1624 if (this.playerProject !=
null)
1626 ClearCustomImplemetationCaches();
1628 PrintText(
"... Player '" + playerProject.Name +
"' successfully loaded.");
1630 foreach (IProject item
in this.playerProject.Projects)
1633 this.LoadPackage(item);
1636 ReadSettings(this.playerProject.Settings);
1638 this.isLoadding =
false;
1643 catch (System.Exception ex)
1648 this.isLoadding =
false;
1651 private void ClearSampleGUI()
1653 this.treeViewOtxProject.Nodes.Clear();
1654 this.gridViewParameter.Rows.Clear();
1655 this.gridViewContext.Rows.Clear();
1656 this.gridViewState.Rows.Clear();
1657 this.gridViewSettings.Rows.Clear();
1660 private void ClearCustomImplemetationCaches()
1662 if (this.contextVariableImplementation !=
null)
1663 this.contextVariableImplementation.ResetAllValues();
1665 if (this.contextVariableOutputImpl !=
null)
1666 this.contextVariableOutputImpl.ResetAllValues();
1668 if (this.stateVariableImplementation !=
null)
1669 this.stateVariableImplementation.ResetAllValues();
1675 private IProject LoadPtx(IRuntimeManager runtimeManager)
1677 IProject project =
null;
1679 if (runtimeManager.IsProtected(cbFilePath.Text))
1681 project = runtimeManager.LoadPtx(cbFilePath.Text, txtPassword.Text.Trim());
1685 project = runtimeManager.LoadPtx(cbFilePath.Text);
1688 if (project.MainProcedure !=
null)
1690 buttonExecuteMain.Enabled =
true;
1697 private IPlayerProject LoadPpx(IRuntimeManager runtimeManager)
1699 IPlayerProject playerProject =
null;
1701 if (runtimeManager.IsProtected(cbFilePath.Text))
1703 playerProject = runtimeManager.LoadPpx(cbFilePath.Text, txtPassword.Text.Trim());
1707 playerProject = runtimeManager.LoadPpx(cbFilePath.Text);
1710 return playerProject;
1714 private void LoadPackage(IProject project)
1716 PrintText(
"Browse project...");
1718 IPackage[] packages = project.Packages;
1719 if (packages ==
null)
1721 IDocument document = project.StartupDocument;
1722 this.treeViewOtxProject.Nodes.Add(CreateDocumentNode(document));
1726 string treeNodeText = project.Name;
1727 if (!String.IsNullOrWhiteSpace(project.Version))
1728 treeNodeText = String.Format(
"{0} ({1})", treeNodeText, project.Version);
1730 TreeNode root =
new TreeNode(treeNodeText);
1731 root.ImageKey = root.SelectedImageKey =
"ODFProject.bmp";
1732 foreach (IPackage pack
in packages)
1734 root.Nodes.Add(this.CreatePackageNode(pack));
1737 this.treeViewOtxProject.Nodes.Add(root);
1740 this.treeViewOtxProject.Enabled = this.gridViewParameter.Enabled =
true;
1741 this.treeViewOtxProject.ExpandAll();
1742 this.treeViewOtxProject.SelectedNode = startupNode;
1743 this.treeViewOtxProject.Focus();
1745 PrintText(
"... project browsing finished.");
1749 private TreeNode CreateDocumentNode(IDocument doc)
1751 TreeNode documentNode =
new TreeNode(doc.Name);
1752 documentNode.Tag = doc;
1753 documentNode.ImageKey = documentNode.SelectedImageKey =
"DocumentOTX16.bmp";
1756 documentNode.Text +=
" (StartUp)";
1759 foreach (IProcedure p
in doc.Procedures)
1761 TreeNode procedureNode = CreateProcedureNode(p);
1762 documentNode.Nodes.Add(procedureNode);
1763 if (doc.IsStartup && p.Name ==
"main")
1765 startupNode = procedureNode;
1766 buttonExecuteMain.Enabled =
true;
1768 else if (startupNode ==
null)
1770 startupNode = procedureNode;
1774 return documentNode;
1778 private TreeNode CreateProcedureNode(IProcedure procedure)
1780 if (checkBoxCyclicReload.Checked &&
1781 procedureToExecute !=
null &&
1782 procedureToExecute.FullName == procedure.FullName)
1784 procedureToExecute = procedure;
1787 TreeNode procedureNode =
new TreeNode(procedure.Name);
1788 procedureNode.ImageKey = procedureNode.SelectedImageKey =
"Procedure.bmp";
1789 procedureNode.Tag = procedure;
1790 return procedureNode;
1794 private TreeNode CreatePackageNode(IPackage pack)
1796 TreeNode packageNode =
new TreeNode(pack.Name);
1797 packageNode.Tag = pack;
1798 packageNode.ImageKey = packageNode.SelectedImageKey =
"Package.bmp";
1800 List<IDocument> documents = pack.Documents.ToList();
1801 foreach (IDocument doc
in documents)
1803 packageNode.Nodes.Add(CreateDocumentNode(doc));
1806 foreach (IPackage package
in pack.Packages)
1808 packageNode.Nodes.Add(this.CreatePackageNode(package));
1814 private void gridView_CellContentClick(
object sender, DataGridViewCellEventArgs e)
1820 DataGridView gridView = sender as DataGridView;
1821 DataGridViewComboBoxCell comboBoxCell = gridView.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell;
1822 if (comboBoxCell !=
null)
1824 gridView.BeginEdit(
true);
1825 (gridView.EditingControl as DataGridViewComboBoxEditingControl).DroppedDown =
true;
1832 gridView_CellValueChanged(sender, e);
1836 private void gridView_CellValueChanged(
object sender, DataGridViewCellEventArgs e)
1838 DataGridView gridView = sender as DataGridView;
1841 if (gridView == this.gridViewParameter)
1843 columnName = dataGridViewTextBoxColumnValue.Name;
1845 else if (gridView == this.gridViewContext)
1847 columnName = dataGridViewTextBoxColumnContextValue.Name;
1854 if (!this.isLoadding && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == columnName &&
1856 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewCheckBoxCell ||
1857 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewComboBoxCell
1862 this.Validate(
false);
1867 void gridViewParameter_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1869 DataGridView gridView = sender as DataGridView;
1870 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name)
1872 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1873 if (parameter.Value !=
null)
1875 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnValue.Name].Value = ConvertValue2String(parameter.Value);
1876 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDetails.Name].Value = GetDetails(parameter.Value);
1883 void gridViewParameter_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1885 DataGridView gridView = sender as DataGridView;
1886 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 &&
1887 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name &&
1888 !gridView.Rows[e.RowIndex].ReadOnly &&
1889 e.FormattedValue !=
null)
1891 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1892 if (e.FormattedValue.ToString() == ValueConverter.Value2String(parameter.Value) || e.FormattedValue.ToString() == ConvertValue2String(parameter.Value))
1897 object value =
null;
1901 value = ValueConverter.String2Value(e.FormattedValue.ToString(), parameter.DataType);
1903 catch (System.Exception ex)
1916 System.Media.SystemSounds.Exclamation.Play();
1920 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDataType.Name].ErrorText =
string.Empty;
1921 if (parameter is IProcedureInParameter)
1922 (parameter as IProcedureInParameter).Value = value;
1923 else if (parameter is IProcedureInOutParameter)
1924 (parameter as IProcedureInOutParameter).Value = value;
1935 void gridViewContextVariable_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1937 DataGridView gridView = sender as DataGridView;
1938 if (!this.isLoadding && gridView !=
null &&
1940 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name)
1942 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1943 if (gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag !=
null)
1945 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1946 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1952 void gridViewContextVariable_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1954 DataGridView gridView = sender as DataGridView;
1955 if (!this.isLoadding && gridView !=
null &&
1957 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name &&
1958 !gridView.Rows[e.RowIndex].ReadOnly &&
1959 e.FormattedValue !=
null)
1961 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1962 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))
1967 object value =
null;
1971 value = ValueConverter.String2Value(e.FormattedValue.ToString(), context.DataType);
1973 catch (System.Exception ex)
1986 System.Media.SystemSounds.Exclamation.Play();
1992 string fullNameContextVariable = context.Document.FullName +
'.' + context.Name;
1993 this.contextVariableImplementation.SetValue(fullNameContextVariable, value);
1994 this.contextVariableOutputImpl.SetValue(fullNameContextVariable, value);
1995 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = value;
1996 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDataType.Name].ErrorText =
string.Empty;
2007 private void treeViewOtxProject_AfterSelect(
object sender, TreeViewEventArgs e)
2009 TreeNode node = e.Node;
2013 this.gridViewParameter.Rows.Clear();
2014 this.gridViewContext.Rows.Clear();
2015 this.gridViewState.Rows.Clear();
2017 if (node.Tag is IProcedure)
2019 IProcedure procedure = node.Tag as IProcedure;
2020 ClearCustomImplemetationCaches();
2021 UpdateGridview(procedure);
2023 buttonExecuteSelectedProcedure.Enabled =
true;
2024 this.project = GetProject(procedure);
2029 buttonExecuteSelectedProcedure.Enabled =
false;
2033 private IProject GetProject(IProcedure procedure)
2035 if (procedure !=
null)
2037 IPackage
package = procedure.Document.Package;
2038 if (package !=
null)
2040 while (package.Parent !=
null)
2042 package = package.Parent;
2045 return package.Project;
2051 private void treeViewOtxProject_DrawNode(
object sender, DrawTreeNodeEventArgs e)
2053 e.DrawDefault =
true;
2057 private void buttonReadSettings_Click(
object sender, EventArgs e)
2059 Dictionary<string, string> settings =
null;
2060 if (this.playerProject !=
null)
2062 settings = this.playerProject.Settings;
2064 else if (this.project !=
null)
2066 settings = this.project.Settings;
2068 ReadSettings(settings);
2071 private void ReadSettings(Dictionary<string, string> settings)
2073 if (settings !=
null)
2075 PrintText(
"Read settings");
2077 gridViewSettings.Rows.Clear();
2079 foreach (KeyValuePair<string, string> setting
in settings)
2081 object[] values =
new object[] { setting.Key, setting.Value };
2082 this.gridViewSettings.Rows.Add(values);
2088 private void buttonWriteSettings_Click(
object sender, EventArgs e)
2091 string valueSetting;
2092 int selectedSettingPosition = 0;
2093 Dictionary<string, string> newSettings =
new Dictionary<string, string>();
2095 if (this.gridViewSettings.SelectedRows.Count != 0)
2097 selectedSettingPosition = this.gridViewSettings.SelectedRows[0].Index;
2102 if (project !=
null || playerProject !=
null)
2104 foreach (DataGridViewRow row
in this.gridViewSettings.Rows)
2106 nameSetting = row.Cells[this.dataGridViewTextBoxColumnSettingName.Name].Value.ToString();
2107 valueSetting = row.Cells[this.dataGridViewTextBoxColumnSettingValue.Name].Value?.ToString();
2109 newSettings.Add(nameSetting, valueSetting);
2112 if (playerProject !=
null)
2114 playerProject.Settings = newSettings;
2115 ReadSettings(playerProject.Settings);
2119 project.Settings = newSettings;
2120 ReadSettings(project.Settings);
2123 this.gridViewSettings.Rows[selectedSettingPosition].Selected =
true;
2124 this.gridViewSettings.Rows[selectedSettingPosition].Cells[dataGridViewTextBoxColumnSettingValue.Name].Selected =
true;
2126 PrintText(
"Write settings finished");
2129 catch (System.Exception ex)
2135 private void checkBoxCyclicExecution_CheckedChanged(
object sender, EventArgs e)
2137 this.checkBoxCyclicReload.Enabled = this.checkBoxNewRuntimeManager.Enabled = this.checkBoxCyclicExecution.Checked;
2139 if (!this.checkBoxCyclicExecution.Checked)
2141 this.checkBoxCyclicReload.Checked = this.checkBoxNewRuntimeManager.Checked =
false;
2144 SyncWithParent(this.creatorForm?.checkBoxCyclicExecution, this.checkBoxCyclicExecution);
2147 private void checkBoxAsyncExecution_CheckedChanged(
object sender, EventArgs e)
2149 SyncWithParent(this.creatorForm?.checkBoxAsyncExecution, this.checkBoxAsyncExecution);
2152 private void checkBoxNewRuntimeManager_CheckedChanged(
object sender, EventArgs e)
2154 if (this.checkBoxNewRuntimeManager.Checked)
2156 this.checkBoxCyclicReload.Checked =
true;
2159 SyncWithParent(this.creatorForm?.checkBoxNewRuntimeManager, this.checkBoxNewRuntimeManager);
2162 private void checkBoxCyclicReload_CheckedChanged(
object sender, EventArgs e)
2164 SyncWithParent(this.creatorForm?.checkBoxCyclicReload, this.checkBoxCyclicReload);
2168 private void buttonExecuteSelectedProcedure_Click(
object sender, EventArgs e)
2172 if (treeViewOtxProject.SelectedNode !=
null && treeViewOtxProject.SelectedNode.Tag is IProcedure)
2174 IDocument document = treeViewOtxProject.SelectedNode.Parent.Tag as IDocument;
2175 List<string> listItemsReviewed =
new List<string>();
2177 this.procedureToExecute = treeViewOtxProject.SelectedNode.Tag as IProcedure;
2178 this.ExecuteProcedure();
2182 PrintText(
"Please select Procedure to execute");
2186 catch (System.Exception ex)
2191 SyncWithParent(this.creatorForm?.buttonExecuteSelectedProcedure,
null,
true);
2196 private void buttonExecuteMain_Click(
object sender, EventArgs e)
2200 if (project !=
null)
2202 treeViewOtxProject.SelectedNode = startupNode;
2203 this.procedureToExecute = project.MainProcedure;
2204 this.ExecuteProcedure();
2208 PrintText(
"There is no project has been loaded. Please reload the project");
2211 catch (System.Exception ex)
2216 SyncWithParent(this.creatorForm?.buttonExecuteMain,
null,
true);
2220 private async
void ExecuteProcedure()
2222 PrintText(
"Start procedure execution...");
2224 if (checkBoxAsyncExecution.Checked ==
false)
2226 this.buttonExecuteMain.Enabled =
false;
2227 this.buttonExecuteSelectedProcedure.Enabled =
false;
2232 if (this.globalRuntimeManager !=
null && procedureToExecute !=
null)
2234 this.buttonStop.Enabled =
true;
2236 CheckBatteryIgnitionState(this.globalRuntimeManager);
2238 if (checkBoxCyclicExecution.Checked)
2240 ThreadPool.QueueUserWorkItem(state => DoCyclic());
2245 if (checkBoxAsyncExecution.Checked)
2247 this.globalRuntimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2251 await Task.Run(() => this.globalRuntimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text)));
2257 PrintText(
"RuntimeManager is null or no Procedure is selected to run.");
2260 catch (System.Exception ex)
2264 UpdateButtonStateAfterThrowException();
2268 private void UpdateButtonStateAfterThrowException()
2270 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
2271 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
2273 UpdateExecutionStateButtons(
false);
2274 UpdatePauseButton(
true,
false);
2276 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
2277 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
2281 private void DoCyclic()
2283 DateTime startTime = DateTime.Now;
2288 while (checkBoxCyclicExecution.Checked)
2290 IRuntimeManager runtimeManager =
null;
2291 IRuntimeContext runtimeContext =
null;
2294 this.cyclicExecutionCount++;
2296 if (this.checkBoxNewRuntimeManager.Checked)
2298 runtimeManager = CreateRuntimeManager();
2302 runtimeManager = this.globalRuntimeManager;
2305 CheckCyclicReloadOrNewRuntimeManager(runtimeManager);
2307 cyclicExecuteAsyncIsProcessing =
true;
2308 CheckBatteryIgnitionState(this.globalRuntimeManager);
2310 if (this.checkBoxAsyncExecution.Checked)
2312 runtimeContext = runtimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2313 if (runtimeContext !=
null)
2316 Application.DoEvents();
2322 runtimeContext = runtimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2327 this.cyclicExecutionCount = 0;
2332 catch (System.Exception ex)
2336 UpdateButtonStateAfterThrowException();
2340 Invoke(
new MethodInvoker(delegate ()
2342 if (this.checkBoxNewRuntimeManager.Checked)
2344 LoadContextFile(this.globalRuntimeManager);
2348 PrintText(
"Cyclic execution finished");
2350 var duration = DateTime.Now - startTime;
2351 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);
2353 this.cyclicExecutionCount -= cyclic;
2354 if (this.cyclicExecutionCount < 0)
2356 this.cyclicExecutionCount = 0;
2359 if (this.checkBoxAdd2Output.Checked)
2365 MessageBox.Show(text);
2368 private void WaitCyclicExecuteAsyncIsProcessing()
2370 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2373 while (cyclicExecuteAsyncIsProcessing)
2376 Application.DoEvents();
2382 private void CheckCyclicReloadOrNewRuntimeManager(IRuntimeManager runtimeMgr,
bool waitCyclic =
true)
2386 WaitCyclicExecuteAsyncIsProcessing();
2391 Invoke(
new MethodInvoker(delegate ()
2393 CheckCyclicReloadOrNewRuntimeManager(runtimeMgr,
false);
2398 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2400 LoadContextFile(runtimeMgr);
2403 if (this.checkBoxCyclicExecution.Checked)
2405 this.checkBoxCyclicExecution.Text =
"Cyclic (" + this.cyclicExecutionCount +
")";
2409 this.checkBoxCyclicExecution.Text =
"Cyclic";
2414 private void buttonStop_Click(
object sender, EventArgs e)
2416 if (this.globalRuntimeManager !=
null)
2418 PrintText(String.Format(
"Try to stop all running procedures..."));
2419 this.globalRuntimeManager.StopAll();
2420 this.procedureExecutionCount = 0;
2424 this.checkBoxCyclicExecution.Checked =
false;
2426 SyncWithParent(this.creatorForm?.buttonStop);
2429 private void PrintException(System.Exception ex,
string additionalText =
"")
2431 PrintText(String.Format(
"!!! {2}{0}: {1}", ex.GetType().Name, ex.Message, additionalText));
2432 System.Media.SystemSounds.Hand.Play();
2435 private void PrintText(
string text)
2439 this.Invoke(
new Action(() => PrintText(text)));
2443 if (!this.checkBoxAdd2Output.Checked)
2449 lock (printTextLock)
2451 if (this.listBoxOuput.Items.Count >= 10000)
2453 buttonClearOutput_Click(
null,
null);
2456 string prefixString = GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime();
2457 string itemToAdd = prefixString + text +
"\t\t";
2459 this.listBoxOuput.Items.Add(itemToAdd);
2460 this.listBoxOuput.SelectedItems.Clear();
2461 this.listBoxOuput.TopIndex = listBoxOuput.Items.Count - 1;
2463 if (this.listBoxOuput.Items.Count >= 7500)
2465 this.labelOutputOverflow.Visible =
true;
2470 Application.DoEvents();
2474 private string GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime()
2476 DateTime now = DateTime.Now;
2477 var duration = now - this.lastTime;
2479 this.lastTime = now;
2481 string timeDurationString = String.Format(
"{0:HH:mm:ss.fff} {1,6:#,##0} ms ", now, duration.TotalMilliseconds);
2482 return timeDurationString;
2485 private void buttonCopyRow_Click(
object sender, EventArgs e)
2487 if (this.listBoxOuput.SelectedItems !=
null)
2489 string text =
string.Empty;
2490 foreach (
string row
in this.listBoxOuput.SelectedItems)
2492 text += row.Trim(
'\t') +
"\n";
2495 Clipboard.SetText(text);
2499 private void buttonClearOutput_Click(
object sender, EventArgs e)
2501 this.listBoxOuput.Items.Clear();
2502 this.labelOutputOverflow.Visible =
false;
2503 this.buttonCopyRow.Enabled =
false;
2507 private void UpdateGridview(IProcedure procedure)
2509 if (procedure ==
null ||
2510 procedure.Parameters ==
null)
2515 UpdateGridviewParameter(procedure);
2517 IDocument document = procedure.Document;
2518 if (document !=
null)
2520 List<string> listItemsReviewed =
new List<string>();
2521 UpdateGridViewContextVariable(document,
false, listItemsReviewed);
2523 listItemsReviewed.Clear();
2524 UpdateGridViewStateVariable(document,
false, listItemsReviewed);
2528 private void UpdateGridviewParameter(IProcedure procedure)
2530 foreach (IProcedureParameter param
in procedure.Parameters)
2532 UpdateGridviewParameter(param);
2537 private void UpdateGridviewParameter(IProcedureParameter parameter)
2539 if (parameter ==
null)
2544 bool bValueWasSet =
false;
2547 string collumnName = dataGridViewTextBoxColumnName.Name;
2548 string collumnValue = dataGridViewTextBoxColumnValue.Name;
2549 string collumnDetails = dataGridViewTextBoxColumnDetails.Name;
2550 foreach (DataGridViewRow row
in this.gridViewParameter.Rows)
2552 if (row.Cells[collumnName].Value.Equals(parameter.Name))
2556 if (parameter.Value !=
null)
2558 row.Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2561 catch (System.Exception ex)
2563 row.Cells[collumnValue].ErrorText = ex.Message;
2566 bValueWasSet =
true;
2574 string direction = parameter is IProcedureInParameter ?
"In" : (parameter is IProcedureInOutParameter ?
"InOut" :
"Out");
2575 object[] values =
new object[] { parameter.Name, direction, parameter.DataType };
2576 int index = this.gridViewParameter.Rows.Add(values);
2578 this.gridViewParameter.Rows[index].Tag = parameter;
2580 this.gridViewParameter.Rows[index].ReadOnly = parameter is IProcedureOutParameter || parameter.InitValue ==
null;
2582 if (parameter.DataType.Equals(
"Boolean"))
2584 gridViewParameter.Rows[index].Cells[collumnValue] =
new DataGridViewCheckBoxCell();
2585 DataGridViewCheckBoxCell cell = gridViewParameter.Rows[index].Cells[collumnValue] as DataGridViewCheckBoxCell;
2586 cell.Value = ConvertValue2String(parameter.Value);
2587 cell.Tag = parameter.Value;
2589 else if (parameter.Value is EnumerationElement)
2591 gridViewParameter.Rows[index].Cells[collumnValue] =
new DataGridViewComboBoxCell();
2592 DataGridViewComboBoxCell cell = gridViewParameter.Rows[index].Cells[collumnValue] as DataGridViewComboBoxCell;
2593 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2594 cell.FlatStyle = FlatStyle.Flat;
2595 cell.DisplayMember =
"Name";
2596 cell.ValueMember =
"Name";
2597 cell.DataSource = (parameter.Value as EnumerationElement).Enumeration.Elements;
2598 cell.Value = ConvertValue2String(parameter.Value);
2599 cell.Tag = parameter.Value;
2605 if (parameter.Value !=
null)
2607 gridViewParameter.Rows[index].Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2610 catch (System.Exception ex)
2612 gridViewParameter.Rows[index].Cells[collumnValue].ErrorText = ex.Message;
2616 gridViewParameter.Rows[index].Cells[collumnDetails].Value = GetDetails(parameter.Value);
2620 private string ConvertValue2String(
object value)
2624 return string.Empty;
2627 return ValueConverter.Value2String(value);
2630 private string GetDetails(
object value)
2634 return string.Empty;
2637 if (value is TranslationKey translationKey)
2639 if (!
string.IsNullOrEmpty(translationKey.TextIdMappingName))
2641 return string.Format(
"MappingName: {0}", translationKey.TextIdMappingName);
2644 else if (value is EnumerationElement enumerationElement)
2646 if (enumerationElement.TranslationKey !=
null)
2648 if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId) && !
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextIdMappingName))
2650 return string.Format(
"TextId: {0}, MappingName: {1}", enumerationElement.TranslationKey.TextId, enumerationElement.TranslationKey.TextIdMappingName);
2652 else if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId))
2654 return string.Format(
"TextId: {0}", enumerationElement.TranslationKey.TextId);
2657 return string.Format(
"MappingName: {0}", enumerationElement.TranslationKey.TextIdMappingName);
2661 return string.Empty;
2665 private void UpdateGridViewContextVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2667 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2668 if (listItemsReviewed.Contains(@
namespace))
2673 listItemsReviewed.Add(@
namespace);
2674 foreach (IContextVariable contextVariable
in document.ContextVariables)
2676 if (contextVariable ==
null)
2681 bool bValueWasSet =
false;
2684 foreach (DataGridViewRow row
in this.gridViewContext.Rows)
2686 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))
2688 if (radioButtonDefaultImplementation.Checked)
2690 object contextVariableValue = this.contextVariableImplementation.GetValue(
null, contextVariable,
null);
2691 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariableValue !=
null ? ConvertValue2String(contextVariableValue) : null;
2695 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariable.InitValue !=
null ? ConvertValue2String(contextVariable.InitValue) : null;
2698 bValueWasSet =
true;
2706 object[] values =
null;
2707 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + contextVariable.Name) : contextVariable.Name, contextVariable.DataType };
2708 int index = this.gridViewContext.Rows.Add(values);
2710 object contextVariableValue = contextVariable.InitValue;
2712 this.gridViewContext.Rows[index].Tag = contextVariable;
2713 this.gridViewContext.Rows[index].ReadOnly = contextVariable.InitValue ==
null;
2714 this.gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = contextVariable.InitValue;
2715 if (contextVariable.DataType.Equals(
"Boolean"))
2717 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] =
new DataGridViewCheckBoxCell();
2718 DataGridViewCheckBoxCell cell = gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] as DataGridViewCheckBoxCell;
2719 cell.Value = ConvertValue2String(contextVariableValue);
2720 cell.Tag = contextVariableValue;
2722 else if(contextVariableValue is EnumerationElement)
2724 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] =
new DataGridViewComboBoxCell();
2725 DataGridViewComboBoxCell cell = gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] as DataGridViewComboBoxCell;
2726 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2727 cell.FlatStyle = FlatStyle.Flat;
2728 cell.DisplayMember =
"Name";
2729 cell.ValueMember =
"Name";
2730 cell.DataSource = (contextVariableValue as EnumerationElement).Enumeration.Elements;
2731 cell.Value = ConvertValue2String(contextVariableValue);
2732 cell.Tag = contextVariableValue;
2738 if (contextVariableValue !=
null)
2740 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(contextVariableValue);
2744 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value =
null;
2747 catch (System.Exception ex)
2749 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].ErrorText = ex.Message;
2753 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(contextVariableValue);
2759 foreach (IDocument importDoc
in document.Imports)
2761 UpdateGridViewContextVariable(importDoc,
true, listItemsReviewed);
2764 catch (System.Exception ex)
2771 private void StateVariableValueChanged(IStateVariable stateVariable,
object value)
2773 if (this.InvokeRequired)
2775 this.Invoke(
new Action(() => StateVariableValueChanged(stateVariable, value)));
2779 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2780 stateVariable.MappingName,
2781 (stateVariable.MappingIndex > -1 ?
"[" + stateVariable.MappingIndex +
"]" : String.Empty));
2782 string strValue =
"null";
2785 strValue = ValueConverter.Value2String(value);
2791 string outputLog = String.Format(
"StateVariableChanged({0} {1}.{2}{3} = {4})",
2792 stateVariable.DataType,
2793 stateVariable.Document.FullName,
2797 PrintText(outputLog);
2798 UpdateGridViewStateVariable(stateVariable);
2801 private void ContextVariableRead(IContextVariable contextVariable,
object value)
2803 if (this.InvokeRequired)
2805 this.Invoke(
new Action(() => ContextVariableRead(contextVariable, value)));
2809 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2810 contextVariable.MappingName,
2811 (contextVariable.MappingIndex > -1 ?
"[" + contextVariable.MappingIndex +
"]" : String.Empty));
2812 string strValue =
"null";
2815 strValue = ValueConverter.Value2String(value);
2820 string outputLog = String.Format(
"ContextVariableRead({0} {1}.{2}{3} = {4})",
2821 contextVariable.DataType,
2822 contextVariable.Document.FullName,
2823 contextVariable.Name,
2827 PrintText(outputLog);
2830 private void UpdateGridViewStateVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2832 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2833 if (listItemsReviewed.Contains(@
namespace))
2838 listItemsReviewed.Add(@
namespace);
2839 foreach (IStateVariable stateVariable
in document.StateVariables)
2841 object[] values =
null;
2842 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + stateVariable.Name) : stateVariable.Name, stateVariable.DataType };
2843 int index = this.gridViewState.Rows.Add(values);
2845 this.gridViewState.Rows[index].Tag = stateVariable;
2847 if (stateVariable.DataType.Equals(
"Boolean"))
2849 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] =
new DataGridViewCheckBoxCell();
2850 DataGridViewCheckBoxCell cell = gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] as DataGridViewCheckBoxCell;
2851 cell.Value = ConvertValue2String(stateVariable.InitValue);
2852 cell.Tag = stateVariable.InitValue;
2854 else if (stateVariable.InitValue is EnumerationElement)
2856 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] =
new DataGridViewComboBoxCell();
2857 DataGridViewComboBoxCell cell = gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] as DataGridViewComboBoxCell;
2858 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2859 cell.FlatStyle = FlatStyle.Flat;
2860 cell.DisplayMember =
"Name";
2861 cell.ValueMember =
"Name";
2862 cell.DataSource = (stateVariable.InitValue as EnumerationElement).Enumeration.Elements;
2863 cell.Value = ConvertValue2String(stateVariable.InitValue);
2864 cell.Tag = stateVariable.InitValue;
2870 if (stateVariable.InitValue !=
null)
2872 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariable.InitValue);
2875 catch (System.Exception ex)
2877 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2881 if (stateVariable.InitValue !=
null)
2883 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariable.InitValue);
2889 foreach (IDocument importDoc
in document.Imports)
2891 UpdateGridViewStateVariable(importDoc,
true, listItemsReviewed);
2894 catch (System.Exception ex)
2902 private void UpdateGridViewStateVariable(IStateVariable stateVar)
2904 if (stateVar ==
null)
2910 foreach (DataGridViewRow row
in this.gridViewState.Rows)
2912 if (row.Cells[
this.dataGridViewTextBoxColumnStateName.Name].Value !=
null && row.Tag == stateVar)
2914 object stateVariableValue =
null;
2916 if (radioButtonDefaultImplementation.Checked)
2917 stateVariableValue = this.stateVariableImplementation.GetValue(stateVar);
2919 stateVariableValue = stateVar.InitValue;
2921 if (stateVariableValue !=
null)
2925 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariableValue);
2927 catch (System.Exception ex)
2929 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2932 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariableValue);
2936 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value =
null;
2937 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value =
string.Empty;
2943 Application.DoEvents();
2946 private void buttonNewInstance_Click(
object sender, EventArgs e)
2948 Form form =
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this);
2952 private void buttonNewInstanceNewThread_Click(
object sender, EventArgs e)
2954 Thread thread =
new Thread(
new ThreadStart(NewInstanceInThread));
2955 thread.SetApartmentState(ApartmentState.STA);
2959 private void NewInstanceInThread()
2961 Application.Run(
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this));
2964 private void buttonHmi_Click(
object sender, EventArgs e)
2966 if (this.buttonHmi.Checked)
2968 hmiWindow =
new HmiWindow();
2969 hmiWindow.FormClosing += HmiWindow_FormClosing;
2970 hmiWindow.SizeChanged += HmiWindow_SizeChanged;
2971 hmiWindow.Activated += HmiWindow_Activated;
2974 hmiWindow.Size =
new Size(userSettings.HmiWindowWidth, userSettings.HmiWindowHeight);
2975 hmiWindow.Location =
new Point(this.Location.X +
this.Size.Width,
this.Location.Y);
2976 if (this.creatorForm !=
null && this.creatorForm.hmiWindow !=
null)
2978 this.hmiWindow.Size = this.creatorForm.hmiWindow.Size;
2981 hmiWindow.BringToFront();
2983 customScreenImplementation.HmiScreenContainer = this.hmiWindow.HmiControl;
2985 else if (this.hmiWindow !=
null)
2987 this.hmiWindow.Close();
2990 SyncWithParent(this.creatorForm?.buttonHmi, this.buttonHmi);
2993 private void HmiWindow_FormClosing(
object sender, FormClosingEventArgs e)
2995 customScreenImplementation.HmiScreenContainer =
null;
2996 this.hmiWindow =
null;
2998 this.buttonHmi.Checked =
false;
3001 private void HmiWindow_Activated(
object sender, EventArgs e)
3003 if (customScreenImplementation !=
null)
3005 customScreenImplementation.ActivateHmiScreen();
3009 private void HmiWindow_SizeChanged(
object sender, EventArgs e)
3011 userSettings.HmiWindowWidth = this.hmiWindow.Width;
3012 userSettings.HmiWindowHeight = this.hmiWindow.Height;
3014 if (customScreenImplementation !=
null)
3016 customScreenImplementation.RefreshHmiScreen();
3020 private void CustomScreenImplementation_KeyDown(Runtime.Api.Custom.KeyEventArgs e)
3022 string key =
"Unknown";
3023 if (e is WpfKeyEventArgs)
3025 WpfKeyEventArgs wpfArgs = e as WpfKeyEventArgs;
3026 key = wpfArgs.Key.ToString();
3027 if (wpfArgs.ModifierKey == System.Windows.Input.ModifierKeys.Alt &&
3028 wpfArgs.Key == System.Windows.Input.Key.F4)
3032 else if (wpfArgs.Key == System.Windows.Input.Key.F10 || wpfArgs.Key == System.Windows.Input.Key.LeftAlt || wpfArgs.Key == System.Windows.Input.Key.RightAlt)
3037 else if (e is FormKeyEventArgs)
3039 FormKeyEventArgs formArgs = e as FormKeyEventArgs;
3040 if (formArgs.ModifierKey == Keys.Alt &&
3041 formArgs.Key == Keys.F4)
3045 else if (formArgs.Key == Keys.F10 || formArgs.Key == Keys.Alt)
3049 key = formArgs.Key.ToString();
3052 this.PrintText(
"CustomScreenImplementation_KeyDown(" + key +
")");
3056 private void SampleForm_FormClosing(
object sender, FormClosingEventArgs e)
3058 listForms.Remove(
this);
3061 if (this.globalRuntimeManager !=
null)
3063 this.globalRuntimeManager.StopAll();
3064 this.globalRuntimeManager.ProcedurePending -= ProcedurePending;
3065 this.globalRuntimeManager.ProcedureStarted -= ProcedureStarted;
3066 this.globalRuntimeManager.ProcedurePaused -= ProcedurePaused;
3067 this.globalRuntimeManager.ProcedureContinued -= ProcedureContinued;
3068 this.globalRuntimeManager.ProcedureFinished -= ProcedureFinished;
3069 this.globalRuntimeManager.ProcedureStopped -= ProcedureStopped;
3070 this.globalRuntimeManager.ProcedureAborted -= ProcedureAborted;
3071 this.globalRuntimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
3074 this.stateVariableImplementation.StateVariableValueChanged -= StateVariableValueChanged;
3076 basicScreenOutputImpl.LogEvent -= PrintText;
3077 customScreenOutputImpl.LogEvent -= PrintText;
3078 loggingOutputImpl.LogEvent -= PrintText;
3079 contextVariableOutputImpl.LogEvent -= PrintText;
3081 stateVariableOutputImpl.LogEvent -= PrintText;
3082 measureOutputImpl.LogEvent -= PrintText;
3083 i18NOutputImpl.LogEvent -= PrintText;
3084 serviceProviderOutputImpl.LogEvent -= PrintText;
3086 sqlOutputImpl.LogEvent -= PrintText;
3087 commonDialogsOutputImpl.LogEvent -= PrintText;
3092 private void SaveSettings()
3094 if (this.creatorForm ==
null)
3097 userSettings.Ptx_Ppx_Directory = cbFilePath.Text.Trim();
3098 userSettings.Ptx_Ppx_DirectoryList =
string.Join(
";", this.cbFilePath.Items.Cast<Object>().Select(item => item.ToString()).ToArray());
3100 userSettings.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text.Trim());
3101 userSettings.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text.Trim());
3102 userSettings.Profiling = this.checkBoxProfiling.Checked;
3103 userSettings.ProfilingMaxFileSize = Convert.ToInt32(this.textBoxProfilingSize.Text.Trim());
3104 userSettings.TraceLevels = RuntimeConfig.Instance.TraceLevel;
3105 userSettings.TracingDirectory = textBoxTraceFolder.Text.Trim();
3107 userSettings.WindowWidth = this.Size.Width;
3108 userSettings.WindowHeight = this.Size.Height;
3109 userSettings.WindowLocationX = this.Location.X;
3110 userSettings.WindowLocationY = this.Location.Y;
3111 userSettings.CustomImplTypes = GetCurrentCustomImpl();
3112 SaveSocketPortOrPipeName();
3114 userSettings.Asynchron = checkBoxAsyncExecution.Checked;
3115 userSettings.Cyclic = checkBoxCyclicExecution.Checked;
3116 userSettings.CyclicReload = checkBoxCyclicReload.Checked;
3117 userSettings.NewRunTimeManager = checkBoxNewRuntimeManager.Checked;
3118 userSettings.AddMessageToOutput = checkBoxAdd2Output.Checked;
3119 userSettings.StartAllParents = checkBoxStartAllParents.Checked;
3121 userSettings.TimeOut = (ulong)Convert.ToInt32(
this.textBoxTimeout.Text.Trim());
3122 userSettings.ConnectionState = checkBoxUseConnectionState.Checked;
3123 userSettings.Ignition = checkBoxIgnition.CheckState == CheckState.Checked ? 1 : (checkBoxIgnition.CheckState == CheckState.Unchecked ? 0 : -1);
3124 userSettings.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text.Trim());
3125 userSettings.VoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text.Trim());
3127 userSettings.RuntimeContextName = this.textBoxRuntimeContextName.Text.Trim();
3129 SaveSettingUtil.Save();
3133 private void SaveSocketPortOrPipeName()
3135 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
3139 case IpcTypes.SOCKET:
3143 userSettings.DiagManagerPort = Convert.ToUInt16(textBoxDiagPortPipe.Text.Trim());
3144 userSettings.RuntimePort = Convert.ToUInt16(textBoxRtPortPipe.Text.Trim());
3145 userSettings.IpcType = IpcTypes.SOCKET.ToString();
3147 catch (System.Exception)
3149 userSettings.DiagManagerPort = SampleConstants.DEFAULT_DM_PORT;
3150 userSettings.RuntimePort = SampleConstants.DEFAULT_RT_PORT;
3157 string diagManagerPipeName = textBoxDiagPortPipe.Text.Trim();
3158 string runtimePipeName = textBoxRtPortPipe.Text.Trim();
3160 userSettings.DiagManagerPipeName = (diagManagerPipeName !=
string.Empty) ? diagManagerPipeName : SampleConstants.DEFAULT_DM_PIPE_NAME;
3161 userSettings.RuntimePipeName = (runtimePipeName !=
string.Empty) ? runtimePipeName : SampleConstants.DEFAULT_RT_PIPE_NAME;
3162 userSettings.IpcType = IpcTypes.PIPE.ToString();
3171 private void textBoxRuntimeContextName_TextChanged(
object sender, EventArgs e)
3173 this.runtimeContextName = this.textBoxRuntimeContextName.Text = this.textBoxRuntimeContextName.Text.Trim();
3174 SetTitle(this.title);
3177 private void listBoxOuput_SelectedIndexChanged(
object sender, EventArgs e)
3179 this.buttonCopyRow.Enabled = this.listBoxOuput.SelectedItems.Count > 0;
3182 private void buttonPause_Click(
object sender, EventArgs e)
3184 lock (this.runtimeContexts)
3186 if (this.buttonPause.Checked)
3188 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3192 runtimeContext.Pause();
3198 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3202 runtimeContext.Continue();
3208 SyncWithParent(this.creatorForm?.buttonPause, this.buttonPause);
3211 private void AddRuntimeContext(IRuntimeContext context)
3213 lock (this.runtimeContexts)
3215 if (!this.runtimeContexts.Contains(context))
3217 this.runtimeContexts.Add(context);
3220 if (!runtimeContextsExecutionStartTime.ContainsKey(context))
3222 runtimeContextsExecutionStartTime.Add(context, DateTime.Now);
3227 private void RemoveRuntimeContext(IRuntimeContext context)
3229 lock (this.runtimeContexts)
3231 if (this.runtimeContexts.Contains(context))
3233 this.runtimeContexts.Remove(context);
3236 if (runtimeContextsExecutionStartTime.ContainsKey(context))
3238 runtimeContextsExecutionStartTime.Remove(context);
3243 private bool IsPauseEnabled()
3245 lock (this.runtimeContexts)
3247 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3259 private bool IsContinueEnable()
3261 lock (this.runtimeContexts)
3263 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3275 private void SetExpectedState()
3277 if (this.useConnectionState)
3279 if (this.KL15State ==
null)
3283 else if (this.KL15State.Value)
3298 private void checkBoxUseConnectionState_CheckedChanged(
object sender, EventArgs e)
3300 this.useConnectionState = this.checkBoxUseConnectionState.Checked;
3301 this.EnableConnectionState();
3302 this.SetExpectedState();
3304 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
3305 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
3307 SyncWithParent(this.creatorForm?.checkBoxUseConnectionState, this.checkBoxUseConnectionState);
3310 private void CheckBoxKL15_CheckStateChanged(
object sender, System.EventArgs e)
3312 switch (this.checkBoxIgnition.CheckState)
3314 case CheckState.Checked:
3315 this.KL15State =
true;
3317 case CheckState.Unchecked:
3318 this.KL15State =
false;
3321 this.KL15State =
null;
3325 this.SetExpectedState();
3327 SyncWithParent(this.creatorForm?.checkBoxIgnition, this.checkBoxIgnition);
3330 private void EnableConnectionState()
3332 this.labelExpectedState.Enabled = this.useConnectionState;
3333 this.labelBatteryState.Enabled = this.useConnectionState;
3334 this.checkBoxIgnition.Enabled = this.useConnectionState;
3335 this.labelPollingTime.Enabled = this.useConnectionState;
3336 this.textBoxPollingTime.Enabled = this.useConnectionState;
3337 this.labelVoltageThreshold.Enabled = this.useConnectionState;
3338 this.textBoxVoltageThreshold.Enabled = this.useConnectionState;
3339 this.buttonCheckBatteryIgnition.Enabled = this.useConnectionState;
3342 private void buttonCheckBatteryIgnition_Click(
object sender, EventArgs e)
3344 CheckBatteryIgnitionState(this.globalRuntimeManager);
3346 SyncWithParent(this.creatorForm?.buttonCheckBatteryIgnition, this.buttonCheckBatteryIgnition);
3349 private void textBoxPollingTime_TextChanged(
object sender, EventArgs e)
3353 if (Convert.ToInt32(
this.textBoxPollingTime.Text) <= 0)
3355 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3360 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3363 SyncWithParent(this.creatorForm?.textBoxPollingTime, this.textBoxPollingTime);
3366 private void textBoxBatteryVoltageThreshold_TextChanged(
object sender, EventArgs e)
3370 if (Convert.ToInt32(
this.textBoxVoltageThreshold.Text) <= 0)
3372 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3377 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3380 SyncWithParent(this.creatorForm?.textBoxVoltageThreshold, this.textBoxVoltageThreshold);
3383 private void CheckBatteryIgnitionState(IRuntimeManager runtimeManager)
3385 if (this.useConnectionState)
3387 runtimeManager.DiagConnectionState.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text);
3388 runtimeManager.DiagConnectionState.BatteryVoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text);
3389 ClampState batteryState = runtimeManager.DiagConnectionState.BatteryState;
3390 ClampState ignitionState = runtimeManager.DiagConnectionState.IgnitionState;
3392 SetBatteryIgnitionState(batteryState, ignitionState);
3394 PrintText(
"Check DiagConnection State - BatteryState = " + batteryState.ToString() +
", IgnitionState = " + ignitionState.ToString());
3398 private void SetBatteryIgnitionState(ClampState batteryState, ClampState ignitionState)
3400 switch (batteryState)
3403 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryNotAvailable16;
3406 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOff16;
3409 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOn16;
3413 switch (ignitionState)
3416 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionNotAvailable16;
3419 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOff16;
3422 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOn16;
3427 private void ShowConnectionStateMessage(IRuntimeContext runtimeContext)
3429 if (runtimeContext !=
null)
3431 System.Media.SystemSounds.Beep.Play();
3433 switch (this.expectedConnectionState)
3436 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3437 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! --");
3438 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3441 this.PrintText(
"------------------------------------------------------------------------------------");
3442 this.PrintText(
"-- Not expected connection state: The ignition must be OFF. Please switch it OFF! --");
3443 this.PrintText(
"------------------------------------------------------------------------------------");
3446 this.PrintText(
"----------------------------------------------------------------------------------");
3447 this.PrintText(
"-- Not expected connection state: The ignition must be ON. Please switch it ON! --");
3448 this.PrintText(
"----------------------------------------------------------------------------------");
3456 private void checkBoxAdd2Output_CheckedChanged(
object sender, EventArgs e)
3458 SyncWithParent(this.creatorForm?.checkBoxAdd2Output, this.checkBoxAdd2Output);
3461 private void ParentNumericUpDownSetValue(NumericUpDown numericUpDown,
int value)
3463 var action =
new Action(() => numericUpDown.Value = value);
3464 if (numericUpDown.InvokeRequired)
3465 this.creatorForm.Invoke(action);
3470 private void comboBoxTraceLevel_SelectedIndexChanged(
object sender, EventArgs e)
3472 SyncWithParent(this.creatorForm?.comboBoxTraceLevel, this.comboBoxTraceLevel);
3474 private void txtPassword_TextChanged(
object sender, EventArgs e)
3476 SyncWithParent(this.creatorForm?.txtPassword, this.txtPassword);
3479 private void textBoxTimeout_TextChanged(
object sender, EventArgs e)
3481 SyncWithParent(this.creatorForm?.textBoxTimeout, this.textBoxTimeout);
3484 private void checkBoxProfiling_CheckedChanged(
object sender, EventArgs e)
3486 if (globalRuntimeManager ==
null)
3489 PrintText(
"Set Profiling to " + this.checkBoxProfiling.Checked.ToString());
3493 RuntimeConfig.Instance.Profiling = this.checkBoxProfiling.Checked;
3494 SyncWithParent(this.creatorForm?.checkBoxProfiling, this.checkBoxProfiling);
3497 catch (System.Exception ex)
3500 this.checkBoxProfiling.Checked = RuntimeConfig.Instance.Profiling;
3504 private void textBoxTraceFileMaxSize_TextChanged(
object sender, EventArgs e)
3506 if (globalRuntimeManager ==
null)
3511 RuntimeConfig.Instance.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text);
3512 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxSize, this.textBoxTraceFileMaxSize);
3515 catch (System.Exception ex)
3520 PrintText(
"TraceFileMaxSize is " + RuntimeConfig.Instance.TraceFileMaxSize.ToString());
3523 private void textBoxProfilingSize_TextChanged(
object sender, EventArgs e)
3525 if (globalRuntimeManager ==
null)
3530 RuntimeConfig.Instance.ProfilingMaxFileSize = Convert.ToInt32(this.textBoxProfilingSize.Text);
3531 SyncWithParent(this.creatorForm?.textBoxProfilingSize, this.textBoxProfilingSize);
3534 catch (System.Exception ex)
3539 PrintText(
"ProfilingFileMaxSize is " + RuntimeConfig.Instance.ProfilingMaxFileSize.ToString());
3542 private void textBoxTraceFileMaxCount_TextChanged(
object sender, EventArgs e)
3544 if (globalRuntimeManager ==
null)
3549 RuntimeConfig.Instance.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text);
3550 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxCount, this.textBoxTraceFileMaxCount);
3552 catch (System.Exception ex)
3557 PrintText(
"TraceFileMaxCount is " + RuntimeConfig.Instance.TraceFileMaxCount.ToString());
3560 private void WebServerTimer_Tick(
object sender, EventArgs e)
3562 this.UpdateWebServerButton();
3565 int isStartWebSever = -1;
3566 private void UpdateWebServerButton()
3568 if (this.InvokeRequired)
3570 this.Invoke(
new Action(() => UpdateWebServerButton()));
3574 if (customScreenImplementation ==
null)
3576 this.buttonStartStopWebServer.Enabled =
false;
3580 this.buttonStartStopWebServer.Enabled =
true;
3581 if (DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3583 if (isStartWebSever == 1)
3588 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StopWebServer;
3589 isStartWebSever = 1;
3593 if (isStartWebSever == 0)
3598 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StartWebServer;
3599 isStartWebSever = 0;
3603 private void buttonStartStopWebServer_Click(
object sender, EventArgs e)
3605 if (this.InvokeRequired)
3607 this.Invoke(
new Action(() => buttonStartStopWebServer_Click(sender, e)));
3611 if (customScreenImplementation ==
null)
3616 if (!DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3618 customScreenImplementation.StartHtmlWebServer();
3622 customScreenImplementation.StopHtmlWebServer();
3626 private void buttonLicense_Click(
object sender, EventArgs e)
3628 LicenseForm licenseForm =
new LicenseForm(
this);
3629 licenseForm.ShowDialog(
this);
3632 public void ReloadRuntimeManager()
3636 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
3637 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
3639 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
3642 this.globalRuntimeManager = CreateRuntimeManager();
3646 catch (System.Exception ex)
3649 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