Example #1
0
        // 7.4 MarketBuy
        private void JournalMarketBuy(string jstr)
        {
            MarketBuyEvent marketbuy = JsonConvert.DeserializeObject <MarketBuyEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #2
0
        // 8.18 MissionCompleted
        private void JournalMissionCompleted(string jstr)
        {
            MissionCompletedEvent missioncomplete = JsonConvert.DeserializeObject <MissionCompletedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missioncomplete.MissionID))
                {
                    // Remove mission
                    db.ActiveMissions.RemoveRange(db.ActiveMissions.Where(o => o.MissionID == missioncomplete.MissionID));
                    db.SaveChanges();
                }

                if (db.CargoHolds.Any(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo == true))
                {
                    CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo == true).First();
                    if (cargoitem.Qty == missioncomplete.Count)
                    {
                        //Remove item of cargo
                        //db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo = true));
                        db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                    }
                    else
                    {
                        //Update quantity of cargo
                        cargoitem.Qty = cargoitem.Qty - missioncomplete.Count;
                    }
                    db.SaveChanges();
                }
                if ((missioncomplete.CommodityReward != null) && (missioncomplete.CommodityReward.Count > 0))
                {
                    foreach (var item in missioncomplete.CommodityReward)
                    {
                        Commodity commod = db.Commodities.Where(p => p.EDCodeName == item.Name.ToLower()).First();
                        if (db.CargoHolds.Any(o => o.CommodityName == commod.CommodityName && o.MissionCargo == false))
                        {
                            //Update CargoHold record
                            CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName == commod.CommodityName && o.MissionCargo == false).First();
                            var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                            cargoUpdate.Qty = cargoUpdate.Qty + item.Count;
                            cargoUpdate.AvgPurchasePrice = existingCargoValue / cargoUpdate.Qty;
                        }
                        else
                        {
                            //Add CargoHold record
                            db.CargoHolds.Add(new CargoHold()
                            {
                                CommodityName = commod.CommodityName, Qty = item.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                            });
                        }
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #3
0
        // 7.6 Miningrefined
        private void JournalMiningRefined(string jstr)
        {
            MiningRefinedEvent miningrefined = JsonConvert.DeserializeObject <MiningRefinedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Mined Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #4
0
        // 7.5 MarketSell
        private void JournalMarketSell(string jstr)
        {
            MarketSellEvent marketsell = JsonConvert.DeserializeObject <MarketSellEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                db.Dispose();
            }
        }
Example #5
0
        // 7 Trade
        // 7.2 CollectCargo
        private void JournalCollectCargo(string jstr)
        {
            CollectCargoEvent collectcargo = JsonConvert.DeserializeObject <CollectCargoEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
Example #6
0
        // 3 Startup
        // 3.1 Cargo
        private void JournalCargo(string jstr)
        {
            CargoEvent cargo = JsonConvert.DeserializeObject <CargoEvent>(jstr);

            // Reset stored list of Cargo
            using (var db = new EDTSQLEntities())
            {
                var allrecords = db.CargoHolds;
                foreach (CargoHold item in allrecords)
                {
                    item.StockChecked = false; //false
                }
                db.SaveChanges();
                DisplayCargo();

                foreach (var inventitem in cargo.Inventory)
                {
                    //Lookup NiceName of Cargo Item from Commodities table
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == inventitem.Name).First();
                    //Locate Cargo Item in CargoHold table
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper()))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper()).First();
                        cargoUpdate.StockChecked = true;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = inventitem.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                // Delete Cargo entries not found on load of Journal
                db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.StockChecked == false));
                db.SaveChanges();
                db.Dispose();
            }
        }
Example #7
0
        // 8 Station Services
        // 8.17 MissionAccepted
        private void JournalMissionAccepted(string jstr)
        {
            MissionAcceptedEvent missionaccept = JsonConvert.DeserializeObject <MissionAcceptedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missionaccept.MissionID))
                {
                    return;
                }

                DateTimeOffset dto = new DateTimeOffset(missionaccept.getExpiryAsDate());

                if (missionaccept.Commodity_Localised != null)
                {
                    missionaccept.Commodity_Localised = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(missionaccept.Commodity_Localised);
                }

                string MissType = "";
                if (missionaccept.Name.Contains("Collect"))
                {
                    MissType = "Collect";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()}) - Required", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Delivery"))
                {
                    MissType = "Delivery";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()})", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Courier"))
                {
                    MissType = "Courier";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = "Data Only", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Salvage"))
                {
                    MissType = "Salvage";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()})", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                db.SaveChanges();

                if (missionaccept.Name.Contains("Delivery") == true)
                {
                    if (db.CargoHolds.Any(o => o.CommodityName == missionaccept.Commodity_Localised))
                    {
                        // Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName == missionaccept.Commodity_Localised && o.MissionCargo == true).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + missionaccept.Count;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = missionaccept.Commodity_Localised, Qty = missionaccept.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = true
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }