Exemplo n.º 1
0
        private void StartBudgetProcess(object sender, EventArgs e)
        {
            string cmdLetName = null;

            if (this.context.InvocationInfo != null)
            {
                cmdLetName = this.context.InvocationInfo.CommandName;
            }
            this.DisposeCostHandle();
            this.SafeBudgetAction(delegate(BudgetInformation budgetInfo)
            {
                CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.UserBudgetOnStart, budgetInfo.Budget.GetCmdletBudgetUsage());
            });
            this.SafeBudgetAction(delegate(BudgetInformation budgetInfo)
            {
                budgetInfo.Budget.EndLocal();
            });
            this.SafeBudgetAction(delegate(BudgetInformation budgetInfo)
            {
                budgetInfo.Handle = budgetInfo.Budget.StartCmdlet(cmdLetName);
            });
            if (!this.casCostHandleDisabled)
            {
                this.SafeBudgetAction(delegate(BudgetInformation budgetInfo)
                {
                    try
                    {
                        budgetInfo.Budget.StartLocal(string.Format("Task.StartBudgetProcess.{0}", cmdLetName), default(TimeSpan));
                        budgetInfo.Budget.LocalCostHandle.MaxLiveTime = TimeSpan.FromHours(1.0);
                    }
                    catch (InvalidOperationException)
                    {
                        try
                        {
                            CmdletLogger.SafeAppendGenericError("StartLocalBudgetFailed", cmdLetName, false);
                            budgetInfo.Budget.EndLocal();
                        }
                        catch (Exception)
                        {
                        }
                    }
                });
                return;
            }
            ThrottlingModule <T> .LogInformationTrace("CasCostHandle is not enabled in cmdlet '{0}'", new object[]
            {
                cmdLetName
            });
        }
Exemplo n.º 2
0
        // Token: 0x060015C1 RID: 5569 RVA: 0x00050C28 File Offset: 0x0004EE28
        private void LogCmdletIterationEvent()
        {
            bool flag  = this.context.ExchangeRunspaceConfig == null;
            bool flag2 = VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.WriteEventLogInEnglish.Enabled && (CultureInfo.CurrentUICulture != CmdletLogHelper.DefaultLoggingCulture || CultureInfo.CurrentCulture != CmdletLogHelper.DefaultLoggingCulture);

            object[] array = new object[27];
            array[0] = ((this.context.InvocationInfo != null) ? this.context.InvocationInfo.DisplayName : string.Empty);
            array[1] = ((this.context.InvocationInfo == null) ? null : TaskVerboseStringHelper.FormatUserSpecifiedParameters(this.context.InvocationInfo.UserSpecifiedParameters ?? new PropertyBag()));
            array[2] = (flag ? ((this.context.UserInfo != null && this.context.UserInfo.ExecutingUserId != null) ? this.context.UserInfo.ExecutingUserId.ToString() : string.Empty) : this.context.ExchangeRunspaceConfig.IdentityName);
            array[3] = (flag ? null : this.context.ExchangeRunspaceConfig.LogonUserSid);
            array[4] = null;
            if (!flag)
            {
                SecurityIdentifier securityIdentifier = null;
                this.context.ExchangeRunspaceConfig.TryGetExecutingUserSid(out securityIdentifier);
                array[4] = securityIdentifier;
            }
            array[5] = this.GenerateApplicationString();
            array[6] = CmdletIterationEventModule.processIdAndName;
            array[7] = (flag ? ((this.context.UserInfo != null) ? this.context.UserInfo.CurrentOrganizationId : null) : this.context.ExchangeRunspaceConfig.OrganizationId);
            array[8] = Environment.CurrentManagedThreadId;
            DateTime utcNow = DateTime.UtcNow;

            array[9] = utcNow.Subtract(this.lastDateTimeValue);
            this.lastDateTimeValue = utcNow;
            ADDriverContext threadADContext = ADSessionSettings.GetThreadADContext();

            if (threadADContext == null)
            {
                array[10] = null;
            }
            else
            {
                array[10] = (flag2 ? TaskVerboseStringHelper.GetADServerSettings(null, threadADContext.ServerSettings, CmdletLogHelper.DefaultLoggingCulture) : TaskVerboseStringHelper.GetADServerSettings(null, threadADContext.ServerSettings, null));
            }
            if (this.context.ErrorInfo.HasErrors)
            {
                if (this.context.ErrorInfo.Exception != null)
                {
                    Exception exception = this.context.ErrorInfo.Exception;
                    array[11] = exception;
                    array[12] = this.context.ErrorInfo.ExchangeErrorCategory.Value;
                    if (exception != null && exception.InnerException != null)
                    {
                        array[13] = exception.InnerException;
                    }
                    if (exception is LocalizedException)
                    {
                        array[14] = ((LocalizedException)exception).LocalizedString.StringId;
                        if (!flag2)
                        {
                            goto IL_2DE;
                        }
                        LocalizedException ex             = (LocalizedException)exception;
                        IFormatProvider    formatProvider = ex.FormatProvider;
                        try
                        {
                            ex.FormatProvider = CmdletLogHelper.DefaultLoggingCulture;
                            array[11]         = ex.ToString();
                            goto IL_2DE;
                        }
                        finally
                        {
                            ex.FormatProvider = formatProvider;
                        }
                    }
                    array[14] = "NonLocalizedException";
                }
                else
                {
                    array[11] = "null";
                }
            }
IL_2DE:
            object obj;

            this.context.Items.TryGetValue("Log_AdditionalLogData", out obj);
            array[15] = obj;
            LocalizedString delayedInfo = ThrottlingModule <ResourceThrottlingCallback> .GetDelayedInfo(this.context);

            if (!string.IsNullOrEmpty(delayedInfo))
            {
                array[16] = (flag2 ? delayedInfo.ToString(CmdletLogHelper.DefaultLoggingCulture) : delayedInfo) + ThrottlingModule <ResourceThrottlingCallback> .GetThrottlingInfo(this.context);
            }
            array[17] = SuppressingPiiContext.NeedPiiSuppression;
            this.context.Items.TryGetValue("Log_CmdletProxyInfo", out obj);
            array[18] = obj;
            if (this.context.Items.TryGetValue("Log_ProxiedObjectCount", out obj))
            {
                obj = string.Format("{0} objects execution has been proxied to remote server.", obj);
            }
            array[19] = obj;
            if (this.context.Items.TryGetValue("Log_RequestQueryFilterInGetTasks", out obj))
            {
                array[20] = string.Format("Request Filter used is: {0}", obj);
            }
            if (this.context.Items.TryGetValue("Log_InternalQueryFilterInGetTasks", out obj))
            {
                array[21] = string.Format("Cmdlet Filter used is: {0}", obj);
            }
            array[22] = this.outputObjectCount;
            array[23] = "ActivityId: " + ((ActivityContext.ActivityId != null) ? ActivityContext.ActivityId.Value.ToString() : string.Empty);
            if (!flag && this.context.ExchangeRunspaceConfig != null)
            {
                array[24] = this.context.ExchangeRunspaceConfig.GetRBACInformationSummary();
            }
            if (Constants.IsPowerShellWebService && HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.Headers != null)
            {
                array[25] = HttpContext.Current.Request.Headers["client-request-id"];
            }
            array[26] = CultureInfo.CurrentUICulture.Name;
            ExEventLog.EventTuple eventInfo;
            if (this.context.ErrorInfo.HasErrors)
            {
                eventInfo = TaskEventLogConstants.Tuple_LogCmdletError;
            }
            else if (this.context.WasCancelled)
            {
                eventInfo = TaskEventLogConstants.Tuple_LogCmdletCancelled;
            }
            else if (this.wasStopped)
            {
                eventInfo = TaskEventLogConstants.Tuple_LogCmdletStopped;
            }
            else
            {
                eventInfo = this.CmdletSuccessEventTuple;
            }
            try
            {
                TaskLogger.LogEvent("All", eventInfo, array);
            }
            catch (ArgumentException ex2)
            {
                if (this.context.CommandShell != null)
                {
                    this.context.CommandShell.WriteWarning(Strings.WarningCannotWriteToEventLog(ex2.ToString()));
                }
            }
        }
Exemplo n.º 3
0
 private void SafeBudgetAction(Action <BudgetInformation> action)
 {
     foreach (BudgetInformation budgetInformation in from x in this.budgets
              where x.Budget != null
              select x)
     {
         try
         {
             action(budgetInformation);
         }
         catch (OverBudgetException ex)
         {
             if (ex.PolicyPart == "LocalTime" || ex.PolicyPart == "PowerShellMaxCmdlets")
             {
                 OrganizationId organizationId = null;
                 if (this.context.UserInfo != null)
                 {
                     organizationId = this.context.UserInfo.ExecutingUserOrganizationId;
                 }
                 this.LogPeriodicEvent(budgetInformation.ThrottledEventInfo, new object[]
                 {
                     organizationId,
                     budgetInformation.Budget.ToString(),
                     ex
                 });
             }
             if (ex.PolicyPart == "MaxDestructiveCmdletsTimePeriod")
             {
                 OrganizationId organizationId2 = null;
                 if (this.context.UserInfo != null)
                 {
                     organizationId2 = this.context.UserInfo.ExecutingUserOrganizationId;
                 }
                 if (OrganizationId.ForestWideOrgId.Equals(organizationId2))
                 {
                     this.LogPeriodicEvent(TaskEventLogConstants.Tuple_DestructiveTaskThrottledForFirstOrg, new object[]
                     {
                         organizationId2,
                         budgetInformation.Budget.ToString(),
                         ex
                     });
                 }
                 else
                 {
                     this.LogPeriodicEvent(TaskEventLogConstants.Tuple_DestructiveTaskThrottledForTenant, new object[]
                     {
                         organizationId2,
                         budgetInformation.Budget.ToString(),
                         ex
                     });
                 }
             }
             if (ex.PolicyPart == "PowerShellMaxCmdlets" || ex.PolicyPart == "MaxDestructiveCmdletsTimePeriod" || ex.PolicyPart == "LocalTime")
             {
                 this.TriggerFailFast(ex);
                 if (this.context.CommandShell == null)
                 {
                     throw;
                 }
                 this.context.CommandShell.ThrowTerminatingError(ThrottlingModule <T> .WrapOverBudgetException(ex, budgetInformation.Budget), ExchangeErrorCategory.Context, null);
             }
         }
     }
 }