Example #1
0
        /// <summary>
        /// Function that's run when the program first starts.
        /// Set up the data context links with the local variables.
        /// </summary>
        public MainWindow(ViewModel model, IoCNavigationService navigationService, ILogger <MainWindow> logger)
        {
            // Initialize the readonly fields.
            this.mainViewModel     = model;
            this.navigationService = navigationService;
            this._syncContext      = SynchronizationContext.Current !;
            this.logger            = logger;

            try
            {
                // Set up an event handler for any otherwise unhandled exceptions in the code.
                AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
                AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

                // Initialize the window.
                InitializeComponent();

                // Set the title.
                Title = $"{ProductInfo.Name} - {ProductInfo.Version}";

                // Load configuration data
                QuestCollection?quests       = null;
                string?         currentQuest = null;

                try
                {
                    logger.LogDebug("Loading configuration.");
                    NetTallyConfig.Load(out quests, out currentQuest, AdvancedOptions.Instance);
                    logger.LogInformation("Configuration loaded.");
                }
                catch (ConfigurationErrorsException e)
                {
                    MessageBox.Show(e.Message, "Error in configuration.  Current configuration ignored.", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                // Complete the platform setup.
                PlatformSetup(quests, currentQuest);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failure during program startup.");
                ShowWarning("Unable to start the program.", "Failure on startup");
                this.Close();
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mainViewModel">The primary view model of the program.</param>
        public ManageVotesWindow(ViewModel mainViewModel, IoCNavigationService navigationService, ILogger <ManageVotesWindow> logger)
        {
            this.mainViewModel     = mainViewModel;
            this.navigationService = navigationService;
            this.logger            = logger;

            InitializeComponent();

            this.mainViewModel.PropertyChanged += MainViewModel_PropertyChanged;

            // Create filtered, sortable views into the collection for display in the window.
            VoteView1 = new ListCollectionView(this.mainViewModel.AllVotesCollection);
            VoteView2 = new ListCollectionView(this.mainViewModel.AllVotesCollection);

            PropertyGroupDescription groupDescription = new PropertyGroupDescription("Category");

            VoteView1.GroupDescriptions.Add(groupDescription);
            VoteView2.GroupDescriptions.Add(groupDescription);

            if (VoteView1.CanSort && VoteView2.CanSort)
            {
                IComparer voteCompare = new CustomVoteSort();
                VoteView1.CustomSort = voteCompare;
                VoteView2.CustomSort = voteCompare;
            }

            if (VoteView1.CanFilter && VoteView2.CanFilter)
            {
                VoteView1.Filter = (a) => FilterVotes(Filter1String, a as VoteLineBlock);
                VoteView2.Filter = (a) => FilterVotes(Filter2String, a as VoteLineBlock);
            }

            // Initialize starting selected positions
            VoteView1.MoveCurrentToPosition(-1);
            VoteView2.MoveCurrentToFirst();


            // Create filtered views for display in the window.
            VoterView1 = new ListCollectionView(this.mainViewModel.AllVotersCollection);
            VoterView2 = new ListCollectionView(this.mainViewModel.AllVotersCollection);

            VoterView1.CustomSort = Comparer.Default;
            VoterView2.CustomSort = Comparer.Default;

            VoterView1.Filter = (a) => FilterVoters(VoteView1, a as Origin);
            VoterView2.Filter = (a) => FilterVoters(VoteView2, a as Origin);

            // Update the voters to match the votes.
            VoterView1.Refresh();
            VoterView2.Refresh();

            // Populate the context menu with known tasks.
            CreateContextMenuCommands();
            InitKnownTasks();
            UpdateContextMenu();

            // Set the data context for binding.
            DataContext = this;

            Filter1String = "";
            Filter2String = "";
        }