/// <summary> /// Performs the disposal. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { try { _media.DurationElapsedEvent -= media_DurationElapsedEvent; _media.Dispose(); _media = null; Debug.WriteLine("Media Disposed by Region", "Region - Dispose"); } catch (Exception ex) { Trace.WriteLine(new LogMessage("Region - Dispose", "Unable to dispose media. Ex = " + ex.Message), LogType.Audit.ToString()); } finally { if (_media != null) _media = null; } } base.Dispose(disposing); }
/// <summary> /// Start the provided media /// </summary> /// <param name="media"></param> private void StartMedia(Media media) { Trace.WriteLine(new LogMessage("Region - StartMedia", "Starting media"), LogType.Audit.ToString()); media.RenderMedia(); Controls.Add(media); }
/// <summary> /// Stop the provided media /// </summary> private void StopMedia(Media media) { Trace.WriteLine(new LogMessage("Region - Stop Media", "Stopping media"), LogType.Audit.ToString()); // Hide the media media.Hide(); // Remove the controls Controls.Remove(media); // Dispose of the current media try { // Dispose of the media media.Dispose(); } catch (Exception ex) { Trace.WriteLine(new LogMessage("Region - Stop Media", "Unable to dispose. Ex = " + ex.Message), LogType.Audit.ToString()); } }
///<summary> /// Evaulates the change in options ///</summary> private void EvalOptions() { // First time bool initialMedia = (_currentSequence == -1); if (initialMedia) { // Evaluate the width, etc Location = new System.Drawing.Point(_options.left, _options.top); Size = new System.Drawing.Size(_options.width, _options.height); } // Try to populate a new media object for this region Media newMedia = new Media(0, 0, 0, 0); // Loop around trying to start the next media bool startSuccessful = false; int countTries = 0; while (!startSuccessful) { // If we go round this the same number of times as media objects, then we are unsuccessful and should exception if (countTries >= _options.mediaNodes.Count) throw new ArgumentOutOfRangeException("Unable to set and start a media node"); // Lets try again countTries++; // Store the current sequence int temp = _currentSequence; // Set the next media node for this panel if (!SetNextMediaNodeInOptions()) { // For some reason we cannot set a media node... so we need this region to become invalid _hasExpired = true; DurationElapsedEvent(); return; } // If the sequence hasnt been changed, OR the layout has been expired // there has been no change to the sequence, therefore the media we have already created is still valid // or this media has actually been destroyed and we are working out way out the call stack if (_layoutExpired || (_currentSequence == temp)) return; // Store the Current Index _options.CurrentIndex = _currentSequence; // See if we can start the new media object try { newMedia = CreateNextMediaNode(_options); } catch (Exception ex) { Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to create new " + _options.type + " object: " + ex.Message), LogType.Error.ToString()); // Try the next node startSuccessful = false; continue; } // First thing we do is stop the current stat record if (!initialMedia) CloseCurrentStatRecord(); // Start the new media try { StartMedia(newMedia); } catch (Exception ex) { Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to start new " + _options.type + " object: " + ex.Message), LogType.Error.ToString()); startSuccessful = false; continue; } startSuccessful = true; // Remove the old media if (!initialMedia) { StopMedia(_media); _media = null; } // Change the reference _media = newMedia; // Open a stat record OpenStatRecordForMedia(); } }