Beispiel #1
0
        /// <summary>
        /// Method to send an association accept.
        /// </summary>
        /// <param name="associate">The parameters to use for the association accept.</param>
        public void SendAssociateAccept(AssociationParameters associate)
        {
            if (State != DicomAssociationState.Sta3_AwaitingLocalAAssociationResponsePrimative)
            {
                Platform.Log(LogLevel.Error, "Error attempting to send association accept at invalid time in association.");
                SendAssociateAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.NotSpecified);
                throw new DicomNetworkException(
                    "Attempting to send association accept at invalid time in association, aborting");
            }
            var pdu = new AAssociateAC(_assoc);

            EnqueuePdu(pdu.Write());

            State = DicomAssociationState.Sta6_AssociationEstablished;

            if (AssociationEstablished != null)
                AssociationEstablished(_assoc);
        }
Beispiel #2
0
        private bool ProcessRawPDU(RawPDU raw)
        {
            try
            {
                switch (raw.Type)
                {
                    case 0x01:
                        {
                            _assoc = new ServerAssociationParameters();
                            var pdu = new AAssociateRQ(_assoc);
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta3_AwaitingLocalAAssociationResponsePrimative;
                            OnReceiveAssociateRequest(_assoc as ServerAssociationParameters);

                            if (State != DicomAssociationState.Sta13_AwaitingTransportConnectionClose &&
                                State != DicomAssociationState.Sta6_AssociationEstablished)
                            {
                                Platform.Log(LogLevel.Error, "Association incorrectly not accepted or rejected, aborting.");
                                return false;
                            }

                            //if derived class call SendAssociateAccept, it has fired this event
                            //if (AssociationEstablished != null)
                            //    AssociationEstablished(_assoc);

                            return true;
                        }
                    case 0x02:
                        {
                            var pdu = new AAssociateAC(_assoc);
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta6_AssociationEstablished;

                            OnReceiveAssociateAccept(_assoc);

                            if (AssociationEstablished != null)
                                AssociationEstablished(_assoc);

                            return true;
                        }
                    case 0x03:
                        {
                            var pdu = new AAssociateRJ();
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta13_AwaitingTransportConnectionClose;

                            if (AssociationRejected != null)
                                AssociationRejected(pdu.Source, pdu.Reason);

                            OnReceiveAssociateReject(pdu.Result, pdu.Source, pdu.Reason);

                            return true;
                        }
                    case 0x04:
                        {
                            var pdu = new PDataTF();
                            pdu.Read(raw);
                            return ProcessPDataTF(pdu);
                        }
                    case 0x05:
                        {
                            var pdu = new AReleaseRQ();
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta8_AwaitingAReleaseRPLocalUser;

                            OnReceiveReleaseRequest();

                            return true;
                        }
                    case 0x06:
                        {
                            var pdu = new AReleaseRP();
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta13_AwaitingTransportConnectionClose;

                            if (AssociationReleased != null)
                                AssociationReleased(_assoc);

                            OnReceiveReleaseResponse();

                            return true;
                        }
                    case 0x07:
                        {
                            var pdu = new AAbort();
                            pdu.Read(raw);
                            State = DicomAssociationState.Sta1_Idle;

                            if (AssociationAborted != null)
                                AssociationAborted(_assoc, pdu.Reason);

                            OnReceiveAbort(pdu.Source, pdu.Reason);

                            return true;
                        }
                    case 0xFF:
                        {
                            Platform.Log(LogLevel.Error, "Unexpected PDU type: 0xFF.  Potential parsing error.");
                            return false;
                        }
                    default:
                        throw new DicomNetworkException("Unknown PDU type");
                }
            }
            catch (Exception e)
            {
                OnNetworkError(e, true);

                if (NetworkError != null)
                    NetworkError(e);

                Platform.Log(LogLevel.Error, e, "Unexpected exception when processing PDU.");
                return false;
            }
        }