Пример #1
0
        private async void DoLogin(PasswordBox pb)
        {
            LoaderManager.Instance.ShowLoader();
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(StationManager.EndpointName);
                var result = await Task.Run(() =>
                {
                    if (!serv.UserExists(Username, pb.Password))
                    {
                        return(null);
                    }
                    User user    = serv.GetUser(Username, pb.Password);
                    user.Groups  = serv.GetUserGroups(user).ToList();
                    user.Records = serv.GetUserRecords(user).ToList();
                    return(user);
                });


                if (result == null)
                {
                    MessageBox.Show("Oooops. Couldn't find you.");
                    LoaderManager.Instance.HideLoader();
                    return;
                }
                else
                {
                    StationManager.CurrentUser = result;
                    var record = await Task.Run(() => serv.GetUserRecords(result).Where(r => r.EndTime == null).FirstOrDefault());

                    if (record != null)
                    {
                        record.User = result;
                        StationManager.CurRecord = record;
                    }
                    else
                    {
                        Record rec = new Record();
                        rec.User = result;
                        rec.Id   = Guid.NewGuid();
                        StationManager.CurRecord = rec;
                    }
                    LoaderManager.Instance.HideLoader();
                    pb.Clear();
                    NavigationManager.Instance.Navigate(ViewType.MainView);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
                LoaderManager.Instance.HideLoader();
            }
            finally
            {
                serv?.Close();
            }
        }
Пример #2
0
        public static Record GetUnfinishedRecord(User user)
        {
            TimerServerClient serv = null;

            try
            {
                serv = new TimerServerClient(EndpointName);
                var record = serv.GetUserRecords(user).Where(r => r.EndTime == null).FirstOrDefault();
                return(record);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ooops, problems with server \n" + e.Message);
            }
            finally
            {
                serv?.Close();
            }

            return(null);
        }
Пример #3
0
        public MainViewModel()
        {
            _seconds = (StationManager.CurRecord?.StartTime != DateTime.MinValue)
                                ? (long)(DateTime.Now - StationManager.CurRecord.StartTime).TotalSeconds : 0;

            _cb  = new TimerCallback(ChangeText);
            Time = TimeSpan.FromSeconds(_seconds).ToString(@"hh\:mm\:ss");
            ViewSource.Source = StationManager.CurrentUser.Records;

            if (StationManager.CurRecord.StartTime != DateTime.MinValue)
            {
                _timer = new Timer(_cb, null, 0, 1000);
            }

            StationManager.RefreshRecords += () =>
            {
                using (var serv = new TimerServerClient())
                {
                    StationManager.CurrentUser.Records = serv.GetUserRecords(StationManager.CurrentUser).ToList();
                    ViewSource.Source = StationManager.CurrentUser.Records;
                    ViewSource.View.Refresh();
                }
            };

            StationManager.DeleteInfo += () =>
            {
                Records           = new List <Record>();
                ViewSource.Source = Records;
                ViewSource.View?.Refresh();
                StationManager.CurrentUser = null;
                StationManager.CurRecord   = null;
                StationManager.CurGroup    = null;
                StationManager.Groups      = null;
                StationManager.Records     = null;
                StationManager.IsWindow    = false;
            };
        }