Beispiel #1
0
        public LoanViewModel()
        {
            initalLoadLoans();

            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>();
                    switch (e.Notification.Type)
                    {
                    case WebSocketClientNotificationTypeEnum.Add:
                        Loans = new ObservableCollection <Loan>(service.GetAllLoans());
                        break;

                    case WebSocketClientNotificationTypeEnum.Delete:
                        Loans = new ObservableCollection <Loan>(service.GetAllLoans());
                        break;

                    case WebSocketClientNotificationTypeEnum.Update:
                        Loans = new ObservableCollection <Loan>(service.GetAllLoans());
                        break;
                    }
                }
            };

            var bgTask = client.ListenAsync();
        }
        public MainWindowViewModel()
        {
            libraryAdminService = new LibraryAdminService(ConfigurationManager.AppSettings.Get("server")?.ToString());

            var gadgets = libraryAdminService.GetAllGadgets();

            if (gadgets == null)
            {
                MessageBox.Show("Konnte Gadgets nicht vom Server laden.", "Serverfehler", MessageBoxButton.OK);
            }
            else if (gadgets.Count > 0)
            {
                Gadgets = new ObservableCollection <Gadget>(gadgets);

                SelectedGadget = Gadgets.First();
            }
            else
            {
                MessageBox.Show("Keine Gadgets vorhanden. Bitte fügen Sie zuerst ein Gadget hinzu.", "Keine Gadgets vorhanden", MessageBoxButton.OK);
            }


            var loans = libraryAdminService.GetAllLoans();

            if (loans == null)
            {
                MessageBox.Show("Konnte Ausleihen nicht vom Server laden.", "Serverfehler", MessageBoxButton.OK);
                return;
            }
            else if (loans.Count > 0)
            {
                Loans = new ObservableCollection <Loan>(loans);

                SelectedLoan = Loans.First();
            }

            Task.Run(() =>
            {
                while (true)
                {
                    Thread.Sleep(5000);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        loans = libraryAdminService.GetAllLoans();
                        if (loans != null)
                        {
                            Loans.Clear();

                            loans.ForEach(Loans.Add);
                        }
                    });
                }
            });
        }
Beispiel #3
0
 private void LoadLoans()
 {
     foreach (Loan loan in libraryAdminService.GetAllLoans())
     {
         Loans.Add(loan);
     }
 }
Beispiel #4
0
        private void collectData()
        {
            var customers    = service.GetAllCustomers();
            var reservations = service.GetAllReservations();
            var loans        = service.GetAllLoans();

            AllCustomer.Clear();
            foreach (Customer c in customers)
            {
                List <Loan> cLoans = getLoans(c, loans);
                AllCustomer.Add(new AllOfCustomer(c.Studentnumber, c.Name, getReservations(c, reservations), cLoans, getToBackInformations(cLoans)));
            }


            foreach (Reservation r in reservations)
            {
                AllReservations.Add(new ReserveByUser(r.Customer.Name, r.Gadget.Name, r.WaitingPosition, r.IsReady));
            }

            foreach (Loan l in loans)
            {
                DateTime?date = l.ReturnDate;
                if (l.ReturnDate == null)
                {
                    date = l.OverDueDate;
                }
                AllLoans.Add(new LoansByUser(l.Gadget.Name, l.Customer.Name, date, l.IsOverdue, getResByGadget(l, reservations)));
            }
        }
Beispiel #5
0
 private void initalLoadLoans()
 {
     // Load inital all Gadgets and save settings
     service = new LibraryAdminService(ConfigurationManager.AppSettings["serverGadgeothek"]);
     client  = new websocket.WebSocketClient(ConfigurationManager.AppSettings["serverGadgeothek"]);
     Loans   = new ObservableCollection <Loan>(service.GetAllLoans());
 }
Beispiel #6
0
        public MainWindowViewModel()
        {
            dataService = new LibraryAdminService(ConfigurationManager.AppSettings.Get("server")?.ToString());

            try
            {
                Gadgets = new ObservableCollection <GadgetViewModel>(dataService.GetAllGadgets()
                                                                     .Select(g => new GadgetViewModel(g)));
                SelectedGadget = Gadgets.FirstOrDefault();

                Customers = new ObservableCollection <CustomerViewModel>(dataService.GetAllCustomers()
                                                                         .Select(c =>
                {
                    var customerViewModel          = new CustomerViewModel(c);
                    customerViewModel.DataChanged += OnCustomerDataChanged;
                    return(customerViewModel);
                }));
                SelectedCustomer = Customers.FirstOrDefault();

                //dataService.DeleteLoan(dataService.GetLoan("d4b05cc5-5948-472a-bbfd-600b4d7578fa"));

                Loans = new ObservableCollection <LoanViewModel>(dataService.GetAllLoans()
                                                                 .Select(l => new LoanViewModel(l)));
                SelectedLoan = Loans.FirstOrDefault();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Beim Laden ist ein Problem aufgetreten.", ex.Message, MessageBoxButton.OK);
                return;
            }
        }
Beispiel #7
0
 private void AsyncGetLoans()
 {
     foreach (var loan in _service.GetAllLoans())
     {
         Application.Current.Dispatcher.Invoke(() => { AllLoans.Add(loan); });
     }
     IsLoading = false;
 }
Beispiel #8
0
        /// <summary>
        /// demonstrates the use of the admin functions to add/remove
        /// new loans and reservations to/from the gadgeothek
        /// (internally a bit more complicated since holding
        /// referenced values)
        /// </summary>
        public void ShowAdminInteractionForLoans()
        {
            var service = new LibraryAdminService(ServerUrl);

            var rnd      = new Random();
            var randomId = rnd.Next(100000, 999999).ToString();

            var android = service.GetGadget("26");   // Android2
            var michael = service.GetCustomer("10"); // Michael
            var loan    = new Loan(randomId, android, michael, DateTime.Today.AddDays(-1), null);

            if (!service.AddLoan(loan))
            {
                Console.WriteLine($"{loan} konnte nicht hinzugefügt werden werden...");
                return;
            }

            var loans = service.GetAllLoans();

            PrintAll(loans, "Loans (NEW)");

            loan.ReturnDate = DateTime.Now;
            if (!service.UpdateLoan(loan))
            {
                Console.WriteLine($"{loan} konnte nicht aktualisiert werden...");
                return;
            }


            loans = service.GetAllLoans();
            PrintAll(loans, "Loans (NEW 2)");;

            if (!service.DeleteLoan(loan))
            {
                Console.WriteLine($"{loan} konnte nicht gelöscht werden...");
                return;
            }

            loans = service.GetAllLoans();
            PrintAll(loans, "Loans (NEW 3)");
        }
        public Gadgets()
        {
            InitializeComponent();

            LibraryAdminService lib = new LibraryAdminService("http://mge7.dev.ifs.hsr.ch/");

            List <Loan> gadgets = lib.GetAllLoans();

            dgGadgets.ItemsSource = gadgets;

            Regex regex = new Regex("(?<WEAKDAY>Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?<MONTH>[0-9]{1,2})/(?<DAY>[0-9]{1,2})/(?<YEAR>[0-9]*)");
        }
Beispiel #10
0
        public Ausleihe()
        {
            InitializeComponent();
            var service = new LibraryAdminService("http://mge5.dev.ifs.hsr.ch/");


            var gadgets      = service.GetAllGadgets();
            var customers    = service.GetAllCustomers();
            var reservations = service.GetAllReservations();
            var loans        = service.GetAllLoans();



            List <AllOfCustomer> allCustomer = new List <AllOfCustomer>();

            foreach (Customer c in customers)
            {
                List <Loan> cLoans = getLoans(c, loans);
                allCustomer.Add(new AllOfCustomer(c.Studentnumber, c.Name, getReservations(c, reservations), cLoans, getToBackInformations(cLoans)));
            }
            GadgetsByUser.ItemsSource = allCustomer;
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(GadgetsByUser.ItemsSource);

            view.Filter = UserFilter1;


            List <ReserveByUser> allReservations = new List <ReserveByUser>();

            foreach (Reservation r in reservations)
            {
                allReservations.Add(new ReserveByUser(r.Customer.Name, r.Gadget.Name, r.WaitingPosition, r.IsReady));
            }
            ReservationsByUsers.ItemsSource = allReservations;
            CollectionView view2 = (CollectionView)CollectionViewSource.GetDefaultView(ReservationsByUsers.ItemsSource);

            view2.Filter = UserFilter2;


            List <LoansByUser> allLoans = new List <LoansByUser>();

            foreach (Loan l in loans)
            {
                if (l.Gadget != null)
                {
                    allLoans.Add(new LoansByUser(l.Gadget.Name, l.Customer.Name, l.ReturnDate, l.IsOverdue, getResByGadget(l, reservations)));
                }
            }
            LeansByGadget.ItemsSource = allLoans;
            CollectionView view3 = (CollectionView)CollectionViewSource.GetDefaultView(LeansByGadget.ItemsSource);

            view3.Filter = UserFilter3;
        }
