private void GenerateDataSource()
        {
            footballMatches = new List <MainGridModel>();

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add(_header, _mainKey);

                FixturesNames fixturesNames = GetFixturesNames(client);

                if (fixturesNames == null || !fixturesNames.Fixtres.Any())
                {
                    return;
                }

                List <Fixture> fixtures = GetFixtures(client, fixturesNames);

                if (fixtures == null || !fixtures.Any())
                {
                    return;
                }

                foreach (var fixture in fixtures)
                {
                    Prediction predictionResult = GetPredictions(client, fixture);

                    var adviceParts = predictionResult.Advice.Split(':');

                    if (predictionResult.MatchWinner.Contains('N'))
                    {
                        predictionResult.MatchWinner = predictionResult.MatchWinner.Replace('N', 'X');
                    }

                    var translate = client
                                    .GetAsync(new Uri($"https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20200123T082649Z.bc3d13ca3ec650a0.be300a3e44159909b89563a85275b8c16b9006cf&text={predictionResult.Advice}&lang=bg"))
                                    .Result;
                    var content         = translate.Content.ReadAsStringAsync();
                    var parsedTranslate = JObject.Parse(content.Result);
                    var translateModel  = JsonConvert.DeserializeObject <TranslateModel>(parsedTranslate.ToString());
                    if (translateModel != null && translateModel.Text.Contains(_wrongTranslateDraw))
                    {
                        var index = translateModel.Text.IndexOf(_wrongTranslateDraw);
                        translateModel.Text[index] = _correctTranslateDraw;
                    }

                    var model = new MainGridModel
                    {
                        Advice             = translateModel?.Text.FirstOrDefault(), /*adviceParts.Length > 1 ? adviceParts[1] : predictionResult.Advice,*/
                        AwayWinningPercent = predictionResult.WinningPercent?.Away,
                        DrawWinningPercent = predictionResult.WinningPercent?.Draws,
                        HomeWinningPercent = predictionResult.WinningPercent?.Home,
                        MatchWinner        = predictionResult.MatchWinner,
                        FootballMatch      = $"{fixture.HomeTeam.TeamName} - {fixture.AwayTeam.TeamName}",
                        FixtureDate        = fixture.EventDate
                    };

                    footballMatches.Add(model);
                }
            }
        }
Beispiel #2
0
        public MainPresenter(MainGridModel mainGridModel, IMainView view, IMessagesView messagesView, IViewFactory viewFactory,
                             IMessageBoxView messageBoxView, UserStatsDataModel userStatsDataModel, IPresenterFactory presenterFactory,
                             IClientConfiguration clientConfiguration, IProteinService proteinService, IUpdateLogic updateLogic,
                             Core.ScheduledTasks.RetrievalModel retrievalModel, IExternalProcessStarter processStarter,
                             IPreferenceSet prefs, ClientSettingsManager settingsManager)
        {
            _gridModel = mainGridModel;
            _gridModel.AfterResetBindings += (sender, e) =>
            {
                // run asynchronously so binding operation can finish
                _view.BeginInvoke(new Action(() =>
                {
                    DisplaySelectedSlotData();
                    _view.RefreshControlsWithTotalsData(_gridModel.SlotTotals);
                }), null);
            };
            _gridModel.SelectedSlotChanged += (sender, e) =>
            {
                if (e.Index >= 0 && e.Index < _view.DataGridView.Rows.Count)
                {
                    // run asynchronously so binding operation can finish
                    _view.BeginInvoke(new Action(() =>
                    {
                        _view.DataGridView.Rows[e.Index].Selected = true;
                        DisplaySelectedSlotData();
                    }), null);
                }
            };
            _userStatsDataModel = userStatsDataModel;

            // Views
            _view           = view;
            _messagesView   = messagesView;
            _messageBoxView = messageBoxView;
            //
            _viewFactory      = viewFactory;
            _presenterFactory = presenterFactory;
            // Collections
            _clientConfiguration = clientConfiguration;
            _proteinService      = proteinService;
            // Logic Services
            _updateLogic       = updateLogic;
            _updateLogic.Owner = _view;
            _retrievalModel    = retrievalModel;
            _processStarter    = processStarter;
            // Data Services
            _prefs           = prefs;
            _settingsManager = settingsManager;

            _clientConfiguration.ConfigurationChanged += delegate { AutoSaveConfig(); };
        }
Beispiel #3
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();
        }
Beispiel #4
0
        private void LoadGridData(MainGridModel gridModel)
        {
            dataGridView1.DataSource = gridModel.BindingSource;
            dataGridView1.Sorted    += (s, e) => gridModel.ResetSelectedSlot();

            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 workUnitQueue = selectedSlot?.WorkUnitQueue;
                var slotType      = selectedSlot?.SlotType ?? SlotType.Unknown;
                var logLines      = selectedSlot?.CurrentLogLines?.ToList();

                // run asynchronously so binding operation can finish
                BeginInvoke(new Action(() => LoadSelectedSlot(selectedSlot, workUnitQueue, slotType, logLines)));
            };

            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;
                    var workUnitQueue = selectedSlot?.WorkUnitQueue;
                    var slotType      = selectedSlot?.SlotType ?? SlotType.Unknown;
                    var logLines      = selectedSlot?.CurrentLogLines?.ToList();

                    // run asynchronously so binding operation can finish
                    BeginInvoke(new Action(() => LoadSelectedSlot(selectedSlot, workUnitQueue, slotType, logLines)));
                    break;
                }
            };
        }