public MessageForm(BrokeredMessage brokeredMessage, ServiceBusHelper serviceBusHelper, WriteToLogDelegate writeToLog) { this.brokeredMessage = brokeredMessage; this.serviceBusHelper = serviceBusHelper; this.writeToLog = writeToLog; InitializeComponent(); cboBodyType.SelectedIndex = 0; messagePropertyGrid.SelectedObject = brokeredMessage; BodyType bodyType; txtMessageText.Text = JsonSerializerHelper.Indent(XmlHelper.Indent(serviceBusHelper.GetMessageText(brokeredMessage, out bodyType))); // Initialize the DataGridView. bindingSource.DataSource = new BindingList <MessagePropertyInfo>(brokeredMessage.Properties.Select(p => new MessagePropertyInfo(p.Key, GetShortValueTypeName(p.Value), p.Value)).ToList()); propertiesDataGridView.AutoGenerateColumns = false; propertiesDataGridView.AutoSize = true; propertiesDataGridView.DataSource = bindingSource; propertiesDataGridView.ForeColor = SystemColors.WindowText; // Create the Name column var textBoxColumn = new DataGridViewTextBoxColumn { DataPropertyName = PropertyKey, Name = PropertyKey, Width = 138 }; propertiesDataGridView.Columns.Add(textBoxColumn); // Create the Type column var comboBoxColumn = new DataGridViewComboBoxColumn { DataSource = Types, DataPropertyName = PropertyType, Name = PropertyType, Width = 90, FlatStyle = FlatStyle.Flat }; propertiesDataGridView.Columns.Add(comboBoxColumn); // Create the Value column textBoxColumn = new DataGridViewTextBoxColumn { DataPropertyName = PropertyValue, Name = PropertyValue, Width = 138 }; propertiesDataGridView.Columns.Add(textBoxColumn); // Set Grid style propertiesDataGridView.EnableHeadersVisualStyles = false; // Set the selection background color for all the cells. propertiesDataGridView.DefaultCellStyle.SelectionBackColor = Color.FromArgb(92, 125, 150); propertiesDataGridView.DefaultCellStyle.SelectionForeColor = SystemColors.Window; // Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default // value won't override DataGridView.DefaultCellStyle.SelectionBackColor. propertiesDataGridView.RowHeadersDefaultCellStyle.SelectionBackColor = Color.FromArgb(153, 180, 209); // Set the background color for all rows and for alternating rows. // The value for alternating rows overrides the value for all rows. propertiesDataGridView.RowsDefaultCellStyle.BackColor = SystemColors.Window; propertiesDataGridView.RowsDefaultCellStyle.ForeColor = SystemColors.ControlText; //propertiesDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.White; //propertiesDataGridView.AlternatingRowsDefaultCellStyle.ForeColor = SystemColors.ControlText; // Set the row and column header styles. propertiesDataGridView.RowHeadersDefaultCellStyle.BackColor = Color.FromArgb(215, 228, 242); propertiesDataGridView.RowHeadersDefaultCellStyle.ForeColor = SystemColors.ControlText; propertiesDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(215, 228, 242); propertiesDataGridView.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.ControlText; // Get Brokered Message Inspector classes cboSenderInspector.Items.Add(SelectBrokeredMessageInspector); cboSenderInspector.SelectedIndex = 0; if (serviceBusHelper.BrokeredMessageInspectors == null) { return; } foreach (var key in serviceBusHelper.BrokeredMessageInspectors.Keys) { cboSenderInspector.Items.Add(key); } }
public static string Serialize(IEnumerable <object> entities, IEnumerable <string> bodies, bool doNotSerializeBody = false) { var entityEnumerable = entities as object[] ?? entities.ToArray(); var bodyEnumerable = bodies as string[] ?? bodies.ToArray(); if (entityEnumerable.Length == 0 || bodyEnumerable.Length == 0 || entityEnumerable.Length != bodyEnumerable.Length) { return(null); } var type = entityEnumerable[0].GetType(); GetProperties(type); if (!propertyCache.ContainsKey(type.FullName)) { return(null); } var propertyDictionary = propertyCache[type.FullName]; var entityList = new List <SortedDictionary <string, object> >(entityEnumerable.Length); for (var i = 0; i < entityEnumerable.Length; i++) { var entityDictionary = new SortedDictionary <string, object>(); if (!doNotSerializeBody && JsonSerializerHelper.IsJson(bodyEnumerable[i])) { try { entityDictionary.Add("body", JObject.Parse(bodyEnumerable[i])); } catch (Exception) { try { entityDictionary.Add("body", JArray.Parse(bodyEnumerable[i])); } catch (Exception) { entityDictionary.Add("body", bodyEnumerable[i]); } } } else { entityDictionary.Add("body", bodyEnumerable[i]); } foreach (var keyValuePair in propertyDictionary) { var camelCase = string.Format("{0}{1}", keyValuePair.Key.Substring(0, 1).ToLower(CultureInfo.InvariantCulture), keyValuePair.Key.Substring(1, keyValuePair.Key.Length - 1)); entityDictionary.Add(camelCase, null); try { var value = keyValuePair.Value.GetValue(entityEnumerable[i], null); entityDictionary[camelCase] = value; } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } } entityList.Add(entityDictionary); } return(JsonSerializerHelper.Serialize(entityList.ToArray(), Formatting.Indented)); }