Пример #1
0
        /// <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()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
            HAPSettings set = new HAPSettings();

            set.InitHandlers();
        }
Пример #2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            HAPSettings hs = new HAPSettings();

            if (!hs.SiteContainer.Values.ContainsKey("site0"))
            {
                foreach (HAPSetting h in hs.Settings.Values)
                {
                    sites.Items.Add(new ComboBoxItem()
                    {
                        Content = h.Name, DataContext = h
                    });
                }
                sites.SelectedIndex = 1;
            }
            else
            {
                address.Focus(Windows.UI.Xaml.FocusState.Keyboard);
                address.Select(address.Text.Length, 0);
            }
        }
Пример #3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            loading.IsIndeterminate = true;
            login.IsEnabled         = false;
            string s = address.Text;

            if (!s.EndsWith("/"))
            {
                s += "/";
            }
            Uri url = null;

            try
            {
                url = new Uri(new Uri(s), "./api/ad/?" + DateTime.Now.Ticks);
            }
            catch
            {
                MessageDialog mes = new MessageDialog("That Address doesn't seem to be valid");
                mes.Commands.Add(new UICommand("OK"));
                mes.DefaultCommandIndex = 0;
                mes.ShowAsync();
                loading.IsIndeterminate = false;
                login.IsEnabled         = true;
            }
            if (url != null)
            {
                HttpClient c = new HttpClient(HAPSettings.certfilter);
                c.DefaultRequestHeaders.Accept.Add(new Windows.Web.Http.Headers.HttpMediaTypeWithQualityHeaderValue("application/json"));
                HttpStringContent sc  = new HttpStringContent("{ \"username\": \"" + username.Text + "\", \"password\": \"" + password.Password + "\" }", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json");
                string            sc1 = null;
                try
                {
                    var cr = await c.PostAsync(url, sc);

                    sc1 = await cr.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    loading.IsIndeterminate = false;
                    login.IsEnabled         = true;
                    MessageDialog mes = new MessageDialog("An Active Internet Connection is Required\n\n" + ex.ToString());
                    mes.Commands.Add(new UICommand("OK"));
                    mes.DefaultCommandIndex = 0;
                    mes.ShowAsync();
                }
                if (sc1 != null)
                {
                    try
                    {
                        JSON.JSONUser user = JsonConvert.DeserializeObject <JSON.JSONUser>(sc1);
                        if (user.isValid)
                        {
                            HAPSettings hs = new HAPSettings();
                            hs.AddSite(new HAPSetting()
                            {
                                Name = user.SiteName, Address = new Uri(s), Password = password.Password, Username = username.Text
                            });
                            if (hs.SiteContainer.Values.ContainsKey("site0"))
                            {
                                hs.RemoveSite("site0");
                            }

                            HAPSettings.CurrentSite  = hs.Settings[user.SiteName];
                            HAPSettings.CurrentToken = user.ToString();

                            MessageDialog mes = new MessageDialog("Hello " + user.FirstName + ", you are now connected via HAP+ to " + user.SiteName + "");
                            mes.Commands.Add(new UICommand("OK"));
                            mes.DefaultCommandIndex = 0;
                            await mes.ShowAsync();

                            Frame.Navigate(typeof(Browser), "");
                        }
                        else
                        {
                            MessageDialog mes = new MessageDialog("Your Username/Password conbination doesn't match a user at this school!", "Error");
                            mes.Commands.Add(new UICommand("OK"));
                            mes.DefaultCommandIndex = 0;
                            await mes.ShowAsync();

                            loading.IsIndeterminate = false;
                            login.IsEnabled         = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageDialog mes = new MessageDialog((ex.ToString().Contains("404") ? "Your School's Home Access Plus+ Install isn't up-to-date\n\nPlease ask them to upgrade to HAP+ v9 or above" : "Communication Error\n\n" + ex.ToString()));
                        mes.Commands.Add(new UICommand("OK"));
                        mes.DefaultCommandIndex = 0;
                        mes.ShowAsync();
                    }
                }
            }
        }