internal static void Execute(this ICriticalFeature feature, Action action, TaskContext taskContext, string methodNameInLog)
 {
     try
     {
         action();
     }
     catch (Exception ex)
     {
         Guid      uniqueId = taskContext.UniqueId;
         bool      flag     = false;
         Exception ex2;
         bool      needReportException = !TaskHelper.IsTaskKnownException(ex2) && TaskHelper.ShouldReportException(ex2, out flag);
         if (!needReportException)
         {
             CmdletLogger.SafeAppendGenericError(uniqueId, methodNameInLog, ex2.ToString(), false);
         }
         else
         {
             CmdletLogger.SafeAppendGenericError(uniqueId, methodNameInLog, ex2.ToString(), true);
             CmdletLogger.SafeSetLogger(uniqueId, RpsCmdletMetadata.ErrorType, "UnHandled");
         }
         if (feature == null || feature.IsCriticalException(ex2))
         {
             throw;
         }
         if (!flag)
         {
             taskContext.CommandShell.WriteWarning(Strings.WarningTaskModuleSkipped(methodNameInLog, ex2.Message));
         }
         Diagnostics.ReportException(ex2, Constants.CoreEventLogger, TaskEventLogConstants.Tuple_UnhandledException, (object ex) => needReportException, null, ExTraceGlobals.InstrumentationTracer, "Exception from  " + methodNameInLog + ": {0}");
     }
 }
Exemplo n.º 2
0
 internal void SetGroupMailbox(GroupMailboxConfigurationActionType forceConfigurationActionMask, out Exception exception, out ExchangeErrorCategory?errorCategory)
 {
     errorCategory = null;
     try
     {
         this.AddVerboseLog("Start: SetGroupMailbox");
         if (this.addMembers != null || this.removeMembers != null || !this.groupMailbox.IsGroupMailboxConfigured || this.permissionsVersion != null || forceConfigurationActionMask != (GroupMailboxConfigurationActionType)0)
         {
             this.UpdateGroupMailbox(null, forceConfigurationActionMask, this.GetValidGroupMembersFromFromRecipientIds(this.addMembers), this.ResolveUsers(this.removeMembers, new Action <RecipientIdParameter, Exception>(this.ReportResolveUserWarning)));
             if (this.invalidUsers.Length > 0)
             {
                 CmdletLogger.SafeAppendGenericError("UsersWithoutSmtpAddress_Set", this.invalidUsers.ToString(), false);
                 this.invalidUsers.Clear();
             }
         }
         else
         {
             this.AddVerboseLog("No members to update on GroupMailbox or configuration action to execute.");
         }
         exception = null;
     }
     catch (LocalizedException ex)
     {
         exception     = ex;
         errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.ServerTransient);
         if (this.IsWellKnownClientException(ex))
         {
             errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.Client);
         }
     }
     finally
     {
         this.AddVerboseLog("End: SetGroupMailbox");
     }
 }
Exemplo n.º 3
0
 internal void NewGroupMailbox(DatabaseLocationInfo databaseLocationInfo, out Exception exception, out ExchangeErrorCategory?errorCategory)
 {
     errorCategory = null;
     try
     {
         this.AddVerboseLog("Start: NewGroupMailbox");
         this.EnsureGroupIsInDirectoryCache("GroupMailboxContext.NewGroupMailbox");
         this.UpdateGroupMailbox(databaseLocationInfo, (GroupMailboxConfigurationActionType)0, this.GetValidGroupMembersFromFromRecipientIds(this.setMembers), null);
         if (this.invalidUsers.Length > 0)
         {
             CmdletLogger.SafeAppendGenericError("UsersWithoutSmtpAddress_New", this.invalidUsers.ToString(), false);
             this.invalidUsers.Clear();
         }
         exception = null;
     }
     catch (Exception ex)
     {
         exception     = ex;
         errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.ServerTransient);
         if (this.IsWellKnownClientException(ex))
         {
             errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.Client);
         }
     }
     finally
     {
         this.AddVerboseLog("End: NewGroupMailbox");
     }
 }
