/// <summary> /// 显示可升级插件 /// </summary> private void ShowUpdatablePlugins() { if (_installedPlugins == null) return; if (_updateInfos == null) return; var items = new List<PluginModel>(); foreach (var plugin in _installedPlugins) { //判断已安装的插件是否可以更新 var info =_updateInfos.FirstOrDefault(x => x.Name == plugin.PluginInfo.Name && new Version(plugin.PluginInfo.Version) < x.Version.Version); if (info == null) continue; var canUpdate = _host.App.AppVersion >= info.Version.RequiredVersion; info.CanUpdate = canUpdate; var item = new PluginModel(info.Name); item.Author = info.Author; item.InstalledVersion = plugin.PluginInfo.Version; item.AvailableVersion = info.Version.Version.ToString(); item.CanUpdate = info.CanUpdate.ToString(); item.Tag = info; items.Add(item); } _gridViewUpdatable.DataStore = items; }
/// <summary> /// 下载xml文件 /// </summary> private void DownloadUpdateXml() { var tip = new PluginModel("Downloading update xml..."); _gridViewAvailable.DataStore = new List<PluginModel> { tip }; var client = new WebClient(); client.DownloadFileCompleted += client_DownloadFileCompleted; client.DownloadFileAsync(new Uri(_updateXmlUrl), _updateXmlPath); }
/// <summary> /// 显示可用插件 /// </summary> private void ShowAvailablePlugins() { if (_installedPlugins == null) return; if (!File.Exists(_updateXmlPath)) return; var items = new List<PluginModel>(); _updateInfos = ReadUpdateXml(); if (_updateInfos != null) { foreach (var info in _updateInfos) { //在列表中排除已安装的插件 if (_installedPlugins.FirstOrDefault(x => x.PluginInfo.Name == info.Name) != null) continue; var canInstall = _host.App.AppVersion >= info.Version.RequiredVersion; info.CanUpdate = canInstall; var item = new PluginModel(info.Name); item.Author = info.Author; item.AvailableVersion = info.Version.Version.ToString(); item.RequiredVersion = info.Version.RequiredVersion.ToString(); item.CanInstall = info.CanUpdate.ToString(); item.Tag = info; items.Add(item); } } _gridViewAvailable.DataStore = items; }
private void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { _buttonInstall.Enabled = false; var tip = new PluginModel("Can't download update xml"); _gridViewAvailable.DataStore = new List<PluginModel> { tip }; } else { _buttonInstall.Enabled = true; ShowAvailablePlugins(); ShowUpdatablePlugins(); } }