示例#1
0
        /// <summary>
        /// Sends a message to an entity and guarantees the message will be sent on a
        /// specific port (set by the entity settings)
        /// </summary>
        /// <param name="dimse">the message to send</param>
        /// <param name="ae">the entity to send the message</param>
        /// <returns>true if message send was success</returns>
        public bool SendMessageForcePort(AbstractDIMSERequest dimse, Entity ae)
        {
            var(ipLocalEndPoint, success) =
                IpHelper.VerifyIPAddress(this.ApplicationEntity.IpAddress, this.ApplicationEntity.Port);
            if (!success)
            {
                return(false);
            }

            using (var client = new TcpClient(ipLocalEndPoint))
            {
                try
                {
                    var connectionResult = client.BeginConnect(IPAddress.Parse(ae.IpAddress), ae.Port, null, null);
                    success = connectionResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectionTimeout));
                    if (!success)
                    {
                        throw new TimeoutException($"Couldn't connect to {IPAddress.Parse(ae.IpAddress)}:{ae.Port} within {ConnectionTimeout} ms!");
                    }
                    var assoc = new Association(this, client)
                    {
                        AeTitle = ae.AeTitle
                    };
                    PDataMessenger.Send(dimse, assoc);
                    assoc.Listen();
                    return(true);
                }
                catch (Exception e)
                {
                    Logger.Log($"Could not connect to {ae.AeTitle} @{ae.IpAddress}:{ae.Port}", LogPriority.ERROR);
                    Logger.Log($"{e.ToString()}", LogPriority.ERROR);
                    return(false);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Sends a message to an entity
 /// </summary>
 /// <param name="dimse">the message to send</param>
 /// <param name="ae">the entity to send the message</param>
 /// <returns>true if message send was success</returns>
 public bool SendMessage(AbstractDIMSERequest dimse, Entity ae)
 {
     using (var client = new TcpClient())
     {
         try
         {
             var connectionResult = client.BeginConnect(IPAddress.Parse(ae.IpAddress), ae.Port, null, null);
             var completed        = connectionResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectionTimeout));
             if (completed && !client.Client.Connected)
             {
                 throw new TimeoutException($"Couldn't connect to {IPAddress.Parse(ae.IpAddress)}:{ae.Port} within {ConnectionTimeout} ms!");
             }
             var assoc = new Association(this, client)
             {
                 AeTitle = ae.AeTitle
             };
             PDataMessenger.Send(dimse, assoc);
             assoc.Listen(TimeSpan.FromMilliseconds(IdleTimeout));
             return(true);
         }
         catch (Exception e)
         {
             Logger.Log($"Could not connect to {ae.AeTitle} @{ae.IpAddress}:{ae.Port}", LogPriority.ERROR);
             Logger.Log($"{e.ToString()}", LogPriority.ERROR);
             return(false);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Sends a message to an entity
        /// </summary>
        /// <param name="dimse">the message to send</param>
        /// <param name="ae">the entity to send the message</param>
        /// <returns>true if message send was success</returns>
        public bool SendMessage(AbstractDIMSERequest dimse, Entity ae)
        {
            IPAddress ipAddress;

            if (!IPAddress.TryParse(this.ApplicationEntity.IpAddress, out ipAddress))
            {
                Logger.Log($"Could not parse IP address {this.ApplicationEntity.IpAddress}");
            }
            IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, this.ApplicationEntity.Port);

            using (var client = new TcpClient(ipLocalEndPoint))
            {
                try
                {
                    client.ConnectAsync(IPAddress.Parse(ae.IpAddress), ae.Port).Wait();
                    var assoc = new Association(this, client)
                    {
                        AeTitle = ae.AeTitle
                    };
                    PDataMessenger.Send(dimse, assoc);
                    assoc.Listen();
                    return(true);
                }
                catch (Exception e)
                {
                    Logger.Log($"Could not connect to {ae.AeTitle} @{ae.IpAddress}:{ae.Port}", LogPriority.ERROR);
                    Logger.Log($"{e.ToString()}", LogPriority.ERROR);
                    return(false);
                }
            }
        }
示例#4
0
        public void SendMessage(AbstractDIMSERequest dimse, Entity ae)
        {
            var client = new TcpClient();

            client.Connect(IPAddress.Parse(ae.IpAddress), ae.Port);
            var assoc = new Association(this, client)
            {
                AeTitle = ae.AeTitle
            };

            PDataMessenger.Send(dimse, assoc);
            assoc.Listen();
        }
示例#5
0
        /// <summary>
        /// Sends a message to an entity
        /// </summary>
        /// <param name="dimse">the message to send</param>
        /// <param name="ae">the entity to send the message</param>
        /// <returns>true if message send was success</returns>
        public SendStatus SendMessage(AbstractDIMSERequest dimse, Entity ae)
        {
            using (var client = new TcpClient())
            {
                var status = new SendStatus();
                try
                {
                    var connectionResult = client.BeginConnect(IPAddress.Parse(ae.IpAddress), ae.Port, null, null);
                    var completed        = connectionResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectionTimeout));

                    if (completed && !client.Client.Connected)
                    {
                        status.DidConnect = false;
                        return(status);
                    }

                    //Connected. Attempt association
                    status.DidConnect = true;
                    var assoc = new Association(this, client)
                    {
                        AeTitle = ae.AeTitle
                    };

                    AssociationRejectedHandler rejectedHandler = (rej, asc) =>
                    {
                        status.WasRejected = true;
                        status.Reason      = Enum.GetName(typeof(RejectReason_SCU), rej.Reason);
                    };

                    this.AssociationService.AssociationRejectionReceived += rejectedHandler;
                    PDataMessenger.Send(dimse, assoc);
                    assoc.Listen(TimeSpan.FromMilliseconds(IdleTimeout));
                    this.AssociationService.AssociationRejectionReceived -= rejectedHandler;
                    return(status);
                }
                catch (Exception e)
                {
                    Logger.LogError($"Could not connect to {ae.AeTitle} @{ae.IpAddress}:{ae.Port}");
                    Logger.LogError($"{e.ToString()}");
                    return(status);
                }
            }
        }
示例#6
0
 /// <summary>
 /// Sends a message to an entity
 /// </summary>
 /// <param name="dimse">the message to send</param>
 /// <param name="ae">the entity to send the message</param>
 /// <returns>true if message send was success</returns>
 public bool SendMessage(AbstractDIMSERequest dimse, Entity ae)
 {
     using (var client = new TcpClient())
     {
         try
         {
             client.ConnectAsync(IPAddress.Parse(ae.IpAddress), ae.Port).Wait();
             var assoc = new Association(this, client)
             {
                 AeTitle = ae.AeTitle
             };
             PDataMessenger.Send(dimse, assoc);
             assoc.Listen();
             return(true);
         }
         catch (Exception e)
         {
             Logger.Log($"Could not connect to {ae.AeTitle} @{ae.IpAddress}:{ae.Port}", LogPriority.ERROR);
             Logger.Log($"{e.ToString()}", LogPriority.ERROR);
             return(false);
         }
     }
 }