コード例 #1
0
        protected override void AnimatedThreadWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            _initialFlightOpsRecordArray.Clear();
            _resultFlightOpsRecordArray.Clear();
            aircrafts.Clear();

            AnimatedThreadWorker.ReportProgress(0, "load records");

            try
            {
                _initialFlightOpsRecordArray.AddRange(GlobalObjects.PlanOpsCalculator.LoadOpsRecordsByPlanOpsId(_currentPlanOps.ItemId));
                var calculatedItem = GlobalObjects.PlanOpsCalculator.CalculateTripForPeriod(_currentPlanOps);


                if (_initialFlightOpsRecordArray.Count <= 0)
                {
                    _initialFlightOpsRecordArray.AddRange(calculatedItem);
                    foreach (var rec in calculatedItem)
                    {
                        GlobalObjects.NewKeeper.Save(rec);
                    }
                }
                else
                {
                    foreach (var rec in calculatedItem.Where(i => _initialFlightOpsRecordArray.All(q => q.FlightTrackRecordId != i.FlightTrackRecordId)))
                    {
                        GlobalObjects.NewKeeper.Save(rec);
                        _initialFlightOpsRecordArray.Add(rec);
                    }
                }

                AnimatedThreadWorker.ReportProgress(50, "load Aircraft Flights");

                if (_calculated)
                {
                    aircrafts.AddRange(_initialFlightOpsRecordArray.Select(i => i.AircraftId).Distinct());
                    aircrafts.AddRange(_initialFlightOpsRecordArray.Select(i => i.AircraftExchangeId).Distinct());
                    foreach (var aircraft in aircrafts.Distinct())
                    {
                        GlobalObjects.AircraftFlightsCore.LoadAircraftFlightsLight(aircraft);
                    }
                }
            }
            catch (Exception exception)
            {
                Program.Provider.Logger.Log("Error while load records", exception);
            }

            #region Фильтрация директив

            AnimatedThreadWorker.ReportProgress(70, "filter records");

            FilterItems(_initialFlightOpsRecordArray, _resultFlightOpsRecordArray);

            if (AnimatedThreadWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            #endregion


            AnimatedThreadWorker.ReportProgress(100, "Complete");
        }