bool LoadPackage(Marketplace.Scheme.InstalledPackage package)
        {
            bool loaded = false;

            if (package != null)
            {
                var packagepath = Path.Combine(PackagesPath, package.pluginId, package.version);

                if (Directory.Exists(packagepath))
                {
                    foreach (var fname in Directory.GetFiles(packagepath, "*.dll"))
                    {
                        try
                        {
                            Context.AddScriptReference(Assembly.LoadFrom(fname));
                            loaded = true;
                        }
                        catch
                        {
                            // TOOD: log
                        }
                    }
                }
            }

            return(loaded);
        }
        /// <summary>
        /// Installs the (unzipped) nuget package into <see cref="PackagesPath"/> directory.
        /// </summary>
        /// <param name="nugetContentPath">Content of the unzipped nuget.</param>
        /// <param name="nuspecreader">Outputs nuspec file.</param>
        /// <returns>Whether the installation was successful.</returns>
        public Marketplace.Scheme.InstalledPackage InstallPackage(string nugetContentPath, out INuspecCoreReader nuspecreader)
        {
            var nuspecs = Directory.GetFiles(nugetContentPath, "*.nuspec");

            if (nuspecs.Length == 1)
            {
                var nuspec = new NuspecCoreReader(XDocument.Load(nuspecs[0]));

                // TODO: restore dependencies

                // copy lib to packages
                var dllsource = Path.Combine(nugetContentPath, "lib/netstandard2.0");
                var dlltarget = Path.GetFullPath(Path.Combine(PackagesPath, nuspec.GetId(), nuspec.GetVersion().ToNormalizedString()));

                Directory.CreateDirectory(dlltarget);

                foreach (var fpath in Directory.GetFiles(dllsource))
                {
                    var filetarget = Path.Combine(dlltarget, Path.GetFileName(fpath));
                    if (!File.Exists(filetarget))
                    {
                        File.Move(fpath, filetarget);
                    }
                }

                // TODO: try to delete old versions of the package

                //
                var package = new Marketplace.Scheme.InstalledPackage
                {
                    pluginId = nuspec.GetId(),
                    version  = nuspec.GetVersion().ToNormalizedString(),
                    active   = false
                };

                // add packageId to packages.json
                UpdatePackagesJson(json =>
                {
                    json.Add(package);
                });

                //
                nuspecreader = nuspec;
                return(package);
            }
            else
            {
                nuspecreader = null;
                return(null);
            }
        }
Exemple #3
0
        bool LoadPackage(Marketplace.Scheme.InstalledPackage package)
        {
            bool loaded = false;

            if (package != null)
            {
                var packagepath = Path.Combine(PackagesPath, package.pluginId, package.version);

                if (Directory.Exists(packagepath))
                {
                    foreach (var fname in Directory.GetFiles(packagepath, "*.dll"))
                    {
                        try
                        {
                            var ass = Assembly.LoadFrom(fname);
                            foreach (var refass in ass.GetReferencedAssemblies())
                            {
                                if (refass.Name == "PeachPied.WordPress.Sdk" && refass.Version != typeof(PeachPied.WordPress.Sdk.WpApp).Assembly.GetName().Version)
                                {
                                    throw new FileLoadException($"The plugin '{package.pluginId}' is built for a different WpDotNet SDK version and won't be loaded.");
                                }
                            }

                            Context.AddScriptReference(ass);
                            loaded = true;
                        }
                        catch
                        {
                            // TOOD: log
                        }
                    }
                }
            }

            return(loaded);
        }