Exemplo n.º 4
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.º 5
0
        // Token: 0x06001613 RID: 5651 RVA: 0x00052AE4 File Offset: 0x00050CE4
        private static bool ShouldProxyCmdlet(TaskContext context, string remoteServerFqdn, int remoteServerVersion)
        {
            if (string.IsNullOrWhiteSpace(remoteServerFqdn))
            {
                return(false);
            }
            if (context.ExchangeRunspaceConfig == null)
            {
                return(false);
            }
            if (ExTraceGlobals.FaultInjectionTracer.IsTraceEnabled(TraceType.FaultInjection))
            {
                bool flag = false;
                ProxyHelper.FaultInjection_ShouldForcedlyProxyCmdlet(context.ExchangeRunspaceConfig.ConfigurationSettings.OriginalConnectionUri, remoteServerFqdn, ref flag);
                if (flag)
                {
                    return(true);
                }
            }
            string localServerFqdn = TaskHelper.GetLocalServerFqdn(null);

            if (string.IsNullOrEmpty(localServerFqdn))
            {
                CmdletLogger.SafeAppendGenericError(context.UniqueId, "ShouldProxyCmdlet", "GetLocalServerFqdn returns null/empty value", false);
                return(false);
            }
            if (string.Equals(remoteServerFqdn, localServerFqdn, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            if (CmdletProxy.CanServerBeProxiedTo(remoteServerVersion))
            {
                return(true);
            }
            CmdletLogger.SafeAppendGenericInfo(context.UniqueId, "ShouldProxyCmdlet", string.Format("Remote server version {0} doesn't support be proxied.", ProxyHelper.GetFriendlyVersionInformation(remoteServerVersion)));
            return(false);
        }
        // Token: 0x06001606 RID: 5638 RVA: 0x000522DC File Offset: 0x000504DC
        private void OnError(object sender, GenericEventArg <TaskErrorEventArg> genericEventArg)
        {
            if (genericEventArg.Data.ExceptionHandled)
            {
                return;
            }
            Exception exception = genericEventArg.Data.Exception;
            Guid      uniqueId  = this.context.UniqueId;
            Exception ex        = CmdletStaticDataWithUniqueId <Exception> .Get(uniqueId);

            if (ex != null && ex != exception)
            {
                CmdletLogger.SafeAppendGenericError(uniqueId, this.context.Stage.ToString() + ".FromWriteError", ex.ToString(), false);
            }
            bool isUnhandledException = (genericEventArg.Data.IsUnknownException != null) ? genericEventArg.Data.IsUnknownException.Value : TaskHelper.IsTaskUnhandledException(exception);

            CmdletLogger.SafeAppendGenericError(uniqueId, this.context.Stage.ToString(), exception.ToString(), isUnhandledException);
            if (exception is LocalizedException)
            {
                CmdletLogger.SafeAppendGenericError(uniqueId, "ExceptionStringId", ((LocalizedException)exception).LocalizedString.StringId, false);
                if (CmdletLogHelper.NeedConvertLogMessageToUS)
                {
                    LocalizedException ex2            = (LocalizedException)exception;
                    IFormatProvider    formatProvider = ex2.FormatProvider;
                    try
                    {
                        ex2.FormatProvider = CmdletLogHelper.DefaultLoggingCulture;
                        CmdletLogger.SafeAppendGenericError(uniqueId, this.context.Stage.ToString() + "(en-us)", ex2.ToString(), false);
                    }
                    finally
                    {
                        ex2.FormatProvider = formatProvider;
                    }
                }
            }
        }
Exemplo n.º 7
0
        // Token: 0x06001644 RID: 5700 RVA: 0x00053BE8 File Offset: 0x00051DE8
        private void ProxyCmdletExecution(CmdletProxyInfo cmdletProxyInfo)
        {
            ExAssert.RetailAssert(this.context.ExchangeRunspaceConfig != null, "this.context.ExchangeRunspaceConfig should not be null.");
            string remoteServerFqdn           = cmdletProxyInfo.RemoteServerFqdn;
            int    remoteServerVersion        = cmdletProxyInfo.RemoteServerVersion;
            string friendlyVersionInformation = ProxyHelper.GetFriendlyVersionInformation(remoteServerVersion);

            CmdletProxyInfo.ChangeCmdletProxyParametersDelegate changeCmdletProxyParameters = cmdletProxyInfo.ChangeCmdletProxyParameters;
            if (Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.IsTraceEnabled(TraceType.FaultInjection))
            {
                Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <string>(3720752445U, ref remoteServerFqdn);
                UserToken userToken = this.context.ExchangeRunspaceConfig.ConfigurationSettings.UserToken;
                ProxyHelper.FaultInjection_UserSid(ref userToken);
                Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(3452316989U, ref remoteServerVersion);
            }
            string text = this.GeneratePswsProxyCmdlet(changeCmdletProxyParameters);

            ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod = this.DetermineProxyMethod(remoteServerVersion);
            if (this.context.CommandShell != null)
            {
                this.context.CommandShell.WriteVerbose(Strings.VerboseCmdletProxiedToAnotherServer(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString()));
            }
            Guid uniqueId = this.context.UniqueId;

            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServer, this.proxiedObjectCount.ToString(), remoteServerFqdn);
            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServerVersion, this.proxiedObjectCount.ToString(), friendlyVersionInformation.ToString());
            CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyMethod, this.proxiedObjectCount.ToString(), proxyMethod.ToString());
            try
            {
                IEnumerable <PSObject> enumerable;
                if (proxyMethod == ExchangeRunspaceConfigurationSettings.ProxyMethod.RPS)
                {
                    PSCommand command = this.GenerateProxyCmdlet(changeCmdletProxyParameters);
                    Task.TaskWarningLoggingDelegate writeWarning = null;
                    if (this.context.CommandShell != null)
                    {
                        writeWarning = new Task.TaskWarningLoggingDelegate(this.context.CommandShell.WriteWarning);
                    }
                    enumerable = ProxyHelper.RPSProxyExecution(this.context.UniqueId, command, remoteServerFqdn, this.context.ExchangeRunspaceConfig, remoteServerVersion, cmdletProxyInfo.ShouldAsyncProxy, writeWarning);
                }
                else
                {
                    enumerable = CommandInvocation.Invoke(this.context.UniqueId, ProxyHelper.GetPSWSProxySiteUri(remoteServerFqdn), text, CredentialCache.DefaultNetworkCredentials, ProxyHelper.GetPSWSProxyRequestHeaders(this.context.ExchangeRunspaceConfig), this.context.ExchangeRunspaceConfig.TypeTable);
                }
                foreach (PSObject psobject in enumerable)
                {
                    object sendToPipeline = psobject;
                    if (psobject.BaseObject != null && !(psobject.BaseObject is PSCustomObject))
                    {
                        sendToPipeline = psobject.BaseObject;
                    }
                    else if (this.context.ExchangeRunspaceConfig != null)
                    {
                        if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.ECP)
                        {
                            if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.OSP)
                            {
                                goto IL_2CB;
                            }
                        }
                        try
                        {
                            Task.TaskVerboseLoggingDelegate writeVerbose = null;
                            if (this.context.CommandShell != null)
                            {
                                writeVerbose = new Task.TaskVerboseLoggingDelegate(this.context.CommandShell.WriteWarning);
                            }
                            sendToPipeline = ProxyHelper.ConvertPSObjectToOriginalType(psobject, remoteServerVersion, writeVerbose);
                        }
                        catch (Exception ex)
                        {
                            CmdletLogger.SafeAppendGenericError(uniqueId, "ConvertPSObjectToOriginalTyp", ex, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException));
                            Diagnostics.ReportException(ex, Constants.CoreEventLogger, TaskEventLogConstants.Tuple_UnhandledException, null, null, Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer, "Exception from ProxyHelper.ConvertPSObjectToOriginalType : {0}");
                        }
                    }
