<commit_before>﻿using TramlineFive.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TramlineFive.DataAccess.DomainLogic;
using TramlineFive.DataAccess.Repositories;
using TramlineFive.Common.Managers;
using TramlineFive.ViewModels.Wrappers;
using Newtonsoft.Json;
using TramlineFive.Common.Models;

namespace TramlineFive.ViewModels
{
    public class SettingsViewModel : BaseViewModel
    {
        public List<NameValueObject> VehicleTypes { get; private set; }
        public string VehicleTypeKey { get; private set; }
        public string VehicleTypeValue { get; private set; }

        public SettingsViewModel()
        {
            VehicleTypes = VehicleTypeManager.GetNameValuePair();
            VehicleTypeKey = "Name";
            VehicleTypeValue = "Value";
        }

        public async Task ClearHistoryAsync()
        {
            IsClearingHistory = true;

            await HistoryDO.ClearAllAsync();

            IsClearingHistory = false;
        }

        public async Task<string> GetSerializedFavourites()
        {
            return JsonConvert.SerializeObject(await FavouriteDO.AllAsync());
        }

        public bool IsValid()
        {
            return !IsLiveTileEnabled || (!String.IsNullOrEmpty(StopCode) && !String.IsNullOrEmpty(LineNumber));
        }

        public async Task<bool> DoesStopExist()
        {
            IsSwitchable = false;
            IsCheckingStop = true;
            
            bool doesStop = await LineDO.DoesStopAt((VehicleType)SelectedType.Value, LineNumber, StopCode);
            if (!doesStop)
            {
                IsLiveTileEnabled = !IsLiveTileEnabled;
                IsSwitchable = true;<commit_msg>Fix crash when favourite stop input is not numbers.<commit_after>﻿using TramlineFive.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TramlineFive.DataAccess.DomainLogic;
using TramlineFive.DataAccess.Repositories;
using TramlineFive.Common.Managers;
using TramlineFive.ViewModels.Wrappers;
using Newtonsoft.Json;
using TramlineFive.Common.Models;

namespace TramlineFive.ViewModels
{
    public class SettingsViewModel : BaseViewModel
    {
        public List<NameValueObject> VehicleTypes { get; private set; }
        public string VehicleTypeKey { get; private set; }
        public string VehicleTypeValue { get; private set; }

        public SettingsViewModel()
        {
            VehicleTypes = VehicleTypeManager.GetNameValuePair();
            VehicleTypeKey = "Name";
            VehicleTypeValue = "Value";
        }

        public async Task ClearHistoryAsync()
        {
            IsClearingHistory = true;

            await HistoryDO.ClearAllAsync();

            IsClearingHistory = false;
        }

        public async Task<string> GetSerializedFavourites()
        {
            return JsonConvert.SerializeObject(await FavouriteDO.AllAsync());
        }

        public bool IsValid()
        {
            int line;
            int stop;

            return !IsLiveTileEnabled || Int32.TryParse(lineNumber, out line) && Int32.TryParse(stopCode, out stop);
        }

        public async Task<bool> DoesStopExist()
        {
            IsSwitchable = false;
            IsCheckingStop = true;
            
            bool doesStop = await LineDO.DoesStopAt((VehicleType)SelectedType.Value, LineNumber, StopCode);
            if (!doesStop)
            {
                IsLiveTileEnabled = !IsLiveTileEnabled;
                IsSwitchable = true;
{'fraction_non_alphanumeric': 0.07849077389148995, 'fraction_numerical': 0.001101624896722666, 'mean_word_length': 2.416745061147695, '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': '6887786', 'n_tokens_mistral': 994, 'n_tokens_neox': 957, 'n_words': 215}