public Listen ( System.TimeSpan maxWaitTime = null ) : void | ||
maxWaitTime | System.TimeSpan | |
Результат | void |
public IEnumerable <CMoveResponse> GetResponse(CMoveRequest cMove, 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(cMove, assoc); List <CMoveResponse> responses = new List <CMoveResponse>(); EvilDICOM.Network.Services.DIMSEService.DIMSEResponseHandler <CMoveResponse> action = null; action = (resp, asc) => { responses.Add(resp); if (resp.Status != (ushort)Status.PENDING) { this.DIMSEService.CMoveResponseReceived -= action; } }; this.DIMSEService.CMoveResponseReceived += action; assoc.Listen(); return(responses); }
/// <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); } } }
public IEnumerable <CFindResponse> GetResponse(CFindRequest cFind, Entity ae) { var client = new TcpClient(); client.ConnectAsync(IPAddress.Parse(ae.IpAddress), ae.Port).Wait(); var assoc = new Association(this, client) { AeTitle = ae.AeTitle }; PDataMessenger.Send(cFind, assoc); var responses = new List <CFindResponse>(); Services.DIMSEService.DIMSEResponseHandler <CFindResponse> action = null; action = (resp, asc) => { responses.Add(resp); if (resp.Status != (ushort)Status.PENDING) { DIMSEService.CFindResponseReceived -= action; } }; DIMSEService.CFindResponseReceived += action; assoc.Listen(); return(responses); }
/// <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); } } }
/// <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); } } }
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(); }
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(); }
/// <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); } } }
public IEnumerable<CMoveResponse> GetResponse(CMoveRequest cMove, 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(cMove, assoc); List<CMoveResponse> responses = new List<CMoveResponse>(); EvilDICOM.Network.Services.DIMSEService.DIMSEResponseHandler<CMoveResponse> action = null; action = (resp, asc) => { responses.Add(resp); if (resp.Status != (ushort)Status.PENDING) { this.DIMSEService.CMoveResponseReceived -= action; } }; this.DIMSEService.CMoveResponseReceived += action; assoc.Listen(); return responses; }
/// <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); } } }