public async Task <IActionResult> Edit([FromRoute] int id) { if (Request.Method == "GET") { Product p = _productService.Get(id); return(View(p)); } else if (Request.Method == "POST") { ImgHandler imgHandler = new ImgHandler(); Product p = new Product(); p.Name = Request.Form["Name"]; p.Price = Double.Parse(Request.Form["Price"]); p.Description = Request.Form["Description"]; p.Category = Request.Form["Category"]; p.Stock = int.Parse(Request.Form["Stock"]); p.ProductId = id; if (Request.Form.Files.Count == 0) { p.Image = _productService.Get(id).Image; } else { p.Image = await imgHandler.CopyFileAsync(Request.Form.Files["Image"], _env.WebRootPath + "\\images\\"); } p = _productService.EditProduct(p); return(Redirect("/Product/Products")); } else { return(View()); } }
public async Task <IActionResult> Create() { if (Request.Method == "GET") { return(View()); } else if (Request.Method == "POST") { ImgHandler imgHandler = new ImgHandler(); Product product = new Product(); product.Name = Request.Form["Name"]; product.Price = Double.Parse(Request.Form["Price"]); product.Description = Request.Form["Description"]; product.Category = Request.Form["Category"]; product.Stock = int.Parse(Request.Form["Stock"]); product.Image = await imgHandler.CopyFileAsync(Request.Form.Files["Image"], _env.WebRootPath + "\\images\\"); product = _productService.CreateProduct(product); return(Redirect("/Product/Products")); } else { return(View()); } }
private bool CheckSlotPitStatus(Rectangle rec, int slotNumber) { bool canHarvest = false; string word = ImgHandler.ReadBitmap(rec); if (string.IsNullOrEmpty(word)) { word = "UNKNOWN"; } word = word.Trim().ToUpper(); Console.Write($"Status of slot {slotNumber} --> "); if (word == "LEVEL READY") { ConsoleWriter.WriteInformation(word); canHarvest = true; } else if (word == "UNKNOWN") { ConsoleWriter.WriteError("Cannot read status..."); } else if (word == "MAX LEVEL") { ConsoleWriter.WriteWarning(word); HandleMaxLevelSlotPit(slotNumber); } else if (word == @"+0 XP/HOUR") { ConsoleWriter.WriteWarning(word); HandleMaxLevelSlotPit(slotNumber); } else { Console.Write(word); } Console.WriteLine(); return(canHarvest); }
internal bool ShowBastion() { string battlePath = $"{_imgDirPath}{_imgNameBattle}"; if (!File.Exists(battlePath)) { ConsoleWriter.WriteLineError($"Cannot find file {battlePath}"); return(false); } MouseHandler.SetCursorPosition(0, 0); Bitmap bitmapTemoin = new Bitmap(battlePath); int c = 0; debut: WindowHandler.RepositionRaidWindow(raidProcessId); if (c > 20) { throw new Exception("Cannot find the bastion. Number of attempts failed."); } Bitmap bitmapTest = ImgHandler.GetBitmap(_recBattle); if (ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { KeyBoardHandler.SendKey(KEY_ESCAPE); Thread.Sleep(2000); c++; goto debut; } return(true); }
internal void CheckMarket() { string imgPath = $"{_imgDirPath}{_imgMarket}"; string word = string.Empty; Console.WriteLine("-> Starting to check the market..."); if (!File.Exists(imgPath)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPath}. Phase skipped."); Thread.Sleep(500); return; } WindowHandler.RepositionRaidWindow(raidProcessId); MouseHandler.SetCursorPosition(0, 0); Bitmap bitmapTemoin = new Bitmap(imgPath); Bitmap bitmapTest = ImgHandler.GetBitmap(_recMarket); if (!ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { ConsoleWriter.WriteLineInformation("Update detected. Let's go and search for shards !"); Console.WriteLine("Maybe later..."); //MouseHandler.MouseClick(1161, 515); Thread.Sleep(800); } else { Console.WriteLine("No update detected."); Thread.Sleep(100); } }
internal void CheckMine() { string imgPath = $"{_imgDirPath}{_imgNameMine}"; Console.WriteLine("-> Starting to check the mine..."); if (!File.Exists(imgPath)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPath}. Phase skipped."); Thread.Sleep(500); return; } WindowHandler.RepositionRaidWindow(raidProcessId); MouseHandler.SetCursorPosition(0, 0); Bitmap bitmapTemoin = new Bitmap(imgPath); Bitmap bitmapTest = ImgHandler.GetBitmap(_recMine); if (!ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { ConsoleWriter.WriteLineInformation("New gems found. Let's get them."); MouseHandler.MouseClick(823, 404); } else { Console.WriteLine("No gems found."); Thread.Sleep(100); } }
public ActionResult Index(FormCollection form) { try { int x = (int)Convert.ToDouble(form["x"]); int y = (int)Convert.ToDouble(form["y"]); int w = (int)Convert.ToDouble(form["w"]); int h = (int)Convert.ToDouble(form["h"]); string imgsrc = form["imgsrc"].Substring(0, form["imgsrc"].LastIndexOf("?")); //imgsrc 变量没用到,因为我们的Web服务器不允许访问外网,无奈改为下面的Session方法进行传值 /**正常情况将imgsrc是大图的完整路径,所以此处将imgsrc转为据对路径, *调用string path = ImgHandler.CutAvatar(imgsrc, x, y, w, h); *得到小图的路径,需要的话保存到DB */ //获取等比例缩放后的图片 string zoomedPicFullPath = Session["UploadedImgUrl_" + Session["sid"].ToString()].ToString(); try { // 根据坐标、宽高 裁剪头像,获得小图的路径 string cutImagePath = ImgHandler.CutAvatar(zoomedPicFullPath, x, y, w, h); string path = string.Empty; if (!string.IsNullOrEmpty(cutImagePath)) { // 获取裁剪后图像的Url byte[] bytes = StreamHelper.Image2ByteWithPath(cutImagePath); string finalSmallImgPath = DoUploadImageWS(bytes); //保存Path path = ImageUrl + finalSmallImgPath; ViewBag.Path = path; //把头像后半部分path保存到DB,你可能不需要 //long studentID = -1; //long.TryParse(Session["sid"].ToString(), out studentID); //studentLogic.UpdateAvatarUrl(studentID, finalSmallImgPath); return(Json(new { success = true, message = path })); } else { return(Json(new { success = false, message = "" })); } } catch (Exception ex) { return(Json(new { success = false, message = "" })); } } catch (Exception ex) { return(Json(new { success = false, message = "" })); } }
public IHttpActionResult PostImage(ImgHandler img) { var domainPath = AppDomain.CurrentDomain.BaseDirectory; //var path1 = string.Format(, imgName); var fullPath = domainPath + "Images" + @"\" + img.ImgPath + ".jpg"; var image = Image.FromStream(new MemoryStream(Convert.FromBase64String(img.ImgBase64.Remove(0, 23)))); //var path = string.Format("../../img/{0}", img.ImgPath); image.Save(fullPath); return(Ok()); }
internal void CheckThePit() { string imgPath = $"{_imgDirPath}{_imgNamePit}"; string word = string.Empty; Console.WriteLine("-> Starting to check the pit..."); if (!File.Exists(imgPath)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPath}. Phase skipped."); Thread.Sleep(500); return; } WindowHandler.RepositionRaidWindow(raidProcessId); MouseHandler.SetCursorPosition(0, 0); Bitmap bitmapTemoin = new Bitmap(imgPath); Bitmap bitmapTest = ImgHandler.GetBitmap(_recPit); if (!ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { ConsoleWriter.WriteLineInformation("The pit need intervention. Going in..."); MouseHandler.MouseClick(1571, 379); if (CheckSlotPitStatus(_recPitSlot1, 1)) { MouseHandler.MouseClick(764, 472); } if (CheckSlotPitStatus(_recPitSlot2, 2)) { MouseHandler.MouseClick(1004, 472); } if (CheckSlotPitStatus(_recPitSlot3, 3)) { MouseHandler.MouseClick(1245, 472); } if (CheckSlotPitStatus(_recPitSlot4, 4)) { MouseHandler.MouseClick(1497, 472); } if (CheckSlotPitStatus(_recPitSlot5, 5)) { MouseHandler.MouseClick(1868, 472); } } else { Console.WriteLine("No intervention needed."); Thread.Sleep(100); } }
private void HandleMaxLevelSlotPit(int slotNumber) { Thread.Sleep(500); ConsoleWriter.WriteWarning("\nTrying to swap characters..."); switch (slotNumber) { case 1: MouseHandler.MouseClick(875, 316); break; case 2: MouseHandler.MouseClick(1114, 289); break; case 3: MouseHandler.MouseClick(1340, 294); break; case 4: MouseHandler.MouseClick(1548, 319); break; case 5: MouseHandler.MouseClick(1766, 296); break; default: break; } Thread.Sleep(1500); if (ImgHandler.ReadBitmap(_recPitChooseChampionTitle).Trim().ToUpper() == "SELECT CHAMPION" || ImgHandler.AreBitmapsDifferent(ImgHandler.GetBitmap(_recPitChooseChampionTitle), new Bitmap($"{_imgDirPath}{_imgNameChampionTitle}"))) { MouseHandler.MouseClick(1008, 559); Thread.Sleep(1000); MouseHandler.MouseClick(1003, 123); Thread.Sleep(1000); MouseHandler.MouseClick(1541, 562); //KeyBoardHandler.SendKey(KEY_ESCAPE); } else { ConsoleWriter.WriteLineError($"\nCouldn't remove the champion from slot {slotNumber}.\nYou have to do it manually"); } }
internal int RunWeeklyDungeon(int nbLoop, string dungeonName, Rectangle recDungeon, string imgPathDungeon, int mouseX, int mouseY) { int compteur = 0; Console.Write($"-> Starting the {dungeonName} run "); if (nbLoop != 0) { Console.Write($"({nbLoop} run left)"); } Console.WriteLine(); Thread.Sleep(1000); if (GoToDungeonMap()) { Console.WriteLine($"---> Entering the {dungeonName}..."); Thread.Sleep(1000); if (!File.Exists(imgPathDungeon)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPathDungeon}. Run skipped."); return(0); } Bitmap btmDungeon = new Bitmap(imgPathDungeon); Bitmap btmTest = ImgHandler.GetBitmap(recDungeon); if (!ImgHandler.AreBitmapsDifferent(btmDungeon, btmTest, RaidOptions.SavePicturesAllowed)) { MouseHandler.MouseClick(mouseX, mouseY); Thread.Sleep(1000); compteur = AutoBattleForKeeps(nbLoop, compteur, dungeonName); } else { ConsoleWriter.WriteLineWarning($"The {dungeonName} is not available. Run skipped."); return(0); } } if (nbLoop != 0) { return(nbLoop - compteur); } else { return(nbLoop); } }
private bool GoToCampaignMap() { if (!ShowBastion()) { return(false); } KeyBoardHandler.SendKey(KEY_ENTER); if (!(ImgHandler.ReadBitmap(_recDungeonTitle).ToUpper() == "DUNGEONS")) { ConsoleWriter.WriteLineError("Cannot find the campaign. Abort."); return(false); } else { Console.WriteLine("--> Entering the campaign map..."); Thread.Sleep(1000); MouseHandler.MouseClick(812, 321); return(true); } }
private ImagePair SaveFile(HttpPostedFileBase file) { ImagePair imagePair = null; var imgMax = Image.FromStream(file.InputStream); var attachMaxPath = @"\Storage\Chat\" + Guid.NewGuid() + ".png"; var resMax = ImgHandler.SaveImage(imgMax, Server.MapPath("~") + attachMaxPath); var imgMini = ImgHandler.CreateMiniImage(imgMax, 128, 128); var attachMinPath = @"\Storage\Chat\" + Guid.NewGuid() + ".png"; var resMin = ImgHandler.SaveImage(imgMini, Server.MapPath("~") + attachMinPath); if (resMax && resMin) { imagePair = new ImagePair { Small = attachMinPath, Large = attachMaxPath } } ; return(imagePair); } }
private int AutoBattleForKeeps(int nbLoop, int compteur, string keepName) { MouseHandler.MouseWheelDown(25); Thread.Sleep(500); MouseHandler.MouseClick(1803, 380); ConsoleWriter.CountDown("Starting battle in {0} ", _battleCountDown); MouseHandler.MouseClick(1790, 550); DateTime dateStart = DateTime.Now; TimeSpan t; Bitmap bmpReplay = new Bitmap($"{_imgDirPath}{_imgNameReplay}"); Bitmap bmpLvlUp = new Bitmap($"{_imgDirPath}{_imgNameLevelUp}"); compteur++; do { WindowHandler.RepositionRaidWindow(raidProcessId); Thread.Sleep(500); var bmpTestReplay = ImgHandler.GetBitmap(_recReplay); var bmpTestLvlUp = ImgHandler.GetBitmap(_recLevelUp); if (!ImgHandler.AreBitmapsDifferent(bmpReplay, bmpTestReplay, RaidOptions.SavePicturesAllowed)) { t = DateTime.Now - dateStart; ConsoleWriter.KeepAwake(); if ((t.TotalMinutes > 20) && (RaidOptions.CheckMineAllowed || RaidOptions.CheckPitAllowed || RaidOptions.CheckRewardsAllowed)) { Console.Write("\nPausing the battle to check the bastion..."); Thread.Sleep(800); break; } if ((nbLoop != 0) && (compteur >= nbLoop)) { Console.Write("\nMax number of allowed battle reached..."); //switch (keepName) //{ // case "magic keep": // RaidOptions.MagicKeepAllowed = false; // break; // case "void keep": // RaidOptions.VoidKeepAllowed = false; // break; // case "spirit keep": // RaidOptions.SpiritKeepAllowed = false; // break; // case "force keep": // RaidOptions.ForceKeepAllowed = false; // break; // case "arcane keep": // RaidOptions.ArcaneKeepAllowed = false; // break; // default: // throw new ArgumentNullException($"Cannot find the keep '{keepName}' !"); //} break; } KeyBoardHandler.SendKey(KEY_R); compteur++; Thread.Sleep(1000); } else if (!ImgHandler.AreBitmapsDifferent(bmpLvlUp, bmpTestLvlUp, RaidOptions.SavePicturesAllowed)) { KeyBoardHandler.SendKey(KEY_ESCAPE); } if (nbLoop != 0) { Console.Write($"\r=> Starting run {compteur}/{nbLoop} "); } else { Console.Write($"\r=> Starting run {compteur} "); } Thread.Sleep(_battleIdle); } while (true); Console.WriteLine(); return(compteur); }
internal int RunDurhamForest(int nbLoop) { int compteur = 0; DateTime dateStart = DateTime.Now; TimeSpan t; Bitmap bmpReplay = new Bitmap($"{_imgDirPath}{_imgNameReplay}"); Bitmap bmpLvlUp = new Bitmap($"{_imgDirPath}{_imgNameLevelUp}"); Console.Write("-> Starting the Durham Forest run "); if (nbLoop != 0) { Console.Write($"({nbLoop} run left)"); } Console.WriteLine(); Thread.Sleep(1000); if (GoToCampaignMap()) { Console.WriteLine("---> Entering durham forest..."); Thread.Sleep(1000); MouseHandler.MouseDrag(1767, 327, 905, 467); Thread.Sleep(2000); MouseHandler.MouseClick(1239, 271); Thread.Sleep(2000); MouseHandler.MouseClick(1815, 130); ConsoleWriter.CountDown("Starting battle in {0} ", _battleCountDown); MouseHandler.MouseClick(1790, 550); compteur++; do { Thread.Sleep(1000); WindowHandler.RepositionRaidWindow(raidProcessId); Thread.Sleep(500); var bmpTestReplay = ImgHandler.GetBitmap(_recReplay); var bmpTestLvlUp = ImgHandler.GetBitmap(_recLevelUp); if (!ImgHandler.AreBitmapsDifferent(bmpReplay, bmpTestReplay, RaidOptions.SavePicturesAllowed)) { t = DateTime.Now - dateStart; ConsoleWriter.KeepAwake(); if ((t.TotalMinutes > 20) && (RaidOptions.CheckMineAllowed || RaidOptions.CheckPitAllowed || RaidOptions.CheckRewardsAllowed)) { Console.Write("\nPausing the battle to check the bastion..."); Thread.Sleep(800); break; } if ((nbLoop != 0) && (compteur >= nbLoop)) { Console.Write("\nMax number of allowed battle reached..."); RaidOptions.DurhamForestAllowed = false; break; } KeyBoardHandler.SendKey(KEY_R); compteur++; Thread.Sleep(1000); } else if (!ImgHandler.AreBitmapsDifferent(bmpLvlUp, bmpTestLvlUp, RaidOptions.SavePicturesAllowed)) { KeyBoardHandler.SendKey(KEY_ESCAPE); } if (nbLoop != 0) { Console.Write($"\r=> Starting run {compteur}/{nbLoop} "); } else { Console.Write($"\r=> Starting run {compteur} "); } Thread.Sleep(_battleIdle); } while (true); Console.WriteLine(); } if (nbLoop != 0) { return(nbLoop - compteur); } else { return(nbLoop); } }
public ActionResult ProcessUpload(string qqfile) { try { string UploadedImgUrl = string.Empty; //由于应用所在目录会经常切换,所以固定上传到D盘 string uploadFolder = @"D:\UploadImages\original\" + DateTime.Now.ToString("yyyyMM") + "\\"; string imgName = DateTime.Now.ToString("ddHHmmssff"); string imgType = qqfile.Substring(qqfile.LastIndexOf(".")); string uploadPath = string.Empty; //uploadPath = Server.MapPath(uploadFolder); uploadPath = uploadFolder; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } System.Web.HttpBrowserCapabilitiesBase browser = Request.Browser; string BrowType = browser.Browser.ToLower(); if (BrowType == "ie") //IE特殊处理 { string fileName = Request.Files["qqfile"].FileName; imgType = fileName.Substring(fileName.LastIndexOf(".")); using (var inputStream = Request.Files["qqfile"].InputStream) { using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create)) { // 保存上传图片 inputStream.CopyTo(flieStream); } } } else { using (var inputStream = Request.InputStream) { using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create)) { // 保存上传图片 inputStream.CopyTo(flieStream); } } } // 将大图上传到Image Server, 得到大图 UploadedImgUrl // 这步可根据实际情况修改 string largeImgFullPath = uploadPath + imgName + imgType; byte[] bytes = StreamHelper.Image2ByteWithPath(largeImgFullPath); string largeImagePath = DoUploadImageWS(bytes); UploadedImgUrl = ImageUrl + largeImagePath; try { //等比例缩放图片 string zoomedPicFullPath = uploadPath + imgName + "_new" + imgType; // 获取等比例缩放 UploadedImgUrl 后的图片路径 Image newImg = ImgHandler.ZoomPicture(StreamHelper.ImagePath2Img(largeImgFullPath), 400, 400); newImg.Save(zoomedPicFullPath); byte[] bytesNew = StreamHelper.Image2ByteWithPath(zoomedPicFullPath); string largeImagePathNew = DoUploadImageWS(bytesNew); // DoUploadImageWS 为上传图片服务器器方法 UploadedImgUrl = ImageUrl + largeImagePathNew; //保存起来,供裁剪时用 Session["UploadedImgUrl_" + Session["sid"].ToString()] = zoomedPicFullPath; } catch (Exception ex) { //LogHelper.WriteError("校园大使任务中心 等比例缩放图片错误:", ex); } return(Json(new { success = true, message = UploadedImgUrl }, "text/plain", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { fail = true, message = ex.Message }, "text/plain", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } }
internal void CheckPlaytimeRewards() { //daily playtime reward string imgPath = $"{_imgDirPath}{_imgNameReward}"; Console.WriteLine("-> Starting to check the playtime rewards..."); if (!File.Exists(imgPath)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPath}. Phase skipped."); return; } WindowHandler.RepositionRaidWindow(raidProcessId); MouseHandler.SetCursorPosition(0, 0); Bitmap bitmapTemoin = new Bitmap(imgPath); Bitmap bitmapTest = ImgHandler.GetBitmap(_recReward); //bitmapTest.Save("RewardRedDot.bmp"); Thread.Sleep(100); if (!ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { ConsoleWriter.WriteLineInformation("Playtime rewards found. Let's get them."); MouseHandler.MouseClick(1853, 486); Thread.Sleep(100); MouseHandler.MouseClick(1038, 404); Thread.Sleep(100); MouseHandler.MouseClick(1148, 399); Thread.Sleep(100); MouseHandler.MouseClick(1259, 403); Thread.Sleep(100); MouseHandler.MouseClick(1370, 406); Thread.Sleep(100); MouseHandler.MouseClick(1474, 399); Thread.Sleep(100); MouseHandler.MouseClick(1591, 402); Thread.Sleep(100); } else { Console.WriteLine("No rewards found."); Thread.Sleep(100); } ShowBastion(); //daily login rewards imgPath = $"{_imgDirPath}{_imgDailyReward}"; Console.WriteLine("-> Starting to check the daily login rewards..."); if (!File.Exists(imgPath)) { ConsoleWriter.WriteLineWarning($"Cannot find file {imgPath}. Phase skipped."); Thread.Sleep(500); return; } WindowHandler.RepositionRaidWindow(raidProcessId); MouseHandler.SetCursorPosition(0, 0); bitmapTemoin = new Bitmap(imgPath); bitmapTest = ImgHandler.GetBitmap(_recDailyReward); if (!ImgHandler.AreBitmapsDifferent(bitmapTemoin, bitmapTest, RaidOptions.SavePicturesAllowed)) { Console.WriteLine("Daily rewards found. Let's go get them."); MouseHandler.MouseClick(717, 314); MouseHandler.MouseClick(744, 110); KeyBoardHandler.SendKey(KEY_ESCAPE); } else { Console.WriteLine("No rewards found."); Thread.Sleep(500); } }