<commit_before>﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using CK.ControlChannel.Tcp;
using CK.Glouton.Model.Server.Handlers;
using CK.Glouton.Model.Server.Sender;
using CK.Glouton.Model.Services;
using Microsoft.Extensions.Options;

namespace CK.Glouton.Service
{
    public class AlertService : IAlertService
    {
        private readonly ControlChannelClient _controlChannelCLient;
        private readonly TcpControlChannelConfiguration _configuration;
        private readonly IFormatter _formatter;
        private readonly MemoryStream _memoryStream;


        public string[] AvailableConfiguration
        {
            get => new string[] { "Mail" } ;
        }

        public AlertService(IOptions<TcpControlChannelConfiguration> configuration)
        {
            _configuration = configuration.Value;
            _controlChannelCLient = new ControlChannelClient(
                _configuration.Host,
                _configuration.Port,
                _configuration.BuildAuthData(),
                _configuration.IsSecure
                );

            _controlChannelCLient.OpenAsync();

            _memoryStream = new MemoryStream();
            _formatter = new BinaryFormatter();
        }

        public bool SendNewAlert( IAlertExpressionModel alertExpression )
        {
            _memoryStream.Seek(0, SeekOrigin.Begin);
            _memoryStream.Flush();

            _formatter.Serialize(_memoryStream, alertExpression);
            _controlChannelCLient.SendAsync("AddAlertSender", _memoryStream.ToArray()).GetAwaiter().GetResult();

            return true;
        }

        public IMailConfiguration GetMailConfiguration()
        {
            return new MailConfiguration
            {
                Name = "",
                Email = "",
                Contacts = new string[] { },
                SmtpAddress = "",
                SmtpPassword = "",
                SmtpUsername = "",
                SmtpPort = -1
            };
        }
    }
}<commit_msg>[WIP] Some tweaks on AlertService.<commit_after>﻿using CK.ControlChannel.Tcp;
using CK.Glouton.Model.Server.Handlers;
using CK.Glouton.Model.Server.Sender;
using CK.Glouton.Model.Services;
using Microsoft.Extensions.Options;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace CK.Glouton.Service
{
    public class AlertService : IAlertService
    {
        private readonly ControlChannelClient _controlChannelClient;
        private readonly TcpControlChannelConfiguration _configuration;
        private readonly IFormatter _formatter;
        private readonly MemoryStream _memoryStream;


        public string[] AvailableConfiguration => new[] { "Mail" };

        public AlertService( IOptions<TcpControlChannelConfiguration> configuration )
        {
            _configuration = configuration.Value;
            _controlChannelClient = new ControlChannelClient(
                _configuration.Host,
                _configuration.Port,
                _configuration.BuildAuthData(),
                _configuration.IsSecure
                );

            _controlChannelClient.OpenAsync().GetAwaiter().GetResult();

            _memoryStream = new MemoryStream();
            _formatter = new BinaryFormatter();
        }

        public bool SendNewAlert( IAlertExpressionModel alertExpression )
        {
            _memoryStream.Seek( 0, SeekOrigin.Begin );
            _memoryStream.Flush();

            _formatter.Serialize( _memoryStream, alertExpression );
            _controlChannelClient.SendAsync( "AddAlertSender", _memoryStream.ToArray() ).GetAwaiter().GetResult();

            return true;
        }

        public IMailConfiguration GetMailConfiguration()
        {
            return new MailConfiguration
            {
                Name = "",
                Email = "",
                Contacts = new string[] { },
                SmtpAddress = "",
                SmtpPassword = "",
                SmtpUsername = "",
                SmtpPort = -1
            };
        }
    }
}
{'fraction_non_alphanumeric': 0.08013435700575816, 'fraction_numerical': 0.0009596928982725527, 'mean_word_length': 2.095025983667409, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5380880', 'n_tokens_mistral': 1034, 'n_tokens_neox': 971, 'n_words': 197}