public void RemoveRange(params OperationLog[] records) { if (records.Length == 0) { return; } OperationLogs.RemoveRange(records); SaveChanges(); }
public Boolean Add(OperationLog record) { if (record == null) { return(false); } OperationLogs.Add(record); return(SaveChanges() == 1); }
/// <summary> /// 查看详细日志 /// </summary> /// <param name="operationId"></param> /// <returns></returns> public IActionResult _DetailsOperation(int operationId) { OperationLogs logs = operationLogsService.GetOperationLogs(operationId); if (logs != null && logs.Id > 0) { return(View(logs)); } return(View("/Views/Error/GlobalError.cshtml")); }
/// <summary>Handle exception throw during ICommand execution</summary> /// <param name="ex"></param> protected virtual void HandleException(Exception ex) { LogTo.Error(ex, "Exception occured during a user requested operation on a plugin"); Dispatcher.Invoke( () => { var errMsg = $"Operation failed with error: {ex.Message}"; OperationLogs.AppendLine(errMsg); errMsg.ErrorMsgBox(); } ); }
/// <summary>Attempts to install <paramref name="plugin" />.</summary> /// <param name="plugin">The plugin selected in the UI</param> /// <returns></returns> protected virtual async Task InstallPlugin(PluginPackage <PluginMetadata> plugin) { if (!(plugin is OnlinePluginPackage <PluginMetadata> onlinePlugin)) { LogTo.Error($"Install plugin was called with a type that is not OnlinePluginPackage: {plugin.Serialize()}"); return; } bool success = false; try { Status = PluginManagerStatus.Install; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.InstallPluginAsync(onlinePlugin, onlinePlugin.SelectedVersion, CancellationTokenSource.Token) .ConfigureAwait(true)) == false) { return; } var localPlugin = PluginMgr.AllPlugins.FirstOrDefault(p => p.Package.Id == plugin.Id && p.IsDevelopment == false); if (Plugins.Replace(plugin, localPlugin.Package) == false) { throw new InvalidOperationException("Failed to replace old OnlinePluginPackage with new LocalPluginPackage in Plugins"); } localPlugin.Package.SetOnlineVersions(onlinePlugin); } catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException) { success = false; } catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException) { success = true; } finally { PluginMgr.RemoveLogger(LogOperationOutput); CancellationTokenSource = null; Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Install; } }
/// <summary>Uninstall <paramref name="pluginPackage" /></summary> /// <param name="pluginPackage">The plugin to uninstall</param> /// <returns></returns> private async Task PluginUninstall(LocalPluginPackage <PluginMetadata> pluginPackage) { bool success = false; try { Status = PluginManagerStatus.Uninstall; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.UninstallPluginAsync(pluginPackage) .ConfigureAwait(true)) == false) { return; } // Attempt to replace the plugin in the list ; otherwise refresh online plugins bool refresh = true; var onlinePluginsCopy = Plugins; if (onlinePluginsCopy != null) { pluginPackage = onlinePluginsCopy.FirstOrDefault(p => p.Id == pluginPackage.Id) as LocalPluginPackage <PluginMetadata>; if (pluginPackage != null && pluginPackage.OnlineVersions != null) { onlinePluginsCopy.Replace(pluginPackage, new OnlinePluginPackage <PluginMetadata>(pluginPackage)); refresh = false; } } if (refresh) { RefreshPlugins(true).RunAsync(); } } catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException) { success = true; } finally { PluginMgr.RemoveLogger(LogOperationOutput); CancellationTokenSource = null; Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Uninstall; } }
public Boolean Update(OperationLog record) { if (record == null) { return(false); } var attached = OperationLogs.Attach(record); if (attached == null) { return(false); } Entry(attached).State = EntityState.Modified; return(SaveChanges() == 1); }
public Boolean Remove(OperationLog record) { if (record == null) { return(false); } var attached = OperationLogs.Attach(record); if (attached == null) { return(false); } OperationLogs.Remove(attached); return(SaveChanges() == 1); }
protected void LogOperationOutput(string msg) { var match = PluginManagerLogAdapter.RE_Anotar.Match(msg); if (match.Success) { msg = match.Groups[match.Groups.Count - 1].Value; } Dispatcher.Invoke(() => { OperationLogs.AppendLine(msg); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(OperationLogs))); }); }
/// <summary>Cancel running tasks using <see cref="CancellationTokenSource" /></summary> public void CancelTasks() { switch (Status) { case PluginManagerStatus.Install: Dispatcher.InvokeAsync(() => OperationLogs.AppendLine("\nCancelling...")); break; } try { CancellationTokenSource?.Cancel(); } catch (ObjectDisposedException) { } }
private void InsertOperationLog <T>(string sql, string operation, params T[] items) { var log = new OperationLogs { ModelId = 0, ModelJson = JsonConvert.SerializeObject(items), ModelType = "", Operation = LoginUserSection.CurrentUser == null ? "登录" : operation, OperatorId = LoginUserSection.CurrentUser == null ? "" : LoginUserSection.CurrentUser.SystemUserId.ToString(), OperationSQL = sql, OperationTime = DateTime.Now }; using (var connection = CreateConnection()) { connection.Execute(AddOperationLogs, log); } }
private void InsertOperationLog(string sql, string operation, int id) { var log = new OperationLogs { ModelId = id, ModelJson = "", ModelType = "", Operation = operation, OperatorId = LoginUserSection.CurrentUser == null ? "" : LoginUserSection.CurrentUser.SystemUserId.ToString(), OperationSQL = sql, OperationTime = DateTime.Now }; using (var connection = CreateConnection()) { connection.Execute(AddOperationLogs, log); } }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation(1, "User logged in."); OperationLogs log = new OperationLogs(); log.ID = Guid.NewGuid().ToString(); log.UserID = _context.ApplicationUser.Where(p => p.Email == model.Email).First().Id; log.Operation = "LOGIN"; log.OperationResult = "SUCCEED"; log.Action = "LOGIN"; log.Controller = "HOME/ACCOUNT"; log.OperationType = "USERACTION"; log.OperationTime = DateTime.Now; _context.Add(log); _context.SaveChanges(); return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning(2, "User account locked out."); return(View("Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }
/// <summary>Updates <paramref name="plugin" /></summary> /// <param name="plugin">The plugin to update</param> /// <returns></returns> private async Task PluginUpdate(LocalPluginPackage <PluginMetadata> plugin) { bool success = false; try { Status = PluginManagerStatus.Update; OperationLogs.Clear(); PluginMgr.AddLogger(LogOperationOutput); using (CancellationTokenSource = new CancellationTokenSource()) if ((success = await PluginMgr.UpdatePluginAsync(plugin, plugin.SelectedVersion, EnablePrerelease, CancellationTokenSource.Token) .ConfigureAwait(true)) == false) { return; } await PluginMgr.StartPlugin(PluginInstances.FirstOrDefault(pi => pi.Package == plugin)).ConfigureAwait(true); } catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException) { success = false; } catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException) { success = true; } finally { PluginMgr.RemoveLogger(LogOperationOutput); CancellationTokenSource = null; Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Update; } }
public override void OnResultExecuted(ResultExecutedContext context) { var userId = context.HttpContext.User.FindFirst(c => c.Type == ClaimTypes.Sid).Value; var currentUser = context.HttpContext.Session.Get <User>(userId); if (currentUser == null) { currentUser = userService.GetFullUser(HttpContextCore.Current.User.Identity.Name); } if (currentUser == null) { base.OnResultExecuted(context); } string controller = context.RouteData.Values["controller"].ToString(); string action = context.RouteData.Values["action"].ToString(); string url = RequestHelper.RawUrl(context.HttpContext.Request); OperationLogs logs = new OperationLogs(); logs.Source = IsTrusteeship ? "系统设定" : "权限设定"; logs.Description = string.IsNullOrEmpty(Description) ? string.Empty : Description; logs.DateCreated = DateTime.Now; logs.OperatorIp = Utility.GetIP(); logs.OperatorUrl = url; logs.OperatorUserid = currentUser.UserId; logs.OperatorUsername = currentUser.UserName; IEnumerable <PermissionItems> permissionItemsList = permissionItemsService.GetPermissionItemsAll(); if (!IsTrusteeship) { foreach (var item in permissionItemsList) { if (item.ItemUrl.Equals(context.HttpContext.Request.Path.ToString().Replace(".aspx", ""), StringComparison.CurrentCultureIgnoreCase)) { logs.ApplicationId = item.Applicationid; logs.OperationObjectId = item.Itemkey; logs.OperationObjectName = item.Itemname; logs.OperationType = Enum.Parse(typeof(PermissionItemsType), item.ItemType.ToString()).ToString(); break; } } if (logs.OperationObjectId.IsNullOrWhiteSpace()) { logs.OperationObjectId = logs.OperationObjectName = logs.OperationType = string.Empty; logs.ApplicationId = 0; } } else { logs.ApplicationId = 0; logs.OperationObjectId = string.Empty; logs.OperationObjectName = Name; logs.OperationType = Type.ToString(); } operationLogsService.AddOperationLogs(logs); base.OnResultExecuted(context); }