void LessonSelectedExecute(Lesson selectedLesson)
        {
            if (selectedLesson == null)
            {
                throw new ArgumentNullException(nameof(selectedLesson));
            }

            // ************************************************************
            // this block of code is one way to work around the fact that
            // the button that was clicked ate the mouse click, preventing
            // the ListBox from getting it.
            foreach (var lesson in Lessons.Where(l => l.IsSelected))
            {
                lesson.IsSelected = false;
            }
            selectedLesson.IsSelected = true;

            // ************************************************************

            // navigate to the selected lesson
            // if successful set the title, otherwise, display an error message
            _regionManager.Regions[Constants.ContentRegionName].RequestNavigate(selectedLesson.View,
                                                                                result => {
                if (result.Error == null)
                {
                    _lessonSelectedResolver.Resolve().Publish(selectedLesson.Title);
                }
                else
                {
                    _lessonSelectedResolver.Resolve().Publish(result.Error.Message);
                }
            });
        }
Exemplo n.º 2
0
 public ShellViewModel(IEventResolver <LessonSelectedEvent> lessonSelectedResolver)
 {
     if (lessonSelectedResolver == null)
     {
         throw new ArgumentNullException(nameof(lessonSelectedResolver));
     }
     lessonSelectedResolver.Resolve().Subscribe(t => this.LessonTitle = t);
 }
Exemplo n.º 3
0
        public IEventPublisher GetPublisher(ServiceId serviceId, EventId eventId)
        {
            if (_eventingMethods.Count == 0)
            {
                throw new CommunicationMethodNotFoundException("There are no communication methods registered.");
            }

            IServiceDefinition serviceDefinition;
            IEventDefinition   eventDefinition;

            if (_serviceResolver.TryResolve(serviceId, out var serviceRef))
            {
                serviceDefinition = serviceRef.Definition;
                eventDefinition   = _eventResolver.Resolve(serviceDefinition, eventId).Definition;
            }
            else
            {
                throw new ServiceResolveException(serviceId);
            }

            lock (_publisherMap)
            {
                if (_publisherMap.TryGetValue(eventDefinition, out var cachedCommunicator))
                {
                    return(cachedCommunicator);
                }
            }

            var localSettings    = _communicationSettingsProvider.GetEventSettings(eventDefinition, external: false);
            var externalSettings = _communicationSettingsProvider.GetEventSettings(eventDefinition, external: true);

            var localEventingMethod    = GetEventingMethod(localSettings.CommunicationType);
            var externalEventingMethod = GetEventingMethod(externalSettings.CommunicationType);

            var localPublisher = localEventingMethod.CreateEventPublisher(GetConfiguration(eventDefinition));

            var publisher = localPublisher;

            if (externalEventingMethod.Type != localEventingMethod.Type)
            {
                var externalPublisher = externalEventingMethod.CreateEventPublisher(GetConfiguration(eventDefinition, forceExternal: true));
                publisher = new MulticastEventPublisher(localPublisher, externalPublisher);
            }

            lock (_publisherMap)
            {
                if (_publisherMap.TryGetValue(eventDefinition, out var cachedPublisher))
                {
                    (publisher as IDisposable)?.Dispose();
                    return(cachedPublisher);
                }

                _publisherMap.Add(eventDefinition, publisher);
                return(publisher);
            }
        }