Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
 internal ServerLogEvent(string activityId, string cafeSeverName, RequestStatistics stat)
 {
     this.datapointProperties = new Dictionary <string, object>();
     this.datapointProperties.Add("ACTID", activityId);
     this.datapointProperties.Add("CAFE", cafeSeverName);
     this.datapointProperties.Add("URL", stat.RequestUrl);
     this.datapointProperties.Add("REQRESP", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.RequestResponseTime));
     this.datapointProperties.Add("REQPROC", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.HttpHandlerProcessRequestLatency));
     this.datapointProperties.Add("RPATIME", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.RbacPrincipalAcquireLatency));
     this.datapointProperties.Add("NERCS", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.NewExchangeRunspaceConfigurationSettingsLatency));
     this.datapointProperties.Add("GRS", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.GetReportingSchemaLatency));
     this.datapointProperties.Add("NRERC", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.NewRwsExchangeRunspaceConfigurationLatency));
     this.datapointProperties.Add("NRP", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.NewRbacPrincipalLatency));
     this.datapointProperties.Add("GMP", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.GetMetadataProviderLatency));
     this.datapointProperties.Add("GQP", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.GetQueryProviderLatency));
     this.datapointProperties.Add("CGTLFR", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.CreateGenericTypeListForResults));
     this.datapointProperties.Add("CMD", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.CmdletResponseTime));
     this.datapointProperties.Add("ICMD", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.InvokeCmdletLatency));
     this.datapointProperties.Add("ICMDERC", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.InvokeCmdletExcludeRunspaceCreationLatency));
     this.datapointProperties.Add("ICMDE", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.InvokeCmdletExclusiveLatency));
     this.datapointProperties.Add("PSCR", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.PowerShellCreateRunspaceLatency));
     this.datapointProperties.Add("ARWSH", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.ActivateReportingWebServiceHostLatency));
     this.datapointProperties.Add("DRWSH", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.DeactivateReportingWebServiceHostLatency));
     this.datapointProperties.Add("CPSH", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.CreatePSHostLatency));
     this.datapointProperties.Add("IR", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.InitializeRunspaceLatency));
     this.datapointProperties.Add("GISS", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.GetInitialSessionStateLatency));
     this.datapointProperties.Add("CRS", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.ConfigureRunspaceLatency));
     this.datapointProperties.Add("CRSS", stat.GetStatisticsDataPointResult(RequestStatistics.RequestStatItem.CreateRunspaceServerSettingsLatency));
     this.datapointProperties.Add("EX", stat.GetExtendedStatisticsDataPointResult());
 }
Ejemplo n.º 3
0
 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);
         }
     }
 }
Ejemplo n.º 4
0
        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"));
                }
            }
        }
Ejemplo n.º 5
0
        public static void Watch(RequestStatistics.RequestStatItem name, Action action)
        {
            DateTime utcNow = DateTime.UtcNow;

            action();
            if (HttpContext.Current != null && HttpContext.Current.Items != null)
            {
                RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics;
                if (requestStatistics != null)
                {
                    requestStatistics.AddStatisticsDataPoint(name, utcNow, DateTime.UtcNow);
                }
            }
        }
Ejemplo n.º 6
0
        public static RequestStatistics CreateRequestRequestStatistics(HttpContext httpContext)
        {
            RequestStatistics requestStatistics = null;

            if (httpContext.Items != null)
            {
                requestStatistics = (httpContext.Items[RequestStatistics.RequestStatsKey] as RequestStatistics);
                if (requestStatistics == null)
                {
                    requestStatistics            = new RequestStatistics();
                    requestStatistics.RequestUrl = httpContext.Request.RawUrl;
                    httpContext.Items[RequestStatistics.RequestStatsKey] = requestStatistics;
                }
            }
            return(requestStatistics);
        }
Ejemplo n.º 7
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnBeginRequest");
            this.requestStartTime = DateTime.UtcNow;
            ReportingModule.activeRequestsCounter.Increment();
            this.averageRequestTime.Start();
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     context         = httpApplication.Context;

            if (!ActivityContext.IsStarted)
            {
                this.activityScope = ActivityContext.DeserializeFrom(context.Request, null);
            }
            RequestStatistics.CreateRequestRequestStatistics(context);
            this.SetCurrentCulture(context);
            this.AddTrailingSlashToServiceFile(context);
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnBeginRequest - End");
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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);
        }