private void WriteToAzureTable(BrokeredMessage message) { try { EventPoint.Common.EventMessage eventMsg = message.GetBody <EventPoint.Common.EventMessage>(); //var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); EventMessageDataSource ds = new EventMessageDataSource(); EventPoint.Data.EventMessage dataMsg = new EventPoint.Data.EventMessage(); dataMsg.ID = new Random().Next(10000000); // assign a RowKey that will show entries in reverse chronological order, with the Event.ID tacked on dataMsg.RowKey = string.Format("{0:10}_{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks, dataMsg.ID); // convert format dataMsg.Link = eventMsg.Link; dataMsg.Message = eventMsg.Message; dataMsg.Originator = eventMsg.Originator; dataMsg.Priority = eventMsg.Priority; dataMsg.Title = eventMsg.Title; // add message to table storage ds.AddEventMessage(dataMsg); message.Complete(); } catch (Exception) { message.Abandon(); } finally { message.Dispose(); } }
public void RegisterAlert(EventPoint.Common.EventMessage eventMsg) { if (connection == null) { OpenConnection(); } Debug.WriteLine("***>>> RegisterAlert called..."); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = connection; cmd.CommandText = "PersistAlert"; cmd.Parameters.AddWithValue("@Link", eventMsg.Link); cmd.Parameters.AddWithValue("@Message", eventMsg.Message); cmd.Parameters.AddWithValue("@Originator", eventMsg.Originator); cmd.Parameters.AddWithValue("@Priority", eventMsg.Priority); cmd.Parameters.AddWithValue("@Title", eventMsg.Title); try { int ret = cmd.ExecuteNonQuery(); } catch (Exception ex) { if (connection.State != ConnectionState.Open) { OpenConnection(); } int tries = 0; while (tries++ < 10) { if (connection.State == ConnectionState.Connecting) { System.Threading.Thread.Sleep(3000); } } if (connection.State == ConnectionState.Open) { int ret = cmd.ExecuteNonQuery(); } else { Trace.WriteLine("SQL Connection error. Please check the connection string, and if using SQL Azure, ensure you have created a firewall rule for your current IP address"); Trace.WriteLine(string.Format("Error Message: {0}", ex.Message)); throw; } } }
private void btnSendCritical_Click(object sender, EventArgs e) { ChannelFactory <ICriticalEvent> channelFactory = new ChannelFactory <ICriticalEvent>("sbrelay", new EndpointAddress("sb://eventpoint-critical.servicebus.windows.net")); ICriticalEvent ic = channelFactory.CreateChannel(); EventPoint.Common.EventMessage eventMsg = new EventPoint.Common.EventMessage(); eventMsg.Message = "Manually sent from generator"; eventMsg.Priority = "0"; eventMsg.Originator = Environment.UserName; BrokeredMessage brokeredMessage = new BrokeredMessage(eventMsg); brokeredMessage.CorrelationId = eventMsg.Priority; // for CorrelationFilter in subscription //brokeredMessage.Properties["priority"] = evt.Priority; // if SqlFilter is preferred eventTopic.Send(brokeredMessage); }