<commit_before>﻿//#define TRIAL_SIMULATION
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Store;
using Windows.Graphics.Display;
using Windows.Storage;
using Windows.System;
using Windows.UI;
using Windows.UI.Input;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using DjvuApp.Common;
using DjvuApp.Misc;
using DjvuApp.Misc.TrialExperience;
using Microsoft.Practices.ServiceLocation;

namespace DjvuApp.Pages
{
    public sealed partial class MainPage : Page
    {
        private static bool? _hasLicense = null;

        private readonly NavigationHelper _navigationHelper;
        private readonly ResourceLoader _resourceLoader;

        public MainPage()
        {
            InitializeComponent();
            _navigationHelper = new NavigationHelper(this);
            _resourceLoader = ResourceLoader.GetForCurrentView();
        }

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _navigationHelper.OnNavigatedTo(e);

            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;

            if (_hasLicense == null)
            {
                _hasLicense = await LicenseValidator.GetLicenseStatusAsync();
            }
            if (_hasLicense != true)
            {
                var dialog = new MessageDialog("I don't like being pirated...");
                await dialog.ShowAsync();
                Application.Current.Exit();
            }

            UpdateLicenseStatus();

            ShowRateAppDialog();
        }

        private async void ShowRateAppDialog()
        {
            const string key = "RateDialog_AppLaunchCount";
            var settings = ApplicationData.Current.LocalSettings;
            if (!settings.Values.ContainsKey(key))
            {
                settings.Values[key] = 0;
            }

            var count = (int) settings.Values[key];
            
            settings.Values[key] = count + 1;
            count++;

            if (count == 2 || count == 4 || count == 6)
            {
                var content = _resourceLoader.GetString("RateAppDialog_Content");
                var title = _resourceLoader.GetString("RateAppDialog_Title");
                var rateButtonCaption = _resourceLoader.GetString("RateAppDialog_RateButton_Caption");
                var cancelButtonCaption = _resourceLoader.GetString("RateAppDialog_CancelButton_Caption");
                var dialog = new MessageDialog(content, title);

                dialog.Commands.Add(new UICommand(rateButtonCaption, async command =>
                {
                    settings.Values[key] = 1000;
                    await App.RateApp();
                }));
                dialog.Commands.Add(new UICommand(cancelButtonCaption));
                dialog.CancelCommandIndex = unchecked((uint) -1);

                await dialog.ShowAsync();<commit_msg>The rate app dialog now shows more rarely.<commit_after>﻿//#define TRIAL_SIMULATION
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Store;
using Windows.Graphics.Display;
using Windows.Storage;
using Windows.System;
using Windows.UI;
using Windows.UI.Input;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using DjvuApp.Common;
using DjvuApp.Misc;
using DjvuApp.Misc.TrialExperience;
using Microsoft.Practices.ServiceLocation;

namespace DjvuApp.Pages
{
    public sealed partial class MainPage : Page
    {
        private static bool? _hasLicense = null;

        private readonly NavigationHelper _navigationHelper;
        private readonly ResourceLoader _resourceLoader;

        public MainPage()
        {
            InitializeComponent();
            _navigationHelper = new NavigationHelper(this);
            _resourceLoader = ResourceLoader.GetForCurrentView();
        }

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _navigationHelper.OnNavigatedTo(e);

            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;

            if (_hasLicense == null)
            {
                _hasLicense = await LicenseValidator.GetLicenseStatusAsync();
            }
            if (_hasLicense != true)
            {
                var dialog = new MessageDialog("I don't like being pirated...");
                await dialog.ShowAsync();
                Application.Current.Exit();
            }

            UpdateLicenseStatus();

            ShowRateAppDialog();
        }

        private async void ShowRateAppDialog()
        {
            const string key = "RateDialog_AppLaunchCount";
            var settings = ApplicationData.Current.LocalSettings;
            if (!settings.Values.ContainsKey(key))
            {
                settings.Values[key] = 0;
            }

            var count = (int) settings.Values[key];
            
            settings.Values[key] = count + 1;
            count++;

            if (count == 5 || count == 10 || count == 15)
            {
                var content = _resourceLoader.GetString("RateAppDialog_Content");
                var title = _resourceLoader.GetString("RateAppDialog_Title");
                var rateButtonCaption = _resourceLoader.GetString("RateAppDialog_RateButton_Caption");
                var cancelButtonCaption = _resourceLoader.GetString("RateAppDialog_CancelButton_Caption");
                var dialog = new MessageDialog(content, title);

                dialog.Commands.Add(new UICommand(rateButtonCaption, async command =>
                {
                    settings.Values[key] = 1000;
                    await App.RateApp();
                }));
                dialog.Commands.Add(new UICommand(cancelButtonCaption));
                dialog.CancelCommandIndex = unchecked((uint) -1);

                await dialog.ShowAsync();
{'fraction_non_alphanumeric': 0.08556750682292502, 'fraction_numerical': 0.0035318670733665114, 'mean_word_length': 2.203084832904884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7309552', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1499, 'n_words': 334}