public void OnData(MessageType control, Message message) { Logging.Log("VerificationServiceSCP.OnData"); DataSet dicom = message.Dicom; PresentationDataPdu pdu = new PresentationDataPdu(syntaxes[0]); PresentationDataValue pdv = new PresentationDataValue(PresentationContextId, Syntaxes[0], MessageType.LastCommand); DataSet response = new DataSet(); response.Add(t.GroupLength(0), (uint)0);// response.Add(t.AffectedSOPClassUID, this.SOPClassUId); response.Add(t.CommandField, (ushort)CommandType.C_ECHO_RSP); ushort messageId = (ushort)dicom[t.MessageId].Value; response.Add(t.MessageIdBeingRespondedTo, messageId); response.Add(t.CommandDataSetType, (ushort)DataSetType.DataSetNotPresent);// response.Add(t.Status, (ushort)0); pdv.Dicom = response; pdu.Values.Add(pdv); SendPdu("C-ECHO-RSP", pdu); }
public static bool OnPdu(EK.Capture.Dicom.DicomToolKit.ProtocolDataUnit pdu) { switch (pdu.PduType) { case ProtocolDataUnit.Type.A_ASSOCIATE_RQ: { AssociateRequestPdu request = pdu as AssociateRequestPdu; } break; case ProtocolDataUnit.Type.A_ASSOCIATE_AC: { AssociateRequestPdu response = pdu as AssociateRequestPdu; } break; case ProtocolDataUnit.Type.A_ASSOCIATE_RJ: { AssociateRejectPdu reject = pdu as AssociateRejectPdu; } break; case ProtocolDataUnit.Type.P_DATA_TF: { PresentationDataPdu message = pdu as PresentationDataPdu; } break; case ProtocolDataUnit.Type.A_RELEASE_RQ: { AssociationReleasePdu request = pdu as AssociationReleasePdu; } break; case ProtocolDataUnit.Type.A_RELEASE_RP: { AssociationReleasePdu response = pdu as AssociationReleasePdu; } break; case ProtocolDataUnit.Type.A_ABORT: { AssociateAbortPdu abort = pdu as AssociateAbortPdu; } break; } // return true if you change the pdu, false if you did not return(true); }
private void PipeThread(object arg) { threadEvent.Set(); Connection connection = arg as Connection; byte[] buffer = new byte[MaxPduSize]; int position = 0; MethodInfo OnPdu = null; if (assembly != null) { //Use reflection to call the static Main function Module[] mods = assembly.GetModules(false); Type[] types = mods[0].GetTypes(); Type type = mods[0].GetType("Script"); // get a hold of Script OnPdu = type.GetMethod("OnPdu"); } try { NetworkStream input = new NetworkStream(connection.ReadSocket, FileAccess.Read, false); NetworkStream output = new NetworkStream(connection.WriteSocket, FileAccess.Write, false); while (true) { byte[] bytes = Receive(input, buffer, ref position); if (bytes == null) { break; } // if we have some data and a valid script, execute the script MemoryStream memory = new MemoryStream(bytes, 0, bytes.Length); ProtocolDataUnit pdu = null; switch ((ProtocolDataUnit.Type)bytes[0]) { case ProtocolDataUnit.Type.A_ASSOCIATE_RQ: pdu = new AssociateRequestPdu(); pdu.Read(memory); break; case ProtocolDataUnit.Type.A_ASSOCIATE_AC: pdu = new AssociateRequestPdu(); pdu.Read(memory); // we will need to know the transfer syntaxes of presentation data ExtractSyntaxes((AssociateRequestPdu)pdu); break; case ProtocolDataUnit.Type.A_ASSOCIATE_RJ: pdu = new AssociateRejectPdu(); pdu.Read(memory); break; case ProtocolDataUnit.Type.P_DATA_TF: // find the presentation's transfer syntax as negotiated earlier in the association string syntax = syntaxes[bytes[10]]; pdu = new PresentationDataPdu(syntax); pdu.Read(memory); break; case ProtocolDataUnit.Type.A_RELEASE_RQ: pdu = new AssociationReleasePdu((ProtocolDataUnit.Type)bytes[0]); pdu.Read(memory); break; case ProtocolDataUnit.Type.A_RELEASE_RP: pdu = new AssociationReleasePdu(); break; case ProtocolDataUnit.Type.A_ABORT: pdu = new AssociateAbortPdu(); pdu.Read(memory); break; default: Logging.Log(LogLevel.Error, "Unsupported ProtocolDataUnit.Type={0}", bytes[0]); break; } if (connection.LogEnabled) { Logging.Log(LogLevel.Verbose, pdu.Name); string text = String.Format("{0} bytes.", pdu.Length); if (pdu.Length < 8192) { text = pdu.ToText(); } Logging.Log(LogLevel.Verbose, text); } if (assembly != null && pdu != null && OnPdu != null) { // if the script returns true, assume the pdu was changed if (RunScript(OnPdu, pdu)) { // so we re-write the contents into the byte array MemoryStream stream = new MemoryStream(); pdu.Write(stream); bytes = stream.ToArray(); } } // we pass the bytes, altered or not, on to the other side output.Write(bytes, 0, bytes.Length); } } finally { threadEvent.Reset(); connection.Close(); } }