protected void EnableGridView_RowCommand(object sender, GridViewCommandEventArgs e) { string key = e.CommandArgument as string; if (e.CommandName == "statu") { if (!String.IsNullOrEmpty(key)) { PluginInfo info = PluginInfoCollection.CreateInstance(PluginType)[key]; if (info != null) { info.Enable = !info.Enable; info.Save(); } } BindData(); } else if (e.CommandName == "downloadzip") { if (!String.IsNullOrEmpty(key)) { DownloadPlugin(key); } } }
protected void UploadButton_Click(object sender, EventArgs e) { try { string pluginPath = ginfo.PluginsClientPath; if (!Directory.Exists(pluginPath)) { Directory.CreateDirectory(pluginPath); } helper.ExtractZipFile(ZipFileUpload.FileBytes, pluginPath); messages.ShowMessage(message.UploadSuccess); displayInstallButton(); try { PluginName = Path.GetFileNameWithoutExtension(ZipFileUpload.FileName); PluginInfo info = PluginInfoCollection.CreateInstance(PluginType)[PluginName]; info.IsLocal = true; //info.IsInstalled = true; info.Save(); } catch (Exception ex) { We7.Framework.LogHelper.WriteLog(typeof(Plugin_Start), ex); } } catch (Exception ex) { messages.ShowError(message.UploadError); } }
private void BindData() { PluginInfoCollection.CreateInstance(PluginType).Load(); DisablePager.RecorderCount = DisableDataSource.Count; if (DisablePager.PageIndex < 0) { DisablePager.PageIndex = 0; } DisablePager.FreshMyself(); EnablePager.RecorderCount = EnableDataSource.Count; if (EnablePager.PageIndex < 0) { EnablePager.PageIndex = 0; } EnablePager.FreshMyself(); EnableGridView.DataSource = EnableDataSource.GetRange(EnablePager.Begin, EnablePager.Count); EnableGridView.DataBind(); DisableGridView.DataSource = DisableDataSource.GetRange(DisablePager.Begin, DisablePager.Count); DisableGridView.DataBind(); }
/// <summary> /// 取得插件信息 /// </summary> /// <param name="pluginName">插件名称</param> /// <param name="cmd">执行的命令</param> /// <returns>插件信息</returns> private PluginInfo GetPluginInfo(string pluginName, string cmd) { PluginInfo info = null; if (cmd.ToLower() == "download") { info = new PluginInfo(plugintype); info.Directory = Path.GetFileNameWithoutExtension(pluginName); info.FilePath = pluginName; } else if (IsTemplate(pluginName)) { info = new PluginInfo(PluginType.RESOURCE); info.Directory = pluginName; } else //if (pluginName.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { string dir = pluginName.StartsWith("http://", StringComparison.OrdinalIgnoreCase)?Path.GetFileNameWithoutExtension(pluginName):pluginName; info = PluginInfoCollection.CreateInstance(plugintype)[dir]; if (info == null) { info = new PluginInfo(PluginType.RESOURCE); info.Directory = dir; info.FilePath = pluginName; } } return(info); }
public bool IsInstall(string siteLoginName, string sitePassword, string plugintype, string pluginName) { if (CheckAdmin(siteLoginName, sitePassword)) { PluginInfo info = null; //if (cmd.ToLower() == "download") //{ // info = new PluginInfo(plugintype); // info.Directory = pluginName; //} //else //{ info = PluginInfoCollection.CreateInstance(GetPluginType(plugintype))[pluginName]; //} if (info != null && info.IsInstalled) { return(true); } else { return(false); } } else { throw new Exception("登陆名与密码不正确!"); } }
public InitialDomCodeGenerator( PluginInfoCollection plugins, DatabaseSettings databaseSettings, RhetosBuildEnvironment rhetosBuildEnvironment) { _plugins = plugins; _databaseSettings = databaseSettings; _rhetosBuildEnvironment = rhetosBuildEnvironment; }
protected void InitLeftDiv(PluginInfo info) { if (info == null) { return; } Version = info.Version; Author = info.Author; Update = info.UpdateTime.ToString("yyyy年MM月dd日"); Compatible = info.Compatible; DownLoads = info.Clicks.ToString(); info = PluginInfoCollection.CreateInstance(PluginType)[Request.QueryString["key"]]; TitleText = info == null ? "现在安装" : "现在更新"; if (info == null) { switch (PluginType) { case PluginType.RESOURCE: updatetype = 10; break; case PluginType.PLUGIN: updatetype = 0; break; default: updatetype = 10; break; } } else { switch (PluginType) { case PluginType.RESOURCE: updatetype = info.IsLocal ? 4 : 3; break; case PluginType.PLUGIN: updatetype = info.IsLocal ? 2 : 1; break; default: updatetype = info.IsLocal ? 2 : 1; break; } } }
protected void EnableLinkButton_Click(object sender, EventArgs e) { string keys = Request.Form["EnableSeletedCheckbox"]; if (!String.IsNullOrEmpty(keys)) { string[] keylist = keys.Split(",".ToCharArray()); foreach (string key in keylist) { PluginInfo info = PluginInfoCollection.CreateInstance(PluginType)[key]; if (info != null) { info.Enable = true; info.Save(); } } } BindData(); }
string BuildNavString() { string strActive = @"<LI class=TabIn id=tab{0} style='display:{2}'><A>{1}</A> </LI>"; string strLink = @"<LI class=TabOut id=tab{0} style='display:{2}'><A href={3}>{1}</A> </LI>"; int tab = 1; string tabString = ""; string dispay = ""; string rawurl = We7Helper.RemoveParamFromUrl(Request.RawUrl, "tab"); rawurl = We7Helper.RemoveParamFromUrl(Request.RawUrl, "saved"); if (TabID != null && We7Helper.IsNumber(TabID)) { tab = int.Parse(TabID); } //Article a = ArticleHelper.GetArticle(ChannelID); PluginInfo info = null, infoLocale = null; string isRemote = Request.QueryString["remote"]; if (!String.IsNullOrEmpty(isRemote) && isRemote.Trim() == "1") { info = GetRemotePluginInfo(); } else { info = PluginInfoCollection.CreateInstance(PluginType)[Request.QueryString["key"]]; } InitLeftDiv(info); ContentLiteral.Text = ""; if (tab == 1) { tabString += string.Format(strActive, 1, "简介", dispay); ContentLiteral.Text = info != null ? info.Description : ""; } else { tabString += string.Format(strLink, 1, "简介", dispay, We7Helper.AddParamToUrl(rawurl, "tab", "1")); } if (tab == 2) { tabString += string.Format(strActive, 2, "安装", dispay); ContentLiteral.Text = info != null ? info.Deployment.Introduction : ""; } else { tabString += string.Format(strLink, 2, "安装", dispay, We7Helper.AddParamToUrl(rawurl, "tab", "2")); } if (tab == 3) { tabString += string.Format(strActive, 3, "截图", dispay); if (info != null) { StringBuilder sb = new StringBuilder(); foreach (string src in info.Snapshot) { sb.Append(String.Format("<img src='{2}/Temp/{0}/{1}' ></img>", Request.QueryString["key"], src, GeneralConfigs.GetConfig().PluginServer)); } ContentLiteral.Text = sb.ToString(); } } else { tabString += string.Format(strLink, 3, "截图", dispay, We7Helper.AddParamToUrl(rawurl, "tab", "3")); } if (tab == 4) { tabString += string.Format(strActive, 4, "其它", dispay); ContentLiteral.Text = info != null ? info.Others : ""; } else { tabString += string.Format(strLink, 4, "其它", dispay, We7Helper.AddParamToUrl(rawurl, "tab", "4")); } return(tabString); }
public string Run(PluginInfo info, PluginAction action, string pluginPath) { try { WebClient client = new WebClient(); byte[] buffer; try { buffer = client.DownloadData(pluginPath); } catch { buffer = client.DownloadData(pluginPath); } string temppath = Path.Combine(info.PluginsClientPath, "_temp"); if (!Directory.Exists(temppath)) { Directory.CreateDirectory(temppath); } try { ExtractZipFile(buffer, temppath); string pluginCfg = Path.Combine(temppath, info.Directory); pluginCfg = Path.Combine(pluginCfg, "Plugin.xml"); if (File.Exists(pluginCfg)) { PluginInfo tempInfo = new PluginInfo(pluginCfg); if (String.IsNullOrEmpty(tempInfo.Version) || String.Compare(tempInfo.Version, PluignCheckVersionCommand.Version, true) < 0) { if (PluginAction.UPDATE == action || PluginAction.REMOTEUPDATE == action) { return(new PluginJsonResult(false, "插件版本低于" + PluignCheckVersionCommand.Version + ",不能进行更新!").ToString()); } else if (PluginAction.REMOTEINSTALL == action || PluginAction.INSTALL == action) { return(new PluginJsonResult(false, "插件版本低于" + PluignCheckVersionCommand.Version + ",不能进行添加!").ToString()); } } else { ExtractZipFile(buffer, info.PluginsClientPath); PluginInfo localInfo = PluginInfoCollection.CreateInstance(info.PluginType)[info.Directory]; if (info != null) { localInfo.IsLocal = false; localInfo.Save(); } } } else { ExtractZipFile(buffer, info.PluginsClientPath); PluginInfo localInfo = PluginInfoCollection.CreateInstance(info.PluginType)[info.Directory]; if (localInfo != null) { localInfo.IsLocal = false; localInfo.Save(); } } } catch (Exception ex) { return(new PluginJsonResult(false, ex.Message + "堆栈:" + ex.StackTrace + "。Inner:" + ex.InnerException.Message).ToString()); } finally { Directory.Delete(temppath, true); } } catch (Exception ex) { return(new PluginJsonResult(false, ex.Message + "堆栈:" + ex.StackTrace + "。Inner:" + ex.InnerException.Message).ToString()); } return(new PluginJsonResult(true).ToString()); }
public static PluginInfoCollection LoadPlugins(string path) { PluginInfoCollection plgCol = new PluginInfoCollection(); LoadPlugins(path, plgCol); return plgCol; }
public static void LoadPlugins(string path, PluginInfoCollection plgCol) { AppDomain loadDomain = null; try { AppDomainSetup domainSet = new AppDomainSetup { ApplicationBase = path }; loadDomain = AppDomain.CreateDomain("PluginLoadDomain" + new Guid().ToString().GetHashCode().ToString("x"), null, domainSet); PluginLoadingStrategy strat = (PluginLoadingStrategy)loadDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, LoadStrategyType.FullName); PluginShortInfoForLoad[] res = strat.Load(path); foreach (PluginShortInfoForLoad cInf in res) { plgCol.Add(new PluginInformation(cInf.AssemblyFileName, cInf.AssemblyFullName, cInf.ClassName, cInf.PluginLocInfo)); } } #if DEBUG catch(Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } #endif finally { if (loadDomain != null) AppDomain.Unload(loadDomain); } }
protected void UploadButton_Click(object sender, EventArgs e) { try { string pluginName = Path.GetFileNameWithoutExtension(ZipFileUpload.FileName); if (String.IsNullOrEmpty(pluginName)) { Response.Write("文件不能为空!"); return; } string type = Request.QueryString["type"] ?? ""; type = type.Trim(); if (pluginName != type) { Response.Write("请上传需要更新的插件"); return; } string temppath = Path.Combine(ginfo.PluginsClientPath, "_temp"); if (!Directory.Exists(temppath)) { Directory.CreateDirectory(temppath); } helper.ExtractZipFile(ZipFileUpload.FileBytes, temppath); try { string pluginCfg = Path.Combine(temppath, pluginName); pluginCfg = Path.Combine(pluginCfg, "Plugin.xml"); PluginInfo tempInfo = new PluginInfo(pluginCfg); if (String.IsNullOrEmpty(tempInfo.Version) || String.Compare(tempInfo.Version, PluignCheckVersionCommand.Version, true) < 0) { Response.Write("插件版本低于" + PluignCheckVersionCommand.Version + ",不能进行更新!"); } else { helper.ExtractZipFile(ZipFileUpload.FileBytes, ginfo.PluginsClientPath); PluginInfo info = PluginInfoCollection.CreateInstance(PluginType)[pluginName]; if (info != null) { info.LoadXml(); info.IsLocal = true; info.Save(); } string script = "parent.mask.showMessageProgressBar({0})"; string update = "update"; switch (PluginType) { case PluginType.PLUGIN: update = "update"; break; case PluginType.RESOURCE: update = "insctr"; break; } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "update", String.Format(script, "{" + String.Format("action:'{0}',plugin:'{1}',title:'{2}',message:'{3}'", update, pluginName, "更新插件", "更新成功") + "}"), true); } } catch (Exception ex) { } finally { Directory.Delete(temppath, true); } } catch (Exception ex) { Response.Write("更新失败!错误原因:" + ex.Message); } }