<commit_before>﻿using System;
using System.Diagnostics;
using System.Threading.Tasks;
using TUMCampusApp.Classes.Events;
using Windows.Devices.Enumeration;
using Windows.Devices.WiFi;
using Windows.Networking.Connectivity;
using Windows.Security.Credentials;
using Windows.UI.Xaml;

namespace TUMCampusApp.Classes.Helpers
{
    class EduroamHelper
    {
        //--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
        #region --Attributes--
        public const string EDUROAM_SSID = "eduroam";

        private WiFiAdapter adapter = null;
        private DispatcherTimer timer = null;
        private bool stopRequested;

        public delegate void EduroamNetworkFoundEventHandler(WiFiAdapter adapter, EduroamNetworkFoundEventArgs args);

        public event EduroamNetworkFoundEventHandler EduroamNetworkFound;

        #endregion
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 21/03/2018 Created [<NAME>]
        /// </history>
        public EduroamHelper()
        {
            this.stopRequested = false;
        }

        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--
        public async Task connectAsync(WiFiAvailableNetwork network, WiFiReconnectionKind wiFiReconnectionKind, PasswordCredential passwordCredential)
        {
            await adapter.ConnectAsync(network, wiFiReconnectionKind, passwordCredential);
        }

        public async Task installCertificateAsync()
        {

        }

        public async Task<WiFiAccessStatus> requestAccessAsync()
        {
            return await WiFiAdapter.RequestAccessAsync();
        }

        public async Task<WiFiAdapter> loadAdapterAsync()
        {
            DeviceInformationCollection adapterResult = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
            if (adapterResult.Count >= 1)
            {
                return await WiFiAdapter.FromIdAsync(adapterResult[0].Id);
            }
            else
            {
                return null;
            }
        }

        public async Task startSearchingAsync()
        {
            WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync();
            if (access != WiFiAccessStatus.Allowed)
            {
                // No access:
            }
            else
            {
                DeviceInformationCollection adapterResult = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
                if (adapterResult.Count >= 1)
                {
                    adapter = await WiFiAdapter.FromIdAsync(adapterResult[0].Id);
                    adapter.AvailableNetworksChanged += Adapter_AvailableNetworksChanged;
                    await adapter.ScanAsync();
                }
                else
                {
                    // No wifi adapter
                }
            }

            await adapter.ScanAsync();
            timer = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 10)
            };
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        public void stopSearching()
        {
            adapter.AvailableNetworksChanged -= Adapter_AvailableNetworksChanged;
            stopRequested = true;
        }

        #endregion

        #region --Misc Methods (Protected)--


        #endregion
        //--------------------------------------------------------Events:---------------------------------------------------------------------\\
        #region --Events--
        private void Adapter_AvailableNetworksChanged(WiFiAdapter sender, object args)
        {
            foreach (WiFiAvailableNetwork n in sender.NetworkReport.AvailableNetworks)
            {
                if (string.Equals(n.Ssid, EDUROAM_SSID) && n.SecuritySettings.NetworkEncryptionType == NetworkEncryptionType.Ccmp)
                {
                    stopSearching();
                    EduroamNetworkFound?.Invoke(sender, new EduroamNetworkFoundEventArgs(n));
                    return;
                }
            }
        }
<commit_msg>Updated eduroam detection<commit_after>﻿using System;
using System.Diagnostics;
using System.Threading.Tasks;
using TUMCampusApp.Classes.Events;
using Windows.Devices.Enumeration;
using Windows.Devices.WiFi;
using Windows.Networking.Connectivity;
using Windows.Security.Credentials;
using Windows.UI.Xaml;

namespace TUMCampusApp.Classes.Helpers
{
    class EduroamHelper
    {
        //--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
        #region --Attributes--
        public const string EDUROAM_SSID = "eduroam";

        private WiFiAdapter adapter = null;
        private DispatcherTimer timer = null;
        private bool stopRequested;

        public delegate void EduroamNetworkFoundEventHandler(WiFiAdapter adapter, EduroamNetworkFoundEventArgs args);

        public event EduroamNetworkFoundEventHandler EduroamNetworkFound;

        #endregion
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 21/03/2018 Created [<NAME>]
        /// </history>
        public EduroamHelper()
        {
            this.stopRequested = false;
        }

        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--
        public async Task connectAsync(WiFiAvailableNetwork network, WiFiReconnectionKind wiFiReconnectionKind, PasswordCredential passwordCredential)
        {
            await adapter.ConnectAsync(network, wiFiReconnectionKind, passwordCredential);
        }

        public async Task installCertificateAsync()
        {

        }

        public async Task<WiFiAccessStatus> requestAccessAsync()
        {
            return await WiFiAdapter.RequestAccessAsync();
        }

        public async Task<WiFiAdapter> loadAdapterAsync()
        {
            DeviceInformationCollection adapterResult = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
            if (adapterResult.Count >= 1)
            {
                return await WiFiAdapter.FromIdAsync(adapterResult[0].Id);
            }
            else
            {
                return null;
            }
        }

        public async Task startSearchingAsync()
        {
            WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync();
            if (access != WiFiAccessStatus.Allowed)
            {
                // No access:
            }
            else
            {
                DeviceInformationCollection adapterResult = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
                if (adapterResult.Count >= 1)
                {
                    adapter = await WiFiAdapter.FromIdAsync(adapterResult[0].Id);
                    adapter.AvailableNetworksChanged += Adapter_AvailableNetworksChanged;
                    await adapter.ScanAsync();
                }
                else
                {
                    // No wifi adapter
                }
            }

            await adapter.ScanAsync();
            timer = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 10)
            };
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        public void stopSearching()
        {
            adapter.AvailableNetworksChanged -= Adapter_AvailableNetworksChanged;
            stopRequested = true;
        }

        #endregion

        #region --Misc Methods (Protected)--


        #endregion
        //--------------------------------------------------------Events:---------------------------------------------------------------------\\
        #region --Events--
        private void Adapter_AvailableNetworksChanged(WiFiAdapter sender, object args)
        {
            foreach (WiFiAvailableNetwork n in sender.NetworkReport.AvailableNetworks)
            {
                if (string.Equals(n.Ssid, EDUROAM_SSID) && n.SecuritySettings.NetworkEncryptionType == NetworkEncryptionType.Ccmp && n.SecuritySettings.NetworkAuthenticationType == NetworkAuthenticationType.Rsna)
                {
                    stopSearching();
                    EduroamNetworkFound?.Invoke(sender, new EduroamNetworkFoundEventArgs(n));
                    return;
                }
            }
        }

{'fraction_non_alphanumeric': 0.19658385093167702, 'fraction_numerical': 0.0033126293995859213, 'mean_word_length': 1.2311778290993072, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '6806180', 'n_tokens_mistral': 2144, 'n_tokens_neox': 2036, 'n_words': 428}