private void SaveConfiguration()
        {
            RedmineService redmineService;

            try
            {
                redmineService = RedmineService.ConnectAndCreate(RedmineUrl, RedmineApiKey);
            }
            catch (RedmineException ex)
            {
                Messenger.Default.Send(new NotificationMessage($"Error connecting to Redmine service: {ex.Message}"));
                redmineService = null;
            }

            if (redmineService == null)
            {
                Messenger.Default.Send(new RedmineConnectionFailMessage());
            }
            else
            {
                // Save configuration
                _configuration.RedmineApiKey = RedmineApiKey;
                _configuration.RedmineUrl    = RedmineUrl;

                // Send success message
                Messenger.Default.Send(new RedmineConnectionSuccessMessage(redmineService));
            }
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            Messenger.Default.Register <NotificationMessageAction>(this, ShowConfirmation);
            Messenger.Default.Register <NotificationMessage>(this, ShowNotification);
            Messenger.Default.Register <SelectProjectMessage>(this, message => NavigateToSelectProject());
            Messenger.Default.Register <LogTimeMessage>(this, message => NavigateToLogTime());
            Messenger.Default.Register <EditConfigurationMessage>(this, message => NavigateToConfiguration());
            Messenger.Default.Register <UnsavedHoursReportMessage>(this, UpdateUnsavedHours);
            Messenger.Default.Register <ShowHelpMessage>(this, ShowHelpWindow);

            InitializeComponent();

            RedmineService redmineService = null;
            var            configuration  = new LoggerConfiguration();

            if (!string.IsNullOrWhiteSpace(configuration.RedmineUrl) &&
                !string.IsNullOrWhiteSpace(configuration.RedmineApiKey))
            {
                try
                {
                    redmineService = RedmineService.ConnectAndCreate(configuration);
                }
                catch (Exception)
                {
                    redmineService = null;
                }
            }

            if (redmineService != null)
            {
                Messenger.Default.Send(new RedmineConnectionSuccessMessage(redmineService));
                NavigateToSelectProject();
            }
            else
            {
                NavigateToConfiguration();
            }
        }