Пример #1
0
        public UserStatsDataModel(ISynchronizeInvoke synchronizeInvoke, IPreferences preferences, EocStatsScheduledTask scheduledTask)
        {
            _preferences   = preferences;
            _scheduledTask = scheduledTask;
            _mapper        = new MapperConfiguration(cfg => cfg.AddProfile <UserStatsDataModelProfile>()).CreateMapper();

            _preferences.PreferenceChanged += (s, e) =>
            {
                switch (e.Preference)
                {
                case Preference.EnableUserStats:
                    ControlsVisible = _preferences.Get <bool>(Preference.EnableUserStats);
                    if (ControlsVisible)
                    {
                        RefreshFromData();
                    }
                    break;

                case Preference.EocUserId:
                    Refresh();
                    break;
                }
            };

            _scheduledTask.Changed += (s, e) =>
            {
                switch (e.Action)
                {
                case ScheduledTaskChangedAction.Finished:
                    // scheduled task completes on thread pool, but RefreshFromData will trigger UI control updates
                    // provide the ISynchronizeInvoke instance for posting the updates back to the UI thread
                    RefreshFromData(synchronizeInvoke);
                    break;
                }
            };

            ControlsVisible = _preferences.Get <bool>(Preference.EnableUserStats);
            RefreshFromData();
        }
Пример #2
0
        public MainPresenter(MainModel model, ILogger logger, IServiceScopeFactory serviceScopeFactory, MessageBoxPresenter messageBox,
                             ClientConfiguration clientConfiguration, IProteinService proteinService, EocStatsScheduledTask eocStatsScheduledTask)
            : base(model)
        {
            Model  = model;
            Logger = logger ?? NullLogger.Instance;
            ServiceScopeFactory = serviceScopeFactory ?? NullServiceScopeFactory.Instance;
            MessageBox          = messageBox ?? NullMessageBoxPresenter.Instance;
            ClientConfiguration = clientConfiguration;
            ProteinService      = proteinService ?? NullProteinService.Instance;

            UserStatsDataModel = new UserStatsDataModel(Form, Model.Preferences, eocStatsScheduledTask);
            Preferences        = Model.Preferences;
            GridModel          = new MainGridModel(Form, Model.Preferences, clientConfiguration);
            GridModel.Load();

            GridModel.AfterResetBindings += (s, e) =>
            {
                // Create a local reference before handing off to BeginInvoke.
                // This ensures that the BeginInvoke action uses the state of GridModel properties available now,
                // not the state of GridModel properties when the BeginInvoke action is executed (at a later time).
                var selectedSlot = GridModel.SelectedSlot;
                var slotTotals   = GridModel.SlotTotals;
                // run asynchronously so binding operation can finish
                Form.BeginInvoke(new Action(() =>
                {
                    Model.GridModelSelectedSlotChanged(selectedSlot);
                    Model.GridModelSlotTotalsChanged(slotTotals);
                }), null);
            };
            GridModel.PropertyChanged += (s, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(MainGridModel.SelectedSlot):
                    // Create a local reference before handing off to BeginInvoke.
                    // This ensures that the BeginInvoke action uses the state of GridModel properties available now,
                    // not the state of GridModel properties when the BeginInvoke action is executed (at a later time).
                    var selectedSlot = GridModel.SelectedSlot;
                    // run asynchronously so binding operation can finish
                    Form.BeginInvoke(new Action(() => Model.GridModelSelectedSlotChanged(selectedSlot)), null);
                    break;
                }
            };

            _settingsManager = new ClientSettingsManager(Logger);

            ClientConfiguration.ClientConfigurationChanged += (s, e) => AutoSaveConfig();
        }