/// <summary>
        /// Detaches the SmoothStreamingMediaElement from the diagnostic component.
        /// It is recommended that you do not call this directly and instead use DetachFromSMF
        /// </summary>
        internal void DetachFromMediaElement()
        {
            ssme.Unloaded -= ssme_Unloaded;
            if (healthMonitor != null) 
            {
                healthMonitor.Flush();
            }

            healthMonitorLogger.DetachMonitor();
            if (healthMonitor != null)
            {
                healthMonitor.Detach();
                healthMonitor = null;
            }
            ssme = null;
            IsAttached = false;
        }
 /// <summary>
 /// Detaches the diagnostic from being monitored
 /// </summary>
 public void DetachMonitor()
 {
     healthMonitor.EdgeServerCompleted -= healthMonitor_EdgeServerChanged;
     healthMonitor.EventCreated -= healthMonitor_EventCreated;
     healthMonitor.ReportSampledData -= healthMonitor_ReportSampledData;
     healthMonitor.LatencyAlert -= healthMonitor_LatencyAlert;
     healthMonitor.ReportTraceLogs -= healthMonitor_ReportTraceLogs;
     healthMonitor = null;
 }
        /// <summary>
        /// Attaches the SmoothStreamingMediaElement to the diagnostic component so it can be monitored.
        /// It is recommended that you do not call this directly and instead use AttachToSMF
        /// </summary>
        /// <param name="element">An instance of SSME</param>
        internal void AttachToMediaElement(SmoothStreamingMediaElement element)
        {
            // clean up the old media element just in case
            if (IsAttached)
                DetachFromMediaElement();

            // start logging agent if it hasn't been already
            if (!LoggingService.Current.IsSessionStarted)
                LoggingService.Current.StartSession();

            ssme = element;
            ssme.Unloaded += ssme_Unloaded;

            healthMonitor = new HealthMonitor(DiagConfig);
            healthMonitor.Attach(ssme);
            healthMonitorLogger.AttachMonitor(healthMonitor);

            IsAttached = true;
        }
 /// <summary>
 /// Attaches the diagnostic component so it can be monitored
 /// </summary>
 public void AttachMonitor(HealthMonitor monitor)
 {
     // bind to healthMonitor
     healthMonitor = monitor;
     healthMonitor.EdgeServerCompleted += healthMonitor_EdgeServerChanged;
     healthMonitor.EventCreated += healthMonitor_EventCreated;
     healthMonitor.ReportSampledData += healthMonitor_ReportSampledData;
     healthMonitor.LatencyAlert += healthMonitor_LatencyAlert;
     healthMonitor.ReportTraceLogs += healthMonitor_ReportTraceLogs;
     // guarantee that we're not using an old instance anymore
     streamLoadedLog = null;
 }