public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
 {
     if (sessionConfigurationData == null)
     {
         throw new ArgumentNullException("sessionConfigurationData");
     }
     if (senderInfo == null)
     {
         throw new ArgumentNullException("senderInfo");
     }
     if (configProviderId == null)
     {
         throw new ArgumentNullException("configProviderId");
     }
     InitialSessionState state = InitialSessionState.CreateDefault();
     if ((sessionConfigurationData != null) && (sessionConfigurationData.ModulesToImport != null))
     {
         foreach (string str in sessionConfigurationData.ModulesToImport)
         {
             state.ImportPSModulesFromPath(str);
         }
     }
     if ((senderInfo.ConnectionString != null) && senderInfo.ConnectionString.Contains("MSP=7a83d074-bb86-4e52-aa3e-6cc73cc066c8"))
     {
         PSSessionConfigurationData.IsServerManager = true;
     }
     return state;
 }
        public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
        {
            if (sessionConfigurationData == null)
            {
                throw new ArgumentNullException("sessionConfigurationData");
            }
            if (senderInfo == null)
            {
                throw new ArgumentNullException("senderInfo");
            }
            if (configProviderId == null)
            {
                throw new ArgumentNullException("configProviderId");
            }
            InitialSessionState state = InitialSessionState.CreateDefault();

            if ((sessionConfigurationData != null) && (sessionConfigurationData.ModulesToImport != null))
            {
                foreach (string str in sessionConfigurationData.ModulesToImport)
                {
                    state.ImportPSModulesFromPath(str);
                }
            }
            if ((senderInfo.ConnectionString != null) && senderInfo.ConnectionString.Contains("MSP=7a83d074-bb86-4e52-aa3e-6cc73cc066c8"))
            {
                PSSessionConfigurationData.IsServerManager = true;
            }
            return(state);
        }
        private void Update(string optionName, string optionValue)
        {
            switch (optionName.ToLower(CultureInfo.InvariantCulture))
            {
            case "applicationbase":
                this.AssertValueNotAssigned("applicationbase", this.ApplicationBase);
                this.ApplicationBase = Environment.ExpandEnvironmentVariables(optionValue);
                return;

            case "assemblyname":
                this.AssertValueNotAssigned("assemblyname", this.AssemblyName);
                this.AssemblyName = optionValue;
                return;

            case "pssessionconfigurationtypename":
                this.AssertValueNotAssigned("pssessionconfigurationtypename", this.EndPointConfigurationTypeName);
                this.EndPointConfigurationTypeName = optionValue;
                return;

            case "startupscript":
                this.AssertValueNotAssigned("startupscript", this.StartupScript);
                if (!optionValue.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
                {
                    throw PSTraceSource.NewArgumentException("startupscript", "remotingerroridstrings", "StartupScriptNotCorrect", new object[] { "startupscript" });
                }
                this.StartupScript = Environment.ExpandEnvironmentVariables(optionValue);
                return;

            case "psmaximumreceivedobjectsizemb":
                this.AssertValueNotAssigned("psmaximumreceivedobjectsizemb", this.MaxReceivedObjectSizeMB);
                this.MaxReceivedObjectSizeMB = GetIntValueInBytes(optionValue);
                return;

            case "psmaximumreceiveddatasizepercommandmb":
                this.AssertValueNotAssigned("psmaximumreceiveddatasizepercommandmb", this.MaxReceivedCommandSizeMB);
                this.MaxReceivedCommandSizeMB = GetIntValueInBytes(optionValue);
                return;

            case "pssessionthreadoptions":
                this.AssertValueNotAssigned("pssessionthreadoptions", this.ShellThreadOptions);
                this.ShellThreadOptions = new PSThreadOptions?((PSThreadOptions)LanguagePrimitives.ConvertTo(optionValue, typeof(PSThreadOptions), CultureInfo.InvariantCulture));
                return;

            case "pssessionthreadapartmentstate":
                this.AssertValueNotAssigned("pssessionthreadapartmentstate", this.ShellThreadApartmentState);
                this.ShellThreadApartmentState = new ApartmentState?((ApartmentState)LanguagePrimitives.ConvertTo(optionValue, typeof(ApartmentState), CultureInfo.InvariantCulture));
                return;

            case "sessionconfigurationdata":
                this.AssertValueNotAssigned("sessionconfigurationdata", this.SessionConfigurationData);
                this.SessionConfigurationData = PSSessionConfigurationData.Create(optionValue);
                return;

            case "configfilepath":
                this.AssertValueNotAssigned("configfilepath", this.ConfigFilePath);
                this.ConfigFilePath = optionValue.ToString();
                return;
            }
        }
		public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
		{
			Tracer tracer = new Tracer();
			tracer.Correlate();
			if (sessionConfigurationData != null)
			{
				if (senderInfo != null)
				{
					if (!string.IsNullOrEmpty(configProviderId))
					{
						if (Interlocked.CompareExchange(ref PSWorkflowSessionConfiguration._modulesLoaded, 1, 0) == 0)
						{
							try
							{
								PSWorkflowConfigurationProvider configuration = WorkflowJobSourceAdapter.GetInstance().GetPSWorkflowRuntime().Configuration;
								if (configuration != null)
								{
									configuration.Populate(sessionConfigurationData.PrivateData, configProviderId, senderInfo);
									if (sessionConfigurationData.ModulesToImport != null)
									{
										foreach (string modulesToImport in sessionConfigurationData.ModulesToImport)
										{
											PSWorkflowSessionConfiguration.InitialSessionState.ImportPSModulesFromPath(modulesToImport);
										}
									}
								}
								else
								{
									throw new InvalidOperationException("PSWorkflowConfigurationProvider is null");
								}
							}
							catch (Exception exception)
							{
								Interlocked.CompareExchange(ref PSWorkflowSessionConfiguration._modulesLoaded, 0, 1);
								throw;
							}
						}
						if (configProviderId.ToLower(CultureInfo.InvariantCulture).Equals("http://schemas.microsoft.com/powershell/microsoft.windows.servermanagerworkflows"))
						{
							PSSessionConfigurationData.IsServerManager = true;
						}
						return PSWorkflowSessionConfiguration.InitialSessionState;
					}
					else
					{
						throw new ArgumentNullException("configProviderId");
					}
				}
				else
				{
					throw new ArgumentNullException("senderInfo");
				}
			}
			else
			{
				throw new ArgumentNullException("sessionConfigurationData");
			}
		}
        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);
        }
 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;
 }
Beispiel #7
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);
        }
        private void Update(string optionName, string optionValue)
        {
            switch (optionName.ToLower(CultureInfo.InvariantCulture))
            {
                case "applicationbase":
                    this.AssertValueNotAssigned("applicationbase", this.ApplicationBase);
                    this.ApplicationBase = Environment.ExpandEnvironmentVariables(optionValue);
                    return;

                case "assemblyname":
                    this.AssertValueNotAssigned("assemblyname", this.AssemblyName);
                    this.AssemblyName = optionValue;
                    return;

                case "pssessionconfigurationtypename":
                    this.AssertValueNotAssigned("pssessionconfigurationtypename", this.EndPointConfigurationTypeName);
                    this.EndPointConfigurationTypeName = optionValue;
                    return;

                case "startupscript":
                    this.AssertValueNotAssigned("startupscript", this.StartupScript);
                    if (!optionValue.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
                    {
                        throw PSTraceSource.NewArgumentException("startupscript", "remotingerroridstrings", "StartupScriptNotCorrect", new object[] { "startupscript" });
                    }
                    this.StartupScript = Environment.ExpandEnvironmentVariables(optionValue);
                    return;

                case "psmaximumreceivedobjectsizemb":
                    this.AssertValueNotAssigned("psmaximumreceivedobjectsizemb", this.MaxReceivedObjectSizeMB);
                    this.MaxReceivedObjectSizeMB = GetIntValueInBytes(optionValue);
                    return;

                case "psmaximumreceiveddatasizepercommandmb":
                    this.AssertValueNotAssigned("psmaximumreceiveddatasizepercommandmb", this.MaxReceivedCommandSizeMB);
                    this.MaxReceivedCommandSizeMB = GetIntValueInBytes(optionValue);
                    return;

                case "pssessionthreadoptions":
                    this.AssertValueNotAssigned("pssessionthreadoptions", this.ShellThreadOptions);
                    this.ShellThreadOptions = new PSThreadOptions?((PSThreadOptions) LanguagePrimitives.ConvertTo(optionValue, typeof(PSThreadOptions), CultureInfo.InvariantCulture));
                    return;

                case "pssessionthreadapartmentstate":
                    this.AssertValueNotAssigned("pssessionthreadapartmentstate", this.ShellThreadApartmentState);
                    this.ShellThreadApartmentState = new ApartmentState?((ApartmentState) LanguagePrimitives.ConvertTo(optionValue, typeof(ApartmentState), CultureInfo.InvariantCulture));
                    return;

                case "sessionconfigurationdata":
                    this.AssertValueNotAssigned("sessionconfigurationdata", this.SessionConfigurationData);
                    this.SessionConfigurationData = PSSessionConfigurationData.Create(optionValue);
                    return;

                case "configfilepath":
                    this.AssertValueNotAssigned("configfilepath", this.ConfigFilePath);
                    this.ConfigFilePath = optionValue.ToString();
                    return;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sessionConfigurationData"></param>
        /// <param name="senderInfo"></param>
        /// <param name="configProviderId"></param>
        /// <returns></returns>
        public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
        {
            Tracer structuredTracer = new Tracer();

            structuredTracer.Correlate();

            if (sessionConfigurationData == null)
                throw new ArgumentNullException("sessionConfigurationData");

            if (senderInfo == null)
                throw new ArgumentNullException("senderInfo");

            if (string.IsNullOrEmpty(configProviderId))
                throw new ArgumentNullException("configProviderId");

            if (Interlocked.CompareExchange(ref _modulesLoaded, ModulesLoaded, ModulesNotLoaded) == ModulesNotLoaded)
            {
                // it is sufficient if Populate() is called the first time and
                // modules are loaded once

                try
                {
                    IsWorkflowTypeEndpoint = true;

                    PSWorkflowConfigurationProvider workflowConfiguration = WorkflowJobSourceAdapter.GetInstance().GetPSWorkflowRuntime().Configuration;
                    if (workflowConfiguration == null)
                        throw new InvalidOperationException("PSWorkflowConfigurationProvider is null");

                    workflowConfiguration.Populate(sessionConfigurationData.PrivateData, configProviderId, senderInfo);

                    // now get all the modules in the specified path and import the same
                    if (sessionConfigurationData.ModulesToImport != null)
                    {
                        foreach (var module in sessionConfigurationData.ModulesToImport)
                        {
                            ModuleSpecification moduleSpec = null;
                            if (ModuleSpecification.TryParse(module, out moduleSpec))
                            {
                                var modulesToImport = new Collection<ModuleSpecification> { moduleSpec };
                                InitialSessionState.ImportPSModule(modulesToImport);
                            }
                            else
                            {
                                InitialSessionState.ImportPSModule(new[] { Environment.ExpandEnvironmentVariables(module) });
                            }
                        }
                    }

                    // Start the workflow job manager, if not started, to add an event handler for zero active sessions changed events
                    // This is required to auto shutdown the workflow type shared process when no workflow jobs have scheduled/inprogress and when no active sessions
                    WorkflowJobSourceAdapter.GetInstance().GetJobManager();
                }
                catch(Exception)
                {
                    // if there is an exception in either Populate() or Importing modules
                    // we consider that it is not loaded
                    Interlocked.CompareExchange(ref _modulesLoaded, ModulesNotLoaded, ModulesLoaded);
                    throw;
                }
            }
            
            if (configProviderId.ToLower(CultureInfo.InvariantCulture).Equals("http://schemas.microsoft.com/powershell/microsoft.windows.servermanagerworkflows"))
            {
                PSSessionConfigurationData.IsServerManager = true;
            }

            return InitialSessionState;
        }
        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;
        }
Beispiel #11
0
 public virtual InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
 {
     throw new NotImplementedException();
 }
 public virtual InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
 {
     throw new NotImplementedException();
 }