//If window is closing, check if downloads would be stopped and warn
        private void WindowClosing(CancelEventArgs e)
        {
            //Check if there is a file still beeing downloaded, if so, show warning message
            if (EVERadioSessions.Any(s => s.IsDownloading))
            {
                MessageBoxResult result = MessageBox.Show("Download(s) still busy, sure you want to stop?", "Warning", MessageBoxButton.YesNo);

                if (result != MessageBoxResult.Yes)
                {
                    e.Cancel = true;
                }
            }
        }
        //Start downloaden van een bestand
        private async Task DownloadFileAsync(string url, string naam)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.DownloadProgressChanged += Client_DownLoadProcessChanged;  //Om tussentijdse feedback te kunnen geven.
                    wc.DownloadFileCompleted   += Client_DownloadProcessComplete; //Om feedback te kunnen geven bij voltooing

                    //Make instance off class library
                    DownloadEVERadioSessions downloadEVERadioSessionsClassLib = new DownloadEVERadioSessions();

                    if (UseProxy)                                                                    //Use a proxy if the user wants to
                    {
                        GetProxyModel proxyinfo = downloadEVERadioSessionsClassLib.GetRandomProxy(); //Get a random proxy

                        wc.Proxy = new WebProxy(proxyinfo.Ip, proxyinfo.Port);                       //Proxy instellen
                    }

                    //timer per download starten
                    EVERadioSession evers = EVERadioSessions.Find(f => f.FileName == naam.Split('\\').Last());
                    evers.StopWatch.Start();

                    //Extra informatie per download bijhouden.
                    evers.TimeStarted = DateTime.Now;

                    await wc.DownloadFileTaskAsync(new Uri(url), naam);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                if (ex.Message == "Unable to connect to the remote server")
                {
                    FeedbackList.Add("Error, try again with Proxy enabled");
                }
                else
                {
                    FeedbackList.Add("Bestand: " + naam.Split('\\').Last() + " - Something went wrong, maybe this helps: " + ex.Message);
                }

                FeedbackColor = "Red";
            }
        }
 //Download de geselecteerde sessies
 private void DownloadSelected()
 {
     try
     {
         //Sessies ophalen die geselecteerd zijn
         foreach (EVERadioSession sessie in EVERadioSessions.Where(item => item.IsSelected))
         {
             HandleSession(sessie);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Foutboodschap: " + ex.Message);
         FeedbackColor = "Red";
         FeedbackList.Add("DownloadSelected failed: " + ex.Message);
     }
 }
        //When the download is progressing.
        private void Client_DownLoadProcessChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            //De meegezonden sessie ophalen
            string sessiontolookfor = ((Uri)((TaskCompletionSource <object>)e.UserState).Task.AsyncState).Segments[4].ToString();

            //Opzoeken van de bestandsnaam in de sessielijst
            EVERadioSession evers = EVERadioSessions.Find(f => f.FileName == sessiontolookfor);

            //TODO: Stopwatch per sessie ophalen en downloadsnelheid berekenen.
            //Console.WriteLine("Downloadsnelheid " + evers.FileName + " = " + (e.BytesReceived / 1024d / evers.StopWatch.Elapsed.TotalSeconds) + "kb/s");
            evers.DownloadSpeed = e.BytesReceived / 1024d / evers.StopWatch.Elapsed.TotalSeconds;
            evers.FileSize      = e.TotalBytesToReceive / 1000000;


            //Als we iets gevonden hebben vullen we een percentage in.
            if (evers != null)
            {
                evers.Progress = e.ProgressPercentage;
            }
        }
        //When the download completed
        private void Client_DownloadProcessComplete(object sender, AsyncCompletedEventArgs e)
        {
            //De meegezonden sessie ophalen
            string sessiontolookfor = ((Uri)((TaskCompletionSource <object>)e.UserState).Task.AsyncState).Segments[4].ToString();

            //Opzoeken van de bestandsnaam in de sessielijst
            EVERadioSession evers = EVERadioSessions.Find(f => f.FileName == sessiontolookfor);

            //Resetten van downloadsnelheid stopwatch
            evers.StopWatch.Reset();

            //Klaar met downloaden
            evers.IsDownloading = false;

            //Als we iets gevonden hebben vullen we een percentage in.
            if (evers != null)
            {
                evers.Progress         = 100;
                evers.Achtergrondkleur = "GreenYellow";
            }
        }
        //Get all the sessions and show them in the overviewlist
        private void GetAllSessions()
        {
            try
            {
                using (WebClient client = new WebClient())
                {
                    //We downloaden de EVE-Radio pagina
                    string htmlCode = client.DownloadString("https://gamingnow.net/gn_rewind/rewind/");

                    //We splitsen de herbeluister divs op basis van hun ID
                    string[] stringSeperators = new string[] { "<div class='parentPresent' style='display:none;'>" };
                    string[] rewinds          = htmlCode.Split(stringSeperators, StringSplitOptions.None).Skip(1).ToArray();//Het eerste dat we eruit halen is rommel.

                    //Nu gaan we voor elk van de gevonden rewinds de starturl opzoeken
                    foreach (string rewind in rewinds)
                    {
                        //We vinden de startpositie van de tekst die we willen, de eindpositie, en halen daar de lengte uit.
                        int startPos = rewind.IndexOf("Listen from: <a href='#' onclick=\"javascript:doCmd({rewind:'") + "Listen from: <a href='#' onclick=\"javascript:doCmd({rewind:'".Length;
                        int length   = rewind.IndexOf("'}); return false;\">Start") - startPos;

                        string downloadUrl  = rewind.Substring(startPos, length);
                        string bestandsnaam = downloadUrl.Split('/').Last();

                        //Starten met downloadsnelheidsberekening
                        Stopwatch sw = new Stopwatch();

                        EVERadioSessions.Add(new EVERadioSession()
                        {
                            FilePath = downloadUrl, FileName = bestandsnaam, StopWatch = sw, IsDownloading = false
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                FeedbackColor = "Red";
                FeedbackList.Add("Failed getting all sessions. Maybe this helps: " + ex.Message);
            }
        }