示例#1
0
        public static HAPSetting Parse(string[] s)
        {
            HAPSetting set = new HAPSetting()
            {
                Name = s[0]
            };

            if (s[0] != "site0")
            {
                set.Address = new Uri(s[1]);
                PasswordVault vault = new PasswordVault();
                if (vault.FindAllByResource("HAP+ Credentials").Count(c => c.UserName.EndsWith(set.Address.DnsSafeHost)) == 0)
                {
                    set.PasswordInVault = false;
                }
                else
                {
                    PasswordCredential cred = vault.FindAllByResource("HAP+ Credentials").Single(c => c.UserName.EndsWith(set.Address.DnsSafeHost));
                    set.Username = cred.UserName.Substring(0, cred.UserName.IndexOf('@'));
                    cred.RetrievePassword();
                    set.Password = cred.Password;
                }
            }
            return(set);
        }
示例#2
0
        private void sites_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox box = (ComboBox)sender;
            var      no  = box.SelectedIndex;

            try
            {
                if (no == 0)
                {
                    address.Text          = "https://";
                    username.Text         = "";
                    password.Password     = "";
                    removesite.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    address.Focus(Windows.UI.Xaml.FocusState.Keyboard);
                    address.Select(address.Text.Length, 0);
                }
                else if (no > 0)
                {
                    HAPSetting h = (HAPSetting)((ComboBoxItem)box.SelectedItem).DataContext;
                    address.Text          = h.Address.ToString();
                    username.Text         = h.Username;
                    password.Password     = h.Password;
                    removesite.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    login.Focus(Windows.UI.Xaml.FocusState.Programmatic);
                }
            }
            catch { }
        }
示例#3
0
        public void AddSite(HAPSetting value)
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            Windows.Storage.ApplicationDataContainer container       = roamingSettings.CreateContainer("hapSites", Windows.Storage.ApplicationDataCreateDisposition.Always);
            roamingSettings.Containers["hapSites"].Values[value.Name] = value.ToString();
            List <string> s = new List <string>();

            s.AddRange((string[])roamingSettings.Values["sites"]);
            if (!s.Contains(value.Name))
            {
                s.Add(value.Name);
            }
            roamingSettings.Values["sites"] = s.ToArray();
        }
示例#4
0
 public void UpdateSite(string key, HAPSetting value)
 {
     RemoveSite(key);
     AddSite(value);
 }