IL_2CB:
                    if (this.context.CommandShell != null)
                    {
                        this.context.CommandShell.WriteObject(sendToPipeline);
                    }
                }
            }
            catch (Exception ex2)
            {
                CmdletLogger.SafeAppendGenericError(this.context.UniqueId, "ProxyCmdletExecution", ex2, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException));
                if (this.context.CommandShell != null)
                {
                    this.context.CommandShell.WriteError(new CmdletProxyException(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString(), ex2.Message), ExchangeErrorCategory.ServerOperation, null);
                }
            }
        }
        // Token: 0x06001608 RID: 5640 RVA: 0x000524C4 File Offset: 0x000506C4
        private void CommitLog(string loggingStep)
        {
            if (!this.logPendingCommit)
            {
                return;
            }
            this.logPendingCommit = false;
            Guid cmdletUniqueId = this.context.UniqueId;

            try
            {
                CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.CmdletUniqueId, cmdletUniqueId);
                if (loggingStep != null)
                {
                    CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "Logging", loggingStep);
                }
                CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.ProcessId, Constants.ProcessId);
                CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.ProcessName, Constants.ProcessName);
                CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.ThreadId, Environment.CurrentManagedThreadId);
                CmdletLatencyTracker.EndInternalTracking(cmdletUniqueId, "Cmd");
                CmdletLatencyTracker.PushLatencyDetailsToLog(cmdletUniqueId, CmdletLogHelper.FuncNameToLogMetaDic, delegate(Enum metadata, double latency)
                {
                    CmdletLogger.UpdateLatency(cmdletUniqueId, metadata, latency);
                }, delegate(string funcName, string totalLatency)
                {
                    CmdletLogger.SafeAppendColumn(RpsCommonMetadata.GenericLatency, funcName, totalLatency);
                });
                long num = CmdletLatencyTracker.StopLatencyTracker(cmdletUniqueId);
                CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.TotalTime, num);
                CmdletLatencyTracker.DisposeLatencyTracker(cmdletUniqueId);
                if (!this.parametersSetInLog)
                {
                    if (this.context.InvocationInfo != null)
                    {
                        CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.Cmdlet, this.context.InvocationInfo.CommandName);
                        CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.Parameters, TaskVerboseStringHelper.FormatUserSpecifiedParameters(this.context.InvocationInfo.UserSpecifiedParameters ?? new PropertyBag()));
                    }
                    else
                    {
                        CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "InvocationInfo", "null");
                    }
                }
                TaskUserInfo userInfo = this.context.UserInfo;
                if (userInfo != null)
                {
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.TenantId, userInfo.ExecutingUserOrganizationId.GetFriendlyName());
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.AuthenticatedUser, (userInfo.ExecutingWindowsLiveId != SmtpAddress.Empty) ? userInfo.ExecutingWindowsLiveId.ToString() : ((userInfo.ExecutingUserId != null && !string.IsNullOrWhiteSpace(userInfo.ExecutingUserId.Name)) ? userInfo.ExecutingUserId.Name : userInfo.ExecutingUserIdentityName));
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.EffectiveOrganization, userInfo.CurrentOrganizationId.GetFriendlyName());
                }
                else
                {
                    CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "UserInfo", "null");
                }
                if (this.context.ExchangeRunspaceConfig != null)
                {
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.UserServicePlan, this.context.ExchangeRunspaceConfig.ServicePlanForLogging);
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.IsAdmin, this.context.ExchangeRunspaceConfig.HasAdminRoles);
                    if (this.context.ExchangeRunspaceConfig.ConfigurationSettings != null && this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.Unknown)
                    {
                        CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.ClientApplication, this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication);
                    }
                }
                else
                {
                    CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "ExchangeRunspaceConfig", "null");
                }
                if (!CmdletLogHelper.DefaultLoggingCulture.Equals(CultureInfo.CurrentUICulture) || !CmdletLogHelper.DefaultLoggingCulture.Equals(CultureInfo.CurrentCulture))
                {
                    CmdletLogger.SafeSetLogger(cmdletUniqueId, RpsCmdletMetadata.CultureInfo, CultureInfo.CurrentUICulture + "," + CultureInfo.CurrentCulture);
                }
            }
            catch (Exception ex)
            {
                Diagnostics.LogExceptionWithTrace(Constants.CoreEventLogger, TaskEventLogConstants.Tuple_NonCrashingException, null, ExTraceGlobals.InstrumentationTracer, null, "Exception from CmdletLogger.AsyncCommit : {0}", ex);
                CmdletLogger.SafeAppendGenericError(cmdletUniqueId, "CommitLog", ex, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException));
            }
            finally
            {
                try
                {
                    CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.EndTime, DateTime.UtcNow);
                    CmdletLogger.AsyncCommit(cmdletUniqueId, true);
                    CmdletThreadStaticData.UnRegisterCmdletUniqueId(cmdletUniqueId);
                }
                catch (Exception exception)
                {
                    this.logPendingCommit = true;
                    Diagnostics.LogExceptionWithTrace(Constants.CoreEventLogger, TaskEventLogConstants.Tuple_NonCrashingException, null, ExTraceGlobals.InstrumentationTracer, null, "Exception from CmdletLogger.AsyncCommit : {0}", exception);
                }
            }
        }