Beispiel #1
0
        internal static void SynchronizeWallet()
        {
            var users = GetUsers();

            foreach (var user in users)
            {
                if (!user.SynchronizeTransactions)
                {
                    continue;
                }

                var token = user.GetAccessToken();
                if (token != null)
                {
                    // var balance = EveSwaggerInterface.GetWalletBalance(token, user.Id);
                    var transactions = EveSwaggerInterface.GetWalletTransactions(token, user.Id);

                    if (transactions == null)
                    {
                        user.SynchronizeTransactions = false;
                        continue;
                    }

                    foreach (var transaction in transactions)
                    {
                        if (!transaction.is_buy)
                        {
                            continue;
                        }

                        var eoiDataAsset = _eoiDataAsset.FirstOrDefault(x => x.Id == transaction.type_id);
                        if (eoiDataAsset != null)
                        {
                            eoiDataAsset.AddTransaction(transaction);
                        }
                    }
                }
            }

            var eoiDataAssets = _eoiDataAsset.ToList();

            foreach (var asset in eoiDataAssets)
            {
                asset.Clean();

                if (!asset.HasPrice())
                {
                    foreach (var eoiAsset in asset.GetEoiAssets())
                    {
                        EoiInterface.RemoveAsset(eoiAsset);
                    }

                    asset.Delete();
                    _eoiDataAsset.Remove(asset);
                }
                else
                {
                    asset.UpdateEoiAssets();

                    foreach (var eoiAsset in asset.GetEoiAssets())
                    {
                    }
                }
            }
        }
Beispiel #2
0
        internal static void SynchronizeAssets()
        {
            foreach (var eoiDataAsset in _eoiDataAsset)
            {
                eoiDataAsset.Synchronized = false;
                eoiDataAsset.Reset();
            }

            var users = GetUsers();

            foreach (var user in users)
            {
                if (!user.SynchronizeAssets)
                {
                    continue;
                }

                var token = user.GetAccessToken();
                if (token != null)
                {
                    var esiAssets = EveSwaggerInterface.GetAssets(token, user.Id);
                    if (esiAssets == null)
                    {
                        user.SynchronizeAssets = false;
                        continue;
                    }

                    foreach (var esiAsset in esiAssets)
                    {
                        if (esiAsset.is_singleton)
                        {
                            continue;
                        }

                        if (esiAsset.location_flag != "Unlocked" && esiAsset.location_flag != "Locked" && esiAsset.location_flag != "Cargo" && esiAsset.location_flag != "Deliveries" &&
                            esiAsset.location_flag != "Hangar" && esiAsset.location_flag != "HangarAll")
                        {
                            continue;
                        }

                        if (esiAsset.is_blueprint_copy)
                        {
                            continue;
                        }

                        var eoiDataAsset = _eoiDataAsset.FirstOrDefault(x => x.Id == esiAsset.type_id);
                        if (eoiDataAsset == null)
                        {
                            eoiDataAsset = new EoiDataAsset(esiAsset);
                            _eoiDataAsset.Add(eoiDataAsset);
                        }
                        else
                        {
                            eoiDataAsset.Synchronize(esiAsset);
                        }

                        eoiDataAsset.Synchronized = true;
                    }
                }
            }

            var eoiDataAssetsToRemove = _eoiDataAsset.Where(x => x.Synchronized == false || x.GetQuantity() <= 0).ToList();

            foreach (var asset in eoiDataAssetsToRemove)
            {
                foreach (var eoiAsset in asset.GetEoiAssets())
                {
                    EoiInterface.RemoveAsset(eoiAsset);
                }

                asset.Delete();
                _eoiDataAsset.Remove(asset);
            }
        }
        internal void UpdateEoiAssets()
        {
            if (_fileSystemAsset == null)
            {
                return;
            }

            var transactions = _fileSystemAsset.GetOrderedTransactions();
            var quantity     = _fileSystemAsset.Quantity;

            var usedEoiAssets = new List <EoiAsset>();

            _eoiAssets.ForEach(x => x.Quantity = 0);

            foreach (var transaction in transactions)
            {
                var eoiAsset = _eoiAssets.FirstOrDefault(x => x.Price == transaction.unit_price);

                if (eoiAsset == null)
                {
                    eoiAsset = new EoiAsset();

                    if (_type != null)
                    {
                        eoiAsset.Name = _type.Name;
                    }
                    else
                    {
                        eoiAsset.Name = "Unknown";
                    }

                    eoiAsset.Price = transaction.unit_price;

                    if (quantity > transaction.quantity)
                    {
                        eoiAsset.Quantity = transaction.quantity;
                    }
                    else if (quantity > 0)
                    {
                        eoiAsset.Quantity = quantity;
                    }

                    quantity -= transaction.quantity;

                    _eoiAssets.Add(eoiAsset);
                    EoiInterface.AddAsset(eoiAsset);
                }
                else
                {
                    if (quantity > transaction.quantity)
                    {
                        eoiAsset.Quantity += transaction.quantity;
                    }
                    else if (quantity > 0)
                    {
                        eoiAsset.Quantity += quantity;
                    }

                    quantity -= transaction.quantity;
                }

                usedEoiAssets.Add(eoiAsset);
            }

            if (quantity > 0)
            {
                var eoiAsset = _eoiAssets.FirstOrDefault(x => x.Price == 0);

                if (eoiAsset == null)
                {
                    eoiAsset = new EoiAsset();

                    if (_type != null)
                    {
                        eoiAsset.Name = _type.Name;
                    }

                    eoiAsset.Price    = 0;
                    eoiAsset.Quantity = quantity;

                    _eoiAssets.Add(eoiAsset);
                }
                else
                {
                    eoiAsset.Quantity += quantity;
                }

                usedEoiAssets.Add(eoiAsset);
            }

            foreach (var eoiAsset in _eoiAssets.ToList())
            {
                if (!usedEoiAssets.Contains(eoiAsset))
                {
                    _eoiAssets.Remove(eoiAsset);
                    EoiInterface.RemoveAsset(eoiAsset);
                }
            }
        }