示例#1
0
        public NngCollectionFixture()
        {
            var managedAssemblyPath = Path.GetDirectoryName(GetType().Assembly.Location);
            var alc = new NngLoadContext(managedAssemblyPath);

            Factory = NngLoadContext.Init(alc);
        }
示例#2
0
        private static IAPIFactory <IMessage> CreateNngFactory()
        {
            var path = Path.GetDirectoryName(typeof(Constants).Assembly.Location);
            var ctx  = new NngLoadContext(path);

            return(NngLoadContext.Init(ctx));
        }
示例#3
0
文件: Program.cs 项目: Comprime/lms
        static async Task Main(string[] args)
        {
            var uri     = "ipc://tester";
            var path    = Path.GetDirectoryName(typeof(Program).Assembly.Location);
            var ctx     = new NngLoadContext(path);
            var factory = NngLoadContext.Init(ctx);

            using var cts = new CancellationTokenSource(8000);
            await Task.WhenAll(

                // Set up server interface
                Task.Run(async() => {
                await using var server =
                                Lms.CreateServerBuilder()
                                .AddFunction <int, int>("Tester", Tester)
                                .AddFunction <int, int>("ThrowException", ThrowException)
                                .Build(factory, uri, null, loggerFactory.CreateLogger <IServer>());
                await server.Listen(8, cts.Token);
            }),

                // Client Tester request loop
                Task.Run(async() => {
                await using var client = Lms.CreateClient(factory, uri, null, loggerFactory.CreateLogger <IClient>());
                var random             = new Random();
                while (!cts.Token.IsCancellationRequested)
                {
                    var request = random.Next();
                    var result  = await client.Request <int, int>("Tester", request, cts.Token);
                    logger.LogInformation("Requested {Request} and got {Result}", request, result);
                }
            }),

                // Client Tester request loop
                Task.Run(async() => {
                await using var client = Lms.CreateClient(factory, uri, null, loggerFactory.CreateLogger <IClient>());
                while (!cts.Token.IsCancellationRequested)
                {
                    try {
                        var result = await client.Request <int, int>("ThrowException", 20, cts.Token);
                    }catch (Exception e) {
                        logger.LogInformation("Called ThrowException and got a {Type} saying {Message}\n{StackTrace}", e.GetType(), e.Message, e.StackTrace);
                    }
                }
            })
                );
        }
示例#4
0
        public NngCollectionFixture()
        {
            var dirInfo = new DirectoryInfo(Path.GetDirectoryName(GetType().Assembly.Location));
            // Assume we're in:
            // <root>/tests/bin/Debug/netcoreapp2.1/
            // And we need to get to:
            // <root>/nng.NETCore/bin/Debug/netstandard2.0/
            var root = dirInfo.Parent.Parent.Parent.Parent.FullName;

            #if DEBUG
            var configuration = "Debug";
            #else
            var configuration = "Release";
            #endif
            var managedAssemblyPath = Path.Combine(root, "packer", "bin", configuration);
            var alc = new NngLoadContext(managedAssemblyPath);
            Factory = NngLoadContext.Init(alc);
        }
示例#5
0
        static async Task Main(string[] args)
        {
            const string url     = "ipc:///tmp/i8KtK2KwLi1o7WaVBbEKpRLPtAEYayfoptqAFYxfQgrus1g6m.ipc";
            var          path    = Path.GetDirectoryName(typeof(Program).Assembly.Location);
            var          ctx     = new NngLoadContext(path);
            var          factory = NngLoadContext.Init(ctx);

            using var sock = factory.SubscriberOpen().Unwrap();
            sock.Dial(url).Unwrap();
            sock.SetOpt("sub:subscribe", new byte[] { });

            var cancellationSource = new CancellationTokenSource();

            await Task.Run(() =>
            {
                while (!cancellationSource.IsCancellationRequested)
                {
                    var msg    = sock.RecvMsg().Unwrap();
                    var buffer = msg.AsSpan().ToArray();

                    BytesToTx(buffer);
                }
            }, cancellationSource.Token);
        }