예제 #1
0
        /// <summary>
        /// Download image by name.
        /// https://azurlane.koumakan.jp/Template: + id
        /// </summary>
        /// <param name="id">Image name (without "Template:" and without extension)</param>
        /// <returns></returns>
        public override async Task Download(string id)
        {
            Status = Statuses.InProgress;
            string imagePath = GetImageFolder(id) + "/" + id;

            if (File.Exists(imagePath))
            {
                File.Delete(imagePath);
            }

            string tag = await GetIconsTag("Template:" + id);

            string url = GetIconsUrl(tag);

            if (!string.IsNullOrEmpty(url))
            {
                using (CargoContext cargoContext = new CargoContext())
                {
                    Icon icon = new Icon
                    {
                        Name     = id,
                        FileName = await DownloadImageByUrl(url, id + ".png")
                    };

                    if (await cargoContext.Icons.FindAsync(icon.Name) == null)
                    {
                        cargoContext.Icons.Add(icon);
                        await cargoContext.SaveChangesAsync();
                    }
                }
            }

            Status = Statuses.DownloadComplete;
        }
예제 #2
0
        private void Seed()
        {
            using (CargoContext cargoContext = new CargoContext())
            {
                List <GunStats> gunStats = cargoContext.GunsStats.Where(gs => gs.GunName == "2 x 7.7mm MG GL.2").ToList();

                if (gunStats == null || gunStats.Count == 0)
                {
                    GunStats gun = new GunStats();

                    gun.GunName = "2 x 7.7mm MG GL.2";
                    gun.GunTech = "T0";
                    gun.Rld     = 75;
                    gun.Rld3    = 70;
                    gun.Rld6    = 66;
                    gun.RldMax  = 60;

                    gun.Dmg    = 9;
                    gun.Dmg3   = 12;
                    gun.Dmg6   = 17;
                    gun.DmgMax = 22;

                    cargoContext.GunsStats.Add(gun);
                }

                cargoContext.SaveChanges();
            }
        }
예제 #3
0
        /// <summary>
        /// Create relationships depending on values of Equipment.{ Tech, Type, Stars }.
        /// If { Tech, Type, Stars } doesn't exists, creates it.
        /// </summary>
        /// <param name="equipment">Piece of equipment</param>
        /// <param name="cargoContext">CargoContext</param>
        private void CreateRelationships(Equipment equipment, CargoContext cargoContext)
        {
            EquipmentTech equipmentTech = cargoContext.EquipmentTeches.Find(equipment.Tech);
            EquipmentType equipmentType = cargoContext.EquipmentTypes.Find(equipment.Type);

            if (equipmentType == null)
            {
                equipmentType = new EquipmentType {
                    Name = equipment.Type
                };
                cargoContext.EquipmentTypes.Add(equipmentType);
            }

            if (equipmentTech == null)
            {
                equipmentTech = new EquipmentTech {
                    Name = equipment.Tech
                };
                cargoContext.EquipmentTeches.Add(equipmentTech);
            }

            equipment.FK_Tech = equipmentTech;
            equipment.FK_Type = equipmentType;

            cargoContext.SaveChanges();
        }
예제 #4
0
        public void FillList(string newTypeFullName)
        {
            List <string> dbTypes = GetDbTypes(newTypeFullName);
            DPSData       dpsData = new DPSData(newTypeFullName);

            using (CargoContext cargoContext = new CargoContext())
            {
                List <Equipment> equipment = new List <Equipment>();

                var temp = cargoContext.ShipGirlsEquipment.Where(e => dbTypes.Contains(e.Type))
                           .Include(e => e.FK_Tech)
                           .Include(e => e.FK_Nationality)
                           .Include(e => e.FK_Nationality.FK_Icon)
                           .Include(e => e.FK_Type);

                if (temp != null)
                {
                    equipment.AddRange(temp);
                }

                ActionBlock <Equipment> loadBlock = new ActionBlock <Equipment>(
                    (equip) =>
                {
                    AddItemToList(equip, equip.FK_Type.Name, dpsData);
                });

                foreach (Equipment equip in equipment)
                {
                    loadBlock.Post(equip);
                }

                loadBlock.Complete();
                loadBlock.Completion.Wait();
            }
        }
