Exemplo n.º 1
0
 /// <summary>
 /// Creates an MqttMessage from a data stream
 /// </summary>
 /// <param name="str">Input stream</param>
 /// <param name="header">The first byte of the fixed header of the message</param>
 public MqttMessage(INetworkStream str, byte header)
 {
     this._timestamp = DateTime.Now.Ticks;
     ConstructHeader(header);
     variableHeaderLength = DecodeVariableHeaderLength(str);
     ConstructFromStream(str);
 }
Exemplo n.º 2
0
 public void Connect()
 {
     _channel = StreamFactory.CreateStream(_connString);
     readOp = _channel.BeginRead(headerBuffer, 0, 1, callback, null);
     // Give the qosManager a handle to the streams
     qosManager.SetStreamManager(this);
     _connected = true;
 }
Exemplo n.º 3
0
 private ITcpClientFactory CreateClientFactory()
 {
    var tcpClientFactory = MockRepository.GenerateStub<ITcpClientFactory>();
    _tcpClient = MockRepository.GenerateMock<ITcpClient>();
    _stream = MockRepository.GenerateMock<INetworkStream>();
    tcpClientFactory.Stub(x => x.Create()).Return(_tcpClient);
    return tcpClientFactory;
 }
Exemplo n.º 4
0
		public INetworkStream GetStream ()
		{
			if (_stream == null) 
			{
				_stream = new IosNetworkStream (_client.GetStream ());
			}	

			return _stream;
		}
Exemplo n.º 5
0
 public static IAsyncResult BeginSend(
     this DicomClient @this,
     INetworkStream stream,
     string callingAe,
     string calledAe,
     AsyncCallback callback,
     object state)
 {
     return AsyncFactory.ToBegin(@this.SendAsync(stream, callingAe, calledAe), callback, state);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomService"/> class.
        /// </summary>
        /// <param name="stream">Network stream.</param>
        /// <param name="fallbackEncoding">Fallback encoding.</param>
        /// <param name="log">Logger</param>
        protected DicomService(INetworkStream stream, Encoding fallbackEncoding, Logger log)
        {
            _network = stream;
            _lock = new object();
            _pduQueue = new Queue<PDU>();
            MaximumPDUsInQueue = 16;
            _msgQueue = new Queue<DicomMessage>();
            _pending = new List<DicomRequest>();
            _isConnected = true;
            _fallbackEncoding = fallbackEncoding ?? DicomEncoding.Default;
            Logger = log ?? LogManager.GetLogger("Dicom.Network");
            Options = new DicomServiceOptions();

            BackgroundWorker = ReadAndProcessPDUAsync();
        }
Exemplo n.º 7
0
        protected override void ConstructFromStream(INetworkStream str)
        {
            int payloadLen = base.variableHeaderLength;

            _topic = ReadStringFromStream(str);
            payloadLen -= (GetUTF8StringLength(_topic) + 2);

            if (msgQos != QoS.BestEfforts) {
              _messageID = ReadUshortFromStream(str);
              payloadLen -= 2;
            }

            _payload = new byte[payloadLen];

            ReadCompleteBuffer(str, _payload);
        }
Exemplo n.º 8
0
 public PrintService(INetworkStream stream, Encoding fallbackEncoding, Dicom.Log.Logger log)
     : base(stream, fallbackEncoding, log)
 {
     var pi = stream.GetType()
         .GetProperty(
             "Socket",
             System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
     if (pi != null)
     {
         var endPoint =
             ((System.Net.Sockets.Socket)pi.GetValue(stream, null)).RemoteEndPoint as System.Net.IPEndPoint;
         RemoteIP = endPoint.Address;
     }
     else
     {
         RemoteIP = new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 });
     }
 }
