public HttpResponseMessage Update(HttpRequestMessage request, LogEntryViewModel logentry) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray()); } else { LogEntry _logentry = _logentriesRepository.GetSingle(logentry.ID); if (_logentry == null) { response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid LogEntry."); } else { _logentry.UpdateLogEntry(logentry); logentry.LogEntryImage = _logentry.LogEntryImage; _logentriesRepository.Edit(_logentry); _unitOfWork.Commit(); response = request.CreateResponse(HttpStatusCode.OK, logentry); } } return response; })); }
//[ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "ID,Hours,Project,Employee")] LogEntryViewModel logEntry) { if (ModelState.IsValid) { var Empls = db.Employees.ToList(); var Projs = db.Projects.ToList(); var Employee = db.Employees.Find(logEntry.Employee); var Project = db.Projects.Find(logEntry.Project); if (Employee == null) { ModelState.AddModelError("Employee", "You must choose an employee to submit time"); return(View(logEntry)); } else if (Project == null) { ModelState.AddModelError("Project", "You must choose an project to submit time"); return(View(logEntry)); } else { db.EntryLogs.Add(new LogEntry() { CreatedDate = DateTime.Now, Hours = logEntry.Hours, Project = Project, Employee = Employee }); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(logEntry)); }
private LogEntryViewModel BuildLogEntryViewModel(LogEntity entity) { var model = new LogEntryViewModel(); if (entity != null) { model.InjectFrom(entity); if (!string.IsNullOrWhiteSpace(entity.Properties)) { var xDoc = new XmlDocument(); xDoc.LoadXml(entity.Properties); var nodes = xDoc.FirstChild.SelectNodes("property"); foreach (XmlNode node in nodes) { model.Properties.Add( node.Attributes["key"].Value, node.InnerText ); } } } return(model); }
//public LogEntry GetLogEntry(int logEntryId, string userName, string applicationName) //{ // LogEntry logEntry = null; // string logMessage = "Obteniendo un LogEntry"; // try // { // logEntry = db.LogEntries.Where(l => l.LogEntryId == logEntryId).Include(lg => lg.LogCategory).Include(log => log.LogLevel).FirstOrDefault(); // } // catch (Exception ex) // { // commonSecurityService.SaveLogEntry("ERR", // "Critical", // ex, // logMessage, // logEntryId.ToString(), userName, applicationName // ); // logEntry = null; // return logEntry; // } // return logEntry; //} //public List<LogEntry> GetLogEntries(string userName, string applicationName) //{ // List<LogEntry> logEntries = null; // string logMessage = "Listar todos los LogEntries"; // try // { // logEntries = db.LogEntries.Include(p => p.LogCategory).Include(p => p.LogLevel).ToList(); // } // catch (Exception ex) // { // commonSecurityService.SaveLogEntry("ERR", // "Critical", // ex, // logMessage, // string.Empty, userName, applicationName // ); // logEntries = null; // return logEntries; // } // return logEntries; //} //public List<LogEntry> GetLogEntries(DateTime startDate, DateTime FechaFin, string userName, string applicationName) //{ // List<LogEntry> logEntries = null; // string logMessage = string.Format("Listar los LogEntries comprendidos entre: {0} y {1}", startDate.ToString(), FechaFin.ToString()); // try // { // logEntries = db.LogEntries.Where(l => DateTime.Compare(l.LogDate.Date, startDate.Date) <= 0 && DateTime.Compare(FechaFin.Date, l.LogDate.Date) >= 0).Include(lg => lg.LogCategory).Include(log => log.LogLevel).ToList(); // } // catch (Exception ex) // { // commonSecurityService.SaveLogEntry("ERR", // "Critical", // ex, // logMessage, // string.Empty, userName, applicationName // ); // logEntries = null; // return logEntries; // } // return logEntries; //} //public List<LogEntry> GetLogEntriesByParameter(string parametro) //{ // switch (parametro) // { // case "ApplicationName": // return (new List<LogEntry>(db.LogEntries.GroupBy(x => x.ApplicationName).Select(g => g.First()))); // case "MachineIP": // return (new List<LogEntry>(db.LogEntries.GroupBy(x => x.MachineIP).Select(g => g.First()))); // case "UserName": // return (new List<LogEntry>(db.LogEntries.GroupBy(x => x.UserName).Select(g => g.First()))); // case "MachineName": // return (new List<LogEntry>(db.LogEntries.GroupBy(x => x.MachineName).Select(g => g.First()))); // default: // return null; // } //} //public async Task<List<LogEntry>> GetListaFiltradaLogEntry(int LogLevelId, int LogCategoryId, string ApplicationName, string MachineIP, string UserName, string MachineName) //{ // // return (new List<LogEntry>(db.LogEntries.Where(x => x.LogLevel.LogLevelId == LogLevelId && x.ApplicationName == ApplicationName && x.MachineIP == MachineIP && x.UserName == UserName && x.MachineName == MachineName))); // return await ((db.LogEntries. // Where(x => (x.LogLevel.LogLevelId == LogLevelId || LogLevelId == 0) // && (x.LogCategoryId == LogCategoryId || LogCategoryId == 0) // && (x.ApplicationName == ApplicationName || ApplicationName == null) // && (x.MachineIP == MachineIP || MachineIP == null) // && (x.UserName == UserName || UserName == null) // && (x.MachineName == MachineName || MachineName == null))).ToListAsync()); //} public async Task <List <LogEntry> > GetLogEntryFiltrado(LogEntryViewModel LogEntryViewModel) { var lista = new List <LogEntry>(); try { using (HttpClient cliente = new HttpClient()) { var request = JsonConvert.SerializeObject(LogEntryViewModel); var content = new StringContent(request, Encoding.UTF8, "application/json"); cliente.BaseAddress = new Uri("http://localhost:61615"); var url = "/api/LogEntries/ListaFiltradaLogEntry"; var respuesta = await cliente.PostAsync(url, content); var result = await respuesta.Content.ReadAsStringAsync(); lista = JsonConvert.DeserializeObject <List <LogEntry> >(result); return(lista); } } catch (Exception) { return(lista); throw; } }
public async Task <List <LogEntry> > GetListaFiltradaLogEntry([FromBody] LogEntryViewModel LogEntryViewModel) { var DateStart = LogEntryViewModel.LogDateStart.HasValue ? LogEntryViewModel.LogDateStart : null; var DateFinish = LogEntryViewModel.LogDateFinish.HasValue ? LogEntryViewModel.LogDateFinish : null; try { return(await((db.LogEntries. Where(x => (x.LogLevel.LogLevelId == LogEntryViewModel.LogLevelId || LogEntryViewModel.LogLevelId == 0) && (x.LogCategoryId == LogEntryViewModel.LogCategoryId || LogEntryViewModel.LogCategoryId == 0) && (x.ApplicationName.Contains(LogEntryViewModel.ApplicationName) || LogEntryViewModel.ApplicationName == null) && (x.MachineIP.Contains(LogEntryViewModel.MachineIP) || LogEntryViewModel.MachineIP == null) && (x.UserName.Contains(LogEntryViewModel.UserName) || LogEntryViewModel.UserName == null) && (x.LogDate.Date >= DateStart || DateStart == null) && (x.LogDate.Date <= DateFinish || DateFinish == null) && (x.MachineName.Contains(LogEntryViewModel.MachineName) || LogEntryViewModel.MachineName == null))).OrderByDescending(x => x.LogDate).ToListAsync())); } catch (Exception ex) { await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.Logs), ExceptionTrace = ex, Message = Mensaje.Excepcion, LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "", }); return(new List <LogEntry>()); } }
public ActionResult GetLogEntry(Int32?Id) { //https://msdn.microsoft.com/en-us/data/jj574232.aspx LogEntry _entry = null; LogEntryViewModel _dataItem = null; if (Id == null) { ModelState.AddModelError(string.Empty, $"No specific Log ID provided."); return(JsonFormResponse()); } else { using (DBManager db = new DBManager()) { _entry = db.getConnection().Query <LogEntry>($"select * from Logs where id={Id}").SingleOrDefault(); } if (_entry == null) { ModelState.AddModelError(string.Empty, $"Log Entry [{Id.ToString()}] not found. Please try again."); return(JsonFormResponse()); } _dataItem = new LogEntryViewModel(_entry); } return(new JsonNetResult() { Data = new { item = _dataItem }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
private void showMatchingRuleAndDetails(DataGrid grid, DataGridCell cell) { LogEntryViewModel selectedEntry = (LogEntryViewModel)grid.SelectedItem; if (selectedEntry != null && Reason.Equals(cell.Column) && cell.IsFocused && cell.IsSelected) { // Filter which blocked the connection NetshHelper.FilterResult blockingFilter = NetshHelper.getBlockingFilter(int.Parse(selectedEntry.FilterId), refreshData: RefreshFilterData); RefreshFilterData = false; string blockingFilterDetails = blockingFilter != null ? $"\n-----------------------------------------\nFilter rule which triggered the event:\n\t{selectedEntry.FilterId}: {blockingFilter.name} - {blockingFilter.description}\n" : "\n\n... No filter rule found ..."; //// Other matching filters for process //IEnumerable<FirewallHelper.Rule> rules = FirewallHelper.GetMatchingRulesForEvent(int.Parse(selectedEntry.Pid), selectedEntry.Path, selectedEntry.TargetIP, selectedEntry.TargetPort, blockOnly: false, outgoingOnly: false); //string reasonDetails = $"\nMatching Rules for | {selectedEntry.FileName} | {selectedEntry.Pid} | {selectedEntry.TargetIP}:{selectedEntry.TargetPort} |"; //foreach (FirewallHelper.Rule rule in rules.Take(10)) //{ // reasonDetails += $"\n'{rule.Name}' | {rule.ActionStr} | {rule.DirectionStr} | {rule.AppPkgId} | profile={rule.ProfilesStr} | svc={rule.ServiceName} | {System.IO.Path.GetFileName(rule.ApplicationName)}"; //} //if (rules.Count() > 10) //{ // reasonDetails += "\n...more..."; //} //else if (rules.Count() == 0) //{ // reasonDetails += "\n... no matching rules found ..."; //} showToolTip((Control)cell, selectedEntry.Reason_Info + blockingFilterDetails); // + reasonDetails); } else { closeToolTip(); } }
public ActionResult Details(int id, int page = 1, int count = Constants.LogEntriesPerPage) { var log = this.logService.GetTrainingLogById(id); if (log == null) { return(HttpNotFound()); } var isAuthenticated = this.authenticationProvider.IsAuthenticated; var currentUserId = this.authenticationProvider.CurrentUserId; var isAdmin = this.authenticationProvider.IsInRole(currentUserId, Constants.AdministratorRoleName); var canEdit = (log.User?.Id.Equals(currentUserId) ?? false) || isAdmin; var canVote = (log.Votes .FirstOrDefault(v => v.UserId.Equals(currentUserId))) == null && !canEdit && isAuthenticated; if (page < 0) { page = (log.Entries.Count - 1) / count + 1; } var entries = log.Entries .Select(e => LogEntryViewModel.FromEntry(e, currentUserId, isAdmin)) .ToPagedList(page, count); var model = this.factory.CreateLogDetailsViewModel(log, isAuthenticated, canEdit, canVote, entries); return(this.View(model)); }
public bool Accept(LogEntryViewModel logEntry) { int severity = SPUtility.GetSeverity(logEntry.Level); bool accept = (severity >= minSeverity); return(accept); }
public void Notify(LogEntryViewModel logEntry) { MailMessage message = new MailMessage(sender, recepients); message.Subject = "SharePoint Log"; message.Body = logEntry.Message; client.Send(message); }
public static void UpdateLogEntry(this LogEntry logentry, LogEntryViewModel logentryVM) { logentry.Logdate = logentryVM.Logdate; logentry.EntryTime = logentryVM.EntryTime; logentry.DepartTime = logentryVM.DepartTime; logentry.WorkerdHours = logentryVM.WorkerdHours; //*** We excluded the LogEntryImage property from UpdateLogEntry extension cause we will be using a specific FileUpload action to upload images. // logentry.LogEntryImage = logentryVM.LogEntryImage; }
public PartialViewResult EditEntry(LogEntryViewModel model) { if (ModelState.IsValid) { var result = this.entryService.EditEntry(model.EntryId, model.Content); model.Content = result.Content; } return(this.PartialView("_EntryContentPartial", model)); }
public async Task <IActionResult> ConsultaFiltrada(LogEntryViewModel view) { var log = new LogEntryViewModel(); log.LogEntrys = new List <LogEntry>(); //int pageSize = 10; //int pageIndex = 1; //pageIndex = page.HasValue ? Convert.ToInt32(page) : 1; //ViewBag.CurrentSort = sortOrder; //sortOrder = String.IsNullOrEmpty(sortOrder) ? "LogDate" : sortOrder; //IPagedList<LogEntry> logEntrys = null; //switch (sortOrder) //{ // case "LogDate": // if (sortOrder.Equals(CurrentSort)) // { view.LogEntrys = await logEntryService.GetLogEntryFiltrado(view); // logEntrys.ToPagedList(pageIndex, pageSize); // } // products = _db.Products.OrderByDescending // (m => m.ProductID).ToPagedList(pageIndex, pageSize); // else // products = _db.Products.OrderBy // (m => m.ProductID).ToPagedList(pageIndex, pageSize); // break; //case "ProductName": // if (sortOrder.Equals(CurrentSort)) // products = _db.Products.OrderByDescending // (m => m.ProductName).ToPagedList(pageIndex, pageSize); // else // products = _db.Products.OrderBy // (m => m.ProductName).ToPagedList(pageIndex, pageSize); /*break*/; // Add sorting statements for other columns //case "Default": // view.LogEntrys = await logEntryService.GetLogEntryFiltrado(view); // logEntrys.ToPagedList(pageIndex, pageSize); // break; //} ViewData["ShortName"] = new SelectList(await logLevelService.GetLogLevels(), "LogLevelId", "ShortName"); ViewData["Name"] = new SelectList(await logCategoryService.GetLogCategories(), "LogCategoryId", "Name"); //ViewData["ShortName"] = new SelectList(await logLevelService.GetLogLevels(), "LogLevelId", "ShortName"); //ViewData["Name"] = new SelectList(await logCategoryService.GetLogCategories(), "LogCategoryId", "Name"); return(View("Index", view)); }
protected LogEntryViewModel LogVm(Level level) { var m = new LogEntryViewModel(new LogEntry() { Data = new LoggingEventData { Level = level } }); return(m); }
public void TestDetails_ShouldSetCorrectEntriesToModel(int id, string userId, int page, int count) { // Arrange var entry = new LogEntry { Log = new TrainingLog() }; var entries = new List <LogEntry> { entry }; var user = new User { Id = userId }; var log = new TrainingLog { User = user, Entries = entries }; var mockedLogService = new Mock <ILogService>(); mockedLogService.Setup(s => s.GetTrainingLogById(It.IsAny <int>())).Returns(log); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var entryViewModel = new LogEntryViewModel(); var viewModelEntries = new List <LogEntryViewModel> { entryViewModel }; var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateLogDetailsViewModel(It.IsAny <TrainingLog>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IPagedList <LogEntryViewModel> >())) .Returns((TrainingLog trainingLog, bool isAuthenticated, bool isOwner, bool canVote, IPagedList <LogEntryViewModel> entriesPagedList) => new LogDetailsViewModel { Entries = viewModelEntries.ToPagedList(page, count) }); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); // Act var result = controller.Details(id, page, count) as ViewResult; // Assert CollectionAssert.AreEqual(viewModelEntries, ((LogDetailsViewModel)result.Model).Entries); }
/// <summary> /// Finds the log entry at the specified index. /// </summary> /// <param name="index">The index.</param> /// <returns></returns> private bool Find(int index) { LogEntryViewModel item = (LogEntryViewModel)this.LogListView.Items[index]; if (item.LogEntry.ContainsText(this.FindTextBox.Text)) { this.LogListView.SelectedIndex = index; this.LogListView.ScrollIntoView(this.LogListView.SelectedItem); ListViewItem lvi = this.LogListView.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem; lvi.BringIntoView(); lvi.Focus(); return(true); } return(false); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if DEBUG GlobalVariables.IsAdmin = true; string[] args = e.Args; if (args.Length > 0) { switch (args[0]) { case "test": GlobalVariables.InTestMode = true; break; default: break; } } #endif if (GlobalVariables.gColorAppSettings.Load() && GlobalVariables.fluorescenceSettings.Load() && GlobalVariables.spectrumSettings.Load()) { var window = new MainWindow(); // Create the ViewModel to which // the main window binds. LogEntry = new LogEntryViewModel(); var viewModel = new MainWindowViewModel(); // Allow all controls in the window to // bind to the ViewModel by setting the // DataContext, which propagates down // the element tree. window.DataContext = viewModel; window.Closing += viewModel.OnWindowClosing; window.Show(); } else { MessageBox.Show("An error occurred before the application could start.\n\nCould not load settings. ", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Stop); Shutdown(); } }
private static List <LogEntryViewModel> ConvertLogEntryQueryByteArrayResultToLogEntryVms(byte[][] logEntries) { if (!logEntries.Any()) { return(new List <LogEntryViewModel>()); } if (logEntries.Length < 2) { throw new Exception("Exactly 1 result; should be 2 or some larger multiple of 2 (or zero)."); } var logEntryVms = new List <LogEntryViewModel>(); var ts = GetTimeStampFromByteArray(logEntries[1]); var prevEntryTimeStamp = ts.FromMillisecondsSinceEpochToCurrentDateTimeUtc().ToLocalTime(); ushort entryNumber = 0; for (var i = 0; i < logEntries.Length; i += 2) { entryNumber++; var vm = new LogEntryViewModel(); var currentTs = GetTimeStampFromByteArray(logEntries[i + 1]); var currentEntryTimeStamp = currentTs.FromMillisecondsSinceEpochToCurrentDateTimeUtc().ToLocalTime(); // If this log entry is the first of a new day in the sequence, we reset the entry number if (currentEntryTimeStamp.Date > prevEntryTimeStamp.Date) { entryNumber = 1; prevEntryTimeStamp = currentEntryTimeStamp; } // Log entry text is stored in Redis with the timestamp prepended to it; so here getting only the text after the timestamp // -it it stored in Redis this way to satisfy the Redis Type Sorted Set requirement that any item in the set be distinct var entryText = Encoding.UTF8.GetString(logEntries[i]).Substring(13); vm.DateTime = currentEntryTimeStamp.FormatForDisplay(); vm.EntryNumber = entryNumber; vm.Text = entryText; vm.EpochMs = currentTs; logEntryVms.Add(vm); } return(logEntryVms); }
EventLogEntryType GetLevel(LogEntryViewModel logEntry) { switch (logEntry.Level) { case "Medium": case "High": case "CriticalEvent": case "Exception": case "UnExpected": return(EventLogEntryType.Error); case "Warning": return(EventLogEntryType.Warning); default: return(EventLogEntryType.Information); } }
public void TestEditEntry_ShouldSetViewModelCorrectly(int entryId, string content) { // Arrange var mockedService = new Mock <IEntryService>(); var mockedProvider = new Mock <IAuthenticationProvider>(); var controller = new EntriesController(mockedService.Object, mockedProvider.Object); var model = new LogEntryViewModel { EntryId = entryId, Content = content }; // Act, Assert controller .WithCallTo(c => c.EditEntry(model)) .ShouldRenderPartialView("_EntryContentPartial") .WithModel <LogEntryViewModel>(m => Assert.AreSame(model, m)); }
public void TestEditEntry_ShouldCallEntryServiceEditEntryCorrectly(int entryId, string content) { // Arrange var mockedService = new Mock <IEntryService>(); var mockedProvider = new Mock <IAuthenticationProvider>(); var controller = new EntriesController(mockedService.Object, mockedProvider.Object); var model = new LogEntryViewModel { EntryId = entryId, Content = content }; // Act controller.EditEntry(model); // Assert mockedService.Verify(s => s.EditEntry(entryId, content), Times.Once); }
public async Task <IActionResult> Index() { var log = new LogEntryViewModel(); log.LogEntrys = new List <LogEntry>(); //log.LogLevels = db.LogLevels.ToList(); ViewData["ShortName"] = new SelectList(await logLevelService.GetLogLevels(), "LogLevelId", "ShortName"); ViewData["Name"] = new SelectList(await logCategoryService.GetLogCategories(), "LogCategoryId", "Name"); //ViewData["ApplicationName"] = new SelectList(logEntryService.GetLogEntriesByParameter("ApplicationName"), "LogLevelId", "ApplicationName"); //ViewData["MachineIP"] = new SelectList(logEntryService.GetLogEntriesByParameter("MachineIP"), "LogLevelId", "MachineIP"); //ViewData["UserName"] = new SelectList(logEntryService.GetLogEntriesByParameter("UserName"), "LogLevelId", "UserName"); //ViewData["MachineName"] = new SelectList(logEntryService.GetLogEntriesByParameter("MachineName"), "LogLevelId", "MachineName"); return(View(log)); }
// GET: Home/Create public ActionResult Create() { var model = new LogEntryViewModel() { Employees = db .Employees.Select(emp => new SelectListItem() { Text = emp.LastName + ", " + emp.FirstName, Value = emp.ID.ToString() }).ToList(), Projects = db.Projects .Select(proj => new SelectListItem() { Text = proj.ProjectName, Value = proj.ID.ToString() }).ToList() }; return(View(model)); }
void UpdateLogViewModel() { for (int i = lastShownIndex; i < RaftHost.Raft.PersistedState.LogEntries.Count; i++) { var logEntry = RaftHost.Raft.PersistedState.LogEntries[i]; LogEntryViewModel entryViewModel = new LogEntryViewModel(logEntry); if (Log.Count >= LogVisibleEntryLimit) { Log.RemoveAt(Log.Count - 1); } Log.Insert(0, entryViewModel); if (logEntry.CommitIndex < 1) { throw new InvalidOperationException("Log entry index must be grater than 0"); } lastShownIndex = logEntry.CommitIndex; } lastShownIndex = RaftHost.Raft.PersistedState.LogEntries.Count; UpdateMargins(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if DEBUG GlobalVariables.IsAdmin = true; string[] args = e.Args; if (args.Length > 0) { switch (args[0]) { case "test": GlobalVariables.InTestMode = true; break; default: break; } } #endif gColor.Model.AppSettings.Load(); GlobalVariables.LightStableSettings.Load(); var window = new MainWindow(); // Create the ViewModel to which // the main window binds. LogEntry = new LogEntryViewModel(); var viewModel = new MainWindowViewModel(); // Allow all controls in the window to // bind to the ViewModel by setting the // DataContext, which propagates down // the element tree. window.DataContext = viewModel; window.Closing += viewModel.OnWindowClosing; window.Show(); }
private void Application_Startup(object sender, StartupEventArgs e) { #if DEBUG IsAdmin = true; #endif if (!Settings.Load() || !motorSettings.Load()) { MessageBox.Show("Could not load settinsg file", "Cannot start"); App.Current.Shutdown(); return; } LogEntry = new LogEntryViewModel(); var window = new MainWindow(); viewModel = new MainWindowViewModel(); window.DataContext = viewModel; window.Closing += viewModel.OnWindowClosing; window.Show(); }
public async Task <List <LogEntry> > GetListaFiltradaLogEntry([FromBody] LogEntryViewModel LogEntryViewModel) { //return await db.LogEntries.Where(x => x.UserName == "Nestor").ToListAsync(); var DateStart = LogEntryViewModel.LogDateStart.HasValue ? LogEntryViewModel.LogDateStart : null; var DateFinish = LogEntryViewModel.LogDateFinish.HasValue ? LogEntryViewModel.LogDateFinish : null; try { return(await((db.LogEntries. Where(x => (x.LogLevel.LogLevelId == LogEntryViewModel.LogLevelId || LogEntryViewModel.LogLevelId == 0) && (x.LogCategoryId == LogEntryViewModel.LogCategoryId || LogEntryViewModel.LogCategoryId == 0) && (x.ApplicationName.Contains(LogEntryViewModel.ApplicationName) || LogEntryViewModel.ApplicationName == null) && (x.MachineIP.Contains(LogEntryViewModel.MachineIP) || LogEntryViewModel.MachineIP == null) && (x.UserName.Contains(LogEntryViewModel.UserName) || LogEntryViewModel.UserName == null) && (x.LogDate.Date >= DateStart || DateStart == null) && (x.LogDate.Date <= DateFinish || DateFinish == null) && (x.MachineName.Contains(LogEntryViewModel.MachineName) || LogEntryViewModel.MachineName == null))).OrderByDescending(x => x.LogDate).ToListAsync())); } catch (Exception ex) { throw; } }
public void TestEditEntry_ShouldSetViewModelContentCorrectly(int entryId, string content) { // Arrange var mockedService = new Mock <IEntryService>(); mockedService.Setup(s => s.EditEntry(It.IsAny <int>(), It.IsAny <string>())) .Returns(new LogEntry { Content = content }); var mockedProvider = new Mock <IAuthenticationProvider>(); var controller = new EntriesController(mockedService.Object, mockedProvider.Object); var model = new LogEntryViewModel { EntryId = entryId, Content = content }; // Act var result = controller.EditEntry(model); // Assert Assert.AreEqual(content, ((LogEntryViewModel)result.Model).Content); }
internal void HandleEventLogNotification(object sender, EntryWrittenEventArgs eventArgs) { var entry = eventArgs.Entry; bool allowed = EventLogAsyncReader.IsFirewallEventAllowed(entry.InstanceId); activityWindow.ShowActivity(allowed ? ActivityWindow.ActivityEnum.Allowed : ActivityWindow.ActivityEnum.Blocked); if (allowed || !LogEntryViewModel.TryCreateFromEventLogEntry(entry, 0, out CurrentConn view)) { return; } LogHelper.Info($"Handle {view.Direction}-going connection for '{view.FileName}', service: {view.ServiceName} ..."); if (!AddItem(view)) { //This connection is blocked by a specific rule. No action necessary. LogHelper.Info($"{view.Direction}-going connection for '{view.FileName}' is blocked by a rule - ignored."); return; } //if (notifierWindow.WindowState == WindowState.Minimized) //{ // notifierWindow.ShowActivityTrayIcon($"Notifier blocked connections - click tray icon to show"); // max 64 chars! //} }
/// <summary> /// Handles the SelectionChanged event of the LogListView control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param> private void LogListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.Clear(); LogEntryViewModel logentry = this.LogListView.SelectedItem as LogEntryViewModel; if (logentry != null) { this.LogTypeImage.Source = logentry.Image; this.LevelTextBox.Text = logentry.LogEntry.Level; this.TimeStampTextBox.Text = string.Format("{0} {1}", logentry.LogEntry.TimeStamp.ToShortDateString(), logentry.LogEntry.TimeStamp.ToShortTimeString()); this.MachineNameTextBox.Text = logentry.LogEntry.MachineName; this.ThreadTextBox.Text = logentry.LogEntry.Thread; this.ItemTextBox.Text = logentry.LogEntry.Item.ToString(); this.HostNameTextBox.Text = logentry.LogEntry.HostName; this.UserNameTextBox.Text = logentry.LogEntry.UserName; this.AppTextBox.Text = logentry.LogEntry.App; this.ClassTextBox.Text = logentry.LogEntry.Class; this.MethodTextBox.Text = logentry.LogEntry.Method; this.LineTextBox.Text = logentry.LogEntry.Line; this.MessageTextBox.Text = logentry.LogEntry.Message; this.ThrowableTextBox.Text = logentry.LogEntry.Throwable; this.FileTextBox.Text = logentry.LogEntry.File; } }