public String getSegments(String message, String segmentWanted) { StringBuilder t = new StringBuilder(message); hl7 hl7 = new hl7(); message = hl7.StripMLLPContainer(t); int cnt = 0; foreach (char c in message) { if (c == (char)13) { cnt++; } } segmentWanted = segmentWanted.ToUpper().Trim() + "|"; String[] Segments = message.Split((char)13); foreach (String item in Segments) { if (item.IndexOf(segmentWanted) > -1) { return(item); } } return(""); }
// Default constructor public OSServer(Settings intSettings) { exceptionthrown = false; // First we set up our mutex and semaphore mutex = new Mutex(); numconnections = 0; // Then we create our stack of read sockets socketpool = new OSAsyncEventStack(Convert.ToInt32(intSettings.NumConnect)); // Now we create enough read sockets to service the maximum number of clients // that we will allow on the server // We also assign the event handler for IO Completed to each socket as we create it // and set up its buffer to the right size. // Then we push it onto our stack to wait for a client connection for (Int32 i = 0; i < Convert.ToInt32(intSettings.NumConnect); i++) { SocketAsyncEventArgs item = new SocketAsyncEventArgs(); item.Completed += new EventHandler<SocketAsyncEventArgs>(OnIOCompleted); item.SetBuffer(new Byte[Convert.ToInt32(intSettings.BufferSize)], 0, Convert.ToInt32(intSettings.BufferSize)); socketpool.Push(item); } // Create the Mllp Helper object here hl7 hl7 = new hl7(); }
// This method is used to send a message to the server public bool Send(string cmdstring) { hl7 hl7 = new hl7(); cmdstring = hl7.CreateMLLPMessage(cmdstring); exceptionthrown = false; //var parameters = os_util.ParseParams(cmdstring); if (cmdstring.Length > 0) { try { // We need a connection to the server to send a message if (connectionsocket.Connected) { byte[] byData = System.Text.Encoding.ASCII.GetBytes(cmdstring); connectionsocket.Send(byData); // connectionsocket.Receive() return true; } else { try { this.Connect(intSet.RemoteIPAddress, Convert.ToInt32(intSet.RemotePort)); if (connectionsocket.Connected) { byte[] byData = System.Text.Encoding.ASCII.GetBytes(cmdstring); connectionsocket.Send(byData); return true; } return false; } catch (Exception ex) { lasterror = ex.ToString(); return false; } } } catch (Exception ex) { lasterror = ex.ToString(); return false; } } else { lasterror = "No message provided for Send."; return false; } }
public String makeAck(String message) { String tempString = message.Substring(1, message.IndexOf((char)13)); String firstPartAck = @"MSH|^~\&|MagView||||20140510233808||ACK|"; String secondPartAck = "|T|2.x||||||||"; String thirdPartAck = "MSA|AA||||||"; StringBuilder t = new StringBuilder(firstPartAck); String messageId = this.getMessageId(message, 9); String tempString2 = ""; t.Append(messageId); t.Append(secondPartAck); t.Append((char)13); t.Append(thirdPartAck); hl7 hl7 = new hl7(); tempString2 = hl7.CreateMLLPMessage(t.ToString()); this.ack = tempString2; return(tempString2); }