Exemplo n.º 1
0
        public static object TranslateCmdletProxyParameter(object paramValue, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod)
        {
            if (paramValue == null)
            {
                return(null);
            }
            Type type = paramValue.GetType();

            if (type.IsPrimitive)
            {
                return(paramValue);
            }
            if (paramValue is IDictionary)
            {
                return(ProxyHelper.TranslateCmdletProxyDictionaryParameter(paramValue, proxyMethod));
            }
            if (paramValue is ICollection)
            {
                return(ProxyHelper.TranslateCmdletProxyCollectionParameter(paramValue, proxyMethod));
            }
            if (type == typeof(IIdentityParameter))
            {
                return(paramValue.ToString());
            }
            if (type == typeof(SwitchParameter))
            {
                return(((SwitchParameter)paramValue).IsPresent);
            }
            return(paramValue.ToString());
        }
        // Token: 0x060013F2 RID: 5106 RVA: 0x00046384 File Offset: 0x00044584
        internal static ExchangeRunspaceConfigurationSettings CreateConfigurationSettingsFromNameValueCollection(Uri uri, NameValueCollection collection, ExchangeRunspaceConfigurationSettings.ExchangeApplication defaultApplication)
        {
            string text = collection.Get("organization");

            ExchangeRunspaceConfigurationSettings.SerializationLevel serializationLevel = ExchangeRunspaceConfigurationSettings.SerializationLevel.Partial;
            if (collection.Get("serializationLevel") != null)
            {
                Enum.TryParse <ExchangeRunspaceConfigurationSettings.SerializationLevel>(collection.Get("serializationLevel"), true, out serializationLevel);
            }
            string text2 = collection.Get("clientApplication");

            ExchangeRunspaceConfigurationSettings.ExchangeApplication exchangeApplication = defaultApplication;
            if (text2 != null)
            {
                Enum.TryParse <ExchangeRunspaceConfigurationSettings.ExchangeApplication>(text2, true, out exchangeApplication);
            }
            PSLanguageMode pslanguageMode = PSLanguageMode.NoLanguage;

            if (exchangeApplication == ExchangeRunspaceConfigurationSettings.ExchangeApplication.EMC)
            {
                pslanguageMode = PSLanguageMode.NoLanguage;
            }
            ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod = ExchangeRunspaceConfigurationSettings.ProxyMethod.None;
            if (collection.Get("proxyMethod") != null)
            {
                Enum.TryParse <ExchangeRunspaceConfigurationSettings.ProxyMethod>(collection.Get("proxyMethod"), true, out proxyMethod);
            }
            bool flag = false;

            if (collection.Get("proxyFullSerialization") != null)
            {
                bool.TryParse(collection.Get("proxyFullSerialization"), out flag);
            }
            bool encodeDecodeKey = true;

            if (collection.Get("X-EncodeDecode-Key") != null)
            {
                bool.TryParse(collection.Get("X-EncodeDecode-Key"), out encodeDecodeKey);
            }
            bool isProxy = ExchangeRunspaceConfigurationSettings.IsCalledFromProxy(collection);

            return(new ExchangeRunspaceConfigurationSettings(uri, exchangeApplication, text, serializationLevel, pslanguageMode, proxyMethod, flag, encodeDecodeKey, isProxy));
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        private static object TranslateCmdletProxyDictionaryParameter(object paramValue, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod)
        {
            IDictionary dictionary = (IDictionary)paramValue;

            if (proxyMethod == ExchangeRunspaceConfigurationSettings.ProxyMethod.RPS)
            {
                Dictionary <string, object> dictionary2 = new Dictionary <string, object>();
                foreach (object obj in dictionary.Keys)
                {
                    dictionary2.Add(obj.ToString(), ProxyHelper.TranslateCmdletProxyParameter(dictionary[obj], proxyMethod));
                }
                return(dictionary2);
            }
            int           num           = 0;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("{");
            foreach (object obj2 in dictionary.Keys)
            {
                num++;
                stringBuilder.Append(obj2.ToString()).Append(" = ");
                object obj3 = dictionary[obj2];
                if (obj3 == null)
                {
                    stringBuilder.Append(ProxyHelper.nullString);
                }
                else
                {
                    object obj4 = ProxyHelper.TranslateCmdletProxyParameter(obj3, proxyMethod);
                    if (obj4.GetType() == typeof(bool))
                    {
                        stringBuilder.Append(((bool)obj4) ? ProxyHelper.trueString : ProxyHelper.falseString);
                    }
                    else
                    {
                        stringBuilder.Append(obj4.ToString());
                    }
                }
                stringBuilder.Append("; ");
            }
            if (num == 0)
            {
                return(null);
            }
            string str = stringBuilder.ToString().Trim().TrimEnd(new char[]
            {
                ';'
            });

            return(str + "}");
        }
Exemplo n.º 5
0
        private static object TranslateCmdletProxyCollectionParameter(object paramValue, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod)
        {
            ICollection collection = (ICollection)paramValue;

            if (proxyMethod == ExchangeRunspaceConfigurationSettings.ProxyMethod.RPS)
            {
                Collection <object> collection2 = new Collection <object>();
                foreach (object paramValue2 in collection)
                {
                    collection2.Add(ProxyHelper.TranslateCmdletProxyParameter(paramValue2, proxyMethod));
                }
                return(collection2);
            }
            int           num           = 0;
            StringBuilder stringBuilder = new StringBuilder();

            foreach (object paramValue3 in collection)
            {
                num++;
                object obj = ProxyHelper.TranslateCmdletProxyParameter(paramValue3, proxyMethod);
                string arg;
                if (obj == null)
                {
                    arg = ProxyHelper.nullString;
                }
                else if (obj.GetType() == typeof(bool))
                {
                    arg = (((bool)obj) ? ProxyHelper.trueString : ProxyHelper.falseString);
                }
                else
                {
                    arg = obj.ToString().Replace("'", "''");
                }
                stringBuilder.AppendFormat("'{0}',", arg);
            }
            if (num == 0)
            {
                return(null);
            }
            return(stringBuilder.ToString().Trim().TrimEnd(new char[]
            {
                ','
            }));
        }
 // Token: 0x060013D2 RID: 5074 RVA: 0x00046180 File Offset: 0x00044380
 internal ExchangeRunspaceConfigurationSettings(Uri connectionUri, ExchangeRunspaceConfigurationSettings.ExchangeApplication clientApplication, string tenantOrganization, ExchangeRunspaceConfigurationSettings.SerializationLevel serializationLevel, PSLanguageMode languageMode, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod, bool proxyFullSerialization, bool encodeDecodeKey, bool isProxy, ExchangeRunspaceConfigurationSettings.ExchangeUserType user, IEnumerable <KeyValuePair <string, string> > additionalConstraints)
 {
     this.clientApplication      = clientApplication;
     this.serializationLevel     = serializationLevel;
     this.tenantOrganization     = tenantOrganization;
     this.languageMode           = languageMode;
     this.originalConnectionUri  = connectionUri;
     this.proxyMethod            = proxyMethod;
     this.proxyFullSerialization = proxyFullSerialization;
     this.EncodeDecodeKey        = encodeDecodeKey;
     this.IsProxy  = isProxy;
     this.UserType = user;
     this.additionalConstraints = additionalConstraints;
 }
 // Token: 0x060013D1 RID: 5073 RVA: 0x0004615C File Offset: 0x0004435C
 internal ExchangeRunspaceConfigurationSettings(Uri connectionUri, ExchangeRunspaceConfigurationSettings.ExchangeApplication clientApplication, string tenantOrganization, ExchangeRunspaceConfigurationSettings.SerializationLevel serializationLevel, PSLanguageMode languageMode, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod, bool proxyFullSerialization, bool encodeDecodeKey, bool isProxy) : this(connectionUri, clientApplication, tenantOrganization, serializationLevel, languageMode, proxyMethod, proxyFullSerialization, encodeDecodeKey, isProxy, ExchangeRunspaceConfigurationSettings.ExchangeUserType.Unknown, null)
 {
 }
 // Token: 0x060013CF RID: 5071 RVA: 0x00046118 File Offset: 0x00044318
 internal ExchangeRunspaceConfigurationSettings(Uri connectionUri, ExchangeRunspaceConfigurationSettings.ExchangeApplication clientApplication, string tenantOrganization, ExchangeRunspaceConfigurationSettings.SerializationLevel serializationLevel, PSLanguageMode languageMode, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod) : this(connectionUri, clientApplication, tenantOrganization, serializationLevel, languageMode, proxyMethod, false, false)
 {
 }