Exemple #1
0
        private PowerShellPackageProvider Create(PsRequest request, string modulePath, string requiredVersion, bool force, bool logWarning)
        {
            var ps = PowerShell.Create();

            try {
                // load the powershell provider functions into this runspace.
                if (ps.ImportModule(PowerShellProviderFunctions, false) != null)
                {
                    var result = ps.ImportModule(modulePath, force);
                    if (result != null)
                    {
                        try {
                            return(new PowerShellPackageProvider(ps, result, requiredVersion));
                        } catch (Exception e) {
                            e.Dump(request);
                        }
                    }
                    else if (ps.HadErrors)
                    {
                        foreach (var errorMessage in ps.Streams.Error.Select(e => e.ErrorDetails).Select(ed => ed.Message))
                        {
                            if (logWarning)
                            {
                                request.Warning(errorMessage);
                            }
                        }
                    }
                }
                else if (ps.HadErrors)
                {
                    foreach (var errorMessage in ps.Streams.Error.Select(e => e.ErrorDetails).Select(ed => ed.Message))
                    {
                        if (logWarning)
                        {
                            request.Warning(errorMessage);
                        }
                    }
                }
            } catch (Exception e) {
                // something didn't go well.
                // skip it.
                e.Dump(request);
                if (logWarning)
                {
                    request.Warning(e.Message);
                }
            }

            // didn't import correctly.
            ps.Dispose();
            return(null);
        }
        private PowerShellPackageProvider Create(PsRequest request, string modulePath, string requiredVersion, bool force)
        {
            var ps = PowerShell.Create();

            try {
                // load the powershell provider functions into this runspace.
                if (ps.ImportModule(PowerShellProviderFunctions, false) != null)
                {
                    var result = ps.ImportModule(modulePath, force);
                    if (result != null)
                    {
                        try {
                            return(new PowerShellPackageProvider(ps, result, requiredVersion));
                        } catch (Exception e) {
                            e.Dump();
                        }
                    }
                }
            } catch (Exception e) {
                // something didn't go well.
                // skip it.
                e.Dump();
                request.Warning(e.Message);
            }

            // didn't import correctly.
            ps.Dispose();
            return(null);
        }
        private PowerShellPackageProvider Create(PsRequest request, string modulePath, string requiredVersion, bool force, bool logWarning) {
            var ps = PowerShell.Create();
            try {
                // load the powershell provider functions into this runspace.
                if (ps.ImportModule(PowerShellProviderFunctions, false) != null) {
                    var result = ps.ImportModule(modulePath, force);
                    if (result != null) {
                        try {
                            return new PowerShellPackageProvider(ps, result, requiredVersion);
                        } catch (Exception e) {
                            e.Dump();
                        }
                    }
                }
            } catch (Exception e) {
                // something didn't go well.
                // skip it.
                e.Dump();
                if (logWarning) {
                    request.Warning(e.Message);
                }
            }

            // didn't import correctly.
            ps.Dispose();
            return null;
        }