Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            await sbc.Connect("Endpoint=sb://bre-dev02.breanos.local/BreanosSB;StsEndpoint=https://bre-dev02.breanos.local:9355/BreanosSB;RuntimePort=9354;ManagementPort=9355;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=lYVJowZHY5yNBIVHXertZw4wV1hEW9/fIigG1MUZ4fQ=");

            sbc.Message += Sbc_Message;
            string filterString = null;

            /*Console.WriteLine("Please enter a number to select a filter");
             * Console.WriteLine("1: MetaLevel = 9000");
             * Console.WriteLine("2: MetaLevel > 9000");
             * Console.WriteLine("3: MetaLevel < 9000");
             * //RandomValue
             * Console.WriteLine("4: RandomValue LIKE 'Wooo%'");
             * Console.WriteLine("5: Define it yourself");
             * var selection = Console.ReadLine();
             * string filterString = null;
             * switch (selection)
             * {
             *  case "1":
             *      filterString = "MetaLevel = 9000";
             *      break;
             *  case "2":
             *      filterString = "MetaLevel > 9000";
             *      break;
             *  case "3":
             *      filterString = "MetaLevel < 9000";
             *      break;
             *  case "4":
             *      filterString = "RandomValue LIKE 'Wooo%'";
             *      break;
             *  case "5":
             *      Console.WriteLine("Please enter filter string");
             *      filterString = Console.ReadLine();
             *      break;
             *  default:
             *      break;
             * }
             * Console.WriteLine($"Filter set to {filterString}");*/

            await sbc.ListenTo(Topic_Name, Subscription_Name, filterString);

            Console.WriteLine("Waiting for messages...");
            Console.ReadLine();
        }
Esempio n. 3
0
        public void Test_ServiceBusConnector_ServiceDispose()
        {
            // Assert
            var messenger = new ServiceBusMessenger(new ConnectionConfig {
                ConnectionString = "test.test"
            });
            var connector = new ServiceBusConnector <object>(new ServiceBusManager("", new ConnectionConfig()), new Subject <object>(), null);

            // Act - call dispose.
            messenger.Dispose();
            connector.Dispose();

            // Called a second time to test branch.
            messenger.Dispose();
            connector.Dispose();

            // Assert - disposed as expected.
            messenger.Disposed.Should().BeTrue();
            connector.Disposed.Should().BeTrue();
        }