예제 #1
0
        public static async Task Run([TimerTrigger("%ImportTimer%")] TimerInfo timer, TraceWriter log)
        {
            log.Info($"Import started at {DateTime.Now}");
            long importedItemCount = 0;

            try
            {
                importedItemCount = await IotHubClient.ImportDevice(log);
            }
            catch (HttpRequestException httpRequestEx)
            {
            }

            log.Info($"Imported {importedItemCount} new devices to Azure Iot Hub at {DateTime.Now}");
        }
        public static async Task <object> Run([HttpTrigger] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("Import started from http trigger");
            long importedItemCount = 0;

            try
            {
                importedItemCount = await IotHubClient.ImportDevice(log);
            }
            catch (HttpRequestException httpRequestEx)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new
                {
                    error = "Internal Server Error"
                }));
            }

            return(req.CreateResponse(HttpStatusCode.OK, new
            {
                message = $"Imported {importedItemCount} new devices to Azure Iot Hub"
            }));
        }