public void __start_listener(int __port, motSocket.__void_string_delegate __s_callback) { try { __socket = new motSocket(__port, __s_callback); __socket.__use_ssl = __use__ssl; if (__use__ssl) { __worker = new Thread(() => __socket.secure_listen_async()); __worker.Name = "secure listener"; __worker.Start(); } else { __worker = new Thread(new ThreadStart(__socket.listen_async)); __worker.Name = "listener"; __worker.Start(); } } catch (Exception e) { string __err = string.Format("An error occurred while attempting to start the HL7 listener: {0}", e.Message); __ui_args.__event_message = __err; UpdateErrorUI(this, __ui_args); __logger.Error(__err); throw; } }
public async void __start_up(ExecuteArgs __args) { this.__target_address = __args.__gateway_address; this.__target_port = Convert.ToInt32(__args.__gateway_port); this.__sending_app = __args.__sending_application; this.__pharmacy_id = __args.__pharmacy_id; this.__recieving_facility = __args.__receiving_facility; this.__control_number = Convert.ToInt64(Properties.Settings.Default.ControlNumber); try { using (var p = new motSocket(__target_address, __target_port)) { __show_common_event("QuickMAR Proxy Starting Up"); __show_common_event(string.Format("Sending to: {0}:{1}", __args.__gateway_address, __args.__gateway_port)); } await Login("mot", "mot"); } catch (Exception e) { __show_error_event(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__gateway_address, __args.__gateway_port, e.Message)); __logger.Error("Failed to start on {0}:{1}, Error: {2}", __args.__gateway_address, __args.__gateway_port, e.Message); } }
public Listener(string LAddress, int LPort, string GAddress, int GPort) { try { ListenPort = new motSocket(LAddress, LPort); GatewayPort = new motSocket(GAddress, GPort); } catch (Exception ex) { Console.WriteLine("Listener Startup Failure: {0}", ex.Message); } }
// Do the real work here - call delegates to update UI public void __start_up(ExecuteArgs __args) { try { __logger = LogManager.GetLogger("GatewayTester.Main"); __update_event_ui("Proxy Tester Starting Up"); __p = new motSocket(__args.__gateway_address, Convert.ToInt32(__args.__gateway_port)); __update_event_ui(string.Format("Listening on: {0}:{1}, Sending to: {2}:{3}", __args.__listen_address, __args.__listen_port, __args.__gateway_address, __args.__gateway_port)); } catch (Exception e) { __update_error_ui(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message)); __logger.Log(__log_level, "Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message); } }
//string __test_prescriber = "AP\xEE LastName\xEE FirstName\xEE MiddleInitial\xEE Address1\xEE Address2\xEE City\xEE State\xEE Zip\xEE Phone\xEE Comments\xEE DEA_ID\xEE TPID\xEE Speciality\xEE Fax\xEE PagerInfo\xEERxSysDoc1\xEE 1025143\xE2 AP\xEEpLastName\xEEpFirstName\xEEpMiddleInitial\xEEpAddress1\xEEpAddress2\xEEpCity\xEEpState\xEEpZip\xEEPhone\xEEpComments\xEEpDEA_ID\xEEpTPID\xEEpSpeciality\xEEpFax\xEEpPagerInfo\xEERxSysDoc2\xEE 1972834\xE2"; public void __start_up(ExecuteArgs __args) { try { //List<Listener> PortStack = new List<Listener>(); //PortStack.Add(new Listener("localhost", Convert.ToInt32(__args.__listen_port), // __args.__gateway_address, Convert.ToInt32(__args.__gateway_port))); Console.WriteLine("__start_listener: {0}", Thread.CurrentThread.ManagedThreadId); __gateway_address = __args.__gateway_address; __gateway_port = __args.__gateway_port; int __lp = Convert.ToInt32(__args.__listen_port); __socket = new motSocket(__lp, __parse); __socket.__b_stream_processor = __clean_buffer; __socket.__b_protocol_processor = __delimited_protocol_processor; __use_v1 = __args.__use_v1; __send_eof = __args.__send_eof; __debug_mode = __args.__debug_mode; __auto_truncate = __args.__auto_truncate; // This will start the listener and call the callback __worker = new Thread(new ThreadStart(__socket.listen)); __worker.Name = "listener"; __worker.Start(); __update_event_ui("Started listening to on port: " + __args.__listen_port); __update_event_ui(string.Format("Sending data to: {0}:{1}", __args.__gateway_address, __args.__gateway_port)); } catch (Exception e) { string __err = string.Format("An error occurred while attempting to start the delimited gateway listener: {0}", e.Message); Console.WriteLine(__err); __logger.Log(__log_level, __err); __update_error_ui(__err); throw; } }
public void __start_listener(int __port, motSocket.__void_delegate __callback_p) { try { Console.WriteLine("__start_listener: {0}", Thread.CurrentThread.ManagedThreadId); __socket = new motSocket(__port, __callback_p); // This will start the listener and call the callback __worker = new Thread(new ThreadStart(__socket.listen)); __worker.Name = "listener"; __worker.Start(); } catch (Exception e) { string __err = string.Format("An error occurred while attempting to start the HL7 listener: {0}\nExiting ...", e.Message); Console.WriteLine(__err); //__logger.Error(__err); } }
public void __start_up(ExecuteArgs __args) { this.__args = __args; // Test cross thread communication Task.Run(() => { try { __show_common_event("Strucured Data Proxy Starting Up"); } catch (Exception e) { __show_error_event(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message)); __logger.Log(__log_level, "Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message); } }); // Generic listener setup try { Console.WriteLine("__start_listener: {0}", Thread.CurrentThread.ManagedThreadId); int __lp = Convert.ToInt32(__args.__listen_port); __listener = new motSocket(__lp, __parse_data); __worker = new Thread(new ThreadStart(__listener.listen)); __worker.Name = "listener"; __worker.Start(); __show_common_event("Started listening to on port: " + __args.__listen_port); __gateway = new motSocket(__args.__gateway_address, Convert.ToInt32(__args.__gateway_port)); __show_common_event(string.Format("Sending data to: {0}:{1}", __args.__gateway_address, __args.__gateway_port)); } catch (Exception e) { __show_error_event(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message)); __logger.Log(__log_level, "Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message); } }
//------------------------------------------------------------------------------------------------------ public void __send_message(string __message) { try { byte[] __retval = new byte[256]; using (var __target = new motSocket(__target_address, __target_port)) { __target.write(__message); __target.read(ref __retval, 0, 256); __show_common_event(Encoding.UTF8.GetString(__retval, 0, 256)); __control_number++; Properties.Settings.Default.ControlNumber = string.Format("{0,10}", __control_number.ToString("D10")); } } catch (Exception ex) { __show_error_event(string.Format("Message Wite Failed. Error: {0}", ex.Message)); __logger.Error("Message Wite Failed. Error: {0}", ex.Message); } }
public void watchDirectory(string dirName, string __address, string __port) { Logger __logger = LogManager.GetLogger("FileSystemWatcher"); __listen = true; while (__listen) { Thread.Sleep(1024); if (Directory.GetFiles(dirName) != null) { string[] __fileEntries = Directory.GetFiles(dirName); foreach (string __fileName in __fileEntries) { if (__fileName.Contains(".FAILED")) { continue; } try { using (var __socket = new motSocket(__address, Convert.ToInt32(__port), __process_return)) { using (var sr = new StreamReader(__fileName)) { var __mp = new motParser(__socket, sr.ReadToEnd(), __file_type, __auto_truncate, __send_eof, __debug_mode); __ui_args.timestamp = DateTime.Now.ToString(); __ui_args.__event_message = string.Format("Successfully Processed {0}", __fileName); UpdateEventUI(this, __ui_args); } File.Delete(__fileName); } } catch (Exception ex) { if (!File.Exists(__fileName + ".FAILED")) { File.Move(__fileName, __fileName + ".FAILED"); } if (File.Exists(__fileName)) { File.Delete(__fileName); } __ui_args.timestamp = DateTime.Now.ToString(); __ui_args.__event_message = string.Format("Failed While Processing {0} : {1}", __fileName, ex.Message); UpdateErrorUI(this, __ui_args); __logger.Error("Failed While Processing {0} : {1}", __fileName, ex.Message); } } } } Console.WriteLine("Exiting Thread {0}", Thread.CurrentThread.Name); }