예제 #5
0
        public StatTable(string tableName, string healthStatValue, string armorStatValue,
                         string reloadStatValue, string luckStatValue, string fireStatValue, string torpStatValue,
                         string evadeStatValue, string speedStatValue, string airStatValue, string consumptionStatValue,
                         string aaStatValue, string accStatValue, string aswStatValue, string oxygenStatValue, string ammoStatValue)
        {
            HealthStatValue      = healthStatValue;
            StatTableTitle       = tableName;
            ArmorStatValue       = armorStatValue;
            ReloadStatValue      = reloadStatValue;
            LuckStatValue        = luckStatValue;
            FireStatValue        = fireStatValue;
            TorpStatValue        = torpStatValue;
            EvadeStatValue       = evadeStatValue;
            SpeedStatValue       = speedStatValue;
            AirStatValue         = airStatValue;
            ConsumptionStatValue = consumptionStatValue;
            AAStatValue          = aaStatValue;
            AccStatValue         = accStatValue;
            ASWStatValue         = aswStatValue;
            OxygenStatValue      = oxygenStatValue;
            AmmoStatValue        = ammoStatValue;

            using (CargoContext cargoContext = new CargoContext())
            {
                HealthStatIcon       = cargoContext.Icons.Find("Health")?.FileName;
                ArmorStatIcon        = cargoContext.Icons.Find("Armor")?.FileName;
                ReloadStatIcon       = cargoContext.Icons.Find("Reload")?.FileName;
                LuckStatIcon         = cargoContext.Icons.Find("Luck")?.FileName;
                FireStatIcon         = cargoContext.Icons.Find("Firepower")?.FileName;
                TorpStatIcon         = cargoContext.Icons.Find("Torpedo")?.FileName;
                EvadeStatIcon        = cargoContext.Icons.Find("Evasion")?.FileName;
                AAStatIcon           = cargoContext.Icons.Find("Anti-air")?.FileName;
                AirStatIcon          = cargoContext.Icons.Find("Aviation")?.FileName;
                ConsumptionStatIcon  = cargoContext.Icons.Find("Oil consumption")?.FileName;
                AccStatIcon          = cargoContext.Icons.Find("Accuracy")?.FileName;
                ASWStatIcon          = cargoContext.Icons.Find("Anti-submarine warfare")?.FileName;
                OxygenStatIcon       = cargoContext.Icons.Find("Oxygen")?.FileName;
                AmmoStatIcon         = cargoContext.Icons.Find("Ammunition")?.FileName;
                HuntingRangeStatIcon = cargoContext.Icons.Find("Hunting range")?.FileName;
            }

            Width = Height = 25;
        }
