コード例 #1
0
 private void btnOpenForwardDeadLetteredMessagesToForm_Click(object sender, EventArgs e)
 {
     using (var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText))
     {
         if (form.ShowDialog() == DialogResult.OK)
         {
             txtForwardDeadLetteredMessagesTo.Text = form.Path;
         }
     }
 }
コード例 #2
0
 private async void resubmitSelectedDeadletterMessagesInBatchModeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (deadletterDataGridView.SelectedRows.Count <= 0)
         {
             return;
         }
         string entityPath;
         using (var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText))
         {
             if (form.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             if (string.IsNullOrWhiteSpace(form.Path))
             {
                 return;
             }
             entityPath = form.Path;
         }
         var sent = 0;
         var messageSender = await serviceBusHelper.MessagingFactory.CreateMessageSenderAsync(entityPath);
         var messages = deadletterDataGridView.SelectedRows.Cast<DataGridViewRow>().Select(r =>
         {
             BodyType bodyType;
             var message = r.DataBoundItem as BrokeredMessage;
             serviceBusHelper.GetMessageText(message, out bodyType);
             if (bodyType == BodyType.Wcf)
             {
                 var wcfUri = serviceBusHelper.IsCloudNamespace ?
                                  new Uri(serviceBusHelper.NamespaceUri, messageSender.Path) :
                                  new UriBuilder
                                  {
                                      Host = serviceBusHelper.NamespaceUri.Host,
                                      Path = string.Format("{0}/{1}", serviceBusHelper.NamespaceUri.AbsolutePath, messageSender.Path),
                                      Scheme = "sb"
                                  }.Uri;
                 return serviceBusHelper.CreateMessageForWcfReceiver(message,
                                                                     0,
                                                                     false,
                                                                     false,
                                                                     wcfUri);
             }
             return serviceBusHelper.CreateMessageForApiReceiver(message,
                                                                 0,
                                                                 false,
                                                                 false,
                                                                 false,
                                                                 bodyType,
                                                                 null);
         });
         IEnumerable<BrokeredMessage> brokeredMessages = messages as IList<BrokeredMessage> ?? messages.ToList();
         if (brokeredMessages.Any())
         {
             sent = brokeredMessages.Count();
             await messageSender.SendBatchAsync(brokeredMessages);
         }
         writeToLog(string.Format(MessageSentMessage, sent, entityPath));
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
 }
コード例 #3
0
 private void dataPointDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == TypeMetricsDataGridViewColumnIndex)
     {
         return;
     }
     var currentRow = dataPointDataGridView.Rows[e.RowIndex];
     if (e.ColumnIndex != EntityMetricsDataGridViewColumnIndex)
     {
         if (string.IsNullOrWhiteSpace(currentRow.Cells[EntityMetricsDataGridViewColumnIndex].Value as string) ||
             string.IsNullOrWhiteSpace(currentRow.Cells[TypeMetricsDataGridViewColumnIndex].Value as string))
         {
             return;
         }
         dataPointDataGridView.NotifyCurrentCellDirty(true);
         return;
     }
     var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText, true);
     if (form.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     dataPointDataGridView.NotifyCurrentCellDirty(true);
     currentRow.Cells[EntityProperty].Value = form.Path;
     currentRow.Cells[TypeProperty].Value = form.Type;
 }
