/// <summary> /// Unblocks a remote endpoint and resets counters for it. /// </summary> /// <param name="RemoteEndpoint">String-representation of remote endpoint.</param> /// <param name="Protocol">Protocol used to log in.</param> public async Task UnblockAndReset(string RemoteEndpoint, string Protocol) { RemoteEndpoint EP = await this.GetStateObject(RemoteEndpoint, Protocol); EP.LastProtocol = Protocol; EP.Reset(true); await Database.Update(EP); }
/// <summary> /// Unblocks a remote endpoint and resets counters for it. /// </summary> /// <param name="RemoteEndpoint">String-representation of remote endpoint.</param> /// <param name="Protocol">Protocol used to log in.</param> public async Task UnblockAndReset(string RemoteEndpoint, string Protocol) { RemoteEndpoint EP = await this.GetStateObject(RemoteEndpoint, Protocol, true); if (!string.IsNullOrEmpty(Protocol)) { EP.LastProtocol = Protocol; } EP.Reset(true); await Database.Update(EP); }
/// <summary> /// Processes a successful login attempt. /// /// NOTE: Typically, logins are audited by listening on logged events. /// This method should only be called directly when such events are not logged. /// </summary> /// <param name="RemoteEndpoint">String-representation of remote endpoint.</param> /// <param name="Protocol">Protocol used to log in.</param> public async Task ProcessLoginSuccessful(string RemoteEndpoint, string Protocol) { RemoteEndpoint EP = await this.GetStateObject(RemoteEndpoint, Protocol, true); if (EP.LastProtocol == Protocol && !EP.LastFailed) { return; } EP.LastProtocol = Protocol; EP.Reset(false); await Database.Update(EP); }
private async Task <RemoteEndpoint> GetStateObject(string RemoteEndpoint, string Protocol, bool CreateNew) { RemoteEndpoint EP; RemoteEndpoint = this.RemovePort(RemoteEndpoint); lock (this.states) { if (this.states.TryGetValue(RemoteEndpoint, out EP)) { return(EP); } } bool Created = false; bool Updated = false; EP = await Database.FindFirstIgnoreRest <RemoteEndpoint>(new FilterFieldEqualTo("Endpoint", RemoteEndpoint), "Created"); if (EP is null) { if (!CreateNew) { return(null); } EP = new RemoteEndpoint() { Endpoint = RemoteEndpoint, LastProtocol = Protocol, Created = DateTime.Now, Blocked = false, State = new int[this.nrIntervals], Timestamps = new DateTime[this.nrIntervals] }; EP.Reset(false); Created = true; } else { if (EP.State is null || EP.State.Length != this.nrIntervals) { EP.State = new int[this.nrIntervals]; EP.Timestamps = new DateTime[this.nrIntervals]; EP.Reset(false); Updated = true; } } lock (this.states) { if (this.states.TryGetValue(RemoteEndpoint, out RemoteEndpoint EP2)) { return(EP2); } this.states[RemoteEndpoint] = EP; } if (Created) { await Database.Insert(EP); } else if (Updated) { await Database.Update(EP); } return(EP); }