public MainWindow() { InitializeComponent(); service = new LibraryAdminService(ConfigurationSettings.AppSettings.Get("server")); var client = new websocket.WebSocketClient(ConfigurationSettings.AppSettings.Get("server")); this.DataContext = this; Gadgets = new ObservableCollection<Gadget>(service.GetAllGadgets()); Loans = new ObservableCollection<Loan>(service.GetAllLoans()); List<domain.Customer> customers = service.GetAllCustomers(); List<domain.Reservation> reservations = service.GetAllReservations(); //gadgetGrid.ItemsSource = gadgets; //loanGrid.ItemsSource = loans; reservationGrid.ItemsSource = reservations; customerGrid.ItemsSource = customers; client.NotificationReceived += (o, e) => { Console.WriteLine("WebSocket::Notification: " + e.Notification.Target + " > " + e.Notification.Type); // demonstrate how these updates could be further used if (e.Notification.Target == typeof(Loan).Name.ToLower()) { // deserialize the json representation of the data object to an object of type Gadget var loan = e.Notification.DataAs<Loan>(); // now you can use it as usual... //Console.WriteLine("Details: " + gadget); Loans.Add(loan); } }; // spawn a new background thread in which the websocket client listens to notifications from the server var bgTask = client.ListenAsync(); }
public MainWindow() { InitializeComponent(); DataContext = this; ServerUrl = "http://localhost:8080"; Service = new LibraryAdminService(ServerUrl); ClientListener = new WebSocketClient(ServerUrl); ClientListener.NotificationReceived += ClientListenerNotified; ClientListener.ListenAsync(); Gadgets = new ObservableCollection<Gadget>(Service.GetAllGadgets()); Loans = new ObservableCollection<Loan>(Service.GetAllLoans()); InputComboCondition.ItemsSource = Enum.GetValues(typeof(domain.Condition)).Cast<domain.Condition>(); }