コード例 #1
0
        public PackageContent ExtractPackageInfo(Core.Package package)
        {
            string tempPath = Path.Combine(this.TempFolder, Guid.NewGuid().ToString("N").ToUpper());

            package.Extract(tempPath);
            AppDomain tempDomain = ReflectionHelper.LoadAppDomain(tempPath, new Uri(this.GetType().Assembly.CodeBase).LocalPath);

            try {
                object handle;
                try {
                    handle = tempDomain.CreateInstanceAndUnwrap(typeof(PackageScanner).Assembly.GetName().Name, typeof(PackageScanner).FullName);
                } catch (FileNotFoundException) {
                    throw new AppServerException("Package does not contain required assembly " + typeof(PackageScanner).Assembly.Name());
                }
                PackageScanner scanner = handle as PackageScanner;
                if (scanner == null)
                {
                    throw new Exception("Could not load package scanner");
                }
                PackageContent info = scanner.Run();
                Logger.Info(this, "Scanner found " + info.Bootstrappers.Count + " bootstrapper(s) and " + info.Updaters.Count + " updater(s)");
                string manifestFile = Path.Combine(tempPath, "manifest.xml");
                if (File.Exists(manifestFile))
                {
                    Logger.Debug(this, "Loading package manifest " + manifestFile + "...");
                    try {
                        using (FileStream stream = File.Open(manifestFile, FileMode.Open, FileAccess.Read)) {
                            info.Manifest = XmlSerializer.Deserialize <Manifest>(stream);
                            Logger.Debug(this, "Manifest loaded");
                        }
                    } catch (Exception ex) {
                        Logger.Error("Failed to load manifest: " + ex.Message);
                    }
                }
                else
                {
                    Logger.Debug(this, "Package contains no manifest");
                }
                return(info);
            } finally {
                AppDomain.Unload(tempDomain);
                try {
                    Directory.Delete(tempPath, true);
                } catch (Exception ex) {
                    Logger.Warn(this, "Failed to remove temp folder " + tempPath + ": " + ex.Message);
                }
            }
        }