/// <exception cref="Bad"> /// <see cref="Bad.AccessError"/> if respondent is not in required role. /// </exception> /// <exception cref="Bad"> /// <see cref="Bad.UselessRequest"/> if appeal is already resolved. /// </exception> /// <exception cref="Bad"> /// <see cref="Bad.NotAllowed"/> if appeal is not assigned or assigned to other respondent. /// </exception> /// <exception cref="Bad"> /// <see cref="Bad.UnknownError"/>. /// </exception> public async Task ResolveAsync(Appeal appeal, AppUser respondent) { if ((await respondent.LoadRoleSetAsync(Db)).IsNotStaffOrAdmin) { throw Bad.AccessError; } if (appeal.DateResolved != null) { throw Bad.UselessRequest; } if (appeal.DateAssigned == null || appeal.RespondentId != respondent.Id) { throw Bad.NotAllowed; } try { appeal.DateResolved = DateTime.UtcNow; await Db.SaveChangesAsync(); } catch (Exception ex) { Logger.LogError(ex, "Appeal resolving error! (appeal #{AppealId}, respondent #{RespondentId})", appeal.Id, respondent.Id); throw Bad.UnknownError; } OnResolve?.Invoke(appeal.Id); }
// called by retry. Retry passes db instance so that it is not created twice. internal void _OnResolveBase(IDatabase redisDb) { OnResolve?.Invoke(Payload); var success = redisDb.HashDelete(Constants.PendingPromises, GetCompositeKey().ToString()); //if (success == false) // throw new Exception("Resolved an already resolved promise. Duplicate promise ids maybe?"); }
/// <summary>构造函数</summary> /// <param name="connName">配置名</param> private DAL(String connName) { _ConnName = connName; var css = ConnStrs; //if (!css.ContainsKey(connName)) throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串"); if (!css.ContainsKey(connName)) { OnResolve?.Invoke(this, new ResolveEventArgs(connName)); } if (!css.ContainsKey(connName) && _defs.TryGetValue(connName, out var kv)) { AddConnStr(connName, kv.Item1, null, kv.Item2); } if (!css.ContainsKey(connName)) { var connstr = "Data Source=" + Setting.Current.SQLiteDbPath.CombinePath(connName + ".db;Migration=On"); WriteLog("自动为[{0}]设置SQLite连接字符串:{1}", connName, connstr); AddConnStr(connName, connstr, null, "SQLite"); } _ConnStr = css[connName]; if (_ConnStr.IsNullOrEmpty()) { throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串"); } //Queue = new EntityQueue(this); }
internal void _OnResolveBase() { OnResolve?.Invoke(Payload); var db = _redis.GetDatabase(); var success = db.HashDelete(Constants.PendingPromises, GetCompositeKey().ToString()); _lock.Release(); // TODO: this exception somehow goes silent and prevents background thread to close connection. // also for now this is not necessary //if (success == false) // throw new Exception("Resolved an already resolved promise. Duplicate promise ids maybe?"); }
private void OnFinishCommand(bool success) { foreach (var childCommand in ChildStates) { childCommand.FinishCommand(success); } if (success) { OnResolve?.Invoke(this); } else { OnReject?.Invoke(this); } }
public void Resolve(T value) { _value = value; IsResolved = true; OnResolve?.Invoke(value); }