コード例 #1
0
ファイル: SoftwareIdentity.cs プロジェクト: vairam-svs/oneget
 protected override bool YieldDetails(PsRequest r) {
     if (_details != null && _details.Count > 0) {
         // we need to send this back as a set of key/path & value  pairs.
         return _details.Flatten().All(kvp => r.AddMetadata(FastPackageReference,kvp.Key, kvp.Value) != null);
     }
     return true;
 }
コード例 #2
0
ファイル: SoftwareIdentity.cs プロジェクト: vairam-svs/oneget
        public override bool YieldResult(PsRequest r) {
            if (r == null) {
                throw new ArgumentNullException("r");
            }

            return r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null;
        }
コード例 #3
0
ファイル: PackageSource.cs プロジェクト: vairam-svs/oneget
        public override bool YieldResult(PsRequest r) {
            if (r == null) {
                throw new ArgumentNullException("r");
            }

            return r.YieldPackageSource(Name, Location, IsTrusted, IsRegistered,IsValidated) && YieldDetails(r);
        }
コード例 #4
0
        private PowerShellPackageProvider Create(PsRequest req, KeyValuePair <string, string> psModule)
        {
            var ps = PowerShell.Create();

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

            // didn't import correctly.
            ps.Dispose();
            return(null);
        }
コード例 #5
0
ファイル: DynamicOption.cs プロジェクト: notgerry/oneget
 public override bool YieldResult(PsRequest r)
 {
     if (r == null) {
         throw new ArgumentNullException("r");
     }
     return r.YieldDynamicOption(Name, ExpectedType.ToString(), IsRequired) && PermittedValues.WhereNotNull().Select(each => each.ToString()).ToArray().All(v => r.YieldKeyValuePair(Name, v));
 }
コード例 #6
0
 public override bool YieldResult(PsRequest r)
 {
     if (r == null)
     {
         throw new ArgumentNullException("r");
     }
     return(r.YieldDynamicOption(Name, ExpectedType.ToString(), IsRequired) && PermittedValues.WhereNotNull().Select(each => each.ToString()).ToArray().All(v => r.YieldKeyValuePair(Name, v)));
 }
コード例 #7
0
 protected virtual bool YieldDependencies(PsRequest r)
 {
     if (_dependencies != null)
     {
         return(_dependencies.OfType <Dependency>().All(dep => r.AddDependency(dep.ProviderName, dep.PackageName, dep.Version, dep.Source, dep.AppliesTo) != null));
     }
     return(true);
 }
コード例 #8
0
 protected virtual bool YieldEntities(PsRequest r)
 {
     if (_links != null)
     {
         return(_entities.OfType <Entity>().All(entity => r.AddEntity(entity.Name, entity.RegId, entity.Role, entity.Thumbprint) != null));
     }
     return(true);
 }
コード例 #9
0
ファイル: Yieldable.cs プロジェクト: notgerry/oneget
 protected virtual bool YieldDetails(PsRequest r)
 {
     if (_details != null && _details.Count > 0) {
         // we need to send this back as a set of key/path & value  pairs.
         return _details.Flatten().All(kvp => r.YieldKeyValuePair(kvp.Key, kvp.Value));
     }
     return true;
 }
コード例 #10
0
 protected virtual bool YieldLinks(PsRequest r)
 {
     if (_links != null)
     {
         return(_links.OfType <Link>().All(link => r.AddLink(new Uri(link.HRef), link.Relationship, link.MediaType, link.Ownership, link.Use, link.AppliesToMedia, link.Artifact) != null));
     }
     return(true);
 }
コード例 #11
0
ファイル: Feature.cs プロジェクト: 40a/PowerShell
 public override bool YieldResult(PsRequest r) {
     if (r == null) {
         throw new ArgumentNullException("r");
     }
     if (_pair.Value.Length == 0) {
         return r.YieldKeyValuePair(_pair.Key, null);
     }
     return _pair.Value.All(each => r.YieldKeyValuePair(_pair.Key, each));
 }
コード例 #12
0
        protected virtual bool YieldTagId(PsRequest r)
        {
            if (string.IsNullOrWhiteSpace(_tagId))
            {
                return(true);
            }

            return(r.AddTagId(_tagId) != null);
        }
コード例 #13
0
 protected override bool YieldDetails(PsRequest r)
 {
     if (_details != null && _details.Count > 0)
     {
         // we need to send this back as a set of key/path & value  pairs.
         return(_details.Flatten().All(kvp => r.AddMetadata(FastPackageReference, kvp.Key, kvp.Value) != null));
     }
     return(true);
 }
コード例 #14
0
        public override bool YieldResult(PsRequest r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            return(r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null);
        }
コード例 #15
0
ファイル: SoftwareIdentity.cs プロジェクト: jholder70/oneget
        protected virtual bool YieldXmlLang(PsRequest r)
        {
            if (string.IsNullOrWhiteSpace(_xmlLang))
            {
                return(true);
            }

            return(r.AddCulture(_xmlLang) != null);
        }
コード例 #16
0
ファイル: Yieldable.cs プロジェクト: fearthecowboy/oneget
 protected virtual bool YieldDetails(PsRequest r)
 {
     if (_details != null && _details.Count > 0)
     {
         // we need to send this back as a set of key/path & value  pairs.
         return(_details.Flatten().All(kvp => r.YieldKeyValuePair(kvp.Key, kvp.Value)));
     }
     return(true);
 }
コード例 #17
0
        public override bool YieldResult(PsRequest r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            return(r.YieldPackageSource(Name, Location, IsTrusted, IsRegistered, IsValidated) && YieldDetails(r));
        }
コード例 #18
0
 public override bool YieldResult(PsRequest r)
 {
     if (r == null)
     {
         throw new ArgumentNullException("r");
     }
     if (_pair.Value.Length == 0)
     {
         return(r.YieldKeyValuePair(_pair.Key, null));
     }
     return(_pair.Value.All(each => r.YieldKeyValuePair(_pair.Key, each)));
 }
コード例 #19
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);
                }
            }
        }
コード例 #20
0
        public override bool YieldResult(PsRequest r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            // if we get an xml swidtag string, use that
            if (!string.IsNullOrWhiteSpace(_xmlSwidTag))
            {
                return(r.YieldSoftwareIdentityXml(_xmlSwidTag, _commitImmediately) != null);
            }

            return(r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldTagId(r) && YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null);
        }
コード例 #21
0
        public void InitializeProvider(PsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Initializing PowerShell MetaProvider");

            var modules = ScanForModules(request).Distinct().ToArray();

            // try to create each module at least once.
            modules.ParallelForEach(modulePath => AnalyzeModule(request, modulePath));

            request.Debug("Loaded PowerShell Provider Modules ");
        }
コード例 #22
0
        internal IEnumerable <KeyValuePair <string, string> > ScanForModules(PsRequest request)
        {
            // two places we search for modules
            // 1. in this assembly's folder, look for all psd1 and psm1 files.
            //
            // 2. modules in the PSMODULEPATH
            //
            // Import each one of those, and check to see if they have a PackageManagementProviders section in their private data
            using (var ps1 = PowerShell.Create()) {
                if (ps1.ImportModule(PowerShellProviderFunctions) != null)
                {
                    return(AlternativeModuleScan(request).SelectMany(each => ps1.TestModuleManifest(each).SelectMany(GetPackageManagementModules)).ToArray());
                }
            }

            return(Enumerable.Empty <KeyValuePair <string, string> >());
        }
コード例 #23
0
        private IEnumerable <string> AlternativeModuleScan(PsRequest request)
        {
            var psModulePath = Environment.GetEnvironmentVariable("PSModulePath") ?? "";

            IEnumerable <string> paths = psModulePath.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            // add assumed paths just in case the environment variable isn't really set.
            try {
                paths = paths.ConcatSingleItem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"WindowsPowerShell\v1.0\Modules"));
            } catch {
                // skip the folder if it's not valid
            }
            try {
                paths = paths.ConcatSingleItem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"WindowsPowerShell\Modules"));
            }
            catch {
                // skip the folder if it's not valid
            }

            if (!string.IsNullOrWhiteSpace(BaseFolder) && BaseFolder.DirectoryExists())
            {
                paths = paths.ConcatSingleItem(BaseFolder);
            }

            paths = paths.Distinct(new PathEqualityComparer(PathCompareOption.Full)).ToArray();

            var moduleFolders = paths.Where(each => each.DirectoryExists()).SelectMany(each => Directory.EnumerateDirectories(each).Where(dir => !_exclusionList.Contains(Path.GetFileName(dir))));

            var modules = moduleFolders.Select(module => {
                var moduleManifest = Path.Combine(module, Path.GetFileName(module) + ".psd1");
                if (File.Exists(moduleManifest))
                {
                    return(moduleManifest);
                }

                var versions = Directory.EnumerateDirectories(module).Select(dir => new { folder = dir, ver = (FourPartVersion)Path.GetFileName(dir) }).Where(each => each.ver > 0L).OrderByDescending(each => each).Select(each => each.folder);

                return(versions.Select(version => Path.Combine(version, Path.GetFileName(Path.GetFileName(module)) + ".psd1")).FirstOrDefault(File.Exists));
            }).WhereNotNull();

            return(modules.Where(moduleName => File.ReadAllText(moduleName).IndexOf("PackageManagementProviders", StringComparison.OrdinalIgnoreCase) > -1));
        }
コード例 #24
0
        private void AnalyzeModule(PsRequest request, KeyValuePair <string, string> 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;
                }
            }
        }
コード例 #25
0
        public override bool YieldResult(PsRequest r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("r");
            }

            // if we get an xml swidtag string, use that
            if (!string.IsNullOrWhiteSpace(_xmlSwidTag))
            {
                return(r.YieldSoftwareIdentityXml(_xmlSwidTag, _commitImmediately) != null);
            }

            bool result = r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldTagId(r) && YieldXmlLang(r) &&
                          YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null;

            // check whether we have destination
            if (!string.IsNullOrWhiteSpace(_destinationPath))
            {
                var payload = r.AddPayload();

                // could not add the payload, return false
                if (string.IsNullOrWhiteSpace(payload))
                {
                    return(false);
                }

                if (r.AddDirectory(payload, System.IO.Path.GetFileName(_destinationPath), System.IO.Path.GetDirectoryName(_destinationPath), null, true) == null)
                {
                    // cannot add directory
                    return(false);
                }
            }

            return(result);
        }
コード例 #26
0
ファイル: SoftwareIdentity.cs プロジェクト: qbikez/oneget
        protected virtual bool YieldTagId(PsRequest r)
        {
            if (string.IsNullOrWhiteSpace(_tagId))
            {
                return true;
            }

            return r.AddTagId(_tagId) != null;
        }
コード例 #27
0
ファイル: SoftwareIdentity.cs プロジェクト: qbikez/oneget
 protected virtual bool YieldLinks(PsRequest r)
 {
     if( _links != null ) {
         return _links.OfType<Link>().All(link => r.AddLink(new Uri(link.HRef), link.Relationship, link.MediaType, link.Ownership, link.Use, link.AppliesToMedia, link.Artifact) != null);
     }
     return true;
 }
コード例 #28
0
ファイル: SoftwareIdentity.cs プロジェクト: qbikez/oneget
 protected virtual bool YieldEntities(PsRequest r)
 {
     if (_links != null) {
         return _entities.OfType<Entity>().All(entity => r.AddEntity(entity.Name, entity.RegId, entity.Role, entity.Thumbprint) != null);
     }
     return true;
 }
コード例 #29
0
ファイル: SoftwareIdentity.cs プロジェクト: qbikez/oneget
 protected virtual bool YieldDependencies(PsRequest r)
 {
     if (_dependencies != null) {
         return _dependencies.OfType<Dependency>().All(dep => r.AddDependency(dep.ProviderName, dep.PackageName, dep.Version, dep.Source, dep.AppliesTo ) != null);
     }
     return true;
 }
コード例 #30
0
ファイル: SoftwareIdentity.cs プロジェクト: qbikez/oneget
        public override bool YieldResult(PsRequest r)
        {
            if (r == null) {
                throw new ArgumentNullException("r");
            }

            // if we get an xml swidtag string, use that
            if (!string.IsNullOrWhiteSpace(_xmlSwidTag))
            {
                return r.YieldSoftwareIdentityXml(_xmlSwidTag, _commitImmediately) != null;
            }

            return r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldTagId(r) && YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null;
        }
コード例 #31
0
 private object Call(string function, IRequest requestObject, params object[] args)
 {
     return(PsRequest.New(requestObject, this, function).CallPowerShell(args));
 }
コード例 #32
0
        internal object CallPowerShell(PsRequest request, params object[] args)
        {
            // the lock ensures that we're not re-entrant into the same powershell runspace
            lock (_lock) {
                if (!_reentrancyLock.WaitOne(0)) {
                    // this lock is set to false, meaning we're still in a call **ON THIS THREAD**
                    // this is bad karma -- powershell won't let us call into the runspace again
                    // we're going to throw an error here because this indicates that the currently
                    // running powershell call is calling back into PM, and it has called back
                    // into this provider. That's just bad bad bad.
                    throw new Exception("Re-entrancy Violation in powershell module");
                }

                try {
                    // otherwise, this is the first time we've been here during this call.
                    _reentrancyLock.Reset();

                    _powershell.SetVariable("request", request);
                    _powershell.Streams.ClearStreams();

                    // request.Debug("INVOKING PowerShell Fn {0} in {1}", request.CommandInfo.Name, _module.Name);
                    // make sure we don't pass the request to the function.
                    var result = _powershell.InvokeFunction<object>(request.CommandInfo.Name, args);

                    // instead, loop thru results and get
                    if (result == null) {
                        // failure!
                        throw new Exception(Messages.PowershellScriptFunctionFailed.format(_module.Name, request.CommandInfo.Name));
                    }

                    object finalValue = null;

                    foreach (var value in result) {
                        if (_powershell.Streams.Error.Any()) {
                            ReportErrors(request, _powershell.Streams.Error);
                            _powershell.Streams.Error.Clear();
                        }

                        var y = value as Yieldable;
                        if (y != null) {
                            y.YieldResult(request);
                        } else {
                            finalValue = value;
                        }
                    }

                    if (_powershell.Streams.Error.Any()) {
                        ReportErrors(request, _powershell.Streams.Error);
                        _powershell.Streams.Error.Clear();
                    }

                    return finalValue;
                } catch (CmdletInvocationException cie) {
                    var error = cie.ErrorRecord;
                    request.Error(error.FullyQualifiedErrorId, error.CategoryInfo.Category.ToString(), error.TargetObject == null ? null : error.TargetObject.ToString(), error.ErrorDetails == null ? error.Exception.Message : error.ErrorDetails.Message);
                }catch (Exception e) {
                    e.Dump();
                } finally {
                    lock (_stopLock) {
                        if (_stopResult != null){
                            _powershell.EndStop(_stopResult);
                            _stopResult = null;
                        }
                    }
                    _powershell.Clear();
                    _powershell.SetVariable("request", null);
                    // it's ok if someone else calls into this module now.
                    _reentrancyLock.Set();
                }

                return null;
            }
        }
コード例 #33
0
ファイル: Yieldable.cs プロジェクト: notgerry/oneget
 public abstract bool YieldResult(PsRequest r);
コード例 #34
0
ファイル: Yieldable.cs プロジェクト: fearthecowboy/oneget
 public abstract bool YieldResult(PsRequest r);
コード例 #35
0
ファイル: SoftwareIdentity.cs プロジェクト: dfinke/powershell
        protected virtual bool YieldXmlLang(PsRequest r)
        {
            if (string.IsNullOrWhiteSpace(_xmlLang))
            {
                return true;
            }

            return r.AddCulture(_xmlLang) != null;
        }
