Example #1
0
        private void btnPrefix_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtDir.Text))
            {
                return;
            }

            var files = new List<string>(Directory.GetFiles(txtDir.Text));

            files?.ForEach(f =>
            {
                var fileInfo = new FileInfo(f);
                var newFileName = string.Format("{0}\\{1}{2}", fileInfo.Directory, txtPrefix.Text, fileInfo.Name);

                Task.Run(() => { File.Move(f, newFileName); });

                Application.DoEvents();
            });

            MessageBox.Show("Renamed Completed.");
        }
        public async Task<IHttpActionResult> PutProductGroup(long id, ProductGroupDetailsDto productGroupDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var ProductList = productGroupDetails.Products;
            List<Product> products = new List<Product>();

            foreach (var i in ProductList)
            {
                var product = from pr in db.Products where pr.Id == i select pr;
                product.ForEach(pr => products.Add(pr));
            }

            var productGroup = db.ProductGroups.Find(id);

            if (productGroup != null)
            {
                productGroup.Name = productGroupDetails.Name;
            }

            productGroup.Products.Clear();

            products?.ForEach(e=> productGroup.Products.Add(e));

            if (id != productGroup.Id)
            {
                return BadRequest();
            }

            db.Set<ProductGroup>().Attach(productGroup);
            db.Entry(productGroup).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductGroupExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PostProductGroup(ProductGroupDetailsDto productGroupDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var workwrok = productGroupDetails.Products;
            List<Product> products = new List<Product>();

            foreach (var i in workwrok)
            {
                var p = from pt in db.Products where pt.Id == i select pt;
                p.ForEach(pr => products.Add(pr));
            }

            var productGroup = new ProductGroup { Name = productGroupDetails.Name };

            products?.ForEach(e => productGroup.Products.Add(e));

            db.ProductGroups.Add(productGroup);
            await db.SaveChangesAsync();

            productGroupDetails.Id = productGroup.Id;

            return CreatedAtRoute("DefaultApi", new { id = productGroupDetails.Id }, productGroupDetails);
        }
		public static string SaveToDisk(List<string> powerLog)
		{
			try
			{
				if(!Points.Any())
					return null;
				ResolveZonePos();
				ResolveCardIds();
				RemoveObsoletePlays();

				var player = Points.Last().Data.First(x => x.IsPlayer);
				var opponent = Points.Last().Data.First(x => x.HasTag(GameTag.PLAYER_ID) && !x.IsPlayer);
				var playerHero =
					Points.Last()
					      .Data.First(
					                  x =>
					                  x.GetTag(GameTag.CARDTYPE) == (int)CardType.HERO && x.IsControlledBy(player.GetTag(GameTag.CONTROLLER)));
				var opponentHero =
					Points.Last()
					      .Data.FirstOrDefault(
					                           x =>
					                           x.GetTag(GameTag.CARDTYPE) == (int)CardType.HERO
					                           && x.IsControlledBy(opponent.GetTag(GameTag.CONTROLLER)));
				if(opponentHero == null)
				{
					//adventure bosses
					opponentHero =
						Points.Last()
						      .Data.First(
						                  x =>
						                  !string.IsNullOrEmpty(x.CardId)
						                  && ((x.CardId.StartsWith("NAX") && x.CardId.Contains("_01")) || x.CardId.StartsWith("BRMA"))
						                  && Database.GetHeroNameFromId(x.CardId) != null);

					ResolveOpponentName(Database.GetHeroNameFromId(opponentHero.CardId));
				}

				var fileName =
					$"{player.Name}({Database.GetHeroNameFromId(playerHero.CardId)}) vs {opponent.Name}({Database.GetHeroNameFromId(opponentHero.CardId)}) {DateTime.Now.ToString("HHmm-ddMMyy")}";


				if(!Directory.Exists(Config.Instance.ReplayDir))
					Directory.CreateDirectory(Config.Instance.ReplayDir);
				var path = Helper.GetValidFilePath(Config.Instance.ReplayDir, fileName, ".hdtreplay");
				using(var ms = new MemoryStream())
				{
					using(var archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
					{
						var json = archive.CreateEntry("replay.json");
						using(var stream = json.Open())
						using(var sw = new StreamWriter(stream))
							sw.Write(JsonConvert.SerializeObject(Points));

						var hsLog = archive.CreateEntry("output_log.txt");
						using(var logStream = hsLog.Open())
						using(var swLog = new StreamWriter(logStream))
							powerLog?.ForEach(swLog.WriteLine);
					}

					using(var fileStream = new FileStream(path, FileMode.Create))
					{
						ms.Seek(0, SeekOrigin.Begin);
						ms.CopyTo(fileStream);
					}
				}
				return fileName + ".hdtreplay";
			}
			catch(Exception e)
			{
				Log.Error(e);
				return null;
			}
		}
Example #5
0
        public async Task<IHttpActionResult> PostProduct(ProductDetailsDto productDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var workwrok = productDetails.ProductGroups;
            List<ProductGroup> productGroups = new List<ProductGroup>();

            foreach (var i in workwrok)
            {
                var pG = from pg in db.ProductGroups where pg.Id == i select pg;
                pG.ForEach(pg => productGroups.Add(pg));
            }

            var product = new Product(productDetails.Name, productDetails.Price, productDetails.Saleable);
            
            productGroups?.ForEach(e => product.ProductGroups.Add(e));

            db.Products.Add(product);
            await db.SaveChangesAsync();

            productDetails.Id = product.Id;

            return CreatedAtRoute("DefaultApi", new { id = productDetails.Id }, productDetails);
        }
Example #6
0
        /// <summary>
        /// Основной метод отрисовки
        /// </summary>
        /// <param name="obstacles">препятствия</param>
        /// <param name="pointsCar">машина</param>
        /// <param name="detectors">парковочные датчики машины</param>
        /// <param name="destination">конечная точка</param>
        /// <param name="road">дорога</param>
        public void RepaintMap(Rectangle[] obstacles, PointF[] pointsCar, PointF[][] detectors, Rectangle destination, Road road, List<PointF> pointsForCreatingRoad)
        {
            Image image = new Bitmap(pbMap.Width, pbMap.Height);
            Graphics next = Graphics.FromImage(image);

            if (road != null)
                DrawRoad(road, next);
            else
            {
                //При отрисовке дороги эти точки тоже отрисовываются.
                pointsForCreatingRoad?.ForEach(point => DrawPointForCreatingRoad(point, next));
            }

            if (pointsCar != null)
                DrawMap(obstacles, pointsCar, detectors, destination, next);
            if (destination != null)
                DrawDestination(destination, next);

            pbMap.Image = image;
        }
        public async Task<IHttpActionResult> PutProductType(int id, ProductTypeDetailsDto productTypeDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var ProductGroupList = productTypeDetails.ProductGroups;
            List<ProductGroup> productGroups = new List<ProductGroup>();

            foreach (var i in ProductGroupList)
            {
                var pG = from pg in db.ProductGroups where pg.Id == i select pg;
                pG.ForEach(pg => productGroups.Add(pg));
            }

            var productType = db.ProductTypes.Find(id);

            if (productType != null)
            {
                productType.Color = productTypeDetails.Color;
                productType.Name = productTypeDetails.Name;
                productType.Price = productTypeDetails.Price;
            }

            productType.ProductGroups.Clear();

            productGroups?.ForEach(e => productType.ProductGroups.Add(e));


            if (id != productType.Id)
            {
                return BadRequest();
            }

            db.Set<ProductType>().Attach(productType);
            db.Entry(productType).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductTypeExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PutProductTab(int id, ProductTabDetailsDto productTabDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var ProductTypeList = productTabDetails.ProductTypes;
            List<ProductType> productTypes = new List<ProductType>();

            foreach (var i in ProductTypeList)
            {
                var pT = from pt in db.ProductTypes where pt.Id == i select pt;
                pT.ForEach(pt => productTypes.Add(pt));
            }

            var productTab = db.ProductTabs.Find(id);

            if (productTab != null)
            {
                productTab.Active = productTabDetails.Active;
                productTab.Color = productTabDetails.Color;
                productTab.Name = productTabDetails.Name;
                productTab.Priority = productTabDetails.Priority;
            }

            productTab.ProductTypes.Clear();

            productTypes?.ForEach(e => productTab.ProductTypes.Add(e));



            if (id != productTab.Id)
            {
                return BadRequest();
            }

            db.Set<ProductTab>().Attach(productTab);
            db.Entry(productTab).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductTabExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PostProductTab(ProductTabDetailsDto productTabDetails)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var workwrok = productTabDetails.ProductTypes;
            List<ProductType> productTypes = new List<ProductType>();

            foreach (var i in workwrok)
            {
                var pT = from pt in db.ProductTypes where pt.Id == i select pt;
                pT.ForEach(pt => productTypes.Add(pt));
            }

            var productTab = new ProductTab {Active = productTabDetails.Active, Color = productTabDetails.Color, Name = productTabDetails.Name, Priority = productTabDetails.Priority};

            productTypes?.ForEach(e => productTab.ProductTypes.Add(e));

            db.ProductTabs.Add(productTab);
            await db.SaveChangesAsync();

            productTabDetails.Id = productTab.Id;

            return CreatedAtRoute("DefaultApi", new { id = productTabDetails.Id }, productTabDetails);
        }
Example #10
0
		private void UpdatePins(List<AedViewModel> aeds)
		{
			map?.Pins?.Clear();
			aeds?.ForEach(aed => {
				var pin = new Pin {
					Type = PinType.Place,
					Position = new Position(aed.AedInfo.Latitude, aed.AedInfo.Longitude),
					Label =  aed.LocationName,
				};
				map.Pins.Add(pin);
			});
		}