Пример #1
0
        public string MakePortReplace(DCIMModel info)
        {
            string        base64String = string.Empty;
            ServerPortDtl port         = _dbContext.ServerPortDtl.Where(a => a.Id == info.SPort).FirstOrDefault();
            PortMaster    portMaster   = _dbContext.PortMaster.Where(e => e.Id == info.DPort).FirstOrDefault();
            Server        server       = _dbContext.Server.Where(e => e.Id == info.SServer).FirstOrDefault();
            Bitmap        src          = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + server.ImagePath) as Bitmap;
            Bitmap        dest         = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + portMaster.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(port.Xcoordinate, port.Ycoordinate), new Size(port.RectangleXcoordinate, port.RectangleYcoordinate)),
                                   new Rectangle(0, 0, dest.Width, dest.Height),
                                   GraphicsUnit.Pixel);
            }
            string filePath = server.ImagePath;

            src.Dispose();
            target.Save(_hostingEnvironment.ContentRootPath + filePath);
            dest.Dispose();


            base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(_hostingEnvironment.ContentRootPath + filePath));
            port.Port    = portMaster.PortName;
            _dbContext.ServerPortDtl.Update(port);
            _dbContext.SaveChanges();
            return(base64String);
        }
Пример #2
0
        public string MakePath(DCIMModel info)
        {
            string msg = string.Empty;
            var    rec = _dbContext.Connections.Where(e =>
                                                      e.SourcePortId == info.SPort
                                                      ).FirstOrDefault();

            if (rec == null)
            {
                Connections connections = new Connections()
                {
                    DestinationPortId   = info.DPort,
                    DestinationRackId   = info.DRack,
                    DestinationServerId = info.DServer,
                    SourcePortId        = info.SPort,
                    SourceRackId        = info.SRack,
                    SourceServerId      = info.SServer,
                    DestinationSlotId   = info.DSlot,
                    SourceSlotId        = info.SSlot
                };
                _dbContext.Connections.Add(connections);
                _dbContext.SaveChanges();
            }
            else
            {
                msg = "Selected source port is already connected to different destination port. Please disconenct the previous connection and Try again.";
            }
            return(msg);
        }
Пример #3
0
        public string GetReplacePortImage(DCIMModel info)
        {
            string base64String = string.Empty;
            string Image        = _dbContext.PortMaster.Where(e => e.Id == info.DPort).Select(e => e.ImagePath).FirstOrDefault();
            string ImagePath    = _hostingEnvironment.ContentRootPath + Image;

            base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(ImagePath));
            return(base64String);
        }