예제 #6
0
        private void CreateRowIfPossible(string name, string firstDescription, string secondDescription = null,
                                         string icon = null)
        {
            if (!string.IsNullOrEmpty(firstDescription))
            {
                if (icon == null)
                {
                    icon = name;
                }

                using (CargoContext cargoContext = new CargoContext())
                {
                    StatsList.Add(new EquipmentStats
                    {
                        Name = name,
                        Icon = cargoContext.Icons.Find(icon)?.FileName,
                        DescriptionFirstPart  = firstDescription,
                        DescriptionSecondPart = secondDescription
                    });
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Create relationships with icons
        /// </summary>
        public void ConnectIcons()
        {
            using (CargoContext cargoContext = new CargoContext())
            {
                foreach (ShipType shipType in cargoContext.ShipTypes)
                {
                    shipType.FK_Icon = cargoContext.Icons.Find(shipType.Abbreviation);
                }

                foreach (Rarity rarity in cargoContext.Rarities)
                {
                    rarity.FK_Icon = cargoContext.Icons.Find(rarity.Name);
                }

                foreach (Nationality nationality in cargoContext.Nationalities)
                {
                    nationality.FK_Icon = cargoContext.Icons.Find(nationality.Name);
                }

                cargoContext.SaveChanges();
            }
        }
예제 #8
0
        private void SaveData()
        {
            using (CargoContext cargoContext = new CargoContext())
            {
                cargoContext.ClearDPSDataTables();

                cargoContext.ArmourModifiers.AddRange(ArmourModifiers);
                cargoContext.BombsStats.AddRange(BombDLs);
                cargoContext.GunsStats.AddRange(GunsStats);

                foreach (var key in Cooldowns.Keys)
                {
                    var item = cargoContext.EquipmentTypes.Find(key);

                    if (item != null)
                    {
                        item.Cooldown = Cooldowns[key];
                    }
                }

                cargoContext.SaveChanges();
            }
        }
예제 #9
0
        protected BaseEquipmentItem(Equipment equipment)
        {
            Dictionary <int, string> StarsRarities = new Dictionary <int, string>
            {
                [1] = "Normal",
                [2] = "Normal",
                [3] = "Rare",
                [4] = "Elite",
                [5] = "Super Rare",
                [6] = "Ultra Rare",
            };

            string rarity = "Normal";

            if (equipment.Stars != null && (equipment.Stars > 0 && equipment.Stars < 7))
            {
                rarity = StarsRarities[(int)equipment.Stars];
            }

            this.Id              = equipment.EquipmentId;
            this.Name            = equipment.Name;
            this.Nationality     = equipment.FK_Nationality.Name;
            this.NationalityIcon = equipment.FK_Nationality.FK_Icon.FileName;
            this.Type            = equipment.FK_Type.Name;
            this.Icon            = equipment.Image;
            this.Tech            = equipment.FK_Tech.Name;
            this.Rarity          = rarity;
            this.Stars           = equipment.Stars ?? 0;
            this.DisplayMaxStats = true;

            using (CargoContext cargoContext = new CargoContext())
            {
                this.IsMaxRarity = equipment.Stars == cargoContext.ShipGirlsEquipment
                                   .Where(equip => equip.Name == equipment.Name).Max(equip => equip.Stars);
            }
        }
예제 #10
0
        public async Task CreateRelationshipGirlDrop(WhereToGetShipGirl wtg, ShipGirl shipGirl, string note, CargoContext cargoContext)
        {
            ShipGirlWhereToGetShipGirl mtm = new ShipGirlWhereToGetShipGirl
            {
                FK_ShipGirl           = shipGirl,
                FK_WhereToGetShipGirl = wtg,
                Note = note
            };

            if (cargoContext.ShipGirlWhereToGetShipGirl.Count(e => e.FK_ShipGirl.ShipID == mtm.FK_ShipGirl.ShipID &&
                                                              e.FK_WhereToGetShipGirl.Name == mtm.FK_WhereToGetShipGirl.Name) == 0)
            {
                cargoContext.ShipGirlWhereToGetShipGirl.Add(mtm);
                await cargoContext.SaveChangesAsync();
            }
        }
예제 #11
0
 public CargoRepository(CargoContext cargoContext)
 {
     CargoContext = cargoContext;
 }
예제 #12
0
        public DPSData(string equipmentName)
        {
            using (CargoContext cargoContext = new CargoContext())
            {
                float?cooldown = 0;

                switch (equipmentName)
                {
                case "Destroyer Guns":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "DD Gun").ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("DD Gun")?.Cooldown;
                    break;

                case "Light Cruiser Guns":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "CL Gun").ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("CL Gun")?.Cooldown;
                    break;

                case "Battleship Guns":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "BB Gun").ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("BB Gun")?.Cooldown;
                    break;

                case "Large Cruiser Guns":
                case "Heavy Cruiser Guns":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "CA Gun").ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("CA Gun")?.Cooldown;
                    break;

                case "Submarine Torpedoes":
                case "Ship Torpedoes":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "Torpedo").ToList();
                    break;

                case "Torpedo Bomber Planes":
                    PlanesBombs     = cargoContext.BombsStats.ToList();
                    PlanesGuns      = cargoContext.GunsStats.ToList();
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "Torpedo Bomber").ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("Torpedo Bomber")?.Cooldown;
                    break;

                case "Fighter Planes":
                case "Dive Bomber Planes":
                case "Seaplanes":
                    ArmourModifiers = cargoContext.ArmourModifiers.Where(am => am.WeaponName == "Bomb").ToList();
                    PlanesBombs     = cargoContext.BombsStats.ToList();
                    PlanesGuns      = cargoContext.GunsStats.ToList();
                    cooldown        = cargoContext.EquipmentTypes.Find("Fighter")?.Cooldown;
                    break;

                case "Anti-Air Guns":
                case "Anti-Submarine Equipment":
                case "Auxiliary Equipment":
                    cooldown = cargoContext.EquipmentTypes.Find("AA Gun")?.Cooldown;
                    break;

                default:
                    Logger.Write($"Cannot distinguish equipmentName: {equipmentName}", this.GetType().ToString());
                    // Load All?
                    break;
                }

                Cooldown = cooldown ?? 0;
            }
        }
예제 #13
0
        /// <summary>
        /// Download one piece of Equipment by name and update it or save if it doesn't exist.
        /// </summary>
        /// <param name="id">Name of equipment.</param>
        public override async Task Download(string id)
        {
            Status = Statuses.InProgress;
            List <EquipmentJsonWrapper> wrappedEquipment;

            try
            {
                string responseJson = await GetData("equipment", EquipmentFields, "equipment.Name=\'" + id + "\'");

                wrappedEquipment = JsonConvert.DeserializeObject <List <EquipmentJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize equipment. ID: {id}", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get data for equipment from server. ID: {id}", this.GetType().ToString());
                return;
            }

            EquipmentJsonWrapper wrpEquipment = wrappedEquipment.FirstOrDefault();

            if (wrpEquipment == null)
            {
                Status = Statuses.EmptyResponse;
                return;
            }

            TotalImageCount = wrappedEquipment.Count;

            using (CargoContext cargoContext = new CargoContext())
            {
                downloadBlock.Post(wrpEquipment.Equipment.Image);
                downloadBlock.Complete();

                Nationality nationality = cargoContext.Nationalities.Find(wrpEquipment.Equipment.Nationality);

                if (nationality == null)
                {
                    nationality = new Nationality
                    {
                        Name    = wrpEquipment.Equipment.Nationality,
                        FK_Icon = cargoContext.Icons.Find(wrpEquipment.Equipment.Nationality)
                    };

                    cargoContext.Nationalities.Add(nationality);
                    cargoContext.SaveChanges();
                }

                wrpEquipment.Equipment.FK_Nationality = nationality;
                CreateRelationships(wrpEquipment.Equipment, cargoContext);
                wrpEquipment.Equipment.DropLocation = Refactor(wrpEquipment.Equipment.DropLocation);
                wrpEquipment.Equipment.Notes        = Refactor(wrpEquipment.Equipment.Notes);
                wrpEquipment.Equipment.Name         = Refactor(wrpEquipment.Equipment.Name);
                SavePaths(wrpEquipment.Equipment);

                if (await cargoContext.ShipGirlsEquipment
                    .CountAsync(e => e.Name == wrpEquipment.Equipment.Name) == 0)
                {
                    cargoContext.ShipGirlsEquipment.Add(wrpEquipment.Equipment);
                    await cargoContext.SaveChangesAsync();
                }
                else
                {
                    await cargoContext.Update(wrpEquipment.Equipment);
                }
            }

            //downloadBlock.Completion.Wait();
            Status = Statuses.DownloadComplete;
        }
예제 #14
0
        /// <summary>
        ///  Download all Skills and save them.
        /// </summary>
        public override async Task Download()
        {
            Status             = Statuses.InProgress;
            StatusDataMessage  = "Downloading data.";
            StatusImageMessage = "Pending.";
            List <SkillJsonWrapper> wrappedSkills;

            try
            {
                string responseJson = await GetData("ship_skills, ships", SkillFields,
                                                    "ship_skills._pageName=ships._pageName", "");

                wrappedSkills = JsonConvert.DeserializeObject <List <SkillJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize skills.", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get data for skills from server.", this.GetType().ToString());
                return;
            }

            TotalImageCount = wrappedSkills.Count;
            TotalDataCount  = wrappedSkills.Count;

            using (CargoContext cargoContext = new CargoContext())
            {
                StatusImageMessage = "Adding icons to download queue.";

                foreach (SkillJsonWrapper wrappedSkill in wrappedSkills)
                {
                    downloadBlock.Post(wrappedSkill.Skill.Icon);
                }

                downloadBlock.Complete();

                StatusImageMessage = "Downloading icons.";
                StatusDataMessage  = "Saving data.";

                foreach (SkillJsonWrapper wrappedSkill in wrappedSkills)
                {
                    if (await cargoContext.Skills
                        .CountAsync(e => e.Name == wrappedSkill.Skill.Name) == 0)
                    {
                        wrappedSkill.Skill.FK_ShipGirl
                            = await cargoContext.ShipGirls.FindAsync(wrappedSkill.Skill.ShipID);

                        wrappedSkill.Skill.Detail = RemoveHTML(wrappedSkill.Skill.Detail);
                        SavePaths(wrappedSkill.Skill);
                        cargoContext.Skills.Add(wrappedSkill.Skill);
                    }

                    lock (locker)
                    {
                        CurrentDataCount++;
                    }
                }

                await cargoContext.SaveChangesAsync();
            }

            StatusDataMessage = "Complete.";
            downloadBlock.Completion.Wait();
            Status = Statuses.DownloadComplete;
        }
예제 #15
0
 public EFUnitOfWork(string connectionString)
 {
     db = new CargoContext(connectionString);
 }
예제 #16
0
        /// <summary>
        /// Download all Equipment and save it.
        /// </summary>
        public override async Task Download()
        {
            Status             = Statuses.InProgress;
            StatusDataMessage  = "Downloading data.";
            StatusImageMessage = "Pending.";
            List <EquipmentJsonWrapper> wrappedEquipment;

            try
            {
                string responseJson = await GetData("equipment", EquipmentFields, "");

                wrappedEquipment = JsonConvert.DeserializeObject <List <EquipmentJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to deserialize equipment.", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get data for equipment from server.", this.GetType().ToString());
                return;
            }

            TotalDataCount  = wrappedEquipment.Count;
            TotalImageCount = wrappedEquipment.Count;

            using (CargoContext cargoContext = new CargoContext())
            {
                StatusImageMessage = "Adding images to download queue.";

                // Prevent loading duplicate images.
                HashSet <string> loadingImages = new HashSet <string>();

                foreach (EquipmentJsonWrapper wrpEquipment in wrappedEquipment)
                {
                    string loadingImage = wrpEquipment.Equipment.Image;

                    if (loadingImages.Add(loadingImage))
                    {
                        downloadBlock.Post(loadingImage);
                    }
                    else
                    {
                        lock (locker)
                        {
                            CurrentImageCount++;
                        }
                    }
                }

                downloadBlock.Complete();

                StatusImageMessage = "Downloading images.";
                StatusDataMessage  = "Saving data.";

                foreach (EquipmentJsonWrapper wrpEquipment in wrappedEquipment)
                {
                    if (await cargoContext.ShipGirlsEquipment
                        .CountAsync(e => e.Name == wrpEquipment.Equipment.Name &&
                                    e.Stars == wrpEquipment.Equipment.Stars) == 0)
                    {
                        Nationality nationality = cargoContext.Nationalities.Find(wrpEquipment.Equipment.Nationality);

                        if (nationality == null)
                        {
                            nationality = new Nationality
                            {
                                Name    = wrpEquipment.Equipment.Nationality,
                                FK_Icon = cargoContext.Icons.Find(wrpEquipment.Equipment.Nationality)
                            };

                            cargoContext.Nationalities.Add(nationality);
                            cargoContext.SaveChanges();
                        }

                        wrpEquipment.Equipment.FK_Nationality = nationality;
                        CreateRelationships(wrpEquipment.Equipment, cargoContext);
                        SavePaths(wrpEquipment.Equipment);
                        wrpEquipment.Equipment.DropLocation = Refactor(wrpEquipment.Equipment.DropLocation);
                        wrpEquipment.Equipment.Notes        = Refactor(wrpEquipment.Equipment.Notes);
                        wrpEquipment.Equipment.Name         = Refactor(wrpEquipment.Equipment.Name);
                        cargoContext.ShipGirlsEquipment.Add(wrpEquipment.Equipment);
                    }

                    lock (locker)
                    {
                        CurrentDataCount++;
                    }
                }

                await cargoContext.SaveChangesAsync();
            }

            StatusDataMessage = "Complete.";
            downloadBlock.Completion.Wait();
            // downloadBlock.Completion.ContinueWith(e => { Status = Statuses.DownloadComplete; });
            Status = Statuses.DownloadComplete;
        }
예제 #17
0
        public IconDownloader(int threadsCount = 0) : base(threadsCount)
        {
            DownloadTitle = "Downloading Icons...";

            if (!Directory.Exists(IconsFolderPath))
            {
                Directory.CreateDirectory(IconsFolderPath);
            }

            async Task <string> UrlGetterFunction(string iconName)
            {
                string iconTag = await GetIconsTag(iconName);

                if (iconTag != "")
                {
                    string iconUrl = GetIconsUrl(iconTag);

                    if (iconUrl != null)
                    {
                        using (CargoContext cargoContext = new CargoContext())
                        {
                            string name = iconUrl.Split('/').Last();

                            Icon icon = new Icon
                            {
                                Name     = iconName.Replace("Template:", ""),
                                FileName = GetImageFolder(name) + "/" + name
                            };

                            if (await cargoContext.Icons.FindAsync(icon.Name) == null)
                            {
                                cargoContext.Icons.Add(icon);
                                await cargoContext.SaveChangesAsync();
                            }
                        }

                        return(iconUrl);
                    }
                }

                return(null);
            }

            async Task UrlDownloaderFunction(string iconUrl)
            {
                await DownloadImageByUrl(iconUrl, iconUrl?.Split('/').Last());

                lock (locker)
                {
                    CurrentImageCount++;
                }
            }

            urlGetterBlock = threadsCount <= 0
                ? new TransformBlock <string, string>(UrlGetterFunction)
                : new TransformBlock <string, string>(UrlGetterFunction,
                                                      new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = threadsCount
            });

            urlDownloaderBlock = threadsCount <= 0
                ? new ActionBlock <string>(UrlDownloaderFunction)
                : new ActionBlock <string>(UrlDownloaderFunction,
                                           new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = threadsCount
            });

            urlGetterBlock.LinkTo(urlDownloaderBlock);
            urlGetterBlock.Completion.ContinueWith(delegate { urlDownloaderBlock.Complete(); });
        }
예제 #18
0
 public UserCarsRepository(CargoContext context)
 {
     this.db = context;
 }
예제 #19
0
        /// <summary>
        /// Download ShipGirl's drop locations and update them or save if they doesn't exist.
        /// </summary>
        /// <param name="id">ShipGirl's id</param>
        public override async Task Download(string id)
        {
            Status = Statuses.InProgress;
            List <WTGShipGirlJsonWrapper> wrappedDrops;

            try
            {
                string responseJson = await GetData("shipDrops", DropFields, "shipDrops.ID=\'" + id + "\'");

                wrappedDrops = JsonConvert.DeserializeObject <List <WTGShipGirlJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize WTG for shipgril. Shipgirl ID: {id}", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get WTG data for shipgirl from server. Shipgirl ID: {id}", this.GetType().ToString());
                return;
            }

            WTGShipGirlJsonWrapper wrappedDrop = wrappedDrops.FirstOrDefault();

            if (wrappedDrop == null)
            {
                Status = Statuses.EmptyResponse;
                return;
            }

            // Adding location if didn't exists and creating connection between drop location and ship girl
            using (CargoContext cargoContext = new CargoContext())
            {
                // get dropped ship girl
                ShipGirl shipGirl = await cargoContext.ShipGirls.FindAsync(wrappedDrop.WtgShipGirlJson.ID);

                if (shipGirl != null)
                {
                    // Remove old connections
                    var oldConnections =
                        await cargoContext.ShipGirlWhereToGetShipGirl
                        .Where(e => e.FK_ShipGirl.ShipID == shipGirl.ShipID).ToListAsync();

                    cargoContext.ShipGirlWhereToGetShipGirl.RemoveRange(oldConnections);
                    await cargoContext.SaveChangesAsync();

                    // get all drops locations
                    Dictionary <string, string> dictionary = wrappedDrop.WtgShipGirlJson.GetDrops();

                    if (dictionary.Count > 0)
                    {
                        foreach (string key in dictionary.Keys)
                        {
                            // get location
                            WhereToGetShipGirl whereToGetShipGirl =
                                await cargoContext.WhereToGetShipGirls.FindAsync(key);

                            // check if it exists, if not create
                            if (whereToGetShipGirl == null)
                            {
                                whereToGetShipGirl = cargoContext.WhereToGetShipGirls.Add(new WhereToGetShipGirl {
                                    Name = key
                                });
                                cargoContext.SaveChanges();
                            }

                            //  create connection
                            await CreateRelationshipGirlDrop(whereToGetShipGirl, shipGirl, dictionary[key], cargoContext);
                        }
                    }
                }
            }

            Status = Statuses.DownloadComplete;
        }
예제 #20
0
        /// <summary>
        /// Download all cases of getting a ship girl and save them
        /// </summary>
        public override async Task Download()
        {
            Status            = Statuses.InProgress;
            StatusDataMessage = "Downloading data.";
            List <WTGShipGirlJsonWrapper> wrappedDrops;

            try
            {
                string responseJson = await GetData("shipDrops", DropFields, "");

                wrappedDrops = JsonConvert.DeserializeObject <List <WTGShipGirlJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize WTG.", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get data for WTG from server.", this.GetType().ToString());
                return;
            }

            TotalDataCount    = wrappedDrops.Count;
            StatusDataMessage = "Placing ShipGirls on Maps...";
            // Adding location if didn't exists and creating connection between drop location and ship girl
            using (CargoContext cargoContext = new CargoContext())
            {
                foreach (WTGShipGirlJsonWrapper wrappedDrop in wrappedDrops)
                {
                    // get dropped ship girl
                    ShipGirl shipGirl = await cargoContext.ShipGirls.FindAsync(wrappedDrop.WtgShipGirlJson.ID);

                    if (shipGirl != null)
                    {
                        // get all drops locations
                        Dictionary <string, string> dictionary = wrappedDrop.WtgShipGirlJson.GetDrops();

                        if (dictionary.Count > 0)
                        {
                            foreach (string key in dictionary.Keys)
                            {
                                // get location
                                WhereToGetShipGirl whereToGetShipGirl =
                                    await cargoContext.WhereToGetShipGirls.FindAsync(key);

                                // check if it exists, if not create
                                if (whereToGetShipGirl == null)
                                {
                                    whereToGetShipGirl = cargoContext.WhereToGetShipGirls.Add(new WhereToGetShipGirl {
                                        Name = key
                                    });
                                    cargoContext.SaveChanges();
                                }

                                //  create connection
                                await CreateRelationshipGirlDrop(whereToGetShipGirl, shipGirl, dictionary[key], cargoContext);
                            }
                        }
                    }

                    lock (locker)
                    {
                        CurrentDataCount++;
                    }
                }
            }

            StatusDataMessage = "Complete.";
            Status            = Statuses.DownloadComplete;
        }
예제 #21
0
 public CarRepository(CargoContext context)
 {
     this.db = context;
 }
예제 #22
0
        /// <summary>
        /// Download one Skill by name and update it or save if it doesn't exist.
        /// </summary>
        /// <param name="id">Name of skill.</param>s
        public override async Task Download(string id)
        {
            Status = Statuses.InProgress;
            List <SkillJsonWrapper> wrappedSkills;

            try
            {
                string responseJson = await GetData("ship_skills, ships", SkillFields,
                                                    "ship_skills._pageName=ships._pageName", "ship_skills.Name=\'" + id + "\'");

                wrappedSkills = JsonConvert.DeserializeObject <List <SkillJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize skill. ID: {id}", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get data for skill from server. ID: {id}", this.GetType().ToString());
                return;
            }

            SkillJsonWrapper wrappedSkill = wrappedSkills.FirstOrDefault();

            if (wrappedSkill == null)
            {
                Status = Statuses.EmptyResponse;
                return;
            }

            TotalImageCount = wrappedSkills.Count;

            using (CargoContext cargoContext = new CargoContext())
            {
                downloadBlock.Post(wrappedSkill.Skill.Icon);
                downloadBlock.Complete();

                wrappedSkill.Skill.FK_ShipGirl
                    = await cargoContext.ShipGirls.FindAsync(wrappedSkill.Skill.ShipID);

                wrappedSkill.Skill.Detail = RemoveHTML(wrappedSkill.Skill.Detail);
                SavePaths(wrappedSkill.Skill);

                if (await cargoContext.Skills
                    .CountAsync(e => e.Name == wrappedSkill.Skill.Name) == 0)
                {
                    cargoContext.Skills.Add(wrappedSkill.Skill);
                    await cargoContext.SaveChangesAsync();
                }
                else
                {
                    await cargoContext.Update(wrappedSkill.Skill);
                }
            }

            //downloadBlock.Completion.Wait();
            Status = Statuses.DownloadComplete;
        }
예제 #23
0
        public EquipmentPageViewModel(int id)
        {
            ClosePageCommand = new RelayCommand(obj =>
            {
                Navigation.Service.GoBack();
            });

            using (CargoContext cargoContext = new CargoContext())
            {
                Equipment equipment = cargoContext.ShipGirlsEquipment.Find(id);

                EquipmentName = equipment.Name;
                Rarity        = StarsRarityDictionary[(int)equipment.Stars];
                Image         = equipment.Image;
                EquipmentType = equipment.Type;

                DropLocation = string.IsNullOrEmpty(equipment.DropLocation)
                    ? null
                    : equipment.DropLocation;

                Notes = string.IsNullOrEmpty(equipment.Notes)
                    ? null
                    : equipment.Notes;

                Nation     = equipment.FK_Nationality.Name;
                NationIcon = equipment.FK_Nationality.FK_Icon.FileName;
                UsedByList = new List <EquipmentUsedBy>();


                RarityIcon = cargoContext.Icons.Find(Rarity)?.FileName;

                foreach (ShipType shipType in cargoContext.ShipTypes)
                {
                    string kind = (string)equipment.GetType().GetProperty(shipType.Abbreviation)?.GetValue(equipment);
                    string note = (string)equipment.GetType().GetProperty(shipType.Abbreviation + "Note")
                                  ?.GetValue(equipment);

                    EquipmentUsedBy listItem = new EquipmentUsedBy();

                    switch (kind)
                    {
                    case "2":
                        listItem.Kind = "CalendarText";
                        break;

                    case "1":
                        listItem.Kind = "Check";
                        break;

                    default:
                        listItem.Kind = "Close";
                        break;
                    }

                    listItem.Note = string.IsNullOrEmpty(note) ? null : note;
                    listItem.Icon = shipType.FK_Icon.FileName;
                    listItem.Name = shipType.Name;

                    UsedByList.Add(listItem);
                }

                FillStatsList(equipment);
            }
        }
예제 #24
0
        /// <summary>
        /// Download all Skills of ShipGirl and update them or save if they doesn't exist.
        /// </summary>
        /// <param name="shipGirl">ShipGirl which skills need update.</param>
        /// <param name="cargoContext">DB context</param>
        public async Task Download(ShipGirl shipGirl, CargoContext cargoContext)
        {
            Status = Statuses.InProgress;
            List <SkillJsonWrapper> wrappedSkills;

            try
            {
                string responseJson = await GetData("ship_skills, ships", SkillFields,
                                                    "ship_skills._pageName=ships._pageName", "ships.ShipID=\'" + shipGirl.ShipID + "\'");

                wrappedSkills = JsonConvert.DeserializeObject <List <SkillJsonWrapper> >(responseJson);
            }
            catch (JsonException)
            {
                Status = Statuses.ErrorInDeserialization;
                Logger.Write($"Failed to desirialize skills for shipgirl. Shipirl ID: {shipGirl.ShipID}", this.GetType().ToString());
                return;
            }
            catch
            {
                Status = Statuses.DownloadError;
                Logger.Write($"Failed to get skills data for shipgir from server. Shipgirl ID: {shipGirl.ShipID}", this.GetType().ToString());
                return;
            }

            if (wrappedSkills.Count == 0)
            {
                Status = Statuses.EmptyResponse;
                return;
            }

            TotalImageCount = wrappedSkills.Count;

            foreach (Skill skill in shipGirl.Skills)
            {
                string imagePath = GetImageFolder(skill.Icon) + "/" + skill.Icon;

                if (File.Exists(imagePath))
                {
                    File.Delete(imagePath);
                }
            }

            cargoContext.Skills.RemoveRange(shipGirl.Skills);
            await cargoContext.SaveChangesAsync();

            foreach (SkillJsonWrapper wrappedSkill in wrappedSkills)
            {
                downloadBlock.Post(wrappedSkill.Skill.Icon);
            }

            downloadBlock.Complete();

            foreach (SkillJsonWrapper wrappedSkill in wrappedSkills)
            {
                wrappedSkill.Skill.FK_ShipGirl = shipGirl;
                wrappedSkill.Skill.Detail      = RemoveHTML(wrappedSkill.Skill.Detail);
                SavePaths(wrappedSkill.Skill);

                if (await cargoContext.Skills
                    .CountAsync(e => e.Name == wrappedSkill.Skill.Name) == 0)
                {
                    cargoContext.Skills.Add(wrappedSkill.Skill);
                    await cargoContext.SaveChangesAsync();
                }
                else
                {
                    await cargoContext.Update(wrappedSkill.Skill);
                }
            }

            downloadBlock.Completion.Wait();
            Status = Statuses.DownloadComplete;
        }