private List <CommandViewModel> CreateControlPanelCommands() { List <CommandViewModel> m = new List <CommandViewModel> { new CommandViewModel( Strings.MainWindowViewModel_Command_ViewAllCustomers, new RelayCommand(param => ShowAllCustomers())), new CommandViewModel( Strings.MainWindowViewModel_Command_CreateNewCustomer, new RelayCommand(param => CreateNewCustomer())), new CommandViewModel( Strings.MainWindowViewModel_Command_ExitButton, new RelayCommand(param => OnMainWindowViewModelRequestClose())) }; try { Diag.UpdateLog("(12) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t"); foreach (CommandViewModel c in m) { Diag.UpdateLog("\t" + c.ViewModelBaseInstanceName); } } catch (Exception ex) { Diag.UpdateLog("(12) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } return(m); }
private static List <Customer> LoadCustomers(string customerDataFile) { // In a real application, the data would come from an external source, // but for this demo let's keep things simple and use a resource file. using (Stream stream = GetResourceStream(customerDataFile)) using (XmlReader xmlRdr = new XmlTextReader(stream)) { { try { Diag.UpdateLog("(3) CustomerRepository; " + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t"); } catch (Exception ex) { Diag.UpdateLog("(3) CustomerRepository; " + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } return ((from customerElem in XDocument.Load(xmlRdr).Element("customers").Elements("customer") select Customer.CreateCustomer( (double)customerElem.Attribute("totalSales"), (string)customerElem.Attribute("firstName"), (string)customerElem.Attribute("lastName"), (bool)customerElem.Attribute("isCompany"), (string)customerElem.Attribute("email") )).ToList()); } } }
/// <summary> /// Raises this object's PropertyChanged event. /// </summary> /// <param name="propertyName">The property that has a new value.</param> protected virtual void OnPropertyChanged(string propertyName) { VerifyPropertyName(propertyName); PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { Diag.UpdateLog("(19) ViewModelBase():\t" + propertyName + "\t" + handler.Method + "\t" + handler.Target); PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName); handler.Invoke(this, e); } }
private void OnMainWindowViewModelRequestClose() { try { Diag.UpdateLog("(13) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name); } catch (Exception ex) { Diag.UpdateLog("(13) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } if (MainWindowViewModelRequestClose != null) { MainWindowViewModelRequestClose.Invoke(this, EventArgs.Empty); } }
private void CreateAllCustomers() { List <CustomerViewModel> all = (from cust in _customerRepository.GetCustomers() select new CustomerViewModel(cust, _customerRepository)).ToList(); foreach (CustomerViewModel cvm in all) { cvm.PropertyChanged += OnCustomerViewModelPropertyChanged; Diag.UpdateLog("(521654)\tCreateAllCustomers()\t " + cvm.ToString()); } AllCustomers = new ObservableCollection <CustomerViewModel>(all); AllCustomers.CollectionChanged += OnCollectionChanged; }
/// <summary> /// Creates a new repository of customers. /// </summary> /// <param name="customerDataFile">The relative path to an XML resource file that contains customer data.</param> public CustomerRepository(string customerDataFile) { Diag.DataBindingPresentation(); _customers = LoadCustomers(customerDataFile); try { Diag.UpdateLog("(2) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + _customers.Count.ToString()); } catch (Exception ex) { Diag.UpdateLog("(2) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } }
public AllCustomersViewModel(CustomerRepository customerRepository) { Diag.DataBindingPresentation(); if (customerRepository == null) { throw new ArgumentNullException("customerRepository"); } base.ViewModelBaseInstanceName = Strings.AllCustomersViewModel_DisplayName; Diag.UpdateLog("(547865\tAllCustomersViewModel(C )\tbase.ViewModelBaseInstanceName \t" + base.ViewModelBaseInstanceName); _customerRepository = customerRepository; // Subscribe for notifications of when a new customer is saved. _customerRepository.CustomerAdded += OnCustomerAddedToRepository; // Populate the AllCustomers collection with CustomerViewModels. CreateAllCustomers(); }
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count != 0) { foreach (CustomerViewModel cvm in e.NewItems) { cvm.PropertyChanged += OnCustomerViewModelPropertyChanged; Diag.UpdateLog("(742342)\tOnCollectionChanged\te.NewItems\t" + cvm.ToString() + "\t" + e.NewItems.ToString()); } } if (e.OldItems != null && e.OldItems.Count != 0) { foreach (CustomerViewModel cvm in e.OldItems) { cvm.PropertyChanged -= OnCustomerViewModelPropertyChanged; Diag.UpdateLog("(742109)\tOnCollectionChanged\te.OldItems\t" + cvm.ToString() + "\t" + e.OldItems.ToString()); } } }
public CommandViewModel(string displayName, ICommand command) { Diag.DataBindingPresentation(); if (command == null) { throw new ArgumentNullException("command"); } base.ViewModelBaseInstanceName = displayName; Diag.UpdateLog("(789056\tCommandViewModel( )\tbase.ViewModelBaseInstanceName \t" + base.ViewModelBaseInstanceName); ControlPanelHyperlinkInvokeCommand = command; try { Diag.UpdateLog("(6)\t" + this.GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + displayName + ";\t" + command.ToString()); } catch (Exception ex) { Diag.UpdateLog("(6)\t" + this.GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } }
/// <summary> /// Raised when ToggleButtonClicked is clicked /// </summary> public void OnToggleButtonClicked() { try { Diag.UpdateLog("(590213) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t"); } catch (Exception ex) { Diag.UpdateLog("(590213) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } if (ToggleButtonPosition == System.Windows.HorizontalAlignment.Left) { ToggleButtonPosition = _rightAlignment; ToggleButtonMargins = _rightThickness; ToggleButtonColor = _rightColor; } else { ToggleButtonPosition = _leftAlignment; ToggleButtonMargins = _leftThickness; ToggleButtonColor = _leftColor; } }
public MainWindowViewModel(string customerDataFile) { Diag.DataBindingPresentation(); base.ViewModelBaseInstanceName = Strings.MainWindowViewModel_DisplayName; Diag.UpdateLog("(451289)\tMainWindowViewModel()\tbase.ViewModelBaseInstanceName\t" + base.ViewModelBaseInstanceName); _customerRepository = new CustomerRepository(customerDataFile); try { Diag.UpdateLog("(8)\t" + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + base.ViewModelBaseInstanceName + ";\t" + _customerRepository.ToString()); } catch (Exception ex) { Diag.UpdateLog("(8)\t" + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message); } }
protected ViewModelBase() { Diag.UpdateLog("(18)\tViewModelBase()\t" + this.GetType().FullName); }