Beispiel #11
0
 public MainViewModel(String server)
 {
     ServerAddress = server;
     Gadgets       = new ObservableCollection <Gadget>(Service.GetAllGadgets());
     Loans         = new ObservableCollection <Loan>(Service.GetAllLoans());
     Reservations  = new ObservableCollection <Reservation>(Service.GetAllReservations());
     Task.Run(() =>
     {
         while (true)
         {
             Console.WriteLine("Update Loans");
             Thread.Sleep(3000);
             List <Loan> list = Service.GetAllLoans();
             Application.Current.Dispatcher.BeginInvoke(
                 DispatcherPriority.Background,
                 new Action(() => {
                 Loans.Clear();
                 list.ForEach(Loans.Add);
             }));
         }
     });
     Task.Run(() =>
     {
         while (true)
         {
             Console.WriteLine("Update Reservations");
             Thread.Sleep(3000);
             List <Reservation> list = Service.GetAllReservations();
             Application.Current.Dispatcher.BeginInvoke(
                 DispatcherPriority.Background,
                 new Action(() => {
                 Reservations.Clear();
                 list.ForEach(Reservations.Add);
             }));
         }
     });
 }
        private void FillData()
        {
            LoansItem.Clear();
            var         url     = ConfigurationManager.AppSettings["server"];
            var         service = new LibraryAdminService(url);
            List <Loan> loans   = service.GetAllLoans();

            foreach (Loan l in loans)
            {
                if (l.IsLent)
                {
                    LoansItem.Add(l);
                }
            }
        }
Beispiel #13
0
        public void RefreshDataGrid()
        {
            AllGadgets = service.GetAllGadgets();
            GadgetList.Clear();
            if (AllGadgets != null)
            {
                AllGadgets.ForEach(GadgetList.Add);

                AllLoans = service.GetAllLoans();
                LoanList.Clear();
                AllLoans.ForEach(LoanList.Add);
            }
            else
            {
                MessageBox.Show("Keine Verbindung zum Server gefunden!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
            }
        }
        public GadgetViewModel()
        {
            var url = System.Configuration.ConfigurationManager.AppSettings["serverGadgeothek"];

            Service = new LibraryAdminService(url);

            Gadgets = Service.GetAllGadgets();
            Loans   = Service.GetAllLoans();

            EditGadgetCommand   = new RelayCommand.RelayCommand <Object>((o) => EditGadget());
            DeleteGadgetCommand = new RelayCommand.RelayCommand <Object>((o) => DeleteGadget());

            aTimer          = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimerEvent);
            aTimer.Interval = 5000;
            aTimer.Enabled  = true;
            aTimer.Start();
        }
Beispiel #15
0
        /// <summary>
        /// demonstrates how to get the full inventory from the gadgeothek
        /// </summary>
        public void ShowInventory()
        {
            var service = new LibraryAdminService(ServerUrl);

            // no need to login as admin, woohoo :-)

            var gadgets = service.GetAllGadgets();

            PrintAll(gadgets);

            var customers = service.GetAllCustomers();

            PrintAll(customers);

            var reservations = service.GetAllReservations();

            PrintAll(reservations);

            var loans = service.GetAllLoans();

            PrintAll(loans);
        }
Beispiel #16
0
        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 List <Loan> GetAllLoans() => Service.GetAllLoans();
Beispiel #18
0
 public void LoadData()
 {
     Loans.Clear();
     _service.GetAllLoans().ForEach(l => Loans.Add(l));
 }