private void UnregisterMarkerProvider(IMarkerProvider markerProvider)
 {
     markerProvider.MarkersRemoved -= MarkerProvider_MarkersRemoved;
     markerProvider.NewMarkers -= MarkerProvider_NewMarkers;
     markerProvider.RetrieveMarkersFailed -= MarkerProvider_RetrieveMarkersFailed;
     markerProvider.LogReady -= Plugin_LogReady;
     markerProvider.PluginLoadFailed -= Plugin_PluginLoadFailed;
     markerProvider.PluginLoaded -= MarkerProvider_PluginLoaded;
     markerProvider.StopRetrievingMarkers();
     markerProvider.Unload();
 }
 private void RegisterMarkerProvider(IMarkerProvider markerProvider)
 {
     markerProvider.MarkersRemoved += MarkerProvider_MarkersRemoved;
     markerProvider.NewMarkers += MarkerProvider_NewMarkers;
     markerProvider.RetrieveMarkersFailed += MarkerProvider_RetrieveMarkersFailed;
     markerProvider.LogReady += Plugin_LogReady;
     markerProvider.PluginLoadFailed += Plugin_PluginLoadFailed;
     markerProvider.PluginLoaded += MarkerProvider_PluginLoaded;
 }
        private void MarkerProvider_NewMarkers(IMarkerProvider markerProvider, IEnumerable<MediaMarker> newMarkers)
        {
            string logMessage = string.Format(SilverlightMediaFrameworkResources.NewMarkersLogMessage,
                                              newMarkers.Count());
            SendLogEntry(message: logMessage, type: KnownLogEntryTypes.MarkersAdded,
                extendedProperties: new Dictionary<string, object> { { "Count", newMarkers.Count() } });

            foreach (MediaMarker marker in newMarkers)
            {
                if (marker is AdMarker)
                {
                    var adMarker = marker as AdMarker;
                    // Immediate == true will trigger the timeline marker immediately instead of waiting for polling to occur
                    if (adMarker.Immediate)
                    {
                        var duration = adMarker.Duration;
                        adMarker.Begin = RelativeMediaPluginPosition;
                        adMarker.End = adMarker.Begin.Add(duration);    // update the end based on the duration
                        AdMarkers.Add(adMarker);
                        // force a check on the postions, we know there is one that needs to be fired
                        if (!isSeekActive) _adMarkerManager.CheckMarkerPositions(RelativeMediaPluginPosition, AdMarkers, seekInProgress);
                    }
                    else
                    {
                        AdMarkers.Add(adMarker);
                    }
                }
                if (marker is TimelineMediaMarker)
                {
                    var timelineMarker = marker as TimelineMediaMarker;
                    TimelineMarkers.Add(timelineMarker);
                }
                else if (marker is Chapter)
                {
                    Chapters.Add(marker as Chapter);
                }
                else if (marker is CaptionRegion)
                {
                    Captions.Add(marker as CaptionRegion);
                }
            }
        }
 private void MarkerProvider_RetrieveMarkersFailed(IMarkerProvider markerProvider, Exception error)
 {
     string logMessage = string.Format(SilverlightMediaFrameworkResources.RetrieveMarkersFailedLogMessage, error.Message);
     SendLogEntry(KnownLogEntryTypes.RetrieveMarkersFailed, LogLevel.Error, logMessage);
 }
        private void MarkerProvider_MarkersRemoved(IMarkerProvider markerProvider,
                                                   IEnumerable<MediaMarker> removedMarkers)
        {
            string logMessage = string.Format(SilverlightMediaFrameworkResources.MarkersRemovedLogMessage,
                                              removedMarkers.Count());
            SendLogEntry(message: logMessage, type: KnownLogEntryTypes.MarkersRemoved,
                extendedProperties: new Dictionary<string, object> { { "Count", removedMarkers.Count() } });

            foreach (MediaMarker marker in removedMarkers)
            {
                if (marker is AdMarker)
                {
                    AdMarkers.Remove(marker as AdMarker);
                }
                else if (marker is TimelineMediaMarker && marker.Type == KnownMarkerTypes.Timeline)
                {
                    TimelineMarkers.Remove(marker as TimelineMediaMarker);
                }
                else if (marker is Chapter && marker.Type == KnownMarkerTypes.Chapter)
                {
                    Chapters.Remove(marker as Chapter);
                }
                else if (marker is CaptionRegion && marker.Type == KnownMarkerTypes.Caption)
                {
                    Captions.Remove(marker as CaptionRegion);
                }
            }
        }