Ejemplo n.º 1
0
        internal PackageQuery(PackageSource packageSource, PackageSourceListRequest request)
        {
            if (packageSource == null)
            {
                throw new ArgumentNullException("packageSource");
            }

            if(string.IsNullOrWhiteSpace(packageSource.Location) || !System.IO.File.Exists(packageSource.Location))
            {
                request.Warning(Resources.Messages.PackageSourceManifestNotFound, packageSource.Location, Constants.ProviderName);
                return;
            }

            Uri uri;

            if (Uri.TryCreate(packageSource.Location, UriKind.Absolute, out uri))
            {
                if (uri.IsFile)
                {
                    try
                    {
                        //process the file
                        _PackageSourceList = JsonParser.ReadPackageSpec(packageSource, null);
                    }
                    catch (Exception ex)
                    {
                        request.Warning(ex.Message);
                        while (ex.InnerException != null)
                        {
                            ex = ex.InnerException;
                            request.Warning(ex.Message);
                        }
                        request.Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.InvalidPackageListFormat, uri.AbsolutePath));
                        ex.Dump(request);
                    }
                }

                // Uri?
                //TODO: ask a user whether go ahead for downloading an sample PSL.json
            }
            else
            {
                //TODO: Check with GP, DSC Settings, 
                
                request.Verbose(Resources.Messages.UnsupportedPackageSource, packageSource.Location);
                return;
            }
        }
Ejemplo n.º 2
0
        public static Dictionary<string, List<PackageJson>> ReadPackageSpec(PackageSource packageSource, string fileToBeProcessed)
        {
            string packageSpecPath = string.IsNullOrWhiteSpace(fileToBeProcessed) ? packageSource.Location : fileToBeProcessed;

            var jsonFileContent = File.ReadAllText(packageSpecPath);

            PSObject result;

            lock (_powershell)
            {
                _powershell.Commands.Clear();
                _powershell.AddCommand("ConvertFrom-Json").AddParameter("InputObject", jsonFileContent);
                result = _powershell.Invoke().FirstOrDefault();
            }

            var packageListEntries = PopulatePackageSourceList(result, packageSource, null);

            //process dependencies
            return ProcessDependencies(packageListEntries);
        }
Ejemplo n.º 3
0
        public static Dictionary<string, List<PackageJson>> PopulatePackageSourceList(PSObject psObjectEntries, PackageSource packageSource, string key)
        {
            var packageSpecPath = packageSource.Location;

            //read access only, and allow others to read at the same time
            Dictionary<string, List<PackageJson>> packages = new Dictionary<string, List<PackageJson>>(StringComparer.OrdinalIgnoreCase);
            ICollection<PackageJson> list = new List<PackageJson>();

            foreach (var package in psObjectEntries.Properties)
            {
                // if this is an array
                if (package.Value.GetType().GetTypeInfo().IsArray)
                {
                    var result = PopulateFromArray(package.Value as object[], packageSpecPath, key);

                    // check that we got a valid array of entries
                    if (result != null && result.Count > 0)
                    {
                        var common = result.Select(each => each.Common).Where(p => p.Name != null).FirstOrDefault();

                        foreach (var item in result)
                        {
                            if (item.Common != null)
                            {
                                item.IsCommonDefinition = true;
                            }
                            else
                            {
                                item.Common = common;
                                item.FilePath = packageSpecPath;

                                if (string.IsNullOrWhiteSpace(item.Version))
                                {
                                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Messages.VersionNotFound, item.Name));
                                }
                            }

                            item.PackageSource = packageSource;
                        }

                        packages.Add(package.Name, result);
                    }
                }
                else if (package.Value is PSObject)
                {
                    var convertedPackage = ConvertObjectToType(package.Value, typeof(PackageJson)) as PackageJson;

                    if (convertedPackage != null)
                    {
                        if (convertedPackage.Common != null)
                        {
                            convertedPackage.IsCommonDefinition = true;
                        }
                        else
                        {
                            convertedPackage.Common = new CommonDefinition();

                            if (String.IsNullOrWhiteSpace(convertedPackage.Version))
                            {
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Messages.VersionNotFound, convertedPackage.Name, packageSpecPath));
                            }
                        }

                        convertedPackage.FilePath = packageSpecPath;
                        convertedPackage.PackageSource = packageSource;
                        packages.Add(package.Name, new List<PackageJson>() { convertedPackage });
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, Resources.Messages.InvalidPackageListFormat, packageSpecPath));
                }
            }

            return packages;
        }
Ejemplo n.º 4
0
 internal PackageQuery(PackageSource packageSource, string file, PackageSourceListRequest request)
 {
     try
     {
         //process the file
         _PackageSourceList = JsonParser.ReadPackageSpec(packageSource, file);
     }
     catch (Exception ex)
     {
         request.Warning(ex.Message);
         while (ex.InnerException != null)
         {
             ex = ex.InnerException;
             request.Warning(ex.Message);
         }
         request.Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.InvalidPackageListFormat, file));
         ex.Dump(request);
     }
 }
Ejemplo n.º 5
0
        public static Dictionary <string, List <PackageJson> > PopulatePackageSourceList(PSObject psObjectEntries, PackageSource packageSource, string key)
        {
            var packageSpecPath = packageSource.Location;

            //read access only, and allow others to read at the same time
            Dictionary <string, List <PackageJson> > packages = new Dictionary <string, List <PackageJson> >(StringComparer.OrdinalIgnoreCase);
            ICollection <PackageJson> list = new List <PackageJson>();

            foreach (var package in psObjectEntries.Properties)
            {
                // if this is an array
                if (package.Value.GetType().GetTypeInfo().IsArray)
                {
                    var result = PopulateFromArray(package.Value as object[], packageSpecPath, key);

                    // check that we got a valid array of entries
                    if (result != null && result.Count > 0)
                    {
                        var common = result.Select(each => each.Common).Where(p => p.Name != null).FirstOrDefault();

                        foreach (var item in result)
                        {
                            if (item.Common != null)
                            {
                                item.IsCommonDefinition = true;
                            }
                            else
                            {
                                item.Common   = common;
                                item.FilePath = packageSpecPath;

                                if (string.IsNullOrWhiteSpace(item.Version))
                                {
                                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Messages.VersionNotFound, item.Name));
                                }
                            }

                            item.PackageSource = packageSource;
                        }

                        packages.Add(package.Name, result);
                    }
                }
                else if (package.Value is PSObject)
                {
                    var convertedPackage = ConvertObjectToType(package.Value, typeof(PackageJson)) as PackageJson;

                    if (convertedPackage != null)
                    {
                        if (convertedPackage.Common != null)
                        {
                            convertedPackage.IsCommonDefinition = true;
                        }
                        else
                        {
                            convertedPackage.Common = new CommonDefinition();

                            if (String.IsNullOrWhiteSpace(convertedPackage.Version))
                            {
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Messages.VersionNotFound, convertedPackage.Name, packageSpecPath));
                            }
                        }

                        convertedPackage.FilePath      = packageSpecPath;
                        convertedPackage.PackageSource = packageSource;
                        packages.Add(package.Name, new List <PackageJson>()
                        {
                            convertedPackage
                        });
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, Resources.Messages.InvalidPackageListFormat, packageSpecPath));
                }
            }

            return(packages);
        }