Пример #4
0
        public string GetServerImage(DCIMModel info, bool IsDRack)
        {
            string base64String = string.Empty;
            int    rackId       = IsDRack ? info.DRack : info.SRack;
            int    serverId     = IsDRack ? info.DServer : info.SServer;
            var    rackRec      = _dbContext.Rack.Where(e => e.Id == rackId).FirstOrDefault();
            var    serverRec    = _dbContext.Server.Where(e => e.Id == serverId).FirstOrDefault();

            if (rackRec != null)
            {
                string ImagePath = _hostingEnvironment.ContentRootPath + rackRec.ImagePath;
                var    fileName  = Path.GetFileName(ImagePath);
                byte[] fileBytes = System.IO.File.ReadAllBytes(ImagePath);
                var    server    = _dbContext.Server.Where(e => e.Id == serverRec.Id).ToList();
                if (server.Count > 0)
                {
                    using (MemoryStream stream = new MemoryStream(fileBytes))
                    {
                        Bitmap bmp = new Bitmap(stream);
                        for (int i = 0; i < bmp.Width; i++)
                        {
                            for (int j = 0; j < bmp.Height; j++)
                            {
                                foreach (var p in server)
                                {
                                    Pen pen = new Pen(Color.Red, 5);
                                    if (p.Id == serverId)
                                    {
                                        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);
                                    }

                                    i++;
                                }
                            }
                        }
                        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);
        }
Пример #5
0
 public IActionResult GetSlotImage(DCIMModel dCIMModel)
 {
     return(Ok(_service.GetServerSlotImage(dCIMModel, false)));
 }
Пример #6
0
        public IActionResult InsertSlotDetails(DCIMModel dCIMModel)
        {
            var data = _service.InsertSlotDetails(dCIMModel);

            return(Ok(data.Item2));
        }
Пример #7
0
 public IActionResult MakePath(DCIMModel info)
 {
     return(Ok(_service.MakePath(info)));
 }
Пример #8
0
 public String GetServerSPortImage(DCIMModel info)
 {
     return(_service.GetServerPortImage(info, false));
 }
Пример #9
0
 public String GetServerDPortImage(DCIMModel info)
 {
     return(_service.GetServerPortImage(info, true));
 }
Пример #10
0
        public (int, string) InsertSlotDetails(DCIMModel dCIMModel)
        {
            var dSlot = _dbContext.SlotMaster
                        .Where(a => a.Id == dCIMModel.DSlot).FirstOrDefault();
            var dSlotPorts = _dbContext.SlotPort
                             .Where(a => a.SlotId == dCIMModel.DSlot).ToList();
            var sSlot = _dbContext.ServerSlotDtl
                        .Where(a => a.Id == dCIMModel.SSlot).FirstOrDefault();
            var sPortDtl = _dbContext.ServerPortDtl
                           .Where(a => a.ServerSlotDtlId == dCIMModel.SSlot).ToList();
            var Server = _dbContext.Server
                         .Where(a => a.Id == dCIMModel.SServer).FirstOrDefault();
            //this needs to be revisited
            float maxWidth  = dSlot.RectangleXcoordinate;
            float minWidth  = sSlot.RectangleXcoordinate;
            float maxHeight = dSlot.RectangleYcoordinate;
            float minHeight = sSlot.RectangleYcoordinate;
            float widthDiv  = maxWidth / minWidth;
            float heightDiv = maxHeight / minHeight;

            if (sPortDtl.Count > 0)
            {
                _dbContext.RemoveRange(sPortDtl);
                dSlotPorts.ForEach(a =>
                {
                    ServerPortDtl ServerPortDtl        = new ServerPortDtl();
                    ServerPortDtl.Xcoordinate          = Convert.ToInt32(a.Xcoordinate / widthDiv) + sSlot.Xcoordinate;
                    ServerPortDtl.Ycoordinate          = Convert.ToInt32(a.Ycoordinate / heightDiv) + sSlot.Ycoordinate;
                    ServerPortDtl.RectangleXcoordinate = Convert.ToInt32(a.RectangleXcoordinate.Value / widthDiv);
                    ServerPortDtl.RectangleYcoordinate = Convert.ToInt32(a.RectangleYcoordinate.Value / heightDiv);
                    ServerPortDtl.Port            = a.PortName;
                    ServerPortDtl.ServerId        = sSlot.ServerId.Value;
                    ServerPortDtl.ServerSlotDtlId = sSlot.Id;
                    ServerPortDtl.Description     = "desc";
                    _dbContext.Add(ServerPortDtl);
                });
            }
            else
            {
                dSlotPorts.ForEach(a =>
                {
                    ServerPortDtl ServerPortDtl        = new ServerPortDtl();
                    ServerPortDtl.Xcoordinate          = Convert.ToInt32(a.Xcoordinate / widthDiv) + sSlot.Xcoordinate;
                    ServerPortDtl.Ycoordinate          = Convert.ToInt32(a.Ycoordinate / heightDiv) + sSlot.Ycoordinate;
                    ServerPortDtl.RectangleXcoordinate = Convert.ToInt32(a.RectangleXcoordinate.Value / widthDiv);
                    ServerPortDtl.RectangleYcoordinate = Convert.ToInt32(a.RectangleYcoordinate.Value / heightDiv);
                    ServerPortDtl.Port            = a.PortName;
                    ServerPortDtl.ServerId        = sSlot.ServerId.Value;
                    ServerPortDtl.ServerSlotDtlId = sSlot.Id;
                    ServerPortDtl.Description     = "desc";
                    _dbContext.Add(ServerPortDtl);
                });
            }
            Bitmap src1    = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + Server.ImagePath) as Bitmap;
            Bitmap dest1   = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + dSlot.ImagePath) as Bitmap;
            var    target1 = new Bitmap(src1.Width, src1.Height, PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(target1))
            {
                graphics.DrawImage(src1, new Rectangle(new Point(), src1.Size),
                                   new Rectangle(new Point(), src1.Size), GraphicsUnit.Pixel);
                graphics.DrawImage(dest1, new Rectangle(new Point(sSlot.Xcoordinate, sSlot.Ycoordinate),
                                                        new Size(sSlot.RectangleXcoordinate, sSlot.RectangleYcoordinate)),
                                   new Rectangle(0, 0, dest1.Width, dest1.Height),
                                   GraphicsUnit.Pixel);
                graphics.Dispose();
                src1.Dispose();
            }
            string filePath1 = Server.ImagePath;
            int    success   = 0;

            success = _dbContext.SaveChanges();
            target1.Save(_hostingEnvironment.ContentRootPath + filePath1);
            dest1.Dispose();
            string base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(_hostingEnvironment.ContentRootPath + filePath1));

            return(success, base64String);
        }
