public IDisposable BeginContextAwareScope() { // Stack-like behaviour for Non-HttpContext thread: // Only the first call returns a disposer, all nested calls to this method are void. return(HttpContext.Current != null ? (IDisposable)ActionDisposable.Empty : new ContextAwareScope( _state.GetState() == null ? this.EndLifetimeScope : (Action)null)); }
public void EndLifetimeScope() { try { var scope = _state.GetState(); if (scope != null) { scope.Dispose(); _state.RemoveState(); } } catch { } }
public void SetThreadMetadata(string key, object value) { Guard.NotEmpty(key, nameof(key)); var state = _contextState.GetState(); if (state == null) { state = new Dictionary <string, object>(); _contextState.SetState(state); } state[GetContextKey(this, key)] = value; }
/// <summary> /// 外壳设置保存成功之后。 /// </summary> /// <param name="settings">外壳设置信息。</param> void IShellSettingsManagerEventHandler.Saved(ShellSettings settings) { Logger.Debug("外壳 {0} 被保存 ", settings.Name); if (settings.State == TenantState.Invalid) { return; } if (_tenantsToRestart.GetState().Any(t => t.Name.Equals(settings.Name))) { return; } Logger.Debug("标识租户: {0} {1} 需要重启", settings.Name, settings.State); _tenantsToRestart.GetState().Add(settings); }
private bool TryGetCustomThreadProperties(bool create, out IDictionary <string, object> dict) { dict = null; var state = _contextState.GetState(); if (state == null && create) { state = new Dictionary <ModelBase, IDictionary <string, object> >(); _contextState.SetState(state); } if (state != null) { if (!state.TryGetValue(this, out dict)) { if (create) { dict = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); state[this] = dict; } } return(dict != null); } return(false); }
public void EndLifetimeScope() { try { var scope = _state.GetState(); if (scope != null) { try { scope.Resolve <ILogger>().Flush(); } catch { } scope.Dispose(); _state.RemoveState(); } } catch { } }
private static InheritedThemeFileResult GetResolveResult(string virtualPath) { var d = _requestState.GetState(); if (!d.TryGetValue(virtualPath, out var result)) { result = d[virtualPath] = EngineContext.Current.Resolve <IThemeFileResolver>().Resolve(virtualPath); } return(result); }
public void EndLifetimeScope() { try { var scope = _state.GetState(); if (scope != null) { try { //if (DataSettings.DatabaseIsInstalled()) // scope.Resolve<ILogger>().Flush(); } catch { } scope.Dispose(); _state.RemoveState(); } } catch { } }
void StartUpdatedShells() { while (_tenantsToRestart.GetState().Any()) { var settings = _tenantsToRestart.GetState().First(); _tenantsToRestart.GetState().Remove(settings); Logger.Debug("Updating shell: " + settings.Name); lock (_syncLock) { ActivateShell(settings); } } }
protected string ResolveDebugFilePath(string virtualPath) { if (!_isDebug) { return(null); } // Two-Level caching: RequestCache > AppCache var d = _requestState.GetState(); string debugPath; if (!d.TryGetValue(virtualPath, out debugPath)) { string appRelativePath; if (!IsPluginPath(virtualPath, out appRelativePath)) { // don't query again in this request d[virtualPath] = null; return(null); } if (!d.TryGetValue(appRelativePath, out debugPath)) { // (perf) concurrency with ReaderWriterLockSlim seems way faster than ConcurrentDictionary using (_rwLock.GetUpgradeableReadLock()) { if (!_cachedDebugFilePaths.TryGetValue(appRelativePath, out debugPath)) { using (_rwLock.GetWriteLock()) { debugPath = FindDebugFile(appRelativePath); _cachedDebugFilePaths[appRelativePath] = d[appRelativePath] = debugPath; } } } } } return(debugPath); }
/// <summary> /// Checks last path existence /// </summary> /// <returns>true = does exist, no need to check | false = not checked yet</returns> public bool Check(StyleSheetResult styleResult, out TokenizedSassPath path) { path = new TokenizedSassPath(styleResult); var state = _state.GetState(); if (state.Count == 0) { return(false); } var currentPath = path; var lastPath = _state.GetState().Peek(); if (currentPath.Extension.IsEmpty()) { // We dont't allow extension-less Sass files, so no need to check. return(true); } if (lastPath.Dir != currentPath.Dir) { return(false); } if (currentPath.StyleResult.IsBaseImport && lastPath.StyleResult.IsBaseImport && currentPath.FileName == lastPath.FileName) { return(true); } if (currentPath.StyleResult.IsModuleImports && lastPath.StyleResult.IsModuleImports) { return(true); } if (currentPath.StyleResult.IsThemeVars && lastPath.StyleResult.IsThemeVars) { return(true); } // slick.scss.(scss|sass|css) > slick.scss if (Path.GetExtension(currentPath.FileNameWithoutExtension) == ".scss") { return(true); } // slick.(sass|css) > slick.scss if (!currentPath.StyleResult.IsBaseImport && _styleExtensions.Contains(currentPath.Extension) && currentPath.FileNameWithoutExtension == lastPath.FileNameWithoutExtension) { return(true); } // _slick.scss > slick.scss if (currentPath.FileName.StartsWith("_")) { if (currentPath.FileName.Substring(1) == lastPath.FileName) { return(true); } } // slick.(scss|sass|css) > _slick.scss if (lastPath.FileNameWithoutExtension.StartsWith("_")) { if (lastPath.FileNameWithoutExtension == "_" + currentPath.FileNameWithoutExtension) { return(true); } } return(false); }
protected internal void TryAddExtendedThreadInfo(LoggingEvent loggingEvent) { HttpRequest httpRequest = null; try { httpRequest = HttpContext.Current.Request; } catch { loggingEvent.Properties["CustomerId"] = DBNull.Value; loggingEvent.Properties["Url"] = DBNull.Value; loggingEvent.Properties["Referrer"] = DBNull.Value; loggingEvent.Properties["HttpMethod"] = DBNull.Value; loggingEvent.Properties["Ip"] = DBNull.Value; return; } var props = _state.GetState(); // Load the log4net thread with additional properties if they are available var threadInfoMissing = !props.ContainsKey("sm:ThreadInfoAdded"); if (threadInfoMissing) { using (new ActionDisposable(() => props["sm:ThreadInfoAdded"] = true)) { if (DataSettings.DatabaseIsInstalled() && EngineContext.Current.IsFullyInitialized) { var container = EngineContext.Current.ContainerManager; IWorkContext workContext; // CustomerId if (container.TryResolve <IWorkContext>(null, out workContext)) { try { props["CustomerId"] = workContext.CurrentCustomer.Id; } catch { props["CustomerId"] = DBNull.Value; } } IWebHelper webHelper; // Url & stuff if (container.TryResolve <IWebHelper>(null, out webHelper)) { try { props["Url"] = webHelper.GetThisPageUrl(true); props["Referrer"] = webHelper.GetUrlReferrer(); props["HttpMethod"] = httpRequest?.HttpMethod; props["Ip"] = webHelper.GetCurrentIpAddress(); } catch { } } } } } loggingEvent.Properties["CustomerId"] = props.Get("CustomerId") ?? DBNull.Value; loggingEvent.Properties["Url"] = props.Get("Url") ?? DBNull.Value; loggingEvent.Properties["Referrer"] = props.Get("Referrer") ?? DBNull.Value; loggingEvent.Properties["HttpMethod"] = props.Get("HttpMethod") ?? DBNull.Value; loggingEvent.Properties["Ip"] = props.Get("Ip") ?? DBNull.Value; }