コード例 #36
0
ファイル: SoftwareIdentity.cs プロジェクト: dfinke/powershell
        public override bool YieldResult(PsRequest r) {
            if (r == null) {
                throw new ArgumentNullException("r");
            }

            // if we get an xml swidtag string, use that
            if (!string.IsNullOrWhiteSpace(_xmlSwidTag))
            {
                return r.YieldSoftwareIdentityXml(_xmlSwidTag, _commitImmediately) != null;
            }

            bool result = r.YieldSoftwareIdentity(FastPackageReference, Name, Version, VersionScheme, Summary, Source, SearchKey, FullPath, Filename) != null && YieldTagId(r) && YieldXmlLang(r)
                && YieldDetails(r) && YieldEntities(r) && YieldLinks(r) && YieldDependencies(r) && r.AddMetadata(FastPackageReference, "FromTrustedSource", FromTrustedSource.ToString()) != null;

            // check whether we have destination
            if (!string.IsNullOrWhiteSpace(_destinationPath))
            {
                var payload = r.AddPayload();

                // could not add the payload, return false
                if (string.IsNullOrWhiteSpace(payload))
                {
                    return false;
                }

                if (r.AddDirectory(payload, System.IO.Path.GetFileName(_destinationPath), System.IO.Path.GetDirectoryName(_destinationPath), null, true) == null)
                {
                    // cannot add directory
                    return false;
                }
            }

            return result;
        }
コード例 #37
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);
         }
     }
 }
コード例 #38
0
        internal object CallPowerShell(PsRequest request, params object[] args)
        {
            // the lock ensures that we're not re-entrant into the same powershell runspace
            lock (_lock) {
                if (!_reentrancyLock.WaitOne(0))
                {
                    // this lock is set to false, meaning we're still in a call **ON THIS THREAD**
                    // this is bad karma -- powershell won't let us call into the runspace again
                    // we're going to throw an error here because this indicates that the currently
                    // running powershell call is calling back into PM, and it has called back
                    // into this provider. That's just bad bad bad.
                    throw new Exception("Re-entrancy Violation in powershell module");
                }

                try {
                    // otherwise, this is the first time we've been here during this call.
                    _reentrancyLock.Reset();

                    _powershell.SetVariable("request", request);
                    _powershell.Streams.ClearStreams();

                    // request.Debug("INVOKING PowerShell Fn {0} in {1}", request.CommandInfo.Name, _module.Name);
                    // make sure we don't pass the request to the function.
                    var result = _powershell.InvokeFunction <object>(request.CommandInfo.Name, args);

                    // instead, loop thru results and get
                    if (result == null)
                    {
                        // failure!
                        throw new Exception(Messages.PowershellScriptFunctionFailed.format(_module.Name, request.CommandInfo.Name));
                    }

                    object finalValue = null;

                    foreach (var value in result)
                    {
                        if (_powershell.Streams.Error.Any())
                        {
                            ReportErrors(request, _powershell.Streams.Error);
                            _powershell.Streams.Error.Clear();
                        }

                        var y = value as Yieldable;
                        if (y != null)
                        {
                            y.YieldResult(request);
                        }
                        else
                        {
                            finalValue = value;
                        }
                    }

                    if (_powershell.Streams.Error.Any())
                    {
                        ReportErrors(request, _powershell.Streams.Error);
                        _powershell.Streams.Error.Clear();
                    }

                    return(finalValue);
                } catch (CmdletInvocationException cie) {
                    var error = cie.ErrorRecord;
                    request.Error(error.FullyQualifiedErrorId, error.CategoryInfo.Category.ToString(), error.TargetObject == null ? null : error.TargetObject.ToString(), error.ErrorDetails == null ? error.Exception.Message : error.ErrorDetails.Message);
                }catch (Exception e) {
                    e.Dump();
                } finally {
                    lock (_stopLock) {
                        if (_stopResult != null)
                        {
                            _powershell.EndStop(_stopResult);
                            _stopResult = null;
                        }
                    }
                    _powershell.Clear();
                    _powershell.SetVariable("request", null);
                    // it's ok if someone else calls into this module now.
                    _reentrancyLock.Set();
                }

                return(null);
            }
        }