コード例 #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                using (var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText))
                {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(form.Path))
                    {
                        return;
                    }
                    BodyType bodyType;
                    if (!Enum.TryParse(cboBodyType.Text, true, out bodyType))
                    {
                        bodyType = BodyType.Stream;
                    }
                    var             messageSender = serviceBusHelper.MessagingFactory.CreateMessageSender(form.Path);
                    BrokeredMessage outboundMessage;
                    if (bodyType == BodyType.Wcf)
                    {
                        var wcfUri = serviceBusHelper.IsCloudNamespace ?
                                     new Uri(serviceBusHelper.NamespaceUri, messageSender.Path) :
                                     new UriBuilder
                        {
                            Host   = serviceBusHelper.NamespaceUri.Host,
                            Path   = string.Format("{0}/{1}", serviceBusHelper.NamespaceUri.AbsolutePath, messageSender.Path),
                            Scheme = "sb"
                        }.Uri;
                        outboundMessage = serviceBusHelper.CreateMessageForWcfReceiver(brokeredMessage.Clone(txtMessageText.Text),
                                                                                       0,
                                                                                       false,
                                                                                       false,
                                                                                       wcfUri);
                    }
                    else
                    {
                        outboundMessage = serviceBusHelper.CreateMessageForApiReceiver(brokeredMessage.Clone(txtMessageText.Text),
                                                                                       0,
                                                                                       false,
                                                                                       false,
                                                                                       false,
                                                                                       bodyType,
                                                                                       cboSenderInspector.SelectedIndex > 0 ?
                                                                                       Activator.CreateInstance(serviceBusHelper.BrokeredMessageInspectors[cboSenderInspector.Text]) as IBrokeredMessageInspector :
                                                                                       null);
                    }
                    outboundMessage.Properties.Clear();
                    var warningCollection = new ConcurrentBag <string>();
                    foreach (var messagePropertyInfo in bindingSource.Cast <MessagePropertyInfo>())
                    {
                        try
                        {
                            messagePropertyInfo.Key = messagePropertyInfo.Key.Trim();
                            if (messagePropertyInfo.Type != StringType && messagePropertyInfo.Value == null)
                            {
                                warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyValueCannotBeNull, messagePropertyInfo.Key));
                            }
                            else
                            {
                                if (outboundMessage.Properties.ContainsKey(messagePropertyInfo.Key))
                                {
                                    outboundMessage.Properties[messagePropertyInfo.Key] = ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value);
                                }
                                else
                                {
                                    outboundMessage.Properties.Add(messagePropertyInfo.Key, ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyConversionError, messagePropertyInfo.Key, ex.Message));
                        }
                    }
                    if (warningCollection.Count > 0)
                    {
                        var builder  = new StringBuilder(WarningHeader);
                        var warnings = warningCollection.ToArray <string>();
                        for (var i = 0; i < warningCollection.Count; i++)
                        {
                            builder.AppendFormat(WarningFormat, warnings[i]);
                        }
                        writeToLog(builder.ToString());
                    }

                    long elapsedMilliseconds;
                    serviceBusHelper.SendMessage(messageSender,
                                                 outboundMessage,
                                                 0,
                                                 bodyType == BodyType.Wcf,
                                                 false,
                                                 true,
                                                 true,
                                                 out elapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
コード例 #5
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                using (var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText))
                {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(form.Path))
                    {
                        return;
                    }
                    BodyType bodyType;
                    if (!Enum.TryParse(cboBodyType.Text, true, out bodyType))
                    {
                        bodyType = BodyType.Stream;
                    }
                    var messageSender = serviceBusHelper.MessagingFactory.CreateMessageSender(form.Path);
                    BrokeredMessage outboundMessage;
                    if (bodyType == BodyType.Wcf)
                    {
                        var wcfUri = serviceBusHelper.IsCloudNamespace ?
                                         new Uri(serviceBusHelper.NamespaceUri, messageSender.Path) :
                                         new UriBuilder
                                         {
                                             Host = serviceBusHelper.NamespaceUri.Host,
                                             Path = string.Format("{0}/{1}", serviceBusHelper.NamespaceUri.AbsolutePath, messageSender.Path),
                                             Scheme = "sb"
                                         }.Uri;
                        outboundMessage = serviceBusHelper.CreateMessageForWcfReceiver(brokeredMessage.Clone(txtMessageText.Text),
                                                                                       0,
                                                                                       false,
                                                                                       false,
                                                                                       wcfUri);
                    }
                    else
                    {
                        outboundMessage = serviceBusHelper.CreateMessageForApiReceiver(brokeredMessage.Clone(txtMessageText.Text),
                                                                                       0,
                                                                                       false,
                                                                                       false,
                                                                                       false,
                                                                                       bodyType,
                                                                                       cboSenderInspector.SelectedIndex > 0 ?
                                                                                       Activator.CreateInstance(serviceBusHelper.BrokeredMessageInspectors[cboSenderInspector.Text]) as IBrokeredMessageInspector :
                                                                                       null);
                    }
                    outboundMessage.Properties.Clear();
                    var warningCollection = new ConcurrentBag<string>();
                    foreach (var messagePropertyInfo in bindingSource.Cast<MessagePropertyInfo>())
                    {
                        try
                        {
                            messagePropertyInfo.Key = messagePropertyInfo.Key.Trim();
                            if (messagePropertyInfo.Type != StringType && messagePropertyInfo.Value == null)
                            {
                                warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyValueCannotBeNull, messagePropertyInfo.Key));
                            }
                            else
                            {
                                if (outboundMessage.Properties.ContainsKey(messagePropertyInfo.Key))
                                {
                                    outboundMessage.Properties[messagePropertyInfo.Key] = ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value);
                                }
                                else
                                {
                                    outboundMessage.Properties.Add(messagePropertyInfo.Key, ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyConversionError, messagePropertyInfo.Key, ex.Message));
                        }
                    }
                    if (warningCollection.Count > 0)
                    {
                        var builder = new StringBuilder(WarningHeader);
                        var warnings = warningCollection.ToArray<string>();
                        for (var i = 0; i < warningCollection.Count; i++)
                        {
                            builder.AppendFormat(WarningFormat, warnings[i]);
                        }
                        writeToLog(builder.ToString());
                    }

                    long elapsedMilliseconds;
                    serviceBusHelper.SendMessage(messageSender,
                                                 outboundMessage,
                                                 0,
                                                 bodyType == BodyType.Wcf,
                                                 false,
                                                 true,
                                                 true,
                                                 out elapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
コード例 #6
0
 private async void dataPointDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     var dataGridViewColumn = dataPointDataGridView.Columns[DeleteName];
     if (dataGridViewColumn != null && 
         e.ColumnIndex == dataGridViewColumn.Index && 
         e.RowIndex > -1 && 
        !dataPointDataGridView.Rows[e.RowIndex].IsNewRow)
     {
         dataPointDataGridView.Rows.RemoveAt(e.RowIndex);
         return;
     }
     if (e.ColumnIndex == TypeMetricsDataGridViewColumnIndex)
     {
         return;
     }
     var currentRow = dataPointDataGridView.Rows[e.RowIndex];
     if (e.ColumnIndex != EntityMetricsDataGridViewColumnIndex)
     {
         if (string.IsNullOrWhiteSpace(currentRow.Cells[EntityMetricsDataGridViewColumnIndex].Value as string) ||
             string.IsNullOrWhiteSpace(currentRow.Cells[TypeMetricsDataGridViewColumnIndex].Value as string))
         {
             return;
         }
         dataPointDataGridView.NotifyCurrentCellDirty(true);
         return;
     }
     using (var form = new SelectEntityForm(SelectEntityDialogTitle, 
                                            SelectEntityGrouperTitle, 
                                            SelectEntityLabelText,
                                            true, 
                                            true, 
                                            true, 
                                            true))
     {
         if (form.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         dataPointDataGridView.NotifyCurrentCellDirty(true);
         currentRow.Cells[EntityProperty].Value = form.Path;
         currentRow.Cells[TypeProperty].Value = form.Type;
         var entity = (string)currentRow.Cells[TypeProperty].Value;
         if (string.IsNullOrWhiteSpace(entity))
         {
             return;
         }
         await MetricInfo.GetMetricInfoListAsync(serviceBusHelper.Namespace, entity, form.Path);
         ((DataGridViewComboBoxCell)currentRow.Cells[MetricProperty]).DataSource = MetricInfo.EntityMetricDictionary.ContainsKey(entity) ?
                                                                                   MetricInfo.EntityMetricDictionary[entity] :
                                                                                   null;
     }
 }
コード例 #7
0
        private async void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                using (var form = new SelectEntityForm(SelectEntityDialogTitle, SelectEntityGrouperTitle, SelectEntityLabelText))
                {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(form.Path))
                    {
                        return;
                    }
                    BodyType bodyType;
                    if (!Enum.TryParse(cboBodyType.Text, true, out bodyType))
                    {
                        bodyType = BodyType.Stream;
                    }
                    var messageSender = serviceBusHelper.MessagingFactory.CreateMessageSender(form.Path);
                    var messages      = brokeredMessages != null ?
                                        new List <BrokeredMessage>(brokeredMessages) :
                                        new List <BrokeredMessage>(new [] { brokeredMessage });
                    var outboundMessages = new List <BrokeredMessage>();
                    foreach (var message in messages)
                    {
                        BrokeredMessage outboundMessage;
                        if (bodyType == BodyType.Wcf)
                        {
                            var wcfUri = serviceBusHelper.IsCloudNamespace ?
                                         new Uri(serviceBusHelper.NamespaceUri, messageSender.Path) :
                                         new UriBuilder
                            {
                                Host   = serviceBusHelper.NamespaceUri.Host,
                                Path   = $"{serviceBusHelper.NamespaceUri.AbsolutePath}/{messageSender.Path}",
                                Scheme = "sb"
                            }.Uri;
                            outboundMessage = serviceBusHelper.CreateMessageForWcfReceiver(message.Clone(txtMessageText.Text),
                                                                                           0,
                                                                                           false,
                                                                                           false,
                                                                                           wcfUri);
                        }
                        else
                        {
                            if (brokeredMessage != null)
                            {
                                // For body type ByteArray cloning is not an option. When cloned, supplied body can be only of a string or stream types, but not byte array :(
                                outboundMessage = bodyType == BodyType.ByteArray ?
                                                  brokeredMessage.CloneWithByteArrayBodyType(txtMessageText.Text) :
                                                  brokeredMessage.Clone(txtMessageText.Text);
                            }
                            else
                            {
                                var messageText = serviceBusHelper.GetMessageText(message, out bodyType);

                                // For body type ByteArray cloning is not an option. When cloned, supplied body can be only of a string or stream types, but not byte array :(
                                outboundMessage = bodyType == BodyType.ByteArray ?
                                                  message.CloneWithByteArrayBodyType(messageText) :
                                                  message.Clone(messageText);
                            }

                            outboundMessage = serviceBusHelper.CreateMessageForApiReceiver(outboundMessage,
                                                                                           0,
                                                                                           false,
                                                                                           false,
                                                                                           false,
                                                                                           bodyType,
                                                                                           cboSenderInspector.SelectedIndex > 0 ?
                                                                                           Activator.CreateInstance(serviceBusHelper.BrokeredMessageInspectors[cboSenderInspector.Text]) as IBrokeredMessageInspector :
                                                                                           null);
                        }
                        outboundMessage.Properties.Clear();
                        var warningCollection = new ConcurrentBag <string>();
                        foreach (var messagePropertyInfo in bindingSource.Cast <MessagePropertyInfo>())
                        {
                            try
                            {
                                if (string.Compare(messagePropertyInfo.Key, "DeadLetterReason",
                                                   StringComparison.InvariantCultureIgnoreCase) == 0 ||
                                    string.Compare(messagePropertyInfo.Key, "DeadLetterErrorDescription",
                                                   StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    continue;
                                }
                                messagePropertyInfo.Key = messagePropertyInfo.Key.Trim();
                                if (messagePropertyInfo.Type != StringType && messagePropertyInfo.Value == null)
                                {
                                    warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyValueCannotBeNull, messagePropertyInfo.Key));
                                }
                                else
                                {
                                    if (outboundMessage.Properties.ContainsKey(messagePropertyInfo.Key))
                                    {
                                        outboundMessage.Properties[messagePropertyInfo.Key] = ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value);
                                    }
                                    else
                                    {
                                        outboundMessage.Properties.Add(messagePropertyInfo.Key, ConversionHelper.MapStringTypeToCLRType(messagePropertyInfo.Type, messagePropertyInfo.Value));
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                warningCollection.Add(string.Format(CultureInfo.CurrentUICulture, PropertyConversionError, messagePropertyInfo.Key, ex.Message));
                            }
                        }
                        if (warningCollection.Count <= 0)
                        {
                            outboundMessages.Add(outboundMessage);
                            continue;
                        }
                        var builder  = new StringBuilder(WarningHeader);
                        var warnings = warningCollection.ToArray <string>();
                        for (var i = 0; i < warningCollection.Count; i++)
                        {
                            builder.AppendFormat(WarningFormat, warnings[i]);
                        }
                        writeToLog(builder.ToString());
                    }
                    if (!outboundMessages.Any())
                    {
                        return;
                    }
                    var sent      = outboundMessages.Count;
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    await messageSender.SendBatchAsync(outboundMessages);

                    stopwatch.Stop();
                    writeToLog(string.Format(MessageSentMessage, sent, messageSender.Path, stopwatch.ElapsedMilliseconds));
                    if (brokeredMessages != null)
                    {
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }