private async Task ExecutePhase(IReportContext context, ReportPhase phase, IScope scope) { Logg.Debug(new { op = "start phase", phase }); var agents = context.Agents.Where(_ => _.Phase.HasFlag(phase)).OrderBy(_ => _.Idx).GroupBy(_ => _.Idx).ToArray(); foreach (var grp in agents) { if (grp.Count() == 1) { await grp.First().Execute(context, phase, scope); } else if (grp.All(_ => _.Parallel)) { var waitgroup = new List <Task>(); foreach (var agent in grp) { waitgroup.Add(agent.Execute(context, phase, scope)); } Task.WaitAll(waitgroup.ToArray()); } else { foreach (var agent in grp) { await agent.Execute(context, phase, scope); } } } Logg.Debug(new { op = "end phase", phase }); }
private IIdentity AuthenticateWithValidToken(IHttpRequestDescriptor request, Token currentToken) { var currentExpire = currentToken.Expire.ToUniversalTime(); Token token; if (IsProlongable(request)) { token = TokenService.Prolongate(currentToken); } else { token = currentToken; } var resultExpire = token.Expire.ToUniversalTime(); if (Logg.IsForDebug()) { Logg.Debug( new { request = request.Uri.ToString(), token = "upgrade", from = currentExpire, to = resultExpire } .stringify()); } var result = BuildIdentity(token); return(result); }
public bool Refresh(bool forse) { if (DateTime.Now.AddMilliseconds(-RefreshRate) > LastRefresh) { Logg.Debug(new { cache = "begin refresh" }.stringify()); LastRefresh = DateTime.Now; lock (this) { var currentEtag = ETag; var currentVersion = Version; foreach (var extension in Extensions) { extension.Refresh(forse); } if (currentEtag == ETag && currentVersion == Version) { return(false); } Logg.Trace(new{ cache = "refreshed" }.stringify()); Clear(); return(true); } } return(false); }
private void LogStart(string username, SecureLogonInfo info, IScope context, string opid) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, salt = info.Salt, sign = info.Sign, context }.stringify()); } }
private void LogStart(string username, string password, IScope context, string opid) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, pass = password.GetMd5(), context }.stringify()); } }
private IIdentity ResolveByExtensions(string username, string password, string opid, IScope context) { var extensions = Extensions.OfType <IPasswordLogon>().ToArray(); IIdentity bestresult = null; foreach (var passwordLogon in extensions) { if (Logg.IsForDebug()) { Logg.Debug(new { opid, ext = passwordLogon.GetType().Name, message = "enter" }.stringify()); } var subresult = passwordLogon.Logon(username, password, context); if (Logg.IsForDebug()) { Logg.Debug(new { opid, ext = passwordLogon.GetType().Name, message = null != subresult && subresult.IsAuthenticated }.stringify()); } if (null != subresult && UserActivityState.None != ((Identity)subresult).State) { bestresult = subresult; } if (null != subresult && subresult.IsAuthenticated) { return(subresult); } } return(bestresult); }
public string GetSalt(string username, IScope context = null) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentException("username"); } var opid = GETSALTOPID + Interlocked.Increment(ref logonid); if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, context }); } string result = null; var securelogon = Extensions.OfType <ISecureLogon>().FirstOrDefault(); if (null == securelogon) { if (Logg.IsForError()) { Logg.Error(new { opid, message = "not secure login confugured" }.stringify()); } } else { result = securelogon.GetSalt(username); } if (Logg.IsForDebug()) { Logg.Debug(new { opid, username, salt = result }.stringify()); } return(result); }
public void SimpleMethod() { Logg.Info(GetType().Name); Logg.Info("Process start"); Repo.TestRepository1(); Logg.Info($@"Repo out - {Repo.TestRepository2()}"); Logg.Debug("Process stopped"); }
public IIdentity Logon(string username, string password, IScope context = null) { if (null == UserService) { if (Logg.IsForDebug()) { Logg.Debug("No user service"); } return(null); } var user = UserService.GetUser(username); if (null == user && Logg.IsForDebug()) { Logg.Debug("user is null"); } if (!StateChecker.IsPasswordLogable(user)) { Logg.Debug("user not logable"); return(null); } var result = new Identity { Name = username, AuthenticationType = "hash" }; var state = StateChecker.GetActivityState(user); if (state != UserActivityState.Ok) { Logg.Debug("user is in invalid state " + state); result.State = state; result.IsError = true; result.Error = new SecurityException(state.ToStr()); } else { if (PasswordManager.MatchPassword(user, password)) { Logg.Debug("pass matched"); result.IsAuthenticated = true; result.IsAdmin = user.IsAdmin; result.User = user; } else { Logg.Debug("pass not matched"); result.IsError = true; result.Error = new SecurityException("invalid hash"); } } return(result); }
public IIdentity GetUserIdentity(IHttpRequestDescriptor request) { var currentToken = TokenService.Extract(request); if (Logg.IsForDebug()) { Logg.Debug(new { request = request.Uri.ToString(), action = "extract", token = currentToken }.stringify()); } if (currentToken != null && TokenService.IsValid(request, currentToken)) { return(AuthenticateWithValidToken(request, currentToken)); } var result = (Identity)DefaultIdentitySource.GetUserIdentity(request); result.DisabledToken = currentToken; return(result); }
public async Task <IReportContext> Execute(IReportRequest request) { Logg.Debug(new { op = "start", r = request }.stringify()); var context = InitializeContext(request); try { var scope = new Scope(); await ExecutePhase(context, ReportPhase.Init, scope); await ExecutePhase(context, ReportPhase.Data, scope); await ExecutePhase(context, ReportPhase.Prepare, scope); if (request.DataOnly) { if (null != context.Data) { context.SetHeader("Content-Type", "application/json; charset=utf-8"); context.Write(context.Data.stringify()); } } else { await ExecutePhase(context, ReportPhase.Render, scope); } await ExecutePhase(context, ReportPhase.Finalize, scope); context.Finish(); } catch (Exception e) { Logg.Error(e); context.Error = e; if (!context.Request.NoFinalizeOnError) { context.Finish(e); } } finally { Logg.Trace(new { op = "success", r = request }.stringify()); } return(context); }
public static void OpenBaseUrl(this IWebDriver driver) { Log.Debug("browser"); driver.Url = JsonReader.GetBaseUrl(); }
public static void OpenBaseUrl(this IWebDriver driver) { Log.Debug("browser"); driver.Url = Config.BaseUrl; }