private void SaveBrowserActivity(bool openBrowser) { bool isInvalid = HasErrorsForBrowser(); if (isInvalid) { AlertMessages(ref errorsForBrowser); return; } if (!String.IsNullOrEmpty(ipHostname.Text) && !String.IsNullOrEmpty(port.Text)) { BrowserLog l = new BrowserLog(); l.IpHostname = ipHostname.Text; l.Port = port.Text; l.Protocol = protocolItems.SelectedItem.ToString(); l.Project = ddlProjects.Text; l.LogDateTime = DateTime.Now; l.PenTesterIP = browserTestingIP.Text; string f = CreateFileName(Logger.LoggerTypes.browserlog.ToString(), ddlProjects.Text); projectHelper.SaveBrowserData(f, l); if (openBrowser) { CmdHelper.LaunchInternetExplorer(l); } } }
public void CreateBrowserLog(BrowserLogBinding binding) { try { using (var db = GetMainContext()) { int?deviceId = db.Devices.SingleOrDefault(x => x.ValueId == binding.DeviceId)?.Id; if (!deviceId.HasValue) { throw new ResourceNotFoundException(); } int?domainId = db.Domains.SingleOrDefault(x => x.ValueId == binding.Domain)?.Id; if (!domainId.HasValue) { var webSite = new Model.Database.Main.Net.Web() { Name = binding.Domain, ValueId = binding.Domain }; db.Webs.Add(webSite); var domain = new Domain() { ValueId = binding.Domain, WebId = webSite.Id }; db.Domains.Add(domain); domainId = domain.Id; } var browserLog = new BrowserLog() { DeviceId = deviceId.Value, DomainId = domainId.Value, TimestampStart = binding.Start, TimestampEnd = binding.End, IsSecured = binding.IsSecured }; db.BrowserLogs.Add(browserLog); db.SaveChanges(); } } catch (DbUpdateException) { throw new ResourceExistsException(nameof(BrowserLog)); } }