Exemplo n.º 9
0
        public static MqttMessage CreateMessage(INetworkStream str, byte header)
        {
            // Look at the fixed header to decide what message type we have
            MessageType messageType = (MessageType)((header & 0xf0) >> 4);

            //Log.Write( LogLevel.DEBUG, "Message " + messageType + " received");

            switch (messageType)
            {
                case MessageType.CONNACK:
                    return new MqttConnackMessage(str, header);
                case MessageType.DISCONNECT:
                    return null;
                case MessageType.PINGREQ:
                    return new MqttPingReqMessage();
                case MessageType.PUBACK:
                    return new MqttPubackMessage(str, header);
                case MessageType.PUBCOMP:
                    return new MqttPubcompMessage(str, header);
                case MessageType.PUBLISH:
                    return new MqttPublishMessage(str, header);
                case MessageType.PUBREC:
                    return new MqttPubrecMessage(str, header);
                case MessageType.PUBREL:
                    return new MqttPubrelMessage(str, header);
                case MessageType.SUBACK:
                    return new MqttSubackMessage(str, header);
                case MessageType.UNSUBACK:
                    return new MqttUnsubackMessage(str, header);
                case MessageType.PINGRESP:
                    return new MqttPingRespMessage(str, header);
                case MessageType.UNSUBSCRIBE:
                case MessageType.CONNECT:

                case MessageType.SUBSCRIBE:
                default:
                    throw new Exception("Unsupported Message Type");

            }
        }
Exemplo n.º 10
0
		protected override void ConstructFromStream(INetworkStream str)
        {
            // Read the message ID that the server is acknowlodging
            _ackID = ReadUshortFromStream(str);
            int qosCount = variableHeaderLength - 2;
            grantedQos = new QoS[qosCount];

            for (int i = 0; i < qosCount; i++)
            {
                int res = str.ReadByte();
                if (res != -1)
                {
                    grantedQos[i] = (QoS)res;
                }
                else
                {
                    throw new Exception("Failed to read byte from stream");
                }
            }


        }
Exemplo n.º 11
0
		public MqttPubackMessage(INetworkStream str, byte header) : base(str, header)
        {
          // Nothing to construct
        }
Exemplo n.º 12
0
 public static NetworkStream ToImplementation([CanBeNull] this INetworkStream abstraction)
 {
     return(((IAbstraction <NetworkStream>)abstraction)?.UnsafeConvert());
 }
 internal static void Connect(Connection connection, ITcpClient tcpClient, INetworkStream stream)
 {
     SetupSuccessfulConnectionExpectations(tcpClient, stream);
     connection.Connect("server", 10000, "password");
 }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="stream">The stream to return the tokens from.</param>
 /// <param name="bufferLength">The buffer length to read.</param>
 internal NetworkClient(INetworkStream stream, int bufferLength)
 {
     _stream       = stream;
     _bufferLength = bufferLength;
 }
Exemplo n.º 15
0
 public ImmediateSuccessAsyncDicomCFindProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 16
0
        /// <summary>
        /// Connect to a Folding@Home client server.
        /// </summary>
        /// <param name="host">Hostname or IP address.</param>
        /// <param name="port">TCP port number.</param>
        /// <param name="password">Server password.</param>
        /// <exception cref="InvalidOperationException">Connection is already connected.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="host"/> or <paramref name="password"/> is null.</exception>
        /// <exception cref="TimeoutException">Connection attempt timed out.</exception>
        public void Connect(string host, int port, string password)
        {
            // check connection status, callers should make sure no connection exists first
             if (Connected) throw new InvalidOperationException("Client is already connected.");

             if (host == null) throw new ArgumentNullException("host");
             if (password == null) throw new ArgumentNullException("password");

             if (_tcpClient != null)
             {
            _tcpClient.Dispose();
             }
             _tcpClient = CreateClient();

             IAsyncResult ar = _tcpClient.BeginConnect(host, port, null, null);
             try
             {
            if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectTimeout), false))
            {
               _tcpClient.Close();
               throw new TimeoutException("Client connection has timed out.");
            }

            _tcpClient.EndConnect(ar);
            _stream = _tcpClient.GetStream();

            if (password.Length != 0)
            {
               // send authentication
               SendCommand("auth " + password);
            }
            if (Connected)
            {
               // send connected event
               OnConnectedChanged(new ConnectedChangedEventArgs(true)); // maybe use Connected property?
               // send status message
               OnStatusMessage(new StatusMessageEventArgs(String.Format(CultureInfo.CurrentCulture,
                  "Connected to {0}:{1}", host, port), TraceLevel.Info));
               // start listening for messages
               // from the network stream
               _timer.Start();
            }
             }
             finally
             {
            ar.AsyncWaitHandle.Close();
             }
        }
Exemplo n.º 17
0
 public NeverRespondingDicomServer(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
 {
     _requests = new ConcurrentBag <DicomRequest>();
 }
Exemplo n.º 18
0
 public ChunkedEncoding(INetworkStream serverStream, INetworkStream browserStream)
 {
     buffer             = new byte[BufferSize];
     this.serverStream  = serverStream;
     this.browserStream = browserStream;
 }
Exemplo n.º 19
0
 public QRService(INetworkStream stream, Encoding fallbackEncoding, ILogger log, ILogManager logmanager, INetworkManager network, ITranscoderManager transcoder) : base(stream, fallbackEncoding, log, logmanager, network, transcoder)
 {
     /* initialization per association can be done here */
 }
Exemplo n.º 20
0
 public CStoreScp(INetworkStream stream, Encoding fallbackEncoding, Logger log, ILogManager logManager,
                  INetworkManager networkManager, ITranscoderManager transcoderManager)
     : base(stream, fallbackEncoding, log, logManager, networkManager, transcoderManager)
 {
 }
 public SimpleStorageComitmentProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 22
0
 public SlowPendingResponsesDicomServer(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 23
0
 public SimpleCStoreProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 24
0
 public CFindSCP(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
     m_WorklistRepository = new WorklistRepository();
 }
Exemplo n.º 25
0
 public void Dispose()
 {
     if (_stream != null)
     {
         _logger.LogMessage("Socket", LogLevel.Verbose, "Closing existing network stream.");
         _stream.Close();    // also closes the socket
         _stream = null;
     }
     _socket = null;
 }
Exemplo n.º 26
0
        //---------------------------------------------------------------------
        // Ctor
        //---------------------------------------------------------------------

        public FragmentingStream(INetworkStream stream)
        {
            this.stream = stream;
        }
Exemplo n.º 27
0
 private INetworkStream GetStream()
 {
     if (_stream == null)
     {
         lock (_streamCreationLock)
         {
             if (_stream == null)
             {
                 if (_encryptionLevel == SslProtocols.None)
                 {
                     _stream = new UnsecureStream(_socket);
                 }
                 else
                 {
                     try
                     {
                         _stream = new SecureStream(_remoteHost, _socket, _caCert, _encryptionLevel);
                     }
                     catch (SocketException ex)
                     {
                         if (ex.ErrorCode == -1)
                         {
                             var detail = new ErrorContextException("The remote certificate is invalid according to the validation procedure.", ex);
                             throw detail;
                         }
                         throw;
                     }
                 }
             }
         }
     }
     return _stream;
 }
Exemplo n.º 28
0
 public CStoreSCPProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
     _pacsReader = new PacsNodeReader();
 }
Exemplo n.º 29
0
 protected override void ConstructFromStream(INetworkStream str)
 {
     byte[] buffer = new byte[2];
     ReadCompleteBuffer(str, buffer);
     _response = (MqttConnectionResponse)buffer[1];
 }
Exemplo n.º 30
0
 protected static byte[] ReadCompleteBuffer(INetworkStream str, byte[] buffer)
 {
     int read = 0;
       while (read < buffer.Length)
       {
     int res = str.Stream.Read(buffer, read, buffer.Length - read);
     if (res == -1)
     {
         throw new Exception("End of stream reached whilst filling buffer");
     }
     read += res;
       }
       return buffer;
 }
Exemplo n.º 31
0
 public DicomCEchoProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 32
0
 protected static ushort ReadUshortFromStream(INetworkStream str)
 {
     // Read two bytes and interpret as ushort in Network Order
       byte[] data = new byte[2];
       ReadCompleteBuffer( str, data );
       return (ushort)((data[0] << 8) + data[1]);
 }
Exemplo n.º 33
0
 public PendingAsyncDicomCFindProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 34
0
        /// <summary>
        /// Decodes the length of the variable header and payload from the given stream
        /// </summary>
        /// <param name="str">Input Stream</param>
        /// <returns>Length of the variable header and the payload</returns>
        private int DecodeVariableHeaderLength(INetworkStream str)
        {
            int multiplier = 1 ;
            int value = 0 ;
            int digit = 0;

            do
            {
                digit = str.ReadByte();
                if (digit == -1)
                {
                    return 0;
                }
                value += (digit & 127) * multiplier;
                multiplier *= 128;
            }
            while ((digit & 128) != 0);

            return value;
        }
Exemplo n.º 35
0
        /// <summary>
        /// Relay all received by one stream to another stream.
        /// </summary>
        public static Task RelayToAsync(
            this INetworkStream readStream,
            INetworkStream writeStream,
            CancellationToken token)
        {
            return(Task.Run(async() =>
            {
                // Use a buffer that is as large as possible, but does not exceed
                // any of the two stream's capabilities.
                int bufferSize = Math.Min(
                    writeStream.MaxWriteSize,
                    Math.Max(
                        MaxBufferSize,
                        readStream.MinReadSize));

                var buffer = new byte[bufferSize];

                while (true)
                {
                    token.ThrowIfCancellationRequested();

                    try
                    {
                        TraceSources.Compute.TraceVerbose($"NetworkStream [{readStream} > {writeStream}]: Reading...");
                        int bytesRead = await readStream.ReadAsync(
                            buffer,
                            0,
                            buffer.Length,
                            token).ConfigureAwait(false);

                        if (bytesRead > 0)
                        {
                            TraceSources.Compute.TraceVerbose($"NetworkStream [{readStream} > {writeStream}]: Read {bytesRead} bytes");

                            await writeStream.WriteAsync(buffer, 0, bytesRead, token).ConfigureAwait(false);
                        }
                        else
                        {
                            TraceSources.Compute.TraceVerbose($"NetworkStream [{readStream} > {writeStream}]: gracefully closed connection");

                            // Propagate.
                            await writeStream.CloseAsync(token).ConfigureAwait(false);

                            break;
                        }
                    }
                    catch (NetworkStreamClosedException)
                    {
                        TraceSources.Compute.TraceVerbose($"NetworkStream [{readStream} > {writeStream}]: forcefully closed connection");

                        // Propagate.
                        await writeStream.CloseAsync(token).ConfigureAwait(false);

                        break;
                    }
                    catch (Exception)
                    {
                        TraceSources.Compute.TraceVerbose($"NetworkStream [{readStream} > {writeStream}]: Caught unhandled exception");

                        throw;
                    }
                }
            }));
        }
 public SimpleAssociationAcceptProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 37
0
 public CStoreSCP(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
        private static void SetupSuccessfulConnectionExpectations(ITcpClient tcpClient, INetworkStream stream, bool withPassword = true)
        {
            // setup connect expectations
            var asyncResult = MockRepository.GenerateStub <IAsyncResult>();

            tcpClient.Expect(x => x.BeginConnect("server", 10000, null, null)).Return(asyncResult);
            asyncResult.Stub(x => x.AsyncWaitHandle).Return(new EventWaitHandle(true, EventResetMode.ManualReset));
            tcpClient.Expect(x => x.Client).Return(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)).Repeat.AtLeastOnce();
            tcpClient.Expect(x => x.EndConnect(asyncResult)).Do(new Action <IAsyncResult>(ar =>
            {
                // setup Connected property expectations
                tcpClient.Expect(x => x.Connected).Return(true).Repeat.AtLeastOnce();
            }));
            tcpClient.Expect(x => x.GetStream()).Return(stream);

            if (withPassword)
            {
                // setup SendCommand() expectation
                stream.Expect(x => x.BeginWrite(null, 0, 0, null, null)).IgnoreArguments().Do(
                    new Func <byte[], int, int, AsyncCallback, object, IAsyncResult>(TestUtilities.DoBeginWrite)).Repeat.AtLeastOnce();
            }
        }
Exemplo n.º 39
0
 protected static string ReadStringFromStream(INetworkStream str)
 {
     ushort len = ReadUshortFromStream(str);
       byte[] data = new byte[len];
       ReadCompleteBuffer(str, data);
       UTF8Encoding enc = new UTF8Encoding();
       return enc.GetString(data, 0, data.Length);
 }
Exemplo n.º 40
0
 public CStoreScp(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 41
0
 /// <summary>
 /// Concrete Message classes should extract their variable header and payload from the given stream
 /// </summary>
 /// <param name="str">Input Stream</param>
 protected virtual void ConstructFromStream(INetworkStream str)
 {
     throw new Exception("Protocol does not support receiving this type of message");
 }
Exemplo n.º 42
0
        /// <summary>
        /// Abort DICOM service connection.
        /// </summary>
        public void Abort()
        {
            if (this.aborted) return;

            if (this.associateNotifier != null && !this.associateNotifier.Task.IsCompleted)
            {
                this.associateNotifier.TrySetResult(false);
            }
            if (this.completeNotifier != null) this.completeNotifier.TrySetResult(true);

            if (this.networkStream != null)
            {
                try
                {
                    this.networkStream.Dispose();
                }
                catch
                {
                }
            }

            this.service = null;
            this.networkStream = null;

            this.aborted = true;
        }
        //------------------------------------------------------------------------------
        //
        // Method: ReadAndParseMessageData
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Reads bytes from the inputted network stream and parses them, storing the results in the inputted parameters.
        /// </summary>
        /// <param name="networkStream">The network stream to read data from.</param>
        /// <param name="parseState">Represents the current state of parsing.</param>
        /// <param name="messageSequenceNumberBytes">The bytes containing the message sequence number.</param>
        /// <param name="messageSequenceNumberCurrentPosition">The current read position within the message sequence number bytes.</param>
        /// <param name="messageSequenceNumber">The message sequence number.</param>
        /// <param name="messageSizeHeaderBytes">The header bytes containing the message size.</param>
        /// <param name="messageSizeHeaderCurrentPosition">The current read position within the message size header bytes.</param>
        /// <param name="messageSize">The size of the message body.</param>
        /// <param name="messageBytes">The bytes containing the message body.</param>
        private void ReadAndParseMessageData(INetworkStream networkStream, ref MessageParseState parseState, byte[] messageSequenceNumberBytes, ref int messageSequenceNumberCurrentPosition, ref int messageSequenceNumber, byte[] messageSizeHeaderBytes, ref int messageSizeHeaderCurrentPosition, ref long messageSize, Queue <byte> messageBytes)
        {
            int availableBytes = client.Available;

            if (availableBytes > 0)
            {
                byte[] tempBuffer = new byte[availableBytes];  // Temporary buffer to store bytes read from the network before parsing
                networkStream.Read(ref tempBuffer, 0, availableBytes);

                // Iterate through the bytes in the buffer, advancing the parse state as successive sections (i.e. start delimiter, sequence number, size header, body, etc...) are read
                for (int i = 0; i < tempBuffer.Length; i = i + 1)
                {
                    switch (parseState)
                    {
                    case MessageParseState.StartOfMessage:
                        if (tempBuffer[i] != messageStartDelimiter)
                        {
                            throw new Exception("First byte of received message was expected to be " + messageStartDelimiter.ToString() + ", but was " + tempBuffer[i].ToString() + ".");
                        }
                        else
                        {
                            parseState = MessageParseState.ReadStartDelimiter;
                        }
                        break;

                    case MessageParseState.ReadStartDelimiter:
                        messageSequenceNumberBytes[messageSequenceNumberCurrentPosition] = tempBuffer[i];
                        messageSequenceNumberCurrentPosition++;
                        // If 4 bytes have been read into the sequence number byte array, then set the sequence number, and advance to the next parse state
                        if (messageSequenceNumberCurrentPosition == 4)
                        {
                            // Decode as little endian
                            if (BitConverter.IsLittleEndian == false)
                            {
                                Array.Reverse(messageSequenceNumberBytes);
                            }
                            messageSequenceNumber = BitConverter.ToInt32(messageSequenceNumberBytes, 0);
                            parseState            = MessageParseState.ReadSequenceNumber;
                        }
                        break;

                    case MessageParseState.ReadSequenceNumber:
                        messageSizeHeaderBytes[messageSizeHeaderCurrentPosition] = tempBuffer[i];
                        messageSizeHeaderCurrentPosition++;
                        // If 8 bytes have been read into the message size header byte array, then set the message size, and advance to the next parse state
                        if (messageSizeHeaderCurrentPosition == 8)
                        {
                            // Decode as little endian
                            if (BitConverter.IsLittleEndian == false)
                            {
                                Array.Reverse(messageSizeHeaderBytes);
                            }
                            messageSize = BitConverter.ToInt64(messageSizeHeaderBytes, 0);
                            parseState  = MessageParseState.ReadSizeHeader;
                        }
                        break;

                    case MessageParseState.ReadSizeHeader:
                        messageBytes.Enqueue(tempBuffer[i]);
                        // If the number of bytes read matches the size specified in the header, advance to the next parse state
                        if (messageBytes.Count == messageSize)
                        {
                            parseState = MessageParseState.ReadMessageBody;
                        }
                        break;

                    case MessageParseState.ReadMessageBody:
                        if (tempBuffer[i] != messageEndDelimiter)
                        {
                            throw new Exception("Last byte of received message was expected to be " + messageEndDelimiter.ToString() + ", but was " + tempBuffer[i].ToString() + ".");
                        }
                        else
                        {
                            parseState = MessageParseState.ReadCompleteMessage;
                        }
                        break;

                    case MessageParseState.ReadCompleteMessage:
                        throw new Exception("Surplus data encountered after message delimiter character, starting with " + tempBuffer[i].ToString() + ".");
                    }
                }
            }
        }
 public AcceptOnlyEchoStoreProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
 {
     AcceptedSopClasses.Add(DicomUID.Verification);
     AcceptedSopClasses.AddRange(DicomUID.Enumerate().Where(u => u.IsImageStorage));
 }
Exemplo n.º 45
0
		protected override void ConstructFromStream(INetworkStream str)
        {
            // Nothing to construct
        }
Exemplo n.º 46
0
 public ImmediateSuccessAsyncDicomCFindProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log,
                                                ILogManager logManager, INetworkManager networkManager, ITranscoderManager transcoderManager)
     : base(stream, fallbackEncoding, log, logManager, networkManager, transcoderManager)
 {
 }
Exemplo n.º 47
0
        /// <summary>
        /// Asynchonously send existing requests to DICOM service.
        /// </summary>
        /// <param name="host">DICOM host.</param>
        /// <param name="port">Port.</param>
        /// <param name="useTls">Treu if TLS security should be enabled, false otherwise.</param>
        /// <param name="callingAe">Calling Application Entity Title.</param>
        /// <param name="calledAe">Called Application Entity Title.</param>
        /// <returns>Awaitable task.</returns>
        public async Task SendAsync(string host, int port, bool useTls, string callingAe, string calledAe)
        {
            if (!this.CanSend) return;

            var noDelay = this.Options != null ? this.Options.TcpNoDelay : DicomServiceOptions.Default.TcpNoDelay;
            var ignoreSslPolicyErrors = (this.Options ?? DicomServiceOptions.Default).IgnoreSslPolicyErrors;

            this.networkStream = NetworkManager.CreateNetworkStream(host, port, useTls, noDelay, ignoreSslPolicyErrors);
            this.InitializeSend(this.networkStream.AsStream(), callingAe, calledAe);

            await this.completeNotifier.Task.ConfigureAwait(false);
            this.FinalizeSend();
        }
Exemplo n.º 48
0
 public SimpleStorageComitmentProvider(INetworkStream stream, Encoding fallbackEncoding, ILogger log, ILogManager logManager, INetworkManager networkManager, ITranscoderManager transcoderManager)
     : base(stream, fallbackEncoding, log, logManager, networkManager, transcoderManager)
 {
 }
Exemplo n.º 49
0
        private void FinalizeSend()
        {
            if (!this.associateNotifier.Task.IsCompleted)
            {
                this.associateNotifier.TrySetResult(true);
            }

            if (this.networkStream != null)
            {
                try
                {
                    this.networkStream.Dispose();
                }
                catch
                {
                }
            }

            this.service = null;
            this.networkStream = null;
        }
Exemplo n.º 50
0
 public WorklistService(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 51
0
		protected override void ConstructFromStream(INetworkStream str)
        {
            _ackID = ReadUshortFromStream(str);
        }
        public void Send(IMessage message, INetworkStream outputStream)
        {
            var serialized = serializer.Serialize(message);

            outputStream.Write(serialized, 0, serialized.Length);
        }
Exemplo n.º 53
0
 private void CreateSocket(AddressFamily addressFamily)
 {
     if (_stream != null)
     {
         _logger.LogMessage("Socket", LogLevel.Verbose, "Closing existing network stream.");
         _stream.Close();    // also closes the socket
         _stream = null;
         _socket = null;
     }
     _socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
     //_socket.ReceiveTimeout = MqttProtocolInformation.Settings.NetworkTimeout * 1000;
     //_socket.SendTimeout = MqttProtocolInformation.Settings.NetworkTimeout * 1000;
 }
Exemplo n.º 54
0
 public DicomClientConnection(DicomClient dicomClient, INetworkStream networkStream)
     : base(networkStream, dicomClient.FallbackEncoding, dicomClient.Logger)
 {
     DicomClient   = dicomClient;
     NetworkStream = networkStream;
 }
Exemplo n.º 55
0
 /// <summary>
 /// Close the connection to the Folding@Home client server.
 /// </summary>
 public void Close()
 {
     // stop the timer
      _timer.Stop();
      // close the network stream
      if (_stream != null)
      {
     _stream.Close();
      }
      // remove reference to the network stream
      _stream = null;
      // close the actual connection
      _tcpClient.Close();
      // send connected event
      OnConnectedChanged(new ConnectedChangedEventArgs(false)); // maybe use Connected property?
      // send status message
      OnStatusMessage(new StatusMessageEventArgs("Connection closed.", TraceLevel.Info));
 }
 public AsyncDicomCStoreProviderPreferingUncompressedTS(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 57
0
 /// <summary>
 /// Construct a MqttConneckMessage from a stream
 /// </summary>
 /// <param name="str"></param>
 /// <param name="header"></param>
 public MqttConnackMessage(INetworkStream str, byte header)
     : base(str, header)
 {
 }
 public AsyncDicomCStoreProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
Exemplo n.º 59
0
 public MockCEchoProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log)
     : base(stream, fallbackEncoding, log)
 {
 }
 public AsyncDicomCStoreProvider(INetworkStream stream, Encoding fallbackEncoding, Logger log,
                                 ILogManager logManager, INetworkManager networkManager, ITranscoderManager transcoderManager)
     : base(stream, fallbackEncoding, log, logManager, networkManager, transcoderManager)
 {
 }