Пример #11
0
        public string GetServerPortImage(DCIMModel info, bool isDport)
        {
            string             base64String = string.Empty;
            int                slotId       = isDport ? info.DServer : info.SServer;
            int                portId       = isDport ? info.DPort : info.SPort;
            var                slotRec      = _dbContext.Server.Where(e => e.Id == slotId).FirstOrDefault();
            List <Connections> connections  = new List <Connections>();

            if (isDport)
            {
                connections = _dbContext.Connections.Where(e => e.DestinationServerId == info.DServer).ToList();
            }
            else
            {
                connections = _dbContext.Connections.Where(e => e.SourceServerId == info.SServer).ToList();
            }
            if (slotRec != null)
            {
                string ImagePath = _hostingEnvironment.ContentRootPath + slotRec.ImagePath;
                var    fileName  = Path.GetFileName(ImagePath);
                byte[] fileBytes = System.IO.File.ReadAllBytes(ImagePath);
                var    ports     = _dbContext.ServerPortDtl.Where(e => e.ServerId == slotRec.Id).ToList();
                if (ports.Count > 0)
                {
                    using (MemoryStream stream = new MemoryStream(fileBytes))
                    {
                        Bitmap bmp = new Bitmap(stream);
                        for (int i = 0; i < bmp.Width; i++)
                        {
                            for (int j = 0; j < bmp.Height; j++)
                            {
                                foreach (var p in ports)
                                {
                                    Pen pen = new Pen(Color.Red, 5);
                                    if (isDport)
                                    {
                                        var connected = connections.Where(e => e.DestinationPortId == p.Id).FirstOrDefault();
                                        if (connected != null)
                                        {
                                            pen = new Pen(Color.Blue, 5);
                                        }
                                    }
                                    else
                                    {
                                        var connected = connections.Where(e => e.SourcePortId == p.Id).FirstOrDefault();
                                        if (connected != null)
                                        {
                                            pen = new Pen(Color.Blue, 5);
                                        }
                                    }
                                    if (p.Id == portId)
                                    {
                                        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);
                                    }

                                    i++;
                                }
                            }
                        }
                        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);
        }
Пример #12
0
        public IActionResult ServerPortView(DCIMModel dCIMModel)
        {
            var data = _service.ServerPortView(dCIMModel, false);

            return(Ok(data));
        }
Пример #13
0
 public IActionResult MakePortReplace(DCIMModel info)
 {
     return(Ok(_service.MakePortReplace(info)));
 }
Пример #14
0
 public String GetReplacePortImage(DCIMModel info)
 {
     return(_service.GetReplacePortImage(info));
 }