<commit_before>﻿#r "Newtonsoft.Json"
using System;
using System.Text;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.Devices;
using System.Net;

public static async Task<HttpResponseMessage> Run(string myEventHubMessage, TraceWriter log)
{
    try
    {
        if (myEventHubMessage.StartsWith("["))
        {
            dynamic msgs = JArray.Parse(myEventHubMessage);
            foreach (dynamic msg in msgs)
            {
                if (msg.data == "DroneStart")
                {
                    await send(msg.ToString(), log);
                    break;
                }
            }
        }
        else
        {
            dynamic msg = JObject.Parse(myEventHubMessage);
            if (msg.data == "DroneStart")
            {
                await send(myEventHubMessage, log);
            }
        }
    }
    catch (Microsoft.Azure.Devices.Common.Exceptions.DeviceMaximumQueueDepthExceededException qex)
    {
        log.Info($"{qex.Message}");
        return new HttpResponseMessage(HttpStatusCode.OK);
    }
    catch (Exception ex)
    {
        log.Info($"Error: {ex.GetType()} {ex.Message}\n\t message: {myEventHubMessage}");
        return new HttpResponseMessage(HttpStatusCode.BadRequest);
    }
    return new HttpResponseMessage(HttpStatusCode.OK);
}

static async Task send(string msg, TraceWriter log)
{
    var c2dconn = GetEnvironmentVariable("iothubconnectionstring");
    log.Info(c2dconn);
    ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(c2dconn.Trim(), Microsoft.Azure.Devices.TransportType.Amqp);
    await serviceClient.SendAsync("Drone", new Message(Encoding.UTF8.GetBytes(msg)));
    log.Info($"Message sent to Drone: {msg}");
}
public static string GetEnvironmentVariable(string name)
{
    return System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}<commit_msg>dispose connection<commit_after>﻿#r "Newtonsoft.Json"
using System;
using System.Text;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.Devices;
using System.Net;

public static async Task<HttpResponseMessage> Run(string myEventHubMessage, TraceWriter log)
{
    try
    {
        if (myEventHubMessage.StartsWith("["))
        {
            dynamic msgs = JArray.Parse(myEventHubMessage);
            foreach (dynamic msg in msgs)
            {
                if (msg.data == "DroneStart")
                {
                    await send(msg.ToString(), log);
                    break;
                }
            }
        }
        else
        {
            dynamic msg = JObject.Parse(myEventHubMessage);
            if (msg.data == "DroneStart")
            {
                await send(myEventHubMessage, log);
            }
        }
    }
    catch (Microsoft.Azure.Devices.Common.Exceptions.DeviceMaximumQueueDepthExceededException qex)
    {
        log.Info($"{qex.Message}");
        return new HttpResponseMessage(HttpStatusCode.OK);
    }
    catch (Exception ex)
    {
        log.Info($"Error: {ex.GetType()} {ex.Message}\n\t message: {myEventHubMessage}");
        return new HttpResponseMessage(HttpStatusCode.BadRequest);
    }
    return new HttpResponseMessage(HttpStatusCode.OK);
}

static async Task send(string msg, TraceWriter log)
{
    var c2dconn = GetEnvironmentVariable("iothubconnectionstring");
    using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(c2dconn.Trim(), Microsoft.Azure.Devices.TransportType.Amqp))
    {
        await serviceClient.SendAsync("Drone", new Message(Encoding.UTF8.GetBytes(msg)));
        log.Info($"Message sent to Drone: {msg}");
    }
}
public static string GetEnvironmentVariable(string name)
{
    return System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}
{'fraction_non_alphanumeric': 0.10703851261620186, 'fraction_numerical': 0.0018592297476759628, 'mean_word_length': 2.59694364851958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2770835', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1050, 'n_words': 203}