示例#1
0
        /// <summary>
        /// 指定路径更新当前Bundle
        /// </summary>
        /// <param name="zipFile">更新的Bundle路径</param>
        public void Update(string zipFile)
        {
            log.Debug("模块更新开始!");

            int preState = state;

            if (File.Exists(zipFile))
            {
                string tmpBundleDirectoryPath = string.Format("{0}_{1}", this.GetBundleFolderName(), Guid.NewGuid().ToString());
                BundleUtils.ExtractBundleFile(tmpBundleDirectoryPath, zipFile);
                var xmlNode = BundleConfigProvider.ReadBundleConfig(tmpBundleDirectoryPath);
                try
                {
                    var tmpassemblyName = BundleConfigProvider.GetBundleConfigAssemblyName(xmlNode);
                    var assemblyName    = this.GetBundleAssemblyFileName();
                    if (!assemblyName.Equals(tmpassemblyName))
                    {
                        throw new Exception(string.Format("要更新的插件[{0}]与输入流中的插件[{1}]不匹配!", assemblyName, tmpassemblyName));
                    }
                }
                catch (Exception ex)
                {
                    Directory.Delete(tmpBundleDirectoryPath, true);
                    throw ex;
                }
                //删除当前bundle
                ((IFrameworkInstaller)framework).Delete(this);
                //替换当前bundle
                Directory.Move(tmpBundleDirectoryPath, bundleDirectoryPath);

                //更新配置节点
                this.manifestData = xmlNode;

                //更新Bundle配置信息
                BundleConfigProvider.SyncBundleConfig(this.GetBundleFolderName(), xmlNode);
            }
            //目前插件持续状态存在三种
            if (preState == BundleStateConst.INSTALLED)
            {
                this.Init();
            }
            else if (preState == BundleStateConst.RESOLVED)
            {
                this.Init();
                this.Resolve();
            }
            else if (preState == BundleStateConst.ACTIVE)
            {
                this.Stop();
                this.Init();
                this.Resolve();
                this.Start();
            }
            log.Debug("模块更新完成!");
        }
示例#2
0
        /// <summary>
        /// 安装指定Bundle模块
        /// </summary>
        /// <param name="zipFile">Bundle文件全路径</param>
        /// <returns>已安装的Bundle对象实例</returns>
        public IBundle Install(string zipFile)
        {
            var folderName    = Path.GetFileNameWithoutExtension(zipFile);
            var newBundlePath = Path.Combine(bundlesDirectoryPath, folderName ?? string.Empty);

            log.Debug(string.Format("模块[{0}]安装开始!", folderName));

            //如果存在同名改名
            if (Directory.Exists(newBundlePath))
            {
                folderName    = string.Format("{0}_{1}", folderName, Guid.NewGuid().ToString());
                newBundlePath = Path.Combine(bundlesDirectoryPath, folderName);
            }

            BundleUtils.ExtractBundleFile(newBundlePath, zipFile);

            //读取bundle配置信息
            var xmlNode = BundleConfigProvider.ReadBundleConfig(newBundlePath);

            try
            {
                var assemblyNameNode = xmlNode.Attributes == null ? null : xmlNode.Attributes["AssemblyName"];
                var tmpassemblyName  = assemblyNameNode == null ? string.Empty : assemblyNameNode.Value;
                foreach (IBundle installedBundle in bundleList)
                {
                    //如果此插件的相同版本已经安装
                    var assemblyName = installedBundle.GetBundleAssemblyFileName();
                    if (assemblyName.Equals(tmpassemblyName))
                    {
                        throw new Exception(string.Format("名称为[{0}]的插件已经存在,安装失败!", installedBundle.GetSymbolicName()));
                    }
                }

                //添加Bundle配置信息
                BundleConfigProvider.SyncBundleConfig(folderName, xmlNode);

                IBundle bundle = new Bundle(this, newBundlePath, xmlNode);
                bundleList.Add(bundle);

                log.Debug(string.Format("模块[{0}]安装完成!", folderName));

                return(bundle);
            }
            catch (Exception ex)
            {
                log.Error("指定模块安装失败!", ex);
                Directory.Delete(newBundlePath, true);
                throw;
            }
        }