/// <summary> /// Pass record to RTQC for validate /// </summary> /// <param name="workItem"></param> internal static void SendRecordToRTQC(WorkItem workItem) { // Get the index of record in buffer from workItem int index = (int)workItem.InputParameters; dynamic record; // // To Be Implemented... // SOP should decide the action, eg. save record, pass to rtqc // try { // Get the record from buffer if (DiReCTCore.GetRecordFromBuffer(index, out record)) { // Call RTQC API RTQCModule.OnValidate(record, new AsyncCallback(SaveRecordtoDictionary)); workItem.Complete(); } else { // Exception, index not valid } }catch (Exception ex) { Debug.WriteLine("DMModule.SendRecordToRTQC: " + ex.Message); } }
/// <summary> /// Save the record into Dictionary /// </summary> /// <param name="result"></param> public static void SaveRecordtoDictionary(IWorkItemResult wir) { // Check RTQC return value // Since the return value can only be one, the current solution is // to use KEYVALUEPAIR to store the return value plus the records if (((KeyValuePair <dynamic, bool>)wir.Result).Value) { recordDictionaryManager.SaveRecord(false, ((KeyValuePair <dynamic, bool>)wir.Result).Key); } //WorkItem workItem = (WorkItem)result; //if ((bool)workItem.OutputParameters) //{ // recordDictionaryManager.SaveRecord(false, // workItem.InputParameters); //} //else //{ // recordDictionaryManager.SaveRecord(true, // workItem.InputParameters); //} // Debugging function DiReCTCore.PrintDictionary(null); }
/// <summary> /// Pass record to RTQC for validate /// </summary> /// <param name="workItem"></param> private static void SendRecordToRTQC(int index) { dynamic record; // // To Be Implemented... // SOP should decide the action, eg. save record, pass to rtqc // try { // Get the record from buffer if (DiReCTCore.GetRecordFromBuffer(index, out record)) { // Call RTQC API RTQCModule.OnValidate(record); } else { // Exception, index not valid } }catch (Exception ex) { Debug.WriteLine("DMModule.SendRecordToRTQC: " + ex.Message); } }
/// <summary> /// This function ensures there is only one instance of Core /// </summary> /// <returns></returns> public static DiReCTCore getInstance() { if (_instance == null) { _instance = new DiReCTCore(); } return(_instance); }
/// <summary> /// Save the record into Dictionary /// </summary> /// <param name="result"></param> static void SaveRecordtoDictionary(IAsyncResult result) { WorkItem workItem = (WorkItem)result; if ((bool)workItem.OutputParameters) { recordDictionaryManager.SaveRecord(false, workItem.InputParameters); } else { recordDictionaryManager.SaveRecord(true, workItem.InputParameters); } DiReCTCore.PrintDictionary(null); }
public static void Main() { // Subscribe system log off/shutdown or application close events SystemEvents.SessionEnding += new SessionEndingEventHandler(ShutdownEventHandler); AppDomain.CurrentDomain.ProcessExit += new EventHandler(ShutdownEventHandler); // Initialize objects for main thread try { coreControl = DiReCTCore.getInstance(); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("Thread resource creation failed."); CleanupExit(); } // Initialize objects for threads // Initialize thread objects and control data block of each modules try { ModuleThreadHandles = new Thread[(int)ModuleThread.NumberOfModules]; ModuleControlDataBlocks = new ModuleControlDataBlock[ (int)ModuleThread.NumberOfModules]; ModuleReadyEvents = new AutoResetEvent[ (int)ModuleThread.NumberOfModules]; ModuleInitFailedEvents = new AutoResetEvent[ (int)ModuleThread.NumberOfModules]; } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("Thread resource creation failed."); CleanupExit(); } // AAA Module try { // Create and intialize AAA module ModuleThreadHandles[(int)ModuleThread.AAA] = new Thread(AAAModule.AAAInit); ModuleControlDataBlocks[(int)ModuleThread.AAA] = new ModuleControlDataBlock(); ModuleThreadHandles[(int)ModuleThread.AAA] .Start(ModuleControlDataBlocks[(int)ModuleThread.AAA]); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("AAA module thread creation failed."); CleanupExit(); } // DM Module try { // Create and intialize DM module ModuleThreadHandles[(int)ModuleThread.DM] = new Thread(DMModule.DMInit); ModuleControlDataBlocks[(int)ModuleThread.DM] = new ModuleControlDataBlock(); ModuleThreadHandles[(int)ModuleThread.DM] .Start(ModuleControlDataBlocks[(int)ModuleThread.DM]); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("DM module thread creation failed."); CleanupExit(); } // DS Module try { // Create and intialize DS module ModuleThreadHandles[(int)ModuleThread.DS] = new Thread(DSModule.DSInit); ModuleControlDataBlocks[(int)ModuleThread.DS] = new ModuleControlDataBlock(); ModuleThreadHandles[(int)ModuleThread.DS] .Start(ModuleControlDataBlocks[(int)ModuleThread.DS]); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("DS module thread creation failed."); CleanupExit(); } // MAN Module try { // Create and intialize MAN module ModuleThreadHandles[(int)ModuleThread.MAN] = new Thread(MANModule.MANInit); ModuleControlDataBlocks[(int)ModuleThread.MAN] = new ModuleControlDataBlock(); ModuleThreadHandles[(int)ModuleThread.MAN] .Start(ModuleControlDataBlocks[(int)ModuleThread.MAN]); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("MAN module thread creation failed."); CleanupExit(); } // RTQC Module try { // Create and intialize RTQC module ModuleThreadHandles[(int)ModuleThread.RTQC] = new Thread(RTQCModule.RTQCInit); ModuleControlDataBlocks[(int)ModuleThread.RTQC] = new ModuleControlDataBlock(); ModuleThreadHandles[(int)ModuleThread.RTQC] .Start(ModuleControlDataBlocks[(int)ModuleThread.RTQC]); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("RTQC module thread creation failed."); CleanupExit(); } // Initialize the thread object of GUI thread try { UIThreadHandle = new Thread(UIMainFunction); UIThreadHandle.SetApartmentState(ApartmentState.STA); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("UI thread creation failed."); CleanupExit(); } // Set the array of events for waiting signals raised by // modules using WaitAll and WaitAny below for (int i = 0; i < (int)ModuleThread.NumberOfModules; i++) { ModuleReadyEvents[i] = ModuleControlDataBlocks[i].ThreadParameters .ModuleReadyEvent; ModuleInitFailedEvents[i] = ModuleControlDataBlocks[i].ThreadParameters .ModuleInitFailedEvent; } while (InitHasFailed == false) { if (WaitHandle.WaitAll(ModuleReadyEvents, (int)TimeInterval.LongTime, true)) { Debug.WriteLine( "Phase 1 initialization of all modules complete!"); break; } else { int WaitReturnValue = WaitHandle.WaitAny(ModuleInitFailedEvents, (int)TimeInterval.VeryVeryShortTime, true); if (WaitReturnValue != WaitHandle.WaitTimeout) { InitHasFailed = true; CleanupExit(); } } } Debug.WriteLine("Core Thread ID: " + Thread.CurrentThread.ManagedThreadId); // Signal modules to start working ModuleStartWorkEvent.Set(); // Start to execute UI try { UIThreadHandle.Start(); } catch (ArgumentNullException ex) { Debug.WriteLine(ex.Message); Debug.WriteLine("UI thread can not start!"); CleanupExit(); } coreControl.Run(); UIThreadHandle.Join(); CleanupExit(); //return; }