public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            log.LogInformation("Token Generation Requested");
            var signalR = new AzureSignalR(Environment.GetEnvironmentVariable("AzureSignalRConnectionString"));

            var res = new OkObjectResult(new
            {
                authInfo = new
                {
                    serviceUrl  = signalR.GetClientHubUrl(Environment.GetEnvironmentVariable("HubName")),
                    accessToken = signalR.GenerateAccessToken(Environment.GetEnvironmentVariable("HubName"))
                },
            });

            return(res);
        }
Exemplo n.º 2
0
        public static async Task Run([TimerTrigger("*/10 * * * * *", RunOnStartup = true)] TimerInfo timerTriggerInfo, ILogger log)
        {
            RegistryManager rm     = RegistryManager.CreateFromConnectionString(Environment.GetEnvironmentVariable("IoTHubConnectionString"));
            var             q      = rm.CreateQuery("select * from devices", 10);
            var             result = await q.GetNextAsJsonAsync();

            var devices = new List <DeviceInfo>();
            //var signalR = new AzureSignalR(Environment.GetEnvironmentVariable("AzureSignalRConnectionString"));
            var signalR = new AzureSignalR(Environment.GetEnvironmentVariable("AzureSignalRConnectionString"));

            foreach (var d in result.ToList())
            {
                devices.Add(new DeviceInfo()
                {
                    Id = JsonConvert.DeserializeObject <Device>(d).Id
                });
            }
            await signalR.SendAsync("hub1", "RefreshDeviceList", JsonConvert.SerializeObject(devices));
        }
 public static async Task Run([EventHubTrigger("soselectronics", Connection = "IoTHubReceiveEventsConnectionEndpoint")] EventData message, ILogger log)
 {
     log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");
     var signalR = new AzureSignalR(Environment.GetEnvironmentVariable("AzureSignalRConnectionString"));
     await signalR.SendAsync("hub1", "RefreshMessageForDevice", message.SystemProperties["iothub-connection-device-id"], Encoding.UTF8.GetString(message.Body.Array));
 }