コード例 #1
0
        internal static PSSessionConfigurationData Create(string configurationData)
        {
            PSSessionConfigurationData data = new PSSessionConfigurationData();

            if (!string.IsNullOrEmpty(configurationData))
            {
                configurationData = Unescape(configurationData);
                XmlReaderSettings settings = new XmlReaderSettings {
                    CheckCharacters = false,
                    IgnoreComments  = true,
                    IgnoreProcessingInstructions = true,
                    MaxCharactersInDocument      = 0x2710L,
                    XmlResolver      = null,
                    ConformanceLevel = ConformanceLevel.Fragment
                };
                using (XmlReader reader = XmlReader.Create(new StringReader(configurationData), settings))
                {
                    if (reader.ReadToFollowing("SessionConfigurationData"))
                    {
                        for (bool flag = reader.ReadToDescendant("Param"); flag; flag = reader.ReadToFollowing("Param"))
                        {
                            if (!reader.MoveToAttribute("Name"))
                            {
                                throw PSTraceSource.NewArgumentException(configurationData, "remotingerroridstrings", "NoAttributesFoundForParamElement", new object[] { "Name", "Value", "Param" });
                            }
                            string a = reader.Value;
                            if (string.Equals(a, "PrivateData", StringComparison.OrdinalIgnoreCase))
                            {
                                if (reader.ReadToFollowing("PrivateData"))
                                {
                                    string str2 = reader.ReadOuterXml();
                                    AssertValueNotAssigned("PrivateData", data._privateData);
                                    data._privateData = str2;
                                }
                            }
                            else
                            {
                                if (!reader.MoveToAttribute("Value"))
                                {
                                    throw PSTraceSource.NewArgumentException(configurationData, "remotingerroridstrings", "NoAttributesFoundForParamElement", new object[] { "Name", "Value", "Param" });
                                }
                                string optionValue = reader.Value;
                                data.Update(a, optionValue);
                            }
                        }
                    }
                }
                data.CreateCollectionIfNecessary();
            }
            return(data);
        }
コード例 #2
0
 internal static PSSessionConfigurationData Create(string configurationData)
 {
     PSSessionConfigurationData data = new PSSessionConfigurationData();
     if (!string.IsNullOrEmpty(configurationData))
     {
         configurationData = Unescape(configurationData);
         XmlReaderSettings settings = new XmlReaderSettings {
             CheckCharacters = false,
             IgnoreComments = true,
             IgnoreProcessingInstructions = true,
             MaxCharactersInDocument = 0x2710L,
             XmlResolver = null,
             ConformanceLevel = ConformanceLevel.Fragment
         };
         using (XmlReader reader = XmlReader.Create(new StringReader(configurationData), settings))
         {
             if (reader.ReadToFollowing("SessionConfigurationData"))
             {
                 for (bool flag = reader.ReadToDescendant("Param"); flag; flag = reader.ReadToFollowing("Param"))
                 {
                     if (!reader.MoveToAttribute("Name"))
                     {
                         throw PSTraceSource.NewArgumentException(configurationData, "remotingerroridstrings", "NoAttributesFoundForParamElement", new object[] { "Name", "Value", "Param" });
                     }
                     string a = reader.Value;
                     if (string.Equals(a, "PrivateData", StringComparison.OrdinalIgnoreCase))
                     {
                         if (reader.ReadToFollowing("PrivateData"))
                         {
                             string str2 = reader.ReadOuterXml();
                             AssertValueNotAssigned("PrivateData", data._privateData);
                             data._privateData = str2;
                         }
                     }
                     else
                     {
                         if (!reader.MoveToAttribute("Value"))
                         {
                             throw PSTraceSource.NewArgumentException(configurationData, "remotingerroridstrings", "NoAttributesFoundForParamElement", new object[] { "Name", "Value", "Param" });
                         }
                         string optionValue = reader.Value;
                         data.Update(a, optionValue);
                     }
                 }
             }
         }
         data.CreateCollectionIfNecessary();
     }
     return data;
 }
コード例 #3
0
        internal static PSSessionConfigurationData Create(string configurationData)
        {
            PSSessionConfigurationData configuration = new PSSessionConfigurationData();

            if (String.IsNullOrEmpty(configurationData))
            {
                return(configuration);
            }

            configurationData = Unescape(configurationData);

            XmlReaderSettings readerSettings = new XmlReaderSettings
            {
                CheckCharacters = false,
                IgnoreComments  = true,
                IgnoreProcessingInstructions = true,
                MaxCharactersInDocument      = 10000,
                XmlResolver      = null,
                ConformanceLevel = ConformanceLevel.Fragment
            };

            using (XmlReader reader = XmlReader.Create(new StringReader(configurationData), readerSettings))
            {
                // read the header <SessionConfigurationData>
                if (reader.ReadToFollowing(SessionConfigToken))
                {
                    bool isParamFound = reader.ReadToDescendant(ParamToken);
                    while (isParamFound)
                    {
                        if (!reader.MoveToAttribute(NameToken))
                        {
                            throw PSTraceSource.NewArgumentException(configurationData,
                                                                     RemotingErrorIdStrings.NoAttributesFoundForParamElement,
                                                                     NameToken, ValueToken, ParamToken);
                        }

                        string optionName = reader.Value;

                        if (String.Equals(optionName, PrivateDataToken, StringComparison.OrdinalIgnoreCase))
                        {
                            // this is a PrivateData element which we
                            // need to process
                            if (reader.ReadToFollowing(PrivateDataToken))
                            {
                                string privateData = reader.ReadOuterXml();

                                AssertValueNotAssigned(PrivateDataToken, configuration._privateData);
                                configuration._privateData = privateData;
                            }
                        }
                        else
                        {
                            if (!reader.MoveToAttribute(ValueToken))
                            {
                                throw PSTraceSource.NewArgumentException(configurationData,
                                                                         RemotingErrorIdStrings.NoAttributesFoundForParamElement,
                                                                         NameToken, ValueToken, ParamToken);
                            }

                            string optionValue = reader.Value;
                            configuration.Update(optionName, optionValue);
                        }

                        // move to next Param token.
                        isParamFound = reader.ReadToFollowing(ParamToken);
                    }
                }
            }

            configuration.CreateCollectionIfNecessary();

            return(configuration);
        }
コード例 #4
0
        internal static PSSessionConfigurationData Create(string configurationData)
        {
            PSSessionConfigurationData configuration = new PSSessionConfigurationData();

            if (String.IsNullOrEmpty(configurationData)) return configuration;

            configurationData = Unescape(configurationData);

            XmlReaderSettings readerSettings = new XmlReaderSettings
            {
                CheckCharacters = false,
                IgnoreComments = true,
                IgnoreProcessingInstructions = true,
                MaxCharactersInDocument = 10000,
#if !CORECLR // No XmlReaderSettings.XmlResolver in CoreCLR
                XmlResolver = null,
#endif
                ConformanceLevel = ConformanceLevel.Fragment
            };

            using (XmlReader reader = XmlReader.Create(new StringReader(configurationData), readerSettings))
            {
                // read the header <SessionConfigurationData>
                if (reader.ReadToFollowing(SessionConfigToken))
                {
                    bool isParamFound = reader.ReadToDescendant(ParamToken);
                    while (isParamFound)
                    {
                        if (!reader.MoveToAttribute(NameToken))
                        {
                            throw PSTraceSource.NewArgumentException(configurationData,
                                RemotingErrorIdStrings.NoAttributesFoundForParamElement,
                                NameToken, ValueToken, ParamToken);
                        }

                        string optionName = reader.Value;

                        if (String.Equals(optionName, PrivateDataToken, StringComparison.OrdinalIgnoreCase))
                        {
                            // this is a PrivateData element which we
                            // need to process
                            if (reader.ReadToFollowing(PrivateDataToken))
                            {
                                string privateData = reader.ReadOuterXml();

                                AssertValueNotAssigned(PrivateDataToken, configuration._privateData);
                                configuration._privateData = privateData;
                            }
                        }
                        else
                        {
                            if (!reader.MoveToAttribute(ValueToken))
                            {
                                throw PSTraceSource.NewArgumentException(configurationData,
                                                                         RemotingErrorIdStrings.NoAttributesFoundForParamElement,
                                                                         NameToken, ValueToken, ParamToken);
                            }

                            string optionValue = reader.Value;
                            configuration.Update(optionName, optionValue);
                        }

                        // move to next Param token.
                        isParamFound = reader.ReadToFollowing(ParamToken);
                    }
                }
            }

            configuration.CreateCollectionIfNecessary();

            return configuration;
        }