using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace PdfAcroform
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : Application
    {
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            C1.UWP.LicenseManager.Key =
                "AB4BHgIeB3dQAGQAZgBBAGMAcgBvAGYAbwByAG0AY1aM6PBxHICDZvgjkzMsk8gW" +
                "QEM9kM/AoX7k20rxHiL3RDkuSg6vGfy1ia3H6tCY03idzL9fuGPiDA4mp/yoIV7W" +
                "yy9z5ryzaYPs6us6hXhb59MPD3UmXNLCr2+1HBl7wR+v6MQNk4+13TSdU1eDw9Jx" +
                "GtZy/5wblJF0aXFNDoQFbob61QfY9IMfGI13ZFqxuvLcaZfecZXwDeaUIS/sdho/" +
                "AucIzwoeKmCekJ5wRYwGad8mZ3qJ0H4uG7STBBzZe0rpPYy6Gf5bC6OTtZQ6ZA6y" +
                "sQN8Mi5y9PAJC2rxx0COdiyvHad7mz2QKmGEEkXArxUUgC8WWZOUmbchCQ3o+hMK" +
                "Suyh2cO+W8Kmwn+sobRzyWE2sbFf4TB+oOw/gH04frvrFH0BZj1vhG7tG7muTfRG" +
                "LDSK6OPrq/N34v+wyQZqsotq7ruCEwe7xDGm0tqj1HnsQEJqhTJ5PCMTnoMa+mBO" +
                "AnWqPFRUTMC4DCxb34XNPXNnhcghPKDLs0PopXYAHY2m4gAzFHCkayk4zyoj+VJF" +
                "MOu6fBGYKKgjlu8bD+IphAEJD+bO/BItDy+crsP286dH4FtqjGhabH7NIjS9koId" +
                "PE7bD7W1wVTDRoB3+6LVCYzmTKl9nviK9hl2nCUmvk4MWiTdmfSuUVmSK2FuWTcY" +
                "1Tl0hIhQazDZ2qb5yWYwggVVMIIEPaADAgECAhBBA3jSJjZZehbbJsa9EJSLMA0G" +
                "CSqGSIb3DQEBBQUAMIG0MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24s" +
                "IEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxOzA5BgNVBAsT" +
                "MlRlcm1zIG9mIHVzZSBhdCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhIChj" +
                "KTEwMS4wLAYDVQQDEyVWZXJpU2lnbiBDbGFzcyAzIENvZGUgU2lnbmluZyAyMDEw" +
                "IENBMB4XDTE0MTIxMTAwMDAwMFoXDTE1MTIyMjIzNTk1OVowgYYxCzAJBgNVBAYT" +
                "AkpQMQ8wDQYDVQQIEwZNaXlhZ2kxGDAWBgNVBAcTD1NlbmRhaSBJenVtaS1rdTEX" +
                "MBUGA1UEChQOR3JhcGVDaXR5IGluYy4xGjAYBgNVBAsUEVRvb2xzIERldmVsb3Bt" +
                "ZW50MRcwFQYDVQQDFA5HcmFwZUNpdHkgaW5jLjCCASIwDQYJKoZIhvcNAQEBBQAD" +
                "ggEPADCCAQoCggEBAMEC9splW7KVpAqRB6VVB7XJm8+a60x78HZWNmvAjs/ermp7" +
                "pbh8M9HYuEVTRj8H4baXxFYq4i75e5kNr7s+nGbJ5UfM6CldqbeRsQ4zvRb6npfr" +
                "tcOBwfYOx0woeYQfI6VzLVzhPbGjUDK6qdHZLf/EcvSIKvRbu3ILOE3kuux07gQk" +
                "b++rrSBUyJKXU8nW8c+K+9sfWqHYPb8FF2IazWxhmfIdIoDNKyjr3r/wIn3jQejp" +
                "qfamiHNsU/O26KS0EcvCS5CFOKDT6vvdnAkek3kyLWef+ca/cbFo74vawYGtmw2w" +
                "zw/hcwlANIQaCAxz+5JHQZ3SEg8LLSZ+C8E4T+8CAwEAAaOCAY0wggGJMAkGA1Ud" +
                "EwQCMAAwDgYDVR0PAQH/BAQDAgeAMCsGA1UdHwQkMCIwIKAeoByGGmh0dHA6Ly9z" +
                "Zi5zeW1jYi5jb20vc2YuY3JsMGYGA1UdIARfMF0wWwYLYIZIAYb4RQEHFwMwTDAj" +
                "BggrBgEFBQcCARYXaHR0cHM6Ly9kLnN5bWNiLmNvbS9jcHMwJQYIKwYBBQUHAgIw" +
                "GQwXaHR0cHM6Ly9kLnN5bWNiLmNvbS9ycGEwEwYDVR0lBAwwCgYIKwYBBQUHAwMw" +
                "VwYIKwYBBQUHAQEESzBJMB8GCCsGAQUFBzABhhNodHRwOi8vc2Yuc3ltY2QuY29t" +
                "MCYGCCsGAQUFBzAChhpodHRwOi8vc2Yuc3ltY2IuY29tL3NmLmNydDAfBgNVHSME" +
                "GDAWgBTPmanqeyb0S8mOj9fwBSbv49KnnTAdBgNVHQ4EFgQUAFrwraXUeDX1hBKo" +
                "LAUO+FYbjo4wEQYJYIZIAYb4QgEBBAQDAgQQMBYGCisGAQQBgjcCARsECDAGAQEA" +
                "AQH/MA0GCSqGSIb3DQEBBQUAA4IBAQCIwphaN45b5ViKsRfCA6hbVeqMhNCJmL64" +
                "mqxdYvw3gsF4oOCDoiM6kWhy1NoUd2Lpcr9PjfGJ55ZX4sZlqoxeflTpHgnX8MPJ" +
                "uKpDBsk7WkhiEu65fBwb+g9wQHMMfgY0gjHIAQ2ZEf2PJ6TTSFcvj24wh73dsyqc" +
                "mj290fpwDtHaF2jE5pq/tQBOJ8vDkN46wt4qMhG6nIpOgc9KngyLLdEO7V34KM1N" +
                "b+sN9JkqTWXNoNqlOf7QjYHwlw7Ku7W3kIGK+f1kP1xqTBpXwsBE5sLlnujP+JAq" +
                "V8aKlBJDKRI3IhlrG9CJUmqFNhmZ2f5QE5jAvPQeXevLnMYiqJrgMIICxDCCAayg" +
                "AwIBAgIEDu7u7jANBgkqhkiG9w0BAQUFADAkMSIwIAYDVQQDDBlHQy1VV1AgSW50" +
                "ZXJuYWwgRGV2ZWxvcGVyMB4XDTE2MDUxMjA4NDgwNVoXDTE3MDUxMjA4NDgwNVow" +
                "JDEiMCAGA1UEAwwZR0MtVVdQIEludGVybmFsIERldmVsb3BlcjCCASIwDQYJKoZI" +
                "hvcNAQEBBQADggEPADCCAQoCggEBAJbHH02YVsmFYcV4LYVwfPebCKT3RnOVKTuG" +
                "CF5M48WvI4zl0DtcGr/My3CAzGYWCrCFP5Sa7bA/ZGNdlnq3jgcEo+zJDe5C5K/l" +
                "9DVJZNX4jxvhOP5tm2bfL55kirtDZPo+b5BUOMXIpINd0T35E/W8nZBdulkYNjs5" +
                "oAIdALOM8Ky0V5SeC6cVcUxG67hfpSrVZc+yMRYuajcCjnKxXEF5PJ1UvB1TWtX5" +
                "PljWeTRZPG0R3BsHYYs3BLftbXGsCtVgp6JPTz+HbXVxnAEpzBuTnDw1RqI0yduT" +
                "/P7KUuQCSFeUoUJhoXv1qgCC+VA3fdlJapC9FX4f3BI1RZfNSNECAwEAATANBgkq" +
                "hkiG9w0BAQUFAAOCAQEAPzWzr5PJ4QkNLIoQIGAZ6OvNT8kISdqGrII7dYz4kznt" +
                "BpioHAw8PbeMnppy/ORJf/xJlRiVAtPJaYNNGz0dpSwY6VC1M2aL6MhWD88Mjva0" +
                "F9MXnutVzNhdtd1ImySfZdtfYlZn/NWUbcWkouNcf7l74LziLNfQEvwi9feoMzl2" +
                "dtzhFQ/M9YwsNYAMv71IMI0x7mRUDoNGNOTLXWg6sNvBdIQDjcfna9QPKL5H+Ago" +
                "gtKQYUSxysxL7XC0xhg/vJ2KbccSGkN3bMHLm/YNSUUvRV6vk9u76GYY3HlfhEJT" +
                "xno98j4E6g/k4q3cWc+wEOWNF4uaipEhPp6+/7FpGg==";
            this.InitializeComponent();
            this.Suspending += OnSuspending;
        }

        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {

//#if DEBUG
//            if (System.Diagnostics.Debugger.IsAttached)
//            {
//                this.DebugSettings.EnableFrameRateCounter = true;
//            }
//#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }

        /// <summary>
        /// Invoked when Navigation to a certain page fails
        /// </summary>
        /// <param name="sender">The Frame which failed navigation</param>
        /// <param name="e">Details about the navigation failure</param>
        void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
        }

        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Save application state and stop any background activity
            deferral.Complete();
        }
    }
}
