private void OnSelect1Click(object sender, EventArgs e) { if (_metadataLiveSource != null) { // Close any current displayed Metadata Live Source _metadataLiveSource.LiveContentEvent -= OnLiveContentEvent; _metadataLiveSource.LiveStatusEvent -= OnLiveStatusEvent; _metadataLiveSource.Close(); _metadataLiveSource = null; } ClearAllFlags(); ResetSelections(); ItemPickerForm form = new ItemPickerForm(); form.KindFilter = Kind.Metadata; form.AutoAccept = true; form.Init(Configuration.Instance.GetItems()); // Ask user to select a metadata device if (form.ShowDialog() == DialogResult.OK) { _selectItem1 = form.SelectedItem; deviceSelectButton.Text = _selectItem1.Name; _metadataLiveSource = new MetadataLiveSource(_selectItem1); try { _metadataLiveSource.LiveModeStart = true; _metadataLiveSource.Init(); _metadataLiveSource.LiveContentEvent += OnLiveContentEvent; _metadataLiveSource.LiveStatusEvent += OnLiveStatusEvent; _metadataLiveSource.ErrorEvent += OnErrorEvent; _count = 0; labelCount.Text = _count.ToString(CultureInfo.InvariantCulture); buttonPause.Enabled = true; } catch (Exception ex) { MessageBox.Show(@"Could not Init:" + ex.Message); _metadataLiveSource = null; } } else { _selectItem1 = null; deviceSelectButton.Text = @"Select Metadata device ..."; labelCount.Text = "0"; labelSize.Text = ""; buttonPause.Enabled = false; } }
/// <summary> /// This event is called when metadata is available /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnLiveContentEvent(MetadataLiveSource sender, MetadataLiveContent e) { if (InvokeRequired) { // Make sure we execute on the UI thread before updating UI Controls BeginInvoke(new Action(() => OnLiveContentEvent(sender, e))); } else { if (e.Content != null) { // Display the received metadata var metadataXml = e.Content.GetMetadataString(); textBoxMetadataOutput.Text = metadataXml; labelSize.Text = metadataXml.Length.ToString(CultureInfo.InvariantCulture); _count++; labelCount.Text = "" + _count; } } }
/// <summary> /// This event is called when some exception has occurred /// </summary> /// <param name="sender"></param> /// <param name="exception"></param> private void OnErrorEvent(MetadataLiveSource sender, Exception exception) { if (InvokeRequired) { // Make sure we execute on the UI thread before updating UI Controls BeginInvoke(new Action(() => OnErrorEvent(sender, exception))); } else { // Display the error labelSize.Text = @"Error!"; if (exception is CommunicationMIPException) { textBoxMetadataOutput.Text = @"Connection lost to server ..."; } else { textBoxMetadataOutput.Text = exception.ToString(); } } }