FromJson() public static method

public static FromJson ( string headerPath, ILogger logger ) : Package
headerPath string
logger ILogger
return Package
Ejemplo n.º 1
0
        public Package ScanPackageDirectory(string directory, bool checkCertificates)
        {
            try
            {
                var headerPath = Path.Combine(directory, "pkg.json");

                Package discoveredPkg;

                // get the package name and the installed version
                if (PathHelper.IsValidPath(headerPath))
                {
                    discoveredPkg = Package.FromJson(headerPath, AsLogger());
                    if (discoveredPkg == null)
                    {
                        throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.MalformedHeaderPackage, headerPath));
                    }
                }
                else
                {
                    throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.NoHeaderPackage, headerPath));
                }

                // prevent loading unsigned packages if the certificates are required on package dlls
                if (checkCertificates)
                {
                    CheckPackageNodeLibraryCertificates(directory, discoveredPkg);
                }

                // prevent duplicates
                if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name))
                {
                    this.Add(discoveredPkg);
                    return(discoveredPkg); // success
                }
                throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory));
            }
            catch (Exception e)
            {
                Log(String.Format(Properties.Resources.ExceptionEncountered, directory), WarningLevel.Error);
                Log(e);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public Package ScanPackageDirectory(string directory)
        {
            try
            {
                var headerPath = Path.Combine(directory, "pkg.json");

                Package discoveredPkg = null;

                // get the package name and the installed version
                if (File.Exists(headerPath))
                {
                    discoveredPkg = Package.FromJson(headerPath);
                    if (discoveredPkg == null)
                    {
                        throw new Exception(headerPath + " contains a package with a malformed header.  Ignoring it.");
                    }
                }
                else
                {
                    throw new Exception(headerPath + " contains a package without a header.  Ignoring it.");
                }

                // prevent duplicates
                if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name))
                {
                    LocalPackages.Add(discoveredPkg);
                    return(discoveredPkg); // success
                }
                else
                {
                    throw new Exception("A duplicate of the package called " + discoveredPkg.Name +
                                        " was found at " + discoveredPkg.RootDirectory + ".  Ignoring it.");
                }
            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoLogger.Log("Exception encountered scanning the package directory at " + this.RootPackagesDirectory);
                dynSettings.Controller.DynamoLogger.Log(e.GetType() + ": " + e.Message);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public Package ScanPackageDirectory(string directory)
        {
            try
            {
                var headerPath = Path.Combine(directory, "pkg.json");

                Package discoveredPkg;

                // get the package name and the installed version
                if (File.Exists(headerPath))
                {
                    discoveredPkg = Package.FromJson(headerPath, AsLogger());
                    if (discoveredPkg == null)
                    {
                        throw new Exception(String.Format(Properties.Resources.MalformedHeaderPackage, headerPath));
                    }
                }
                else
                {
                    throw new Exception(String.Format(Properties.Resources.NoHeaderPackage, headerPath));
                }

                // prevent duplicates
                if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name))
                {
                    this.Add(discoveredPkg);
                    return(discoveredPkg); // success
                }
                throw new Exception(String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory));
            }
            catch (Exception e)
            {
                Log(String.Format(Properties.Resources.ExceptionEncountered, this.RootPackagesDirectory), WarningLevel.Error);
                Log(e);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public Package ScanPackageDirectory(string directory, bool checkCertificates)
        {
            try
            {
                var headerPath = Path.Combine(directory, "pkg.json");

                Package discoveredPackage;

                // get the package name and the installed version
                if (PathHelper.IsValidPath(headerPath))
                {
                    discoveredPackage = Package.FromJson(headerPath, AsLogger());
                    if (discoveredPackage == null)
                    {
                        throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.MalformedHeaderPackage, headerPath));
                    }
                }
                else
                {
                    throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.NoHeaderPackage, headerPath));
                }

                // prevent loading unsigned packages if the certificates are required on package dlls
                if (checkCertificates)
                {
                    CheckPackageNodeLibraryCertificates(directory, discoveredPackage);
                }

                var discoveredVersion = CheckAndGetPackageVersion(discoveredPackage.VersionName, discoveredPackage.Name, discoveredPackage.RootDirectory);

                var existingPackage = LocalPackages.FirstOrDefault(package =>
                                                                   (package.Name == discoveredPackage.Name) &&
                                                                   (package.LoadState.State != PackageLoadState.StateTypes.Unloaded));

                // Is this a new package?
                if (existingPackage == null)
                {
                    Add(discoveredPackage);
                    return(discoveredPackage); // success
                }

                // Conflict invloving a built-in package
                if (discoveredPackage.BuiltInPackage || existingPackage.BuiltInPackage)
                {
                    // We show both packages but we mark the new one as unloaded.
                    discoveredPackage.LoadState.SetAsUnloaded();
                    Add(discoveredPackage);
                }

                var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, existingPackage.RootDirectory);

                // Is this a duplicated package?
                if (existingVersion == discoveredVersion)
                {
                    // Duplicated with the same version
                    throw new LibraryLoadFailedException(directory,
                                                         String.Format(Properties.Resources.DulicatedPackage,
                                                                       discoveredPackage.Name,
                                                                       discoveredPackage.RootDirectory));
                }

                // Is the existing version newer?
                if (existingVersion > discoveredVersion)
                {
                    // Older version found, show notification
                    throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedOlderPackage,
                                                                                  existingPackage.Name,
                                                                                  discoveredPackage.RootDirectory,
                                                                                  existingVersion.ToString(),
                                                                                  discoveredVersion.ToString()));
                }

                // Newer version found, show notification.
                throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedNewerPackage,
                                                                              existingPackage.Name,
                                                                              discoveredPackage.RootDirectory,
                                                                              existingVersion.ToString(),
                                                                              discoveredVersion.ToString()));
            }
            catch (Exception e)
            {
                Log(String.Format(Properties.Resources.ExceptionEncountered, directory), WarningLevel.Error);
                Log(e);
            }

            return(null);
        }
Ejemplo n.º 5
0
 public static Package FromDirectory(string rootPath, ILogger logger)
 {
     return(Package.FromJson(Path.Combine(rootPath, "pkg.json"), logger));
 }
Ejemplo n.º 6
0
 public static Package FromDirectory(string rootPath, DynamoModel dynamoModel)
 {
     return(Package.FromJson(Path.Combine(rootPath, "pkg.json"), dynamoModel));
 }