/// <summary> /// Fills a messages body or body stream, according to the on screen options. /// </summary> /// <param name="message">Message body.</param> private void FillMessageBody(System.Messaging.Message message) { //should we write directly to the body stream? if (optionsStreamDirectlyMenuItem.Checked) { if (textSourceRadioButton.Checked) { message.BodyStream = IOUtilities.StringToMemoryStream(textSourceTextBox.Text); } else { message.BodyStream = new FileStream(fileSourceTextBox.Text, FileMode.Open, FileAccess.Read); } } else { //set up the formatter System.Messaging.IMessageFormatter formatter; switch ((MessageFormatterType)formatterComboBoxItem.ComboBox.SelectedValue) { case MessageFormatterType.ActiveX: formatter = new System.Messaging.ActiveXMessageFormatter(); break; case MessageFormatterType.Binary: formatter = new System.Messaging.BinaryMessageFormatter(); break; case MessageFormatterType.Xml: default: formatter = new System.Messaging.XmlMessageFormatter(); break; } message.Formatter = formatter; //set up the body object body; if (textSourceRadioButton.Checked) { if (xmlCheckBox.Checked) { body = CreateXmlDocument(textSourceTextBox.Text); } else { body = textSourceTextBox.Text; } } else { using (StreamReader sr = new StreamReader(fileSourceTextBox.Text)) { body = sr.ReadToEnd(); } if (xmlCheckBox.Checked) { body = CreateXmlDocument(body.ToString()); } } message.Body = body; } }
/// <summary> /// Fills a messages body or body stream, according to the on screen options. /// </summary> /// <param name="message">Message body.</param> private void FillMessageBody(System.Messaging.Message message) { //should we write directly to the body stream? if (optionsStreamDirectlyMenuItem.Checked) { if (textSourceRadioButton.Checked) message.BodyStream = IOUtilities.StringToMemoryStream(textSourceTextBox.Text); else message.BodyStream = new FileStream(fileSourceTextBox.Text, FileMode.Open, FileAccess.Read); } else { //set up the formatter System.Messaging.IMessageFormatter formatter; switch ((MessageFormatterType)formatterComboBoxItem.ComboBox.SelectedValue) { case MessageFormatterType.ActiveX: formatter = new System.Messaging.ActiveXMessageFormatter(); break; case MessageFormatterType.Binary: formatter = new System.Messaging.BinaryMessageFormatter(); break; case MessageFormatterType.Xml: default: formatter = new System.Messaging.XmlMessageFormatter(); break; } message.Formatter = formatter; //set up the body object body; if (textSourceRadioButton.Checked) { if (xmlCheckBox.Checked) { body = CreateXmlDocument(textSourceTextBox.Text); } else body = textSourceTextBox.Text; } else { using (StreamReader sr = new StreamReader(fileSourceTextBox.Text)) { body = sr.ReadToEnd(); } if (xmlCheckBox.Checked) body = CreateXmlDocument(body.ToString()); } message.Body = body; } }