public bool ContainsProvider(VATRPServiceProvider provider) { if (this.providersList == null) { return(false); } var query = from record in this.providersList where record.Label == provider.Label select record; if (query.Any()) { return(true); } IEnumerable <VATRPServiceProvider> allItems = (from c in this.providersList where c.Label == provider.Label select c).ToList(); foreach (var c in allItems) { providersList.Remove(c); } this.DeferredSave(); return(false); }
///<summary> /// Callback that triggers whenever a new provider is selected from the /// dropdown menu. /// Set the address field to the value associated with this provider. ///</summary> ///<param name="sender"></param> ///<param name="args">The ComboBox object that was changed.</param> ///<returns>void</returns> public void OnProviderChanged(object sender, SelectionChangedEventArgs args) { // VATRP1271 - TODO - add a check to ensure that this has not changed prior to doign anything further. VATRPServiceProvider provider = (VATRPServiceProvider)ProviderComboBox.SelectedItem; if (provider != null) { // update the ing logging for the new provider UpdateNetLogger(provider.Address); // Reset the content being disaplyed in the form AuthIDBox.Text = string.Empty; PasswdBox.Password = string.Empty; HostnameBox.Text = provider.Address; Address = provider.Address; UserNameBox.Text = string.Empty; App.CurrentAccount.OutboundProxy = string.Empty; OutboundProxyServerBox.Text = string.Empty; if (string.Equals(provider.Label, "Custom")) { HostnameBox.IsReadOnly = false; HostnameBox.Background = Brushes.White; // Trigger the initial textbox lost focus event to set the placeholder text. OnAddressTextboxLostFocus(sender, null); } else { HostnameBox.IsReadOnly = true; HostnameBox.Background = Brushes.LightGray; HostnameBox.Foreground = Brushes.Black; } } }
///<summary> /// Populate the Provider and Address UI fields with the relevant information /// from the given providerName argument. If this provider does not exist, or /// providerName is null, populate the fields with the first element in the ProviderList. ///</summary> ///<param name="providerName">he name of the provider whose information we want to load into the UI</param> ///<returns>void</returns> public void PopulateProviderFields(String providerName) { // VATRP1271 - TODO - add a check to ensure that this has not changed prior to doing anything further. VATRPServiceProvider serviceProvider = ServiceManager.Instance.ProviderService.FindProviderLooseSearch(providerName); if (serviceProvider == null && ProviderList.Count() > 0) { serviceProvider = ProviderList[0]; } ProviderComboBox.SelectedItem = serviceProvider; }
private void OnProvidersListLoaded(object sender, EventArgs args) { //************************************************************************************************** // When provider list loading is completed. //************************************************************************************************* Providers.Clear(); var providersList = ServiceManager.Instance.ProviderService.GetProviderListFullInfo(); providersList.Sort((a, b) => a.Label.CompareTo(b.Label)); var selectedprovider = ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL, Configuration.ConfEntry.CURRENT_PROVIDER, ""); var provider = ServiceManager.Instance.ProviderService.FindProviderLooseSearch(selectedprovider); VATRPServiceProvider emptyProvider = new VATRPServiceProvider(); emptyProvider.Label = "None"; Providers.Add(new ProviderViewModel(emptyProvider)); foreach (var s in providersList) { if (s.Address == "_nologo" || s.Label == "_nologo") { continue; //If provider logo is not available then continue with next provider. } if (s.Address == null) { continue; //If the provider doesn't have an address, then we can't use it for dial-around } var providerModel = new ProviderViewModel(s); Providers.Add(providerModel); if (provider == null && s.Address == App.CurrentAccount.ProxyHostname) { selectedprovider = s.Label; provider = s; } if (s.Label == selectedprovider) { SelectedProvider = providerModel; } } if (_selectedProvider == null) { if (Providers != null && Providers.Count > 0) { _selectedProvider = Providers[0]; } } SelectedProviderIndex = 0; }
/** * \brief Add a provider to the provider list if it does not already exist. * * @return True always. */ public bool AddProvider(VATRPServiceProvider provider) { var query = from record in this.providersList where record.Label == provider.Label select record; if (query.Any()) { return(true); } this.providersList.Insert(0, provider); this.DeferredSave(); return(true); }
/** * \brief Load provider information from the provider config file. * * If the provider config file does not exist then create a new config file * and populate it with the default providers. * * @return void. */ #region IProviderService private void LoadProviders() { this.loading = true; try { if (!File.Exists(this.fileFullPath)) { File.Create(this.fileFullPath).Close(); // create xml declaration this.providersList = new List <VATRPServiceProvider>(); this.ImmediateSave(); } using (var reader = new StreamReader(this.fileFullPath)) { try { this.providersList = this.xmlSerializer.Deserialize(reader) as List <VATRPServiceProvider>; } catch (InvalidOperationException ie) { LOG.Error("Failed to load history", ie); reader.Close(); File.Delete(this.fileFullPath); } } } catch (Exception e) { LOG.Error("Failed to load history", e); _isStarted = false; loading = false; } VATRPServiceProvider CustomProvider = new VATRPServiceProvider(); CustomProvider.Label = "Custom"; CustomProvider.Address = null; AddProvider(CustomProvider); this.loading = false; _isStarted = true; }
///<summary> /// Callback that triggers whenever the Address textbox is entered /// (focused). Remove the watermark text and set the text color to black. /// Right now this is only registered as a callback when the Address field is /// changed. It allows us to remove the placeholder text when the Address textbox /// is focused ///</summary> ///<param name="sender"></param> ///<param name="e"></param> ///<returns>void</returns> private void OnAddressTextboxFocus(object sender, RoutedEventArgs e) { VATRPServiceProvider provider = (VATRPServiceProvider)ProviderComboBox.SelectedItem;//ServiceManager.Instance.ProviderService.FindProvider(providerName); if (provider == null) { return; } if (!string.Equals(provider.Label, "Custom")) { return; } // If the placeholder is there then remove it and set the text color to black. if (string.Equals(HostnameBox.Text, _placeholderText)) { HostnameBox.Text = ""; HostnameBox.Foreground = Brushes.Black; } Address = HostnameBox.Text; }
public bool DeleteProvider(VATRPServiceProvider provider) { if (string.IsNullOrEmpty(provider.Label)) { return(false); } var query = from record in this.providersList where record.Label == provider.Label select record; if (!query.Any()) { return(false); } this.providersList.Remove(provider); this.DeferredSave(); return(true); }
private bool LoadJsonProviders() { var imgCachePath = BuildStoragePath("img"); try { List<VATRPDomain> domains = Utilities.JsonWebRequest.MakeJsonWebRequest<List<VATRPDomain>>(CDN_DOMAIN_URL); // add these into the cache foreach (VATRPDomain domain in domains) { VATRPServiceProvider provider = ProviderService.FindProviderLooseSearch(domain.name); if (provider == null) { provider = new VATRPServiceProvider(); provider.Label = domain.name; provider.Address = domain.domain; provider.ImageURI = domain.icon2x; provider.IconURI = domain.icon; ProviderService.AddProvider(provider); } else { // update the provider information provider.Label = domain.name; provider.Address = domain.domain; provider.ImageURI = domain.icon2x; provider.IconURI = domain.icon; } if (provider.ImageURI.NotBlank()) provider.LoadImage(imgCachePath, false); if (provider.IconURI.NotBlank()) provider.LoadImage(imgCachePath, true); } VATRPServiceProvider noLogoProvider = ProviderService.FindProviderLooseSearch("_nologo"); if (noLogoProvider == null) { noLogoProvider = new VATRPServiceProvider(); ProviderService.AddProvider(noLogoProvider); } return true; } catch (Exception ex) { // either the domains were mal-formed or we are not able to get to the internet. If this is the case, then allow the cached/defaults. return false; } }
public ProviderViewModel(VATRPServiceProvider provider) { this._provider = provider; _isSelected = false; }
public bool AddProvider(VATRPServiceProvider provider) { var query = from record in this.providersList where record.Label == provider.Label select record; if (query.Any()) { return true; } this.providersList.Insert(0, provider); this.DeferredSave(); return true; }
public bool DeleteProvider(VATRPServiceProvider provider) { if (string.IsNullOrEmpty(provider.Label)) return false; var query = from record in this.providersList where record.Label == provider.Label select record; if (!query.Any()) { return false; } this.providersList.Remove(provider); this.DeferredSave(); return true; }
public bool ContainsProvider(VATRPServiceProvider provider) { if (this.providersList == null) return false; var query = from record in this.providersList where record.Label == provider.Label select record; if (query.Any()) { return true; } IEnumerable<VATRPServiceProvider> allItems = (from c in this.providersList where c.Label == provider.Label select c).ToList(); foreach (var c in allItems) { providersList.Remove(c); } this.DeferredSave(); return false; }
/// <summary> /// Fetch the list of Providers from the CDN server. /// </summary> /// <remarks> /// If any provider configurations are returned from the server then /// override the local list of providers with the server's list. /// This methods attemps to download the logo, URL, and other information /// about the provider from the server. /// </remarks> /// <param>void</param> /// <returns>Task<bool></returns> private async Task <bool> LoadJsonProvidersAsync() { var imgCachePath = BuildStoragePath("img"); try { List <VATRPDomain> domains = await Utilities.JsonWebRequest.MakeJsonWebRequestAsync <List <VATRPDomain> >(CDN_DOMAIN_URL); // Added 3/3/2017 fjr Override Local Providers with the server's List if (m_OverRideLocalProvidersList) { if (domains != null && domains.Count > 0) { ProviderService.ClearProvidersList(); VATRPServiceProvider CustomProvider = new VATRPServiceProvider(); CustomProvider.Address = null; CustomProvider.Label = "Custom"; ProviderService.AddProvider(CustomProvider); } } // add these into the cache foreach (VATRPDomain domain in domains) { VATRPServiceProvider provider = ProviderService.FindProviderLooseSearch(domain.name); if (provider == null) { provider = new VATRPServiceProvider(); provider.Label = domain.name; provider.Address = domain.domain; provider.ImageURI = domain.icon2x; provider.IconURI = domain.icon; ProviderService.AddProvider(provider); } else { // update the provider information provider.Label = domain.name; provider.Address = domain.domain; provider.ImageURI = domain.icon2x; provider.IconURI = domain.icon; } if (provider.ImageURI.NotBlank()) { provider.LoadImage(imgCachePath, false); } if (provider.IconURI.NotBlank()) { provider.LoadImage(imgCachePath, true); } } VATRPServiceProvider noLogoProvider = ProviderService.FindProviderLooseSearch("_nologo"); if (noLogoProvider == null) { noLogoProvider = new VATRPServiceProvider(); ProviderService.AddProvider(noLogoProvider); } return(true); } catch (Exception ex) { // either the domains were mal-formed or we are not able to get to the internet. If this is the case, then allow the cached/defaults. return(false); } }
///<summary> /// Method called when Provider Configuration button is clicked. /// Allows the user to select a JSON configuration file which is /// then stored into the Account's Configuration data member and /// ussed to login the user ///</summary> ///<param name="sender"></param> ///<param name="e"></param> ///<returns>void</returns> public void ProviderConfig_Click(object sender, RoutedEventArgs e) { ACEConfig config; try { var openDlg = new OpenFileDialog() { CheckFileExists = true, CheckPathExists = true, Filter = "Json files (*.json)|*.json", FilterIndex = 0, ShowReadOnly = false, }; if (openDlg.ShowDialog() != true) { return; } string jsonContents = ""; using (StreamReader sr = new StreamReader(openDlg.FileName)) { jsonContents = sr.ReadToEnd(); sr.Close(); } config = JsonConvert.DeserializeObject <ACEConfig>(jsonContents); config.NormalizeValues(); } catch (Exception ex) { string msg = "Invalid configuration file provided. Failed to parse json file."; string caption = "Load failed"; MessageBoxButton button = MessageBoxButton.OK; MessageBox.Show(msg, caption, button, MessageBoxImage.Error); return; } // Update UI // NOTE - this muse be called in its current location, otherwise, // it is possible that the text edit fields on the login page UI // will be reset to null after they are set below because the // on-provider-change callback will execute beforehand. VATRPServiceProvider serviceProvider = ServiceManager.Instance.ProviderService.FindProviderLooseSearch("Custom"); ProviderComboBox.SelectedItem = serviceProvider; config.SetDownloadDate(); // Check to see if this account is cached elsewhere var account = LoadCachedAccountFromFile(App.CurrentAccount.Username); if (account != null) { App.CurrentAccount = account; } // Store configuration in current account config.UpdateVATRPAccountFromACEConfig_login(App.CurrentAccount); UserNameBox.Text = App.CurrentAccount.PhoneNumber; PasswdBox.Password = App.CurrentAccount.Password; Address = App.CurrentAccount.ProxyHostname; AuthIDBox.Text = App.CurrentAccount.AuthID; OutboundProxyServerBox.Text = App.CurrentAccount.OutboundProxy; string hostName = App.CurrentAccount.ProxyHostname; if (!string.IsNullOrWhiteSpace(hostName)) { HostnameBox.Text = hostName; HostnameBox.Foreground = Brushes.Black; } // Update UI string transport = App.CurrentAccount.Transport; if (!transport.Equals(TransportComboBox.Text)) { foreach (var item in TransportComboBox.Items) { var tb = item as TextBlock; string itemString = tb.Text; if (itemString.Equals(transport, StringComparison.InvariantCultureIgnoreCase)) { TransportComboBox.SelectedItem = item; TextBlock selectedItem = TransportComboBox.SelectedItem as TextBlock; if (selectedItem != null) { string test = selectedItem.Text; } break; } } } if (config.sip_register_port != null && config.sip_register_port != 0) { HostPortBox.Text = config.sip_register_port.ToString(); HostPort = (UInt16)config.sip_register_port; App.CurrentAccount.HostPort = HostPort; } }