예제 #1
0
        private async void FetchFromServer()
        {
            _waitDialogService.ShowWaitDialog();

            string message  = "";
            var    settings = new UserSettings();

            try
            {
                var sessions = await _cashGameService.FetchSessionsFromServer(_userSessionId, StartDate, EndDate);

                var newSessions = _sessionRepository.Add(sessions);

                message += "Palvelimelta haettu " + sessions.Count + " sessiota, joista uusia " + newSessions;

                if (settings.SaveAutomaticallyAfterFetch && newSessions > 0)
                {
                    _sessionRepository.SaveAsXml(settings.SessionXMLFilename);
                    message += "\nTiedosto " + settings.SessionXMLFilename + " päivitetty.";
                }
            }
            catch (Exception ex)
            {
                message += ex.Message;
            }

            _waitDialogService.CloseWaitDialog();

            _infoDialogService.ShowDialog(new InfoDialogViewModel(message));

            PlayingSessions = PlayingSession.GroupToPlayingSessions(_sessionRepository.GetAll());
        }
예제 #2
0
        private void OpenFile()
        {
            var fileName = _openFileDialogService.ShowOpenFileDialog();
            var message  = "";

            if (!string.IsNullOrEmpty(fileName))
            {
                bool            xmlImportSuccess = false;
                IList <Session> sessions         = new List <Session>();
                int             sessionsAdded    = 0;

                try
                {
                    sessions         = _sessionRepository.ReadXml(fileName);
                    sessionsAdded    = _sessionRepository.Add(sessions);
                    xmlImportSuccess = true;
                }
                catch (InvalidOperationException)
                {
                }

                // ei ollut xml-tiedosto, yritetään lukea tekstitiedostona
                if (!xmlImportSuccess)
                {
                    sessions      = _cashGameService.GetSessionsFromFile(fileName);
                    sessionsAdded = _sessionRepository.Add(sessions);
                }

                message += "Tiedostosta löytyi " + sessions.Count() + " sessiota, joista uusia " + sessionsAdded;
                _infoDialogService.ShowDialog(new InfoDialogViewModel(message));

                PlayingSessions = PlayingSession.GroupToPlayingSessions(_sessionRepository.GetAll());
                UpdateFilterDates();
            }
        }
예제 #3
0
        private void LoadStoredSessions()
        {
            var settings = new UserSettings();

            try
            {
                var sessions = _sessionRepository.ReadXml(settings.SessionXMLFilename);
                _sessionRepository.Add(sessions);
            }
            catch (InvalidOperationException)
            {
            }

            PlayingSessions = PlayingSession.GroupToPlayingSessions(_sessionRepository.GetAll());
        }
예제 #4
0
        private void ShowSessionsOnly(bool isChecked = true)
        {
            if (isChecked)
            {
                List <Session> sessions = new List <Session>();

                foreach (var playingSession in PlayingSessions)
                {
                    sessions.AddRange(playingSession.Sessions);
                }

                SelectedPlayingSession = new PlayingSession {
                    Sessions = sessions
                };
            }
        }
예제 #5
0
        public void TestCalculateHourly2()
        {
            PlayingSession[] sessions = new PlayingSession[]
            {
                new PlayingSession {
                    Duration = new TimeSpan(1, 0, 0), Result = -10M
                },
                new PlayingSession {
                    Duration = new TimeSpan(2, 0, 0), Result = -30M
                },
                new PlayingSession {
                    Duration = new TimeSpan(1, 0, 0), Result = 0M
                },
                new PlayingSession {
                    Duration = new TimeSpan(6, 0, 0), Result = 30M
                }
            };

            decimal result = Reporter.CalculateResultPerHour(sessions);

            Assert.AreEqual(-1M, result);
        }
예제 #6
0
        public void TestCalculateHourly1()
        {
            PlayingSession[] sessions = new PlayingSession[]
            {
                new PlayingSession {
                    Duration = new TimeSpan(1, 0, 0), Result = 10M
                },
                new PlayingSession {
                    Duration = new TimeSpan(2, 0, 0), Result = 30M
                },
                new PlayingSession {
                    Duration = new TimeSpan(1, 0, 0), Result = 0M
                },
                new PlayingSession {
                    Duration = new TimeSpan(3, 0, 0), Result = 30M
                }
            };

            var result = Reporter.CalculateResultPerHour(sessions);

            Assert.AreEqual(10M, result);
        }
예제 #7
0
        public IList <PlayingSession> GetFilteredPlayingSessions(CashGameFilter filter)
        {
            var sessions = _sessions;

            if (filter.GameTypes != null)
            {
                sessions = _sessions.Where(s => filter.GameTypes.Contains(s.GameType)).ToList();
            }

            var playingSessions = PlayingSession.GroupToPlayingSessions(sessions);

            if (filter.StartDate != null)
            {
                playingSessions = playingSessions.Where(s => s.StartTime.Date >= filter.StartDate.Value.Date).ToList();
            }

            if (filter.EndDate != null)
            {
                playingSessions = playingSessions.Where(s => s.StartTime.Date <= filter.EndDate.Value.Date).ToList();
            }

            return(playingSessions);
        }
예제 #8
0
        private void ClearSessions()
        {
            bool confirmed = false;

            Messenger.Default.Register <NotificationMessage>(this, message =>
            {
                if (message.Notification == "InfoDialogConfirmed")
                {
                    confirmed = true;
                }
            });

            _infoDialogService.ShowDialog(new InfoDialogViewModel("Haluatko varmasti tyhjentää kaikki käteispelitiedot?", showCancelButton: true));

            Messenger.Default.Unregister <NotificationMessage>(this);

            if (confirmed)
            {
                _sessionRepository.RemoveAll();
                PlayingSessions        = PlayingSession.GroupToPlayingSessions(_sessionRepository.GetAll());
                SelectedPlayingSession = null;
                _infoDialogService.ShowDialog(new InfoDialogViewModel("Käteissessiot tyhjennetty"));
            }
        }
예제 #9
0
 private void LoadPlayingSessions()
 {
     PlayingSessions = PlayingSession.GroupToPlayingSessions(_cashGameService.GetSessionsFromFile(_fileName));
 }