Exemplo n.º 1
0
        public void Run()
        {
            IsRunning = true;

            try
            {
                using (var socket = new PullSocket())
                {
                    socket.Options.Linger = TimeSpan.Zero;

                    socket.Bind(clientAddress.ZmqAddress + ":" + GlobalConstants.TcpIpPort.Notification);

                    while (!stopRunning)
                    {
                        var notification = socket.ReceiveNetworkMsg(TimeSpan.FromSeconds(1));

                        if (notification == null)
                        {
                            continue;
                        }

                        switch (notification.Type)
                        {
                        case NetworkMessageType.EventBusNotification:
                        {
                            var eventNotification = (EventBusNotification)notification;

                            if (eventNotification.SessionId == sessionId)
                            {
                                NewDomainEventAvailable(eventNotification.NewEvent);
                            }

                            break;
                        }

                        case NetworkMessageType.PatientAddedNotification:
                        {
                            var patientAddedNotification = (PatientAddedNotification)notification;

                            if (patientAddedNotification.SessionId == sessionId)
                            {
                                NewPatientAvailable(patientAddedNotification.Patient);
                            }

                            break;
                        }

                        case NetworkMessageType.PatientUpdatedNotification:
                        {
                            var patientUpdatedNotification = (PatientUpdatedNotification)notification;

                            if (patientUpdatedNotification.SessionId == sessionId)
                            {
                                UpdatedPatientAvailable(patientUpdatedNotification.Patient);
                            }

                            break;
                        }

                        case NetworkMessageType.TherapyPlaceTypeAddedNotification:
                        {
                            var therpyPlaceTypeAddedNotification = (TherapyPlaceTypeAddedNotification)notification;

                            if (therpyPlaceTypeAddedNotification.SessionId == sessionId)
                            {
                                NewTherapyPlaceTypeAvailable(therpyPlaceTypeAddedNotification.TherapyPlaceType);
                            }

                            break;
                        }

                        case NetworkMessageType.TherapyPlaceTypeUpdatedNotification:
                        {
                            var therpyPlaceTypeUpdatedNotification = (TherapyPlaceTypeUpdatedNotification)notification;

                            if (therpyPlaceTypeUpdatedNotification.SessionId == sessionId)
                            {
                                UpdatedTherapyPlaceTypeAvailable(therpyPlaceTypeUpdatedNotification.TherapyPlaceType);
                            }

                            break;
                        }

                        case NetworkMessageType.LabelAddedNotification:
                        {
                            var labelAddedNotification = (LabelAddedNotification)notification;

                            if (labelAddedNotification.SessionId == sessionId)
                            {
                                NewLabelAvailable(labelAddedNotification.Label);
                            }

                            break;
                        }

                        case NetworkMessageType.LabelUpdatedNotification:
                        {
                            var labelUpdatedNotification = (LabelUpdatedNotification)notification;

                            if (labelUpdatedNotification.SessionId == sessionId)
                            {
                                UpdatedLabelAvailable(labelUpdatedNotification.Label);
                            }

                            break;
                        }

                        default:
                            throw new ArgumentException();
                        }
                    }
                }
            }
            catch
            {
                // Ignored
            }

            IsRunning = false;
        }