// Token: 0x06001493 RID: 5267 RVA: 0x0004CD60 File Offset: 0x0004AF60
 internal CostHandle StartCmdlet(AuthZPluginUserToken userToken)
 {
     if (!this.ShouldThrottling(userToken))
     {
         return(null);
     }
     lock (base.InstanceLock)
     {
         IPowerShellBudget budget = base.GetBudget(userToken, true, true);
         if (budget != null)
         {
             ExTraceGlobals.PublicPluginAPITracer.TraceDebug <string>(0L, "Start budget tracking for Cmdlet, key {0}", this.CreateKey(userToken));
             return(budget.StartCmdlet(null));
         }
         ExTraceGlobals.PublicPluginAPITracer.TraceError <string>(0L, "Try to start budget tracking for Cmdlet, key {0} But the budget doesn't exist.", this.CreateKey(userToken));
     }
     return(null);
 }
Пример #2
0
        private void ThrottleRequest(HttpContext context)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Enter");
            WinRMInfo winRMInfo = context.Items["X-RemotePS-WinRMInfo"] as WinRMInfo;

            if (winRMInfo == null)
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo = null.");
                return;
            }
            string action = winRMInfo.Action;

            if (string.IsNullOrEmpty(action))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo.Action = null.");
                return;
            }
            if (!action.EndsWith(":Command", StringComparison.OrdinalIgnoreCase) && !action.Equals("Command", StringComparison.OrdinalIgnoreCase))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <string>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Not Command Request. WinRMInfo.Action = {0}.", action);
                return;
            }
            IPowerShellBudget   powerShellBudget = null;
            OverBudgetException ex = null;

            try
            {
                try
                {
                    using (new MonitoredScope("ThrottlingHttpModule", "GetBudget", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget = this.GetBudget(context);
                    }
                    if (powerShellBudget == null)
                    {
                        ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] budget = null.");
                        return;
                    }
                    using (new MonitoredScope("ThrottlingHttpModule", "CheckBudgetAndStartCmdlet", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget.StartCmdlet(null);
                        powerShellBudget.TryCheckOverBudget(CostType.CMDLET, out ex);
                    }
                }
                finally
                {
                    if (powerShellBudget != null)
                    {
                        powerShellBudget.Dispose();
                    }
                }
                if (ex != null)
                {
                    string windowsLiveId = context.CurrentUserToken().WindowsLiveId;
                    if (windowsLiveId != null)
                    {
                        FailFastUserCache.Instance.AddUserToCache(windowsLiveId, BlockedType.NewRequest, TimeSpan.Zero);
                        HttpLogger.SafeAppendColumn(RpsCommonMetadata.ContributeToFailFast, "AuthZ-UserSelf", LoggerHelper.GetContributeToFailFastValue("User", windowsLiveId, BlockedType.NewRequest.ToString(), -1.0));
                    }
                    HttpModuleHelper.EndPowerShellRequestWithFriendlyError(context, FailureCategory.AuthZ, ex.GetType().Name, Strings.ErrorOperationTarpitting(ex.BackoffTime / 1000) + string.Format("{2}Policy: {0}; {2}Snapshot: {1}", ex.ThrottlingPolicyDN, ex.Snapshot, Environment.NewLine), "ThrottlingHttpModule", false);
                }
            }
            catch (Exception ex2)
            {
                if (!(ex2 is ThreadAbortException))
                {
                    HttpLogger.SafeAppendGenericError("ThrottlingHttpModule", ex2, new Func <Exception, bool>(KnownException.IsUnhandledException));
                    ExTraceGlobals.HttpModuleTracer.TraceError <Exception>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Get un-Excpected Exception. {0}", ex2);
                }
            }
        }