/// <summary> /// Try to send the message /// </summary> /// <returns></returns> public bool TrySend() { try { // Now send MllpMessageSender sender = new MllpMessageSender(new Uri(this.Target.ConnectionString), this.Target.LlpClientCertificate, this.Target.TrustedIssuerCertificate); ACK response = sender.SendAndReceive(this.Message) as ACK; // See if the ACK is good if (response == null) { this.FailCount += 1; return(false); } if (response.MSA.AcknowledgementCode.Value != "AA" && response.MSA.AcknowledgementCode.Value != "CA") { this.FailCount += 1; return(false); } return(true); } catch (Exception e) { this.FailCount += 1; Trace.TraceError(e.ToString()); return(false); } }
/// <summary> /// Creates a new instance of the sync context /// </summary> public PatientSynchronizer(SynchronizationContext context) { this.m_context = context; Uri crEndpoint = new Uri(ConfigurationManager.AppSettings["crEndpoint"]); String localCertHash = ConfigurationManager.AppSettings["myCertificateHash"], remoteCertHash = ConfigurationManager.AppSettings["remoteCertificateHash"]; // Certs X509Certificate2 localCert = null, remoteCert = null; if (localCertHash != null) { string[] parts = localCertHash.Split(','); StoreLocation loc = (StoreLocation)Enum.Parse(typeof(StoreLocation), parts[0]); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), parts[1]); localCert = MllpMessageSender.FindCertificate(name, loc, X509FindType.FindByThumbprint, parts[2]); } if (remoteCertHash != null) { string[] parts = remoteCertHash.Split(','); StoreLocation loc = (StoreLocation)Enum.Parse(typeof(StoreLocation), parts[0]); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), parts[1]); remoteCert = MllpMessageSender.FindCertificate(name, loc, X509FindType.FindByThumbprint, parts[2]); } this.m_sender = new MllpMessageSender(crEndpoint, localCert, remoteCert); }
/// <summary> /// Tries to send a message to an endpoint. /// </summary> /// <returns>Returns true if the message was sent successfully.</returns> public bool TrySend() { var status = false; try { var sender = new MllpMessageSender(new Uri(this.targetConfiguration.ConnectionString), this.targetConfiguration.LlpClientCertificate, this.targetConfiguration.TrustedIssuerCertificate); var response = sender.SendAndReceive(this.message); if (response is NHapi.Model.V231.Message.ACK) { status = (response as NHapi.Model.V231.Message.ACK).MSA.AcknowledgementCode.Value.ToUpper() == "AA"; } else if (response is ACK) { status = (response as ACK).MSA.AcknowledgmentCode.Value.ToUpper() == "AA"; } else { this.FailCount++; } } catch (Exception e) { this.FailCount++; #if DEBUG this.tracer.TraceEvent(TraceEventType.Error, 0, e.StackTrace); #endif this.tracer.TraceEvent(TraceEventType.Error, 0, e.Message); } return(status); }
/// <summary> /// Get the message sender /// </summary> /// <returns></returns> public MllpMessageSender GetSender() { if (this.m_sender == null) { this.m_sender = new MllpMessageSender(this.Address, (this.Configuration as SllpTransport.SllpConfigurationObject)?.ClientCaCertificate?.GetCertificate(), (this.Configuration as SllpTransport.SllpConfigurationObject)?.ServerCertificate?.GetCertificate()); } return(this.m_sender); }
/// <summary> /// Select a client certificate /// </summary> public void SetClientCertificate(string subject, string store, string location) { if (this.m_sender != null) { throw new InvalidOperationException("Cannot set the certificate after connection open"); } StoreName storeName = (StoreName)Enum.Parse(typeof(StoreName), store); StoreLocation storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), store); this.m_certificate = MllpMessageSender.FindCertificate(storeName, storeLocation, X509FindType.FindBySubjectName, subject); }
/// <summary> /// Send the audit /// </summary> private static void SendAudit(AuditMessage message) { var endpoint = new Uri(ConfigurationManager.AppSettings["arrEndpoint"]); IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(endpoint.Host), endpoint.Port); ITransporter transport = null; switch (endpoint.Scheme) { case "udp": transport = new UdpSyslogTransport(ipep); break; case "tcp": transport = new TcpSyslogTransport(ipep); break; case "stcp": String localCertHash = ConfigurationManager.AppSettings["myCertificateHash"], remoteCertHash = ConfigurationManager.AppSettings["remoteCertificateHash"]; // Certs X509Certificate2 localCert = null, remoteCert = null; if (localCertHash != null) { string[] parts = localCertHash.Split(','); StoreLocation loc = (StoreLocation)Enum.Parse(typeof(StoreLocation), parts[0]); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), parts[1]); localCert = MllpMessageSender.FindCertificate(name, loc, X509FindType.FindByThumbprint, parts[2]); } if (remoteCertHash != null) { string[] parts = remoteCertHash.Split(','); StoreLocation loc = (StoreLocation)Enum.Parse(typeof(StoreLocation), parts[0]); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), parts[1]); remoteCert = MllpMessageSender.FindCertificate(name, loc, X509FindType.FindByThumbprint, parts[2]); } transport = new STcpSyslogTransport(ipep) { ClientCertificate = localCert, ServerCertificate = remoteCert }; break; } // Now now now... we send transport.SendMessage(message); }
/// <summary> /// Open /// </summary> public void Open() { if (string.IsNullOrEmpty(this.SendingApplication) || string.IsNullOrEmpty(this.SendingFacility)) { throw new InvalidOperationException("Missing SendingDevice or SendingFacility"); } else if (string.IsNullOrEmpty(this.Endpoint)) { throw new InvalidOperationException("Missing Endpoint"); } this.m_sender = new MllpMessageSender(new Uri(this.Endpoint), null, null); }
/// <summary> /// Close /// </summary> public void Close() { this.m_sender = null; }