コード例 #1
0
ファイル: Packages.cs プロジェクト: tutul2010/wpdotnet-sdk
        public void Add(InstalledPackage package)
        {
            Remove(package.pluginId);

            installed = new List <InstalledPackage>(installed)
            {
                package
            };
        }
コード例 #2
0
        /// <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 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 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);
            }
        }
コード例 #3
0
        internal bool LoadPackage(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.Standard" && refass.Version != typeof(PeachPied.WordPress.Standard.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);
        }