private async Task Run() { ServiceBusConnector sbc = new ServiceBusConnector(); var fqdn = ConfigurationManager.AppSettings["SB.Fqdn"]; var ns = ConfigurationManager.AppSettings["SB.Ns"]; var hp = ConfigurationManager.AppSettings["SB.HttpPort"]; var tp = ConfigurationManager.AppSettings["SB.TcpPort"]; var hpi = int.Parse(hp); var tpi = int.Parse(tp); sbc.Log += Sbc_Log; await sbc.Connect(ns, fqdn, hpi, tpi); Random r = new Random(); //byte, sbyte, char, short, ushort, int, uint, long, ulong, float, double, decimal, bool, Guid, string, Uri, DateTime, DateTimeOffset, and TimeSpan while (true) { var props = new Dictionary <string, object> { { "Byte", (byte)r.Next(0, 256) }, { "Sbyte", (sbyte)r.Next(-127, 127) }, { "char", (char)r.Next(21, 128) }, { "short", (short)r.Next(0, short.MaxValue + 1) }, { "ushort", (ushort)r.Next(0, short.MaxValue + 1) }, { "int", (int)r.Next(0, short.MaxValue + 1) }, { "uint", (uint)r.Next(0, short.MaxValue + 1) }, { "long", (long)r.Next(0, short.MaxValue + 1) }, { "ulong", (ulong)r.Next(0, short.MaxValue + 1) }, { "float", (float)r.NextDouble() }, { "double", (double)r.NextDouble() }, { "decimal", (decimal)r.NextDouble() }, { "bool", bool.Parse(new[] { "false", "true" }[r.Next(0, 2)]) }, { "Guid", Guid.NewGuid() }, { "string", "gji8r0e9hzg78shuj" }, { "Uri", new Uri("http://www.breanos.com/") }, { "DateTime", DateTime.Now }, { "DateTimeOffset", DateTimeOffset.Now }, { "TimeSpan", TimeSpan.FromMinutes(r.Next()) } }; Console.WriteLine("Press enter to send"); Console.ReadLine(); try { await sbc.Send("lalala", Topic_Name, "stringy", props); } catch (Exception e) { Sbc_Log(null, $"BadException: {e.ToString()}", ServiceBusConnectorLogLevel.Error); } Sbc_Log(null, "Sent!", ServiceBusConnectorLogLevel.Info); } }
/// <summary> /// LineTopic /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Sbc_Message(object sender, OnMessageEventArgs e) { logger.Trace(sender.ToString() + "Sbc_Message called"); try { if (e.ContentType.CompareTo("MU1") == 0) { sbc.Send(e.Content, TOPIC_FOR_STATUS_UPDATE, e.ContentType, e.Properties).Wait(); } else if (e.ContentType.CompareTo("DU1") == 0) { sbc.Send(e.Content, TOPIC_FOR_ANSWER, e.ContentType, e.Properties).Wait(); } else { logger.Trace(sender.ToString() + "Type not valid!: " + e.ContentType); } } catch (Exception ex) { logger.Error(sender.ToString() + "Error:" + ex.ToString()); } }