Пример #1
0
        private DeepStreamConnector()
        {
            _client = new DeepStreamClient("136.144.231.71", 8181);

            var task = Task.Run(async() => await _client.LoginAsync());

            task.Wait();
        }
Пример #2
0
        public static async Task Main()
        {
            var url  = GetEnv("DEEPSTREAM_URL", "localhost:6020").Split(':');
            var host = url[0];
            var port = int.Parse(url[1]);

            Console.WriteLine($"Connecting to DeepStream Server '{host}:{port}'...");
            using (var client = new DeepStreamClient(host, port))
            {
                var user     = GetEnv("DEEPSTREAM_USER", "userA");
                var pwd      = GetEnv("DEEPSTREAM_PWD", "rCOSZxJrgze2AZdVQh12c6ErDMOG0M+Rx5Yu7S5d91c=GS4SbTQYmoaGwjm2shEobg==");
                var loggedIn = await client.LoginAsync(user, pwd);

                if (!loggedIn)
                {
                    throw new InvalidOperationException($"Could not login with user '{user}'");
                }

                Console.WriteLine("Logged in.");

                var eventName = GetEnv("DEEPSTREAM_EVENT", "test");
                // https://github.com/dotnet/roslyn/issues/114
                //using (var disp = await client.Events.SubscribeAsync(eventName, Console.WriteLine))
                var disp = await client.Events.SubscribeAsync(eventName, Console.WriteLine);

                try
                {
                    Console.WriteLine($"Subscribed to '{eventName}'.");
                    await Task.Delay(1000);

                    const string data = "Hello from DotNet";
                    Console.WriteLine($"Publishing '{eventName}: '{data}'...");
                    client.Events.Publish(eventName, data);

                    while (true)
                    {
                        await Task.Delay(1000);
                    }
                }
                finally
                {
                    await disp.DisposeAsync();
                }
            }
        }
Пример #3
0
        async static Task Exec()
        {
            string simulatorId = Guid.NewGuid().ToString();
            var    client      = new DeepStreamClient(Environment.GetEnvironmentVariable("AZSIM_ComHub_IP"), 6020);

            var proc = await client.Rpcs.RegisterProviderAsync <string, string>("command", HandleCommand);


            if (await client.LoginAsync())
            {
                var record = await client.Records.GetRecordAsync(simulatorId);

                record["runtime"]     = "console";
                record["status"]      = "waiting";
                record["simulatorId"] = simulatorId;
                record["frequency"]   = 0;
                record["payload"]     = "";
                record["runtime"]     = "console";

                var list = await client.Records.GetListAsync("simulators");

                list.Add(simulatorId);

                //var disp = await client.Events.SubscribeAsync("test", Console.WriteLine);

                //await Task.Delay(2000);

                //client.Events.Publish("test", "Hello World");

                //await Task.Delay(30000);

                Console.ReadKey();

                //await disp.DisposeAsync();
            }

            client.Dispose();
        }
Пример #4
0
        async static Task Exec()
        {
            Console.WriteLine("Connecting to " + Environment.GetEnvironmentVariable("AZSIM_ComHub_IP") + "...");
            string simulatorHostId = Guid.NewGuid().ToString();
            var    client          = new DeepStreamClient(Environment.GetEnvironmentVariable("AZSIM_ComHub_IP"), 6020);

            if (await client.LoginAsync())
            {
                Console.WriteLine("Connection to hub established");
                Console.WriteLine("Registered as simulator host " + simulatorHostId);
                await client.Rpcs.RegisterProviderAsync <string, string>(simulatorHostId, HandleCommand);

                record = await client.Records.GetRecordAsync(simulatorHostId);

                record["runtime"]         = "W10 Console";
                record["status"]          = "Ready";
                record["simulatorHostId"] = simulatorHostId;

                var list = await client.Records.GetListAsync("simulatorhosts");

                list.Add(simulatorHostId);
            }
        }