Exemplo n.º 1
0
        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 PSWorkflowExecutionOption LoadConfig(string privateData, PSWorkflowConfigurationProvider configuration)
        {
            PSWorkflowExecutionOption pSWorkflowExecutionOption = new PSWorkflowExecutionOption();

            if (!string.IsNullOrEmpty(privateData))
            {
                XmlReaderSettings xmlReaderSetting = new XmlReaderSettings();
                xmlReaderSetting.CheckCharacters = false;
                xmlReaderSetting.IgnoreComments  = true;
                xmlReaderSetting.IgnoreProcessingInstructions = true;
                xmlReaderSetting.MaxCharactersInDocument      = (long)0x2710;
                xmlReaderSetting.XmlResolver      = null;
                xmlReaderSetting.ConformanceLevel = ConformanceLevel.Fragment;
                XmlReaderSettings xmlReaderSetting1 = xmlReaderSetting;
                XmlReader         xmlReader         = XmlReader.Create(new StringReader(privateData), xmlReaderSetting1);
                using (xmlReader)
                {
                    if (xmlReader.ReadToFollowing("PrivateData"))
                    {
                        HashSet <string> strs       = new HashSet <string>();
                        bool             descendant = xmlReader.ReadToDescendant("Param");
                        while (descendant)
                        {
                            if (xmlReader.MoveToAttribute("Name"))
                            {
                                string value = xmlReader.Value;
                                if (xmlReader.MoveToAttribute("Value"))
                                {
                                    if (!strs.Contains(value.ToLower(CultureInfo.InvariantCulture)))
                                    {
                                        string str = xmlReader.Value;
                                        PSWorkflowConfigurationProvider.Update(value, str, pSWorkflowExecutionOption, configuration);
                                        strs.Add(value.ToLower(CultureInfo.InvariantCulture));
                                        descendant = xmlReader.ReadToFollowing("Param");
                                    }
                                    else
                                    {
                                        throw new PSArgumentException(Resources.ParamSpecifiedMoreThanOnce, value);
                                    }
                                }
                                else
                                {
                                    throw new PSArgumentException(Resources.ValueNotSpecifiedForParam);
                                }
                            }
                            else
                            {
                                throw new PSArgumentException(Resources.NameNotSpecifiedForParam);
                            }
                        }
                    }
                }
                return(pSWorkflowExecutionOption);
            }
            else
            {
                return(pSWorkflowExecutionOption);
            }
        }
Exemplo n.º 3
0
        public PSWorkflowRuntime()
        {
            this._syncObject            = new object();
            this._configuration         = new PSWorkflowConfigurationProvider();
            this._configuration.Runtime = this;
            PSCounterSetRegistrar pSCounterSetRegistrar = new PSCounterSetRegistrar(PSWorkflowPerformanceCounterSetInfo.ProviderId, PSWorkflowPerformanceCounterSetInfo.CounterSetId, PSWorkflowPerformanceCounterSetInfo.CounterSetType, PSWorkflowPerformanceCounterSetInfo.CounterInfoArray, null);

            PSWorkflowRuntime._psPerfCountersMgrInst.AddCounterSetInstance(pSCounterSetRegistrar);
            PSModuleInfo.UseAppDomainLevelModuleCache = true;
        }
        internal static PSWorkflowExecutionOption LoadConfig(string privateData, PSWorkflowConfigurationProvider configuration)
        {
            PSWorkflowExecutionOption target = new PSWorkflowExecutionOption();

            if (String.IsNullOrEmpty(privateData))
            {
                return(target);
            }

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

            using (XmlReader reader = XmlReader.Create(new StringReader(privateData), readerSettings))
            {
                // read the header <PrivateData>
                if (reader.ReadToFollowing(PrivateDataToken))
                {
                    HashSet <string> assignedParams = new HashSet <string>();
                    bool             found          = reader.ReadToDescendant(ParamToken);
                    while (found)
                    {
                        if (!reader.MoveToAttribute(NameToken))
                        {
                            throw new PSArgumentException(Resources.NameNotSpecifiedForParam);
                        }

                        string optionName = reader.Value;

                        if (!reader.MoveToAttribute(ValueToken))
                        {
                            throw new PSArgumentException(Resources.ValueNotSpecifiedForParam);
                        }

                        if (assignedParams.Contains(optionName.ToLower(CultureInfo.InvariantCulture)))
                        {
                            throw new PSArgumentException(Resources.ParamSpecifiedMoreThanOnce, optionName);
                        }

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

                        assignedParams.Add(optionName.ToLower(CultureInfo.InvariantCulture));
                        found = reader.ReadToFollowing(ParamToken);
                    }
                }
            }
            return(target);
        }
        internal PSOutOfProcessActivityController(PSWorkflowRuntime runtime)
            : base(runtime)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            Debug.Assert(runtime.Configuration != null, "For now only expecting PSWorkflowConfigurationProvider");

            this._configuration = runtime.Configuration;
            InitializeActivityHostProcesses();
        }
        /// <summary>
        /// PSWorkflowValidator
        /// </summary>
        /// <param name="configuration"></param>
        public PSWorkflowValidator(PSWorkflowConfigurationProvider configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (TestMode)
            {
                System.Threading.Interlocked.Increment(ref ObjectCounter);
            }

            this.Configuration = configuration;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public PSWorkflowRuntime()
        {
            _configuration         = new PSWorkflowConfigurationProvider();
            _configuration.Runtime = this;
            PSCounterSetRegistrar registrar =
                new PSCounterSetRegistrar(
                    PSWorkflowPerformanceCounterSetInfo.ProviderId,
                    PSWorkflowPerformanceCounterSetInfo.CounterSetId,
                    PSWorkflowPerformanceCounterSetInfo.CounterSetType,
                    PSWorkflowPerformanceCounterSetInfo.CounterInfoArray);

            _psPerfCountersMgrInst.AddCounterSetInstance(registrar);

            // Enable caching module paths appdomain-wide.
            System.Management.Automation.PSModuleInfo.UseAppDomainLevelModuleCache = true;
        }
Exemplo n.º 8
0
 public PSWorkflowValidator(PSWorkflowConfigurationProvider configuration)
 {
     this._validationCache = new ConcurrentDictionary <Guid, PSWorkflowValidationResults>();
     if (configuration != null)
     {
         if (PSWorkflowValidator.TestMode)
         {
             Interlocked.Increment(ref PSWorkflowValidator.ObjectCounter);
         }
         this.Configuration = configuration;
         return;
     }
     else
     {
         throw new ArgumentNullException("configuration");
     }
 }
Exemplo n.º 9
0
 internal PSOutOfProcessActivityController(PSWorkflowRuntime runtime) : base(runtime)
 {
     this._hostProcesses    = new Collection <ActivityHostProcess>();
     this._requests         = new ConcurrentQueue <ActivityInvoker>();
     this._structuredTracer = new Tracer();
     this._failedRequests   = new ConcurrentQueue <ActivityInvoker>();
     if (runtime != null)
     {
         this._configuration = runtime.Configuration;
         this.InitializeActivityHostProcesses();
         return;
     }
     else
     {
         throw new ArgumentNullException("runtime");
     }
 }
Exemplo n.º 10
0
 private void OnWSManServerShuttingDownEventRaised(object sender, EventArgs e)
 {
     try
     {
         this.IsShutdownInProgress = true;
         PSWorkflowConfigurationProvider configuration = PSWorkflowRuntime.Instance.Configuration;
         int workflowShutdownTimeoutMSec = configuration.WorkflowShutdownTimeoutMSec;
         this.GetJobManager().ShutdownWorkflowManager(workflowShutdownTimeoutMSec);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         object[]  objArray  = new object[1];
         objArray[0] = exception;
         this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "Shutting down WSMan server: Exception details: {0}", objArray));
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Constructs runtime based on configuration
        /// </summary>
        /// <param name="configuration"></param>
        public PSWorkflowRuntime(PSWorkflowConfigurationProvider configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            // Only allow FullLanguage or ConstraintLanguage or it can be null in that case system wide default will take an affect
            PSLanguageMode?langMode = configuration.LanguageMode;

            if (langMode != null && langMode.HasValue && (langMode.Value == PSLanguageMode.NoLanguage || langMode.Value == PSLanguageMode.RestrictedLanguage))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NotSupportedLanguageMode, langMode.Value.ToString()));
            }

            _configuration         = configuration;
            _configuration.Runtime = this;
        }
        /// <summary>
        /// Handles the wsman server shutting down event.
        /// </summary>
        /// <param name="sender">sender of this event</param>
        /// <param name="e">arguments describing the event</param>
        private void OnWSManServerShuttingDownEventRaised(object sender, EventArgs e)
        {
            try
            {
                IsShutdownInProgress = true;
                PSWorkflowConfigurationProvider _configuration = (PSWorkflowConfigurationProvider)PSWorkflowRuntime.Instance.Configuration;
                int timeout = _configuration.WorkflowShutdownTimeoutMSec;

                GetJobManager().ShutdownWorkflowManager(timeout);
            }
            catch (Exception exception)
            {
                // when exception on shutdown, not much to do much other than logging the exception
                _tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture,
                                                   "Shutting down WSMan server: Exception details: {0}",
                                                   exception));

                Dbg.Assert(false, "Exception has happened during the shutdown API. [Message] " + exception.Message + "[StackTrace] " + exception.StackTrace);
            }
        }
        private bool IsOutOfProcessActivity(Type activityType)
        {
            IEnumerable <string> strs  = this.OutOfProcessActivity;
            IEnumerable <string> strs1 = strs;

            if (strs == null)
            {
                strs1 = (IEnumerable <string>)(new string[0]);
            }
            return(strs1.Any <string>((string outOfProcessActivity) => {
                if (PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, activityType.Name) || PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, activityType.FullName) || PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, string.Concat(activityType.Assembly.GetName().Name, "\\", activityType.Name)) || PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, string.Concat(activityType.Assembly.GetName().Name, "\\", activityType.FullName)) || PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, string.Concat(activityType.Assembly.GetName().FullName, "\\", activityType.Name)))
                {
                    return true;
                }
                else
                {
                    return PSWorkflowConfigurationProvider.IsMatched(outOfProcessActivity, string.Concat(activityType.Assembly.GetName().FullName, "\\", activityType.FullName));
                }
            }
                                      ));
        }
Exemplo n.º 14
0
 public PSWorkflowRuntime(PSWorkflowConfigurationProvider configuration)
 {
     this._syncObject = new object();
     if (configuration != null)
     {
         PSLanguageMode?languageMode = configuration.LanguageMode;
         if (!languageMode.HasValue || !languageMode.HasValue || languageMode.Value != PSLanguageMode.NoLanguage && languageMode.Value != PSLanguageMode.RestrictedLanguage)
         {
             this._configuration         = configuration;
             this._configuration.Runtime = this;
             return;
         }
         else
         {
             object[] str = new object[1];
             str[0] = languageMode.Value.ToString();
             throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NotSupportedLanguageMode, str));
         }
     }
     else
     {
         throw new ArgumentNullException("configuration");
     }
 }
        public void Populate(string applicationPrivateData, string configProviderId)
        {
            string str;

            if (!this._isPopulated)
            {
                lock (this._syncObject)
                {
                    if (!this._isPopulated)
                    {
                        this._privateData = applicationPrivateData;
                        char[] chrArray = new char[1];
                        chrArray[0] = '/';
                        string[] strArrays = configProviderId.Split(chrArray, StringSplitOptions.RemoveEmptyEntries);
                        PSWorkflowConfigurationProvider pSWorkflowConfigurationProvider = this;
                        if ((int)strArrays.Length > 0)
                        {
                            str = strArrays[(int)strArrays.Length - 1];
                        }
                        else
                        {
                            str = configProviderId;
                        }
                        pSWorkflowConfigurationProvider._configProviderId = str;
                        this._isPopulated = true;
                        this._wfOptions   = PSWorkflowConfigurationProvider.LoadConfig(this._privateData, this);
                        this.ResetCaching();
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
        private static void Update(string optionName, string value, PSWorkflowExecutionOption target, PSWorkflowConfigurationProvider configuration)
        {
            bool   flag  = false;
            bool   flag1 = false;
            string lower = optionName.ToLower(CultureInfo.InvariantCulture);
            string str   = lower;

            if (lower != null)
            {
                if (str == "workflowapplicationpersistunloadtimeoutsec")
                {
                    target.WorkflowApplicationPersistUnloadTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "activityprocessidletimeoutsec")
                {
                    target.ActivityProcessIdleTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "allowedactivity")
                {
                    char[] chrArray = new char[1];
                    chrArray[0] = ',';
                    string[] strArrays = value.Split(chrArray, StringSplitOptions.RemoveEmptyEntries);
                    PSWorkflowExecutionOption array = target;
                    string[] strArrays1             = strArrays;
                    array.AllowedActivity = strArrays1.Select <string, string>((string activity) => activity.Trim()).ToArray <string>();
                    return;
                }
                else if (str == "enablevalidation")
                {
                    if (!bool.TryParse(value, out flag))
                    {
                        return;
                    }
                    target.EnableValidation = flag;
                    return;
                }
                else if (str == "persistencepath")
                {
                    target.PersistencePath = Environment.ExpandEnvironmentVariables(value);
                    return;
                }
                else if (str == "maxpersistencestoresizegb")
                {
                    target.MaxPersistenceStoreSizeGB = (long)LanguagePrimitives.ConvertTo(value, typeof(long), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "persistwithencryption")
                {
                    if (!bool.TryParse(value, out flag1))
                    {
                        return;
                    }
                    target.PersistWithEncryption = flag1;
                    return;
                }
                else if (str == "remotenodesessionidletimeoutsec")
                {
                    target.RemoteNodeSessionIdleTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    if (configuration == null)
                    {
                        return;
                    }
                    configuration._remoteNodeSessionIdleTimeoutSec = target.RemoteNodeSessionIdleTimeoutSec;
                    return;
                }
                else if (str == "maxactivityprocesses")
                {
                    target.MaxActivityProcesses = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "maxconnectedsessions")
                {
                    target.MaxConnectedSessions = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "maxdisconnectedsessions")
                {
                    target.MaxDisconnectedSessions = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "maxrunningworkflows")
                {
                    target.MaxRunningWorkflows        = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    configuration._maxInProcRunspaces = target.MaxRunningWorkflows * 2;
                    return;
                }
                else if (str == "maxsessionsperremotenode")
                {
                    target.MaxSessionsPerRemoteNode = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "maxsessionsperworkflow")
                {
                    target.MaxSessionsPerWorkflow = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "outofprocessactivity")
                {
                    char[] chrArray1 = new char[1];
                    chrArray1[0] = ',';
                    string[] strArrays2 = value.Split(chrArray1, StringSplitOptions.RemoveEmptyEntries);
                    PSWorkflowExecutionOption pSWorkflowExecutionOption = target;
                    string[] strArrays3 = strArrays2;
                    pSWorkflowExecutionOption.OutOfProcessActivity = strArrays3.Select <string, string>((string activity) => activity.Trim()).ToArray <string>();
                    return;
                }
                else if (str == "sessionthrottlelimit")
                {
                    target.SessionThrottleLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "validationcachelimit")
                {
                    if (configuration == null)
                    {
                        return;
                    }
                    configuration._validationCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "compiledassemblycachelimit")
                {
                    if (configuration == null)
                    {
                        return;
                    }
                    configuration._compiledAssemblyCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "outofprocessactivitycachelimit")
                {
                    if (configuration == null)
                    {
                        return;
                    }
                    configuration._outOfProcessActivityCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "workflowshutdowntimeoutmsec")
                {
                    target.WorkflowShutdownTimeoutMSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                else if (str == "maxinprocrunspaces")
                {
                    if (configuration == null)
                    {
                        return;
                    }
                    configuration._maxInProcRunspaces = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                    return;
                }
                return;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Using optionName and optionValue updates the current object
        /// </summary>
        /// <param name="optionName"></param>
        /// <param name="value"></param>
        ///  <param name="target"></param>
        ///  <param name="configuration"></param>
        private static void Update(string optionName, string value, PSWorkflowExecutionOption target, PSWorkflowConfigurationProvider configuration)
        {
            switch (optionName.ToLower(CultureInfo.InvariantCulture))
            {
            case TokenWorkflowApplicationPersistUnloadTimeoutSec:
                target.WorkflowApplicationPersistUnloadTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenWSManPluginReportCompletionOnZeroActiveSessionsWaitIntervalMSec:
                target.WSManPluginReportCompletionOnZeroActiveSessionsWaitIntervalMSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenActivitiesCacheCleanupIntervalMSec:
                target.ActivitiesCacheCleanupIntervalMSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenActivityProcessIdleTimeoutSec:
                target.ActivityProcessIdleTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenAllowedActivity:
                string[] activities = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                target.AllowedActivity = activities.Select(activity => activity.Trim()).ToArray();
                break;

            case TokenEnableValidation:
                bool enableValidation;
                if (bool.TryParse(value, out enableValidation))
                {
                    target.EnableValidation = enableValidation;
                }
                break;

            case TokenPersistencePath:
                target.PersistencePath = Environment.ExpandEnvironmentVariables(value);
                break;

            case TokenMaxPersistenceStoreSizeGB:
                target.MaxPersistenceStoreSizeGB = (long)LanguagePrimitives.ConvertTo(value, typeof(long), CultureInfo.InvariantCulture);
                break;

            case TokenPersistWithEncryption:
                bool persistWithEncryption;
                if (bool.TryParse(value, out persistWithEncryption))
                {
                    target.PersistWithEncryption = persistWithEncryption;
                }
                break;

            case TokenRemoteNodeSessionIdleTimeoutSec:
                target.RemoteNodeSessionIdleTimeoutSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                if (configuration != null)
                {
                    configuration._remoteNodeSessionIdleTimeoutSec = target.RemoteNodeSessionIdleTimeoutSec;
                }
                break;

            case TokenMaxActivityProcesses:
                target.MaxActivityProcesses = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenMaxConnectedSessions:
                target.MaxConnectedSessions = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenMaxDisconnectedSessions:
                target.MaxDisconnectedSessions = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenMaxRunningWorkflows:
                target.MaxRunningWorkflows        = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                configuration._maxInProcRunspaces = target.MaxRunningWorkflows * 2;
                break;

            case TokenMaxSessionsPerRemoteNode:
                target.MaxSessionsPerRemoteNode = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenMaxSessionsPerWorkflow:
                target.MaxSessionsPerWorkflow = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenOutOfProcessActivity:
                string[] outofProcActivities = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                target.OutOfProcessActivity = outofProcActivities.Select(activity => activity.Trim()).ToArray();
                break;

            case TokenSessionThrottleLimit:
            {
                target.SessionThrottleLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
            }
            break;

            case TokenValidationCacheLimit:
                if (configuration != null)
                {
                    configuration._validationCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                }
                break;

            case TokenCompiledAssemblyCacheLimit:
                if (configuration != null)
                {
                    configuration._compiledAssemblyCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                }
                break;

            case TokenOutOfProcessActivityCacheLimit:
                if (configuration != null)
                {
                    configuration._outOfProcessActivityCacheLimit = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                }
                break;

            case TokenWorkflowShutdownTimeoutMSec:
                target.WorkflowShutdownTimeoutMSec = (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                break;

            case TokenMaxInProcRunspaces:
            {
                if (configuration != null)
                {
                    configuration._maxInProcRunspaces =
                        (int)LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture);
                }
            }
            break;
            }
        }
        /// <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);
        }