コード例 #1
0
        public void InitializeProvider(PsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Initializing PowerShell MetaProvider");

            // to do : get modules to load (from configuration ?)
            var modules = ScanForModules(request).Distinct().ToArray();

            // try to create each module at least once.
            modules.ParallelForEach(modulePath => {
                request.Debug("Attempting to load PowerShell Provider Module [{0}]", modulePath);
                var provider = Create(request, modulePath);
                if (provider != null)
                {
                    if (provider.GetPackageProviderName() != null)
                    {
                        request.Debug("Loaded PowerShell Package Provider Module: [{0}]", modulePath);
                        // looks good to me, let's add this to the list of moduels this meta provider can create.
                        _packageProviders.AddOrSet(provider.GetPackageProviderName(), provider);
                    }
                    else
                    {
                        provider.Dispose();
                        provider = null;
                    }
                }
            });

            request.Debug("Loaded PowerShell Provider Modules ");
        }
コード例 #2
0
        // lock is on this instance only

        internal void ReportErrors(PsRequest request, IEnumerable <ErrorRecord> errors)
        {
            foreach (var error in errors)
            {
                request.Error(error.FullyQualifiedErrorId, error.CategoryInfo.Category.ToString(), error.TargetObject == null ? null : error.TargetObject.ToString(), error.ErrorDetails == null ? error.Exception.Message : error.ErrorDetails.Message);
                if (!string.IsNullOrWhiteSpace(error.ScriptStackTrace))
                {
                    // give a debug hint if we have a script stack trace. How nice of us.
                    request.Debug(Constants.ScriptStackTrace, error.ScriptStackTrace);
                }
            }
        }