Exemplo n.º 1
0
 public void AddCargo(int caliber)
 {
     CargoContext.Cargos.Add(new Cargo {
         Caliber = caliber
     });
     CargoContext.SaveChanges();
 }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        public ActionResult AddCar([Bind(Include = "Name,Number,Type,Body,Label,Weight,Volume,LoadingType,AddedInfo,Driver,TrailerNumber,TrailerLabel,hasTrailer")] Car car, IEnumerable <HttpPostedFileBase> CarPhoto,
                                   IEnumerable <HttpPostedFileBase> TechPhoto)
        {
            string currentUserId = User.Identity.GetUserId();

            car.UserId = currentUserId;
            if (TechPhoto != null)
            {
                foreach (var file in TechPhoto)
                {
                    if (file != null)
                    {
                        var binaryReader    = new BinaryReader(file.InputStream);
                        var imageBase64Data = Convert.ToBase64String(binaryReader.ReadBytes(file.ContentLength));
                        car.Photos.Add(new Photo {
                            Name = "TechPhoto", Value = imageBase64Data, CarId = car.Id,
                        });
                    }
                    else
                    {
                        ModelState.AddModelError("TechPhoto", "Наличие фото тех.паспорта - обязательно");
                    }
                }
            }
            if (CarPhoto != null)
            {
                foreach (var file in CarPhoto)
                {
                    if (file != null)
                    {
                        //string imageFileName = Path.GetFileName(file.FileName);
                        var binaryReader    = new BinaryReader(file.InputStream);
                        var imageBase64Data = Convert.ToBase64String(binaryReader.ReadBytes(file.ContentLength));
                        car.Photos.Add(new Photo {
                            Name = "CarPhoto", Value = imageBase64Data, CarId = car.Id,
                        });
                    }
                }
            }

            db._Cars.Add(car);
            db.SaveChanges();
            return(Redirect("/MyCars/AllCars"));
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
 public void Save()
 {
     db.SaveChanges();
     // throw new NotImplementedException();
 }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
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;
        }