コード例 #1
0
		private static void LoadDefaults (ref PowerShellEngineConfiguration powerShellEngine)
		{
			var assembly = Assembly.GetEntryAssembly ();
			if (assembly == null) {
				//We're on web!
				powerShellEngine.ApplicationBase = "/Users/bruno/Projects/PowerShell/v1.0"; //TODO: Urgent Change this!
			} else {
				FileInfo entry = new FileInfo (Assembly.GetEntryAssembly ().Location);
				powerShellEngine.ApplicationBase = entry.Directory.FullName;
			}

		}
コード例 #2
0
        private static void LoadDefaults(ref PowerShellEngineConfiguration powerShellEngine)
        {
            var assembly = Assembly.GetEntryAssembly();

            if (assembly == null)
            {
                //We're on web!
                powerShellEngine.ApplicationBase = "/Users/bruno/Projects/PowerShell/v1.0";                 //TODO: Urgent Change this!
            }
            else
            {
                FileInfo entry = new FileInfo(Assembly.GetEntryAssembly().Location);
                powerShellEngine.ApplicationBase = entry.Directory.FullName;
            }
        }
コード例 #3
0
        static PowerShellConfiguration()
        {
            PowerShellEngineConfiguration        powerShellEngine  = new PowerShellEngineConfiguration();
            PowerShellModuleLoggingConfiguraiton powerShellLogging = new PowerShellModuleLoggingConfiguraiton();

            if (!IsWindows)
            {
                LoadDefaults(ref powerShellEngine);
                LoadDefaults(ref powerShellLogging);
                XDocument doc = GetConfigDoc();
                if (doc != null)
                {
                    var root       = doc.Document.Root;
                    var policyRoot = root.Element("Policy");
                    var engine     = root.Element("PowerShellEngine");
                    var appBase    = engine.Element("ApplicationBase").Value;
                    if (!string.IsNullOrEmpty(appBase))
                    {
                        powerShellEngine.ApplicationBase = appBase;
                    }
                    if (policyRoot != null)
                    {
                        var policyNodes = policyRoot.Elements();
                        foreach (var elPol in policyNodes)
                        {
                            _policyValues.Add(elPol.Name.LocalName, elPol.Value);
                        }
                    }
                    var moduleLogging    = root.Element("ModuleLogging");
                    var enableModLogging = moduleLogging.Element("EnableModuleLogging").Value;
                    if (string.Equals(enableModLogging, "0", StringComparison.OrdinalIgnoreCase))
                    {
                        powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Disabled;
                    }
                    else if (!string.Equals(enableModLogging, "1", StringComparison.OrdinalIgnoreCase))
                    {
                        powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Undefined;
                    }
                    else
                    {
                        powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Enabled;
                    }

                    var           moduleNamesKey = moduleLogging.Element("ModuleNames").Elements("ModuleName");
                    List <string> moduleNames    = new List <string>();
                    foreach (var x in moduleNamesKey)
                    {
                        moduleNames.Add(x.Value);
                    }
                    powerShellLogging.ModuleNames = moduleNames;
                }
            }
            else
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Xamarin\PowerShell\" + PSVersionInfo.RegistryVersionKey + @"\PowerShellEngine"))
                {
                    powerShellEngine.ApplicationBase = (string)key.GetValue("ApplicationBase");
                }
                using (RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"Software\Xamarin\PowerShell\ModuleLogging"))                 //"Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging"
                {
                    if (key2 != null)
                    {
                        IEnumerable <string> moduleNames = null;
                        powerShellLogging.EnableModuleLogging = GetModuleLoggingValue("EnableModuleLogging", key2, out moduleNames);
                        powerShellLogging.ModuleNames         = moduleNames;
                        key2.Close();
                    }
                }
            }

            lock (_lock) {
                _powerShellEngine  = powerShellEngine;
                _powerShellLogging = powerShellLogging;
            }
        }
コード例 #4
0
		static PowerShellConfiguration ()
		{
			PowerShellEngineConfiguration powerShellEngine = new PowerShellEngineConfiguration ();
			PowerShellModuleLoggingConfiguraiton powerShellLogging = new PowerShellModuleLoggingConfiguraiton();
			if (!IsWindows) {
				LoadDefaults(ref powerShellEngine);
				LoadDefaults(ref powerShellLogging);
				XDocument doc = GetConfigDoc ();
				if (doc != null)
				{

					var root = doc.Document.Root;
					var policyRoot = root.Element ("Policy");
					var engine = root.Element ("PowerShellEngine");
					var appBase = engine.Element ("ApplicationBase").Value;
					if (!string.IsNullOrEmpty (appBase))
					{
						powerShellEngine.ApplicationBase = appBase;
					}
					if (policyRoot != null) {
						var policyNodes  = policyRoot.Elements ();
						foreach(var elPol in policyNodes)
						{
							_policyValues.Add (elPol.Name.LocalName, elPol.Value);
						}
					}
					var moduleLogging = root.Element ("ModuleLogging");
					var enableModLogging = moduleLogging.Element ("EnableModuleLogging").Value;
					if (string.Equals(enableModLogging, "0", StringComparison.OrdinalIgnoreCase))
					{
						powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Disabled;
					}
					else if (!string.Equals(enableModLogging, "1", StringComparison.OrdinalIgnoreCase))
					{
						powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Undefined;
					}
					else {
						powerShellLogging.EnableModuleLogging = ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Enabled;
					}

					var moduleNamesKey = moduleLogging.Element ("ModuleNames").Elements ("ModuleName");
					List<string> moduleNames = new List<string>();
					foreach(var x in moduleNamesKey)
					{
						moduleNames.Add (x.Value);
					}
					powerShellLogging.ModuleNames = moduleNames;
				}
				
			} else {
				using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Xamarin\PowerShell\" + PSVersionInfo.RegistryVersionKey + @"\PowerShellEngine"))
				{
					powerShellEngine.ApplicationBase = (string) key.GetValue("ApplicationBase");
				}
				using (RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"Software\Xamarin\PowerShell\ModuleLogging")) //"Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging"
				{
					if (key2 != null)
					{
						IEnumerable<string> moduleNames = null;
						powerShellLogging.EnableModuleLogging = GetModuleLoggingValue("EnableModuleLogging", key2, out moduleNames);
						powerShellLogging.ModuleNames = moduleNames;
						key2.Close();
					}
				}
			}

			lock (_lock) {
				_powerShellEngine = powerShellEngine;
				_powerShellLogging = powerShellLogging;
			}
		}