Exemplo n.º 1
0
        protected override bool OnReceiveFileStream(byte pcid, DicomAttributeCollection command, DicomAttributeCollection dataset, byte[] data, int offset, int count, bool isFirst, bool isLast)
        {
            try
            {
                if (isFirst)
                {
                    _filestreamHandler = _handler.OnStartFilestream(this, _assoc as ServerAssociationParameters, pcid, new DicomMessage(command, dataset));
                }

                if (!_filestreamHandler.SaveStreamData(new DicomMessage(command, dataset), data, offset, count))
                {
                    return(false);
                }

                if (isLast)
                {
                    _filestreamHandler.CompleteStream(this, _assoc as ServerAssociationParameters, pcid,
                                                      new DicomMessage(command, dataset));
                    _filestreamHandler = null;
                }

                return(true);
            }
            catch (Exception e)
            {
                OnUserException(e, "Unexpected exception on OnReceiveFileStream");
                return(false);
            }
        }
Exemplo n.º 2
0
        protected override bool OnReceiveFileStream(byte pcid, DicomDataset command, DicomDataset dataset, byte[] data, int offset, int count, bool encounteredStopTag, bool isFirst, bool isLast)
        {
            try
            {
                if (!encounteredStopTag)
                {
                    // Buffer data until we get to the stop tag so all the attributes expected are filled in.
                    if (_bufferedFilestream == null)
                    {
                        _bufferedFilestream = new MemoryStream();
                    }

                    _bufferedFilestream.Write(data, offset, count);
                    return(true);
                }

                if (isFirst || _bufferedFilestream != null)
                {
                    _filestreamHandler = _handler.OnStartFilestream(this, _assoc as ServerAssociationParameters, pcid, new DicomMessage(command, dataset));
                }

                if (_bufferedFilestream != null)
                {
                    var a = _bufferedFilestream.ToArray();
                    _bufferedFilestream = null;

                    if (!_filestreamHandler.SaveStreamData(new DicomMessage(command, dataset), a, 0, a.Length))
                    {
                        return(false);
                    }
                }

                if (!_filestreamHandler.SaveStreamData(new DicomMessage(command, dataset), data, offset, count))
                {
                    return(false);
                }

                if (isLast)
                {
                    _filestreamHandler.CompleteStream(this, _assoc as ServerAssociationParameters, pcid,
                                                      new DicomMessage(command, dataset));
                    _filestreamHandler = null;
                }

                return(true);
            }
            catch (Exception e)
            {
                OnUserException(e, "Unexpected exception on OnReceiveFileStream");
                return(false);
            }
        }