<commit_before>﻿//Main Contributor: <NAME>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace CS410Project
{
    /*Loginout is the object that manages and keeps track of:
     * username, password, FTP server address
     * loginout also, provides functionality for logging in, and logging off
     * loginout keeps track of the time between actions and will force a logoff after X amount of time
     * loginout parses to grab the root link and sends the rest to the client as the currdirectory
     * loginout will also be the one responsible for saving connection info into files, encrypting/decrypting them for future uses
     */
    public class Loginout
    {
        private string username;
        private string password;
        private string destination;
        public string currDirectory { get; set; } 
        //If a user checks if we are logged on, it means we are doing stuff, so we also reset the timeout timer
        private bool loggedin;
        public bool LoggedIn { get { RestartTimer(); return loggedin; } set {/*This does nothing, because you shouldn't be able to set this outside of the object. */} }
        private Timer timeout = new Timer();

        private List<SessionInfo> sessions; //The list of sessions that are loaded/saved for past connections
        private struct SessionInfo
        {
            public string name;
            public string domain;
            public string username;
            public string password;
            
        };

        public Loginout()
        {
            sessions = new List<SessionInfo>();
            loggedin = false;
        }
        
        //Enable the Timeout Timer
        public void EnableTimeoutTimer(ElapsedEventHandler e,uint seconds)
        {
            timeout.Elapsed += e;  //Hooks the timer to an eventhandler function in the main window
            timeout.Interval = seconds * 1000;  //Sets time to seconds * miliseconds
            timeout.Start();
        }

        //Restart Timer
        public void RestartTimer()
        {
            timeout.Stop();
            timeout.Start();
        }

        //Place this method in the timeout event in the main window
        public void Timeout()
        {
            loggedin = false;
            timeout.Stop();
        }

        //Separates the base link from the directory listing and returns a string of the directory listing
        private void parseDestination(string target)
        {
            if (target == null)
                return;

            //Conventional ftp link is "ftp://whatever.what/"
            //So we need to parse through 3 '/' to get base link, then everything else is the currDirectory
            char[] delimiterchars = { '/', '\\' }; //chars to use with parsing
            string[] parsed = target.Split(delimiterchars, StringSplitOptions.RemoveEmptyEntries);
            int counter = 0;
            //Set currDirectory to default as ""
            currDirectory = "";
            foreach (string s in parsed)
            {
                if (counter == 1)
                {
                    this.destination += s;
                    this.destination += "/";
                    counter++;
                    continue;
                }
                if (counter == 0)
                {
                    this.destination = s;
                    this.destination += "//";
                    counter++;
                    continue;
                }
                currDirectory += s;
                currDirectory += "/";
            }
            //Regardless of how the destination is typed, the finished string will have a '/' at the end
        }

        //Logs into the the FTP server using client's establishConnection method
        //This function also passes destination and currDirectory information to Client
        public bool Login(Client client, string username, string password, string destination)
        {
            this.username = username;
            this.password = password;
            this.destination = destination;
            this.loggedin = false; //By default we are not logged into the system
            parseDestination(destination);
            if (!checkValidURI(destination))
                return false;
            if (client.establishConnection(username, password, destination, currDirectory))<commit_msg>Bug fixed about destination name ambiguity<commit_after>﻿//Main Contributor: <NAME>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace CS410Project
{
    /*Loginout is the object that manages and keeps track of:
     * username, password, FTP server address
     * loginout also, provides functionality for logging in, and logging off
     * loginout keeps track of the time between actions and will force a logoff after X amount of time
     * loginout parses to grab the root link and sends the rest to the client as the currdirectory
     * loginout will also be the one responsible for saving connection info into files, encrypting/decrypting them for future uses
     */
    public class Loginout
    {
        private string username;
        private string password;
        private string destination;
        public string currDirectory { get; set; } 
        //If a user checks if we are logged on, it means we are doing stuff, so we also reset the timeout timer
        private bool loggedin;
        public bool LoggedIn { get { RestartTimer(); return loggedin; } set {/*This does nothing, because you shouldn't be able to set this outside of the object. */} }
        private Timer timeout = new Timer();

        private List<SessionInfo> sessions; //The list of sessions that are loaded/saved for past connections
        private struct SessionInfo
        {
            public string name;
            public string domain;
            public string username;
            public string password;
            
        };

        public Loginout()
        {
            sessions = new List<SessionInfo>();
            loggedin = false;
        }
        
        //Enable the Timeout Timer
        public void EnableTimeoutTimer(ElapsedEventHandler e,uint seconds)
        {
            timeout.Elapsed += e;  //Hooks the timer to an eventhandler function in the main window
            timeout.Interval = seconds * 1000;  //Sets time to seconds * miliseconds
            timeout.Start();
        }

        //Restart Timer
        public void RestartTimer()
        {
            timeout.Stop();
            timeout.Start();
        }

        //Place this method in the timeout event in the main window
        public void Timeout()
        {
            loggedin = false;
            timeout.Stop();
        }

        //Separates the base link from the directory listing and returns a string of the directory listing
        private void parseDestination(string target)
        {
            if (target == null)
                return;

            //Conventional ftp link is "ftp://whatever.what/"
            //So we need to parse through 3 '/' to get base link, then everything else is the currDirectory
            char[] delimiterchars = { '/', '\\' }; //chars to use with parsing
            string[] parsed = target.Split(delimiterchars, StringSplitOptions.RemoveEmptyEntries);
            int counter = 0;
            //Set currDirectory to default as ""
            currDirectory = "";
            foreach (string s in parsed)
            {
                if (counter == 1)
                {
                    this.destination += s;
                    this.destination += "/";
                    counter++;
                    continue;
                }
                if (counter == 0)
                {
                    this.destination = s;
                    this.destination += "//";
                    counter++;
                    continue;
                }
                currDirectory += s;
                currDirectory += "/";
            }
            //Regardless of how the destination is typed, the finished string will have a '/' at the end
        }

        //Logs into the the FTP server using client's establishConnection method
        //This function also passes destination and currDirectory information to Client
        public bool Login(Client client, string username, string password, string destination)
        {
            this.username = username;
            this.password = password;
            this.destination = destination;
            parseDestination(this.destination);

            if (!checkValidURI(this.destination))
                return false;
            if (client.establishConnection(username, password, this.destination, currDirectory))
{'fraction_non_alphanumeric': 0.0699426515236703, 'fraction_numerical': 0.002473855841673226, 'mean_word_length': 1.751005258274049, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4591352', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1959, 'n_words': 829}