Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a <see cref="System.Management.Automation.Runspaces.MshConsoleInfo"/> object for the
        /// current Monad version which is already started.
        /// </summary>
        /// <exception cref="PSSnapInException">
        /// One or more default mshsnapins cannot be loaded because the
        /// registry is not populated correctly.
        /// </exception>
        internal static MshConsoleInfo CreateDefaultConfiguration()
        {
            // Steps:
            // 1. Get the current Monad Version
            // 2. Create MshConsoleInfo object.
            // 3. Read default mshsnapins.

            MshConsoleInfo consoleInfo = new MshConsoleInfo(PSVersionInfo.PSVersion);

            try
            {
                consoleInfo._defaultPSSnapIns = PSSnapInReader.ReadEnginePSSnapIns();
            }
            catch (PSArgumentException ae)
            {
                string message = ConsoleInfoErrorStrings.CannotLoadDefaults;
                // If we were unable to load default mshsnapins throw PSSnapInException

                s_mshsnapinTracer.TraceError(message);

                throw new PSSnapInException(message, ae);
            }
            catch (System.Security.SecurityException se)
            {
                string message = ConsoleInfoErrorStrings.CannotLoadDefaults;
                // If we were unable to load default mshsnapins throw PSSnapInException

                s_mshsnapinTracer.TraceError(message);

                throw new PSSnapInException(message, se);
            }

            return(consoleInfo);
        }
Ejemplo n.º 2
0
        internal static MshConsoleInfo CreateDefaultConfiguration()
        {
            MshConsoleInfo info = new MshConsoleInfo(PSVersionInfo.PSVersion);

            try
            {
                info.defaultPSSnapIns = PSSnapInReader.ReadEnginePSSnapIns();
            }
            catch (PSArgumentException exception)
            {
                string cannotLoadDefaults = ConsoleInfoErrorStrings.CannotLoadDefaults;
                _mshsnapinTracer.TraceError(cannotLoadDefaults, new object[0]);
                throw new PSSnapInException(cannotLoadDefaults, exception);
            }
            catch (SecurityException exception2)
            {
                string errorMessageFormat = ConsoleInfoErrorStrings.CannotLoadDefaults;
                _mshsnapinTracer.TraceError(errorMessageFormat, new object[0]);
                throw new PSSnapInException(errorMessageFormat, exception2);
            }
            return(info);
        }
Ejemplo n.º 3
0
 internal static MshConsoleInfo CreateDefaultConfiguration()
 {
     using (MshConsoleInfo.tracer.TraceMethod())
     {
         MshConsoleInfo mshConsoleInfo = new MshConsoleInfo(PSVersionInfo.PSVersion);
         try
         {
             mshConsoleInfo.defaultPSSnapIns = PSSnapInReader.ReadEnginePSSnapIns();
         }
         catch (PSArgumentException ex)
         {
             string resourceString = ResourceManagerCache.GetResourceString("ConsoleInfoErrorStrings", "CannotLoadDefaults");
             MshConsoleInfo._mshsnapinTracer.TraceError(resourceString);
             throw new PSSnapInException(resourceString, (Exception)ex);
         }
         catch (SecurityException ex)
         {
             string resourceString = ResourceManagerCache.GetResourceString("ConsoleInfoErrorStrings", "CannotLoadDefaults");
             MshConsoleInfo._mshsnapinTracer.TraceError(resourceString);
             throw new PSSnapInException(resourceString, (Exception)ex);
         }
         return(mshConsoleInfo);
     }
 }