internal static void RequestMarketHistory()
        {
            if (EveSwaggerInterface.Working())
            {
                return;
            }

            var failedRequests = EveSwaggerInterface.GetFailedHistoryRequests();

            foreach (var failedRequest in failedRequests)
            {
                var esiType = EveSwaggerInterface.GetType(failedRequest.Id);
                if (esiType == null || !esiType.published)
                {
                    var product = EoiDataInterface.GetTypeById(failedRequest.Id);
                    if (product != null)
                    {
                        product.Invalid = true;
                        EoiDataInterface.CheckInvalid();
                    }
                }
            }

            EveSwaggerInterface.ClearFailedHistoryRequests();

            var blueprints = EoiDataInterface.GetBlueprints();

            foreach (var blueprint in blueprints)
            {
                foreach (var product in blueprint.Products)
                {
                    RawEsiPriceHistory marketHistory = null;

                    var region = Regions.GetTradehubRegionId(SolarSystems.GetSolarSystem(SettingsInterface.GlobalSettings.TradeHub));

                    marketHistory = EveSwaggerInterface.GetMarketHistory(product.Id, region);
                    if (marketHistory != null)
                    {
                        var esiDataMarketHistory = _marketHistory.FirstOrDefault(x => Equals(x.History, marketHistory));
                        if (esiDataMarketHistory == null)
                        {
                            var oldEsiDataMarketHistory = _marketHistory.FirstOrDefault(x => x.Id == marketHistory.typeId && x.Region == marketHistory.regionId);
                            if (oldEsiDataMarketHistory != null)
                            {
                                _marketHistory.Remove(oldEsiDataMarketHistory);
                            }

                            _marketHistory.Add(new EsiDataMarketHistory(marketHistory));
                        }
                    }
                }
            }
        }
        internal static void RequestMarketOrders()
        {
            if (EveSwaggerInterface.Working())
            {
                return;
            }

            var failedRequests = EveSwaggerInterface.GetFailedOrdersRequests();

            foreach (var failedRequest in failedRequests)
            {
                var esiType = EveSwaggerInterface.GetType(failedRequest.Id);
                if (esiType == null || !esiType.published)
                {
                    var type = EoiDataInterface.GetTypeById(failedRequest.Id);
                    if (type != null)
                    {
                        type.Invalid = true;
                        EoiDataInterface.CheckInvalid();
                    }
                }
            }

            EveSwaggerInterface.ClearFailedOrdersRequests();

            var assets = EoiDataInterface.GetAssets();

            foreach (var asset in assets)
            {
                RawEsiMarketOrders marketOrders = null;

                var region = Regions.GetTradehubRegionId(SolarSystems.GetSolarSystem(SettingsInterface.GlobalSettings.TradeHub));

                marketOrders = EveSwaggerInterface.GetMarketOrders(asset.Id, region);
                if (marketOrders != null)
                {
                    var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                    if (esiDataMarketOrders == null)
                    {
                        var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                        if (oldEsiDataMarketOrders != null)
                        {
                            _marketOrders.Remove(oldEsiDataMarketOrders);
                        }

                        _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                    }
                }
            }

            var blueprints = EoiDataInterface.GetBlueprints();

            foreach (var blueprint in blueprints)
            {
                {
                    RawEsiMarketOrders marketOrders = null;

                    var region = Regions.GetTradehubRegionId(SolarSystems.GetSolarSystem(SettingsInterface.GlobalSettings.TradeHub));

                    marketOrders = EveSwaggerInterface.GetMarketOrders(blueprint.Id, region);
                    if (marketOrders != null)
                    {
                        var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                        if (esiDataMarketOrders == null)
                        {
                            var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                            if (oldEsiDataMarketOrders != null)
                            {
                                _marketOrders.Remove(oldEsiDataMarketOrders);
                            }

                            _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                        }
                    }
                }

                foreach (var materials in blueprint.Materials)
                {
                    RawEsiMarketOrders marketOrders = null;

                    var region = Regions.GetTradehubRegionId(SolarSystems.GetSolarSystem(SettingsInterface.GlobalSettings.TradeHub));

                    marketOrders = EveSwaggerInterface.GetMarketOrders(materials.Id, region);
                    if (marketOrders != null)
                    {
                        var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                        if (esiDataMarketOrders == null)
                        {
                            var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                            if (oldEsiDataMarketOrders != null)
                            {
                                _marketOrders.Remove(oldEsiDataMarketOrders);
                            }

                            _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                        }
                    }

                    if (region != Regions.TheForge)
                    {
                        marketOrders = EveSwaggerInterface.GetMarketOrders(materials.Id, Regions.TheForge);
                        if (marketOrders != null)
                        {
                            var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                            if (esiDataMarketOrders == null)
                            {
                                var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                                if (oldEsiDataMarketOrders != null)
                                {
                                    _marketOrders.Remove(oldEsiDataMarketOrders);
                                }

                                _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                            }
                        }
                    }
                }

                foreach (var product in blueprint.Products)
                {
                    RawEsiMarketOrders marketOrders = null;

                    var region = Regions.GetTradehubRegionId(SolarSystems.GetSolarSystem(SettingsInterface.GlobalSettings.TradeHub));

                    marketOrders = EveSwaggerInterface.GetMarketOrders(product.Id, region);
                    if (marketOrders != null)
                    {
                        var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                        if (esiDataMarketOrders == null)
                        {
                            var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                            if (oldEsiDataMarketOrders != null)
                            {
                                _marketOrders.Remove(oldEsiDataMarketOrders);
                            }

                            _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                        }
                    }

                    if (region != Regions.TheForge)
                    {
                        marketOrders = EveSwaggerInterface.GetMarketOrders(product.Id, Regions.TheForge);
                        if (marketOrders != null)
                        {
                            var esiDataMarketOrders = _marketOrders.FirstOrDefault(x => Equals(x.Orders, marketOrders));
                            if (esiDataMarketOrders == null)
                            {
                                var oldEsiDataMarketOrders = _marketOrders.FirstOrDefault(x => x.Id == marketOrders.typeId && x.Region == marketOrders.regionId);
                                if (oldEsiDataMarketOrders != null)
                                {
                                    _marketOrders.Remove(oldEsiDataMarketOrders);
                                }

                                _marketOrders.Add(new EsiDataMarketOrders(marketOrders));
                            }
                        }
                    }
                }
            }
        }
 internal static bool Working()
 {
     return(EveSwaggerInterface.Working());
 }
        internal static void Start(Thread mainThread)
        {
            if (mainThread == null)
            {
                return;
            }

            MainThread = mainThread;

            while (!_stop)
            {
                CheckUserAccessTokens();

                if (SettingsInterface.GlobalSettings.EnableAutoUpdater)
                {
                    var updated = false;

                    if (SynchronizeBlueprints())
                    {
                        updated = true;
                    }

                    CheckUpdated(updated, EoiInterface.BlueprintPropertyChanged);
                    updated = false;

                    Status = new BackgroundWorkerStatus("Synchronisiere Assets", -1);
                    SynchronizeAssets();
                    SynchronizeWallet();
                    CheckUpdated(true, EoiInterface.AssetPropertyChanged);

                    Status = new BackgroundWorkerStatus("Synchronisiere Markt Orders", -1);
                    SynchronizeCharacterOrders();
                    CheckUpdated(true, EoiInterface.BlueprintPropertyChanged);

                    if (SettingsInterface.GlobalSettings.EnableCorporationContractsUpdates && !_stop)
                    {
                        Status = new BackgroundWorkerStatus("Synchronisiere Corporation Verträge", -1);
                        if (SynchronizeCorporationContracts())
                        {
                            updated = true;
                        }

                        CheckUpdated(updated, EoiInterface.ContractsPropertyChanged);
                        updated = false;
                    }

                    if (SettingsInterface.GlobalSettings.EnableMarketerUpdates && !_stop)
                    {
                        Status = new BackgroundWorkerStatus("Aktualisiert Markt Preise", -1);
                        if (CheckMarketerData())
                        {
                            updated = true;
                        }

                        CheckUpdated(true, EoiInterface.AssetPropertyChanged);
                        CheckUpdated(updated, EoiInterface.BlueprintPropertyChanged);
                        updated = false;
                    }

                    if (SettingsInterface.GlobalSettings.EnableMarketHistoryUpdates && !_stop)
                    {
                        Status = new BackgroundWorkerStatus("Aktualisiert Markt Verkaufszahlen", -1);
                        if (CheckMarketHistory())
                        {
                            updated = true;
                        }

                        CheckUpdated(updated, EoiInterface.BlueprintPropertyChanged);
                        updated = false;
                    }
                }

                var preStop = false;
                for (int i = 0; i < 30; i++)
                {
                    if (!_stop)
                    {
                        CheckUserAccessTokens();

                        if (_calculateBlueprints)
                        {
                            Status = new BackgroundWorkerStatus("Berechne Blueprints", -1);
                            _calculateBlueprints = false;
                            EoiDataInterface.CalculateAllBlueprints();
                            CheckUpdated(true, EoiInterface.BlueprintPropertyChanged);
                        }

                        if (EveSwaggerInterface.Working())
                        {
                            var state = EveSwaggerInterface.GetProgressState();
                            Status  = new BackgroundWorkerStatus("Download vom Eve Online Server: " + state.FinishedOperations + " / " + state.Operations, state.Progress);
                            preStop = true;
                        }
                        else
                        {
                            Status = new BackgroundWorkerStatus("", 0);
                        }

                        Thread.Sleep(SettingsInterface.GlobalSettings.AutoUpdaterInterval / 30);

                        if (preStop && !EveSwaggerInterface.Working())
                        {
                            i = 30;
                        }
                    }
                }
            }
        }