public IActionResult EditPopup(string btnId, string formId, PluginModel model) { var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(model.SystemName, LoadPluginsMode.All); if (pluginDescriptor == null) { //No plugin found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { //we allow editing of 'friendly name', 'display order', store mappings pluginDescriptor.FriendlyName = model.FriendlyName; pluginDescriptor.DisplayOrder = model.DisplayOrder; pluginDescriptor.LimitedToStores.Clear(); if (model.LimitedToStores && model.SelectedStoreIds != null) { pluginDescriptor.LimitedToStores = model.SelectedStoreIds.ToList(); } PluginFileParser.SavePluginDescriptionFile(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(); //locales foreach (var localized in model.Locales) { pluginDescriptor.Instance().SaveLocalizedFriendlyName(_localizationService, localized.LanguageId, localized.FriendlyName); } //enabled/disabled if (pluginDescriptor.Installed) { var pluginInstance = pluginDescriptor.Instance(); if (pluginInstance is IPaymentMethod) { //payment plugin var pm = (IPaymentMethod)pluginInstance; if (pm.IsPaymentMethodActive(_paymentSettings)) { if (!model.IsEnabled) { //mark as disabled _paymentSettings.ActivePaymentMethodSystemNames.Remove(pm.PluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); } } else { if (model.IsEnabled) { //mark as active _paymentSettings.ActivePaymentMethodSystemNames.Add(pm.PluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); } } } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method var srcm = (IShippingRateComputationMethod)pluginInstance; if (srcm.IsShippingRateComputationMethodActive(_shippingSettings)) { if (!model.IsEnabled) { //mark as disabled _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Remove(srcm.PluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } } else { if (model.IsEnabled) { //mark as active _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add(srcm.PluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } } } else if (pluginInstance is ITaxProvider) { //tax provider if (model.IsEnabled) { _taxSettings.ActiveTaxProviderSystemName = model.SystemName; _settingService.SaveSetting(_taxSettings); } else { _taxSettings.ActiveTaxProviderSystemName = ""; _settingService.SaveSetting(_taxSettings); } } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method var eam = (IExternalAuthenticationMethod)pluginInstance; if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsEnabled) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsEnabled) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } } else if (pluginInstance is IWidgetPlugin) { //Misc plugins var widget = (IWidgetPlugin)pluginInstance; if (widget.IsWidgetActive(_widgetSettings)) { if (!model.IsEnabled) { //mark as disabled _widgetSettings.ActiveWidgetSystemNames.Remove(widget.PluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); } } else { if (model.IsEnabled) { //mark as active _widgetSettings.ActiveWidgetSystemNames.Add(widget.PluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); } } } } _cacheManager.Clear(); ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
private void MigrateInitial() { var installedPlugins = PluginFileParser.ParseInstalledPluginsFile(); if (installedPlugins.Count == 0) { return; } var renamedPlugins = new List <string>(); var pluginRenameMap = new Dictionary <string, string> { { "CurrencyExchange.ECB", null /* null means: remove it */ }, { "CurrencyExchange.MoneyConverter", null }, { "ExternalAuth.OpenId", null }, { "Tax.Free", null }, { "Api.WebApi", "SmartStore.WebApi" }, { "DiscountRequirement.MustBeAssignedToCustomerRole", "SmartStore.DiscountRules" }, { "DiscountRequirement.HadSpentAmount", "SmartStore.DiscountRules" }, { "DiscountRequirement.HasAllProducts", "SmartStore.DiscountRules" }, { "DiscountRequirement.HasOneProduct", "SmartStore.DiscountRules" }, { "DiscountRequirement.Store", "SmartStore.DiscountRules" }, { "DiscountRequirement.BillingCountryIs", "SmartStore.DiscountRules" }, { "DiscountRequirement.ShippingCountryIs", "SmartStore.DiscountRules" }, { "DiscountRequirement.HasPaymentMethod", "SmartStore.DiscountRules.HasPaymentMethod" }, { "DiscountRequirement.HasShippingOption", "SmartStore.DiscountRules.HasShippingOption" }, { "DiscountRequirement.PurchasedAllProducts", "SmartStore.DiscountRules.PurchasedProducts" }, { "DiscountRequirement.PurchasedOneProduct", "SmartStore.DiscountRules.PurchasedProducts" }, { "PromotionFeed.Froogle", "SmartStore.GoogleMerchantCenter" }, { "PromotionFeed.Billiger", "SmartStore.Billiger" }, { "PromotionFeed.ElmarShopinfo", "SmartStore.ElmarShopinfo" }, { "PromotionFeed.Guenstiger", "SmartStore.Guenstiger" }, { "Payments.AccardaKar", "SmartStore.AccardaKar" }, { "Payments.AmazonPay", "SmartStore.AmazonPay" }, { "Developer.DevTools", "SmartStore.DevTools" }, { "ExternalAuth.Facebook", "SmartStore.FacebookAuth" }, { "ExternalAuth.Twitter", "SmartStore.TwitterAuth" }, { "SMS.Clickatell", "SmartStore.Clickatell" }, { "Widgets.GoogleAnalytics", "SmartStore.GoogleAnalytics" }, { "Misc.DemoShop", "SmartStore.DemoShopControlling" }, { "Admin.OrderNumberFormatter", "SmartStore.OrderNumberFormatter" }, { "Admin.Debitoor", "SmartStore.Debitoor" }, { "Widgets.ETracker", "SmartStore.ETracker" }, { "Payments.PayPalDirect", "SmartStore.PayPal" }, { "Payments.PayPalStandard", "SmartStore.PayPal" }, { "Payments.PayPalExpress", "SmartStore.PayPal" }, { "Developer.Glimpse", "SmartStore.Glimpse" }, { "Import.Biz", "SmartStore.BizImporter" }, { "Payments.Sofortueberweisung", "SmartStore.Sofortueberweisung" }, { "Payments.PostFinanceECommerce", "SmartStore.PostFinanceECommerce" }, { "Misc.MailChimp", "SmartStore.MailChimp" }, { "Mobile.SMS.Verizon", "SmartStore.Verizon" }, { "Widgets.LivePersonChat", "SmartStore.LivePersonChat" }, { "Payments.CashOnDelivery", "SmartStore.OfflinePayment" }, { "Payments.Invoice", "SmartStore.OfflinePayment" }, { "Payments.PayInStore", "SmartStore.OfflinePayment" }, { "Payments.Prepayment", "SmartStore.OfflinePayment" }, { "Payments.IPaymentCreditCard", "SmartStore.IPayment" }, { "Payments.IPaymentDirectDebit", "SmartStore.IPayment" }, { "Payments.AuthorizeNet", "SmartStore.AuthorizeNet" }, { "Shipping.AustraliaPost", "SmartStore.AustraliaPost" }, { "Shipping.CanadaPost", "SmartStore.CanadaPost" }, { "Shipping.Fedex", "SmartStore.Fedex" }, { "Shipping.UPS", "SmartStore.UPS" }, { "Payments.Manual", "SmartStore.OfflinePayment" }, { "Shipping.USPS", "SmartStore.USPS" }, { "Widgets.TrustedShopsSeal", "SmartStore.TrustedShops" }, { "Widgets.TrustedShopsCustomerReviews", "SmartStore.TrustedShops" }, { "Widgets.TrustedShopsCustomerProtection", "SmartStore.TrustedShops" }, { "Shipping.ByWeight", "SmartStore.ShippingByWeight" }, { "Payments.DirectDebit", "SmartStore.OfflinePayment" }, { "Tax.FixedRate", "SmartStore.Tax" }, { "Tax.CountryStateZip", "SmartStore.Tax" }, { "Shipping.ByTotal", "SmartStore.Shipping" }, { "Shipping.FixedRate", "SmartStore.Shipping" } }; foreach (var name in installedPlugins) { if (pluginRenameMap.ContainsKey(name)) { string newName = pluginRenameMap[name]; if (newName != null && !renamedPlugins.Contains(newName)) { renamedPlugins.Add(newName); } } else { renamedPlugins.Add(name); } } PluginFileParser.SaveInstalledPluginsFile(renamedPlugins); }
private void ReadPackages(IVirtualPathProvider vpp) { if (!ValidatePaths()) { return; } lstPlugins.DisplayMember = "Name"; lstPlugins.ValueMember = "Path"; lstThemes.DisplayMember = "Name"; lstThemes.ValueMember = "Path"; lstPlugins.Items.Clear(); lstThemes.Items.Clear(); IEnumerable <string> dirs = Enumerable.Empty <string>(); if (vpp.DirectoryExists("~/Plugins") || vpp.DirectoryExists("~/Themes")) { if (vpp.DirectoryExists("~/Plugins")) { dirs = dirs.Concat(vpp.ListDirectories("~/Plugins")); } if (vpp.DirectoryExists("~/Themes")) { dirs = dirs.Concat(vpp.ListDirectories("~/Themes")); } } else { dirs = vpp.ListDirectories("~/"); } foreach (var dir in dirs) { bool isTheme = false; // is it a plugin? var filePath = vpp.Combine(dir, "Description.txt"); if (!vpp.FileExists(filePath)) { // ...no! is it a theme? filePath = vpp.Combine(dir, "theme.config"); if (!vpp.FileExists(filePath)) { continue; } isTheme = true; } try { if (isTheme) { var manifest = ThemeManifest.Create(vpp.MapPath(dir)); lstThemes.Items.Add(new ExtensionInfo(dir, manifest.ThemeName)); } else { var descriptor = PluginFileParser.ParsePluginDescriptionFile(vpp.MapPath(filePath)); if (descriptor != null) { lstPlugins.Items.Add(new ExtensionInfo(dir, descriptor.FolderName)); } } } catch { continue; } } if (lstPlugins.Items.Count > 0) { tabMain.SelectedIndex = 0; } else if (lstThemes.Items.Count > 0) { tabMain.SelectedIndex = 1; } }
public ActionResult EditPopup(string btnId, string formId, PluginModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins)) { return(AccessDeniedView()); } var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(model.SystemName, false); if (pluginDescriptor == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { pluginDescriptor.FriendlyName = model.FriendlyName; pluginDescriptor.Description = model.Description; pluginDescriptor.DisplayOrder = model.DisplayOrder; PluginFileParser.SavePluginDescriptionFile(pluginDescriptor); string settingKey = pluginDescriptor.GetSettingKey("LimitedToStores"); if (model.LimitedToStores && model.SelectedStoreIds != null && model.SelectedStoreIds.Count() > 0) { _settingService.SetSetting <string>(settingKey, string.Join(",", model.SelectedStoreIds)); } else { _settingService.DeleteSetting(settingKey); } // reset plugin and string resources cache _pluginFinder.ReloadPlugins(); _localizationService.ClearCache(); var pluginInstance = pluginDescriptor.Instance(); foreach (var localized in model.Locales) { pluginInstance.SaveLocalizedValue(_localizationService, localized.LanguageId, "FriendlyName", localized.FriendlyName); pluginInstance.SaveLocalizedValue(_localizationService, localized.LanguageId, "Description", localized.Description); } //enabled/disabled if (pluginDescriptor.Installed) { if (pluginInstance is IPaymentMethod) { //payment plugin var pm = (IPaymentMethod)pluginInstance; if (pm.IsPaymentMethodActive(_paymentSettings)) { if (!model.IsEnabled) { //mark as disabled _paymentSettings.ActivePaymentMethodSystemNames.Remove(pm.PluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); } } else { if (model.IsEnabled) { //mark as active _paymentSettings.ActivePaymentMethodSystemNames.Add(pm.PluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); } } } else if (pluginInstance is IShippingRateComputationMethod) { //shipping rate computation method var srcm = (IShippingRateComputationMethod)pluginInstance; if (srcm.IsShippingRateComputationMethodActive(_shippingSettings)) { if (!model.IsEnabled) { //mark as disabled _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Remove(srcm.PluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } } else { if (model.IsEnabled) { //mark as active _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add(srcm.PluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } } } else if (pluginInstance is ITaxProvider) { //tax provider if (model.IsEnabled) { _taxSettings.ActiveTaxProviderSystemName = model.SystemName; _settingService.SaveSetting(_taxSettings); } else { _taxSettings.ActiveTaxProviderSystemName = ""; _settingService.SaveSetting(_taxSettings); } } else if (pluginInstance is IExternalAuthenticationMethod) { //external auth method var eam = (IExternalAuthenticationMethod)pluginInstance; if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsEnabled) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsEnabled) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } } else if (pluginInstance is IWidgetPlugin) { //Misc plugins var widget = (IWidgetPlugin)pluginInstance; if (widget.IsWidgetActive(_widgetSettings)) { if (!model.IsEnabled) { //mark as disabled _widgetSettings.ActiveWidgetSystemNames.Remove(widget.PluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); } } else { if (model.IsEnabled) { //mark as active _widgetSettings.ActiveWidgetSystemNames.Add(widget.PluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); } } } } ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// 上传plugin zip文件 /// </summary> /// <returns></returns> public ActionResult PostFile(string systemName) { string strErrorMsg = ""; string strName = ""; try { string strPath = ""; if (Request.Files.Count > 0) { if (!System.IO.Directory.Exists(string.Format("{0}\\BackUp", Server.MapPath("~/")))) { System.IO.Directory.CreateDirectory(string.Format("{0}\\BackUp", Server.MapPath("~/"))); } HttpPostedFileBase objFile = Request.Files[0]; var pad = DateTime.Now.ToString("yyyyMMddHHmmss"); strPath = string.Format("{0}\\{1}{2}", Server.MapPath("~/pluginsTemp"), pad, System.IO.Path.GetExtension(objFile.FileName)); // dic.Add(objFile.FileName, objFile.InputStream); objFile.SaveAs(strPath); //System.IO.MemoryStream stream = new System.IO.MemoryStream(objZip.ZipContent); SharpZip.UnpackFiles(strPath, string.Format("{0}\\{1}\\", Server.MapPath("~/pluginsTemp"), pad)); var strPathTemp = strPath.Replace(System.IO.Path.GetExtension(objFile.FileName), "\\"); var bolCheck = CheckModule(objFile.FileName, strPathTemp); PluginDescriptor plugTemp = null; if (bolCheck) { plugTemp = PluginFileParser.ParsePluginDescriptionFile(strPathTemp + "\\Description.txt"); if (!string.IsNullOrEmpty(systemName) && systemName != "0" && plugTemp.SystemName != systemName) { throw new Exception("System Name不对,插件不兼容!"); } if (!string.IsNullOrEmpty(systemName) && systemName != "0") //编辑时先删除以前的 { var plugTemp1 = ((List <PluginDescriptor>)PluginManager.AllPlugins) .Find(a => a.SystemName == plugTemp.SystemName); // 如果前后名字对不上,不能装啊 if (plugTemp1 == null) { // 对不上了,看systemName,如果空的话就是添加,否则不让操作 if (!string.IsNullOrEmpty(systemName)) { throw new Exception("System Name不对,插件不兼容!"); } } } else { //是否存在相同的 // plugTemp = PluginManager.GetPluginDescriptor(new DirectoryInfo(System.IO.Path.GetDirectoryName(strPath))); if (((List <PluginDescriptor>)PluginManager.AllPlugins) .Exists(a => a.PluginFileName == plugTemp.PluginFileName)) { strErrorMsg = "the Module has existed!"; bolCheck = false; } else { } } var pluginsVersions = plugTemp.Version.Split('.'); if (pluginsVersions.Length < 4) { strErrorMsg = "the Module's Version format is error! Correct is '40.1.20160911.01'"; bolCheck = false; } } else { System.IO.Directory.Delete(strPathTemp, true); strErrorMsg = "Zip File is not a Module!"; } if (bolCheck) { string strPathTo = string.Format("{0}Plugins\\{1}", Server.MapPath("~/"), plugTemp.SystemName); var plug = plugTemp; if (!Directory.Exists(strPathTo)) { Directory.CreateDirectory(strPathTo); System.IO.File.Copy(strPathTemp + "\\Description.txt", strPathTo + "\\Description.txt"); } plug.InstallFrom = pad; plug.NeedInstalled = false; plug.Installed = false; plug.PluginPath = strPathTo; PluginFileParser.SavePluginDescriptionFile(plug); PluginManager.SavePlugins(plug); } } strName = System.IO.Path.GetFileName(strPath); } catch (Exception ex) { strErrorMsg = "Server Error:" + ex.Message; } if (strErrorMsg != "") { return(Json(new UploadMessageError("1", strErrorMsg, Request["id"]), JsonRequestBehavior.AllowGet)); } else { return(Json(new UploadMessageSuccess(new UploadMessageSuccessMsg(strName, "/pluginsTemp/" + strName), Request["id"]), JsonRequestBehavior.AllowGet)); } }