public string MapServerToRack(RackServerMap rackServerMap) { string base64String = string.Empty; var rack = _dbContext.Rack.Where(e => e.Id == rackServerMap.Rack).FirstOrDefault(); var rackUnit = _dbContext.RackUnit.Where(e => e.Id == rackServerMap.RackUnit).FirstOrDefault(); var server = _dbContext.Server.Where(e => e.Id == rackServerMap.Server).FirstOrDefault(); if (server != null) { Bitmap src = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + rack.ImagePath) as Bitmap; Bitmap dest = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + server.ImagePath) as Bitmap; var target = new Bitmap(src.Width, src.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(target)) { graphics.DrawImage(src, new Rectangle(new Point(), src.Size), new Rectangle(new Point(), src.Size), GraphicsUnit.Pixel); graphics.DrawImage(dest, new Rectangle(new Point(rackUnit.Xcoordinate, rackUnit.Ycoordinate), new Size(rackUnit.RectangleXcoordinate, rackUnit.RectangleYcoordinate)), new Rectangle(0, 0, dest.Width, dest.Height), GraphicsUnit.Pixel); } string filePath = rack.ImagePath; src.Dispose(); target.Save(_hostingEnvironment.ContentRootPath + filePath); dest.Dispose(); base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(_hostingEnvironment.ContentRootPath + filePath)); server.RackId = rackServerMap.Rack; server.RackUnitId = rackServerMap.RackUnit; _dbContext.Update(server); _dbContext.SaveChanges(); } return(base64String); }
public string GetNotMappedServerImage(RackServerMap info) { string base64String = string.Empty; var rackRec = _dbContext.Server.Where(e => e.Id == info.Server).FirstOrDefault(); if (rackRec != null) { string ImagePath = _hostingEnvironment.ContentRootPath + rackRec.ImagePath; base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(ImagePath)); } return(base64String); }
public string GetRackUnitImage(RackServerMap info) { string base64String = string.Empty; int rackId = info.Rack; int rackUnitId = info.RackUnit; var rackRec = _dbContext.Rack.Where(e => e.Id == rackId).FirstOrDefault(); if (rackRec != null) { string ImagePath = _hostingEnvironment.ContentRootPath + rackRec.ImagePath; var fileName = Path.GetFileName(ImagePath); byte[] fileBytes = System.IO.File.ReadAllBytes(ImagePath); var rackUnit = _dbContext.RackUnit.Where(e => e.Id == rackUnitId).ToList(); if (rackUnit.Count > 0) { using (MemoryStream stream = new MemoryStream(fileBytes)) { Bitmap bmp = new Bitmap(stream); { foreach (var p in rackUnit) { Pen pen = new Pen(Color.Red, 5); if (p.Id == rackUnitId) { pen = new Pen(Color.Yellow, 5); } Rectangle rect = new Rectangle(p.Xcoordinate, p.Ycoordinate, p.RectangleXcoordinate, p.RectangleYcoordinate); using (Graphics G = Graphics.FromImage(bmp)) { G.DrawRectangle(pen, rect); } } bmp.Save(@"C:\temp\" + fileName, ImageFormat.Png); // ImageFormat.Jpeg, etc } string path = @"c:\temp\" + fileName; base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(path)); //System.IO.File.Delete(path); } } } return(base64String); }
public IActionResult GetRackUnitImage(RackServerMap rackServerMap) { return(Ok(_service.GetRackUnitImage(rackServerMap))); }
public IActionResult GetNotMappedServerImage(RackServerMap rackServerMap) { return(Ok(_service.GetNotMappedServerImage(rackServerMap))); }
public IActionResult MapServerToRack(RackServerMap rackServerMap) { return(Ok(_service.MapServerToRack(rackServerMap))); }