Esempio n. 1
0
        private void StartTimer_Click(object sender, RoutedEventArgs e)
        {
            var selected = ActivityPicker.SelectedItem as Activity;

            if (selected is null)
            {
                return;
            }

            bindedActivity = selected;
            DataTransactionsService.HandleDataTransaction(new DataTransaction()
            {
                Action = DataTransaction.ActionType.Create,
                Data   = new TimeEntry()
                {
                    Activity  = bindedActivity,
                    StartTime = DateTime.Now
                }
            });

            startTime      = DateTime.Now;
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += TimerTick;
            timer.Start();
            UpdateList();
        }
Esempio n. 2
0
        private async void ResetData_Click(object sender, RoutedEventArgs e)
        {
            var dialogSettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No"
            };

            var result = await Utilities.Utilities.GetWindow()?.ShowMessageAsync("Confirm Data Reset",
                                                                                 "Are you sure you want to reset data? This will delete all data across all synchronized devices.", MessageDialogStyle.AffirmativeAndNegative, dialogSettings);

            if (result == MessageDialogResult.Affirmative)
            {
                DataTransactionsService.ClearData();
            }
        }
Esempio n. 3
0
        private void StopTimer_Click(object sender, RoutedEventArgs e)
        {
            var timeEntry = TimeEntriesService.GetStartedTimeEntry();

            if (timeEntry is null)
            {
                throw new Exception("Time entry already has end time.");
            }

            timeEntry.StopTime = DateTime.Now;

            DataTransactionsService.HandleDataTransaction(new DataTransaction()
            {
                Action = DataTransaction.ActionType.Edit,
                Data   = timeEntry
            });

            timer.Stop();
            UpdateList();
        }
Esempio n. 4
0
        private async void ToggleSynchronization(object sender, RoutedEventArgs e)
        {
            var toggle = sender as ToggleSwitch;

            if (toggle is null || Synchronization)
            {
                return;
            }

            if (!toggle.IsOn)
            {
                SynchronizationInfo.Visibility     = Visibility.Collapsed;
                Settings.Default.SynchronizationOn = false;
                Settings.Default.ClientKey         = string.Empty;
                Settings.Default.ClientSecret      = string.Empty;
                Settings.Default.SecretKey         = string.Empty;
                Synchronization = false;
                Settings.Default.Save();
                return;
            }

            var dialogSettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Create new",
                NegativeButtonText    = "Connect to existing"
            };

            var result = await Utilities.Utilities.GetWindow()?.ShowMessageAsync("Setup Synchronization",
                                                                                 "Do you want to create new synchronization profile or to connect to already existing?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings);

            if (result == MessageDialogResult.Affirmative)
            {
                SynchronizationInfo.Visibility     = Visibility.Visible;
                Settings.Default.SynchronizationOn = true;
                Synchronization = true;
                SecurityService.CreateSecrets();
                await NetworkService.Register();

                await NetworkService.Login();

                await DataTransactionsService.Synchronize();
            }
            else if (result == MessageDialogResult.Negative)
            {
                var inputDialogSettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Connect",
                    NegativeButtonText    = "Cancel"
                };
                var inputResult = await Utilities.Utilities.GetWindow()?.ShowInputAsync("Connect Synchronization Profile", "Enter Synchronization Code", inputDialogSettings);

                if (string.IsNullOrWhiteSpace(inputResult))
                {
                    Settings.Default.Reset();
                    return;
                }

                var values = inputResult.Split(":");
                if (values.Length != 3)
                {
                    return;
                }
                Settings.Default.SynchronizationOn = true;
                Settings.Default.ClientKey         = values[0];
                Settings.Default.ClientSecret      = values[1];
                Settings.Default.SecretKey         = values[2];
                Settings.Default.Save();
                SynchronizationInfo.Visibility = Visibility.Visible;
                SynchronizationCode            = inputResult;
                Synchronization = true;
                await NetworkService.Login();

                await DataTransactionsService.Synchronize();
            }
        }