private void OnEndRequest(object sender, EventArgs e) { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnEndRequest"); HttpApplication httpApplication = (HttpApplication)sender; HttpContext context = httpApplication.Context; ReportingVersion.WriteVersionInfoInResponse(context); ReportingModule.activeRequestsCounter.Decrement(); this.averageRequestTime.Stop(); RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics; if (requestStatistics != null) { requestStatistics.AddStatisticsDataPoint(RequestStatistics.RequestStatItem.RequestResponseTime, this.requestStartTime, DateTime.UtcNow); requestStatistics.AddExtendedStatisticsDataPoint("HTTPCODE", context.Response.StatusCode.ToString()); IPrincipal user = context.User; string text = context.Request.Headers["X-SourceCafeServer"]; ServerLogEvent logEvent = new ServerLogEvent((ActivityContext.ActivityId != null) ? ActivityContext.ActivityId.Value.ToString() : string.Empty, string.IsNullOrEmpty(text) ? string.Empty : text, requestStatistics); ServerLogger.Instance.LogEvent(logEvent); } if (this.activityScope != null && !this.activityScope.IsDisposed) { this.activityScope.End(); } ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnEndRequest - End"); }
public static void WatchMessage(string messageName, string messageData) { if (HttpContext.Current != null && HttpContext.Current.Items != null) { RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics; if (requestStatistics != null) { requestStatistics.AddExtendedStatisticsDataPoint(messageName, messageData); } } }
public static void WatchStartTime(string eventName) { DateTime utcNow = DateTime.UtcNow; if (HttpContext.Current != null && HttpContext.Current.Items != null) { RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics; if (requestStatistics != null) { requestStatistics.AddExtendedStatisticsDataPoint(eventName, utcNow.ToString("hh:mm:ss.ffftt")); } } }
private void OnAuthorizeRequest(object sender, EventArgs e) { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnAuthorizeRequest"); HttpApplication httpApplication = (HttpApplication)sender; HttpContext context = httpApplication.Context; RequestStatistics requestStatistics = context.Items[RequestStatistics.RequestStatsKey] as RequestStatistics; if (context.Request.IsAuthenticated) { requestStatistics.AddExtendedStatisticsDataPoint("AuthN", "True"); try { RbacPrincipal rbacPrincipal = RbacPrincipalManager.Instance.AcquireRbacPrincipalWrapper(context); if (rbacPrincipal != null) { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] RbacPrincipal != null"); context.User = rbacPrincipal; rbacPrincipal.SetCurrentThreadPrincipal(); requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "True"); } else { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] RbacPrincipal == null"); context.Response.StatusCode = 401; httpApplication.CompleteRequest(); requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False"); } goto IL_138; } catch (DataServiceException value) { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] DataServiceException got"); context.Items.Add(RbacAuthorizationManager.DataServiceExceptionKey, value); requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False"); goto IL_138; } } requestStatistics.AddExtendedStatisticsDataPoint("AuthN", "False"); requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False"); IL_138: ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnAuthorizeRequest - End"); }
private RbacPrincipal CreateRbacPrincipal(IIdentity identity, string tenantDomain, string cacheKey, HttpContext httpContext) { ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Create RbacPrincipal. Identity: {0}; tenantDomain: {1}; cacheKey: '{2}'", identity.GetSafeName(true), tenantDomain ?? string.Empty, cacheKey); ExchangeRunspaceConfigurationSettings rbacSettings = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewExchangeRunspaceConfigurationSettingsLatency, delegate { rbacSettings = new ExchangeRunspaceConfigurationSettings(ExchangeRunspaceConfigurationSettings.ExchangeApplication.ReportingWebService, tenantDomain, ExchangeRunspaceConfigurationSettings.SerializationLevel.None); }); ReportingSchema schema = ReportingSchema.GetCurrentReportingSchema(httpContext); try { RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics; if (requestStatistics != null) { requestStatistics.AddExtendedStatisticsDataPoint("AuthType", identity.AuthenticationType); } using (new AverageTimePerfCounter(RwsPerfCounters.AverageRbacPrincipalCreation, RwsPerfCounters.AverageRbacPrincipalCreationBase, true)) { RwsExchangeRunspaceConfiguration rbacConfiguration = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRwsExchangeRunspaceConfigurationLatency, delegate { rbacConfiguration = RwsExchangeRunspaceConfiguration.NewInstance(identity, rbacSettings, schema.CmdletFilter, this.GetSnapinSet()); }); RbacPrincipal rbacPrincipal = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRbacPrincipalLatency, delegate { rbacPrincipal = new RbacPrincipal(rbacConfiguration, cacheKey); }); return(rbacPrincipal); } } catch (CmdletAccessDeniedException ex) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <CmdletAccessDeniedException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CmdletAccessDeniedException: {0}", ex); ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotInOrgScope, Strings.ErrorTenantNotInOrgScope(tenantDomain), ex); } catch (CannotResolveTenantNameException ex2) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <CannotResolveTenantNameException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CannotResolveTenantNameException: {0}", ex2); ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotResolved, Strings.ErrorTenantNotResolved(tenantDomain), ex2); } catch (ADTransientException ex3) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <ADTransientException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] ADTransientException: {0}", ex3); ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, ex3); } catch (DataSourceOperationException ex4) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] DataSourceOperationException: {0}", ex4); ServiceDiagnostics.ThrowError(ReportingErrorCode.ADOperationError, Strings.ADOperationError, ex4); } catch (TimeoutException ex5) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <TimeoutException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] TimeoutException: {0}", ex5); ServiceDiagnostics.ThrowError(ReportingErrorCode.CreateRunspaceConfigTimeoutError, Strings.CreateRunspaceConfigTimeoutError, ex5); } catch (Exception ex6) { HttpRuntime.Cache.Remove(cacheKey); ExTraceGlobals.ReportingWebServiceTracer.TraceError <Exception>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Exception: {0}", ex6); ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, ex6); } return(null); }