public ActionResult Edit(int id) { StorageAccount account = _storageAccountService.Load(id); if (account == null) { ModelState.AddModelError("notfound", ValidationResources.StorageAccountNotFoundError); return(View()); } Identity identity = User.Identity; if (identity.UserId != account.UserId) { ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError); return(View()); } IStoragePlugin plugin = _storagePluginsService.GetStoragePlugin(account.StoragePluginId); if (plugin == null) { ModelState.AddModelError("storage_plugin", ValidationResources.StoragePluginNotFoundError); return(View()); } ViewData.Add(Constants.StorageAccountIdFormKey, account.Id); ViewData.Add(Constants.StampFormKey, account.Stamp.ToBinary()); ViewData.Add(Constants.StorageAccountTitleViewDataKey, account.AccountName); object pluginSettingsModel = plugin.GetAccountConfigurationModel(account.Id); return(View(pluginSettingsModel)); }
public ActionResult Edit([ModelBinder(typeof(StorageAccountSettingsModelBinder))] object model) { if (ModelState.IsValid) { int storageAccountId; long stamp; if (!int.TryParse(Request.Form[Constants.StorageAccountIdFormKey], NumberStyles.Integer, CultureInfo.InvariantCulture, out storageAccountId)) { ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountNotFoundError); return(View()); } if (!long.TryParse(Request.Form[Constants.StampFormKey], NumberStyles.Integer, CultureInfo.InvariantCulture, out stamp)) { ModelState.AddModelError("storage_account_id", ValidationResources.BadRequestError); return(View()); } //account and plugin should be valid, they were checked by model binder StorageAccount account = _storageAccountService.Load(storageAccountId); Identity identity = (Identity)HttpContext.User.Identity; if (identity.UserId != account.UserId) { ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError); return(View()); } IStoragePlugin storagePlugin = _storagePluginsService.GetStoragePlugin(account.StoragePluginId); try { storagePlugin.ApplyConfiguration(storageAccountId, DateTime.FromBinary(stamp), model); TempData.AddRequestSuccessMessage(string.Format(CultureInfo.CurrentCulture, SuccessMessagesResources.StorageAccountUpdatedFormat, account.AccountName)); return(RedirectToAction("Edit")); } catch (StaleObjectException) { ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountStalled); } catch (ObjectNotExistsException) { ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountNotFoundError); } } return(View(model)); }
public StorageFileStreamResult DownloadFile(StorageAccount storageAccount, string url) { if (storageAccount == null) { throw new ArgumentNullException("storageAccount"); } if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } IStoragePlugin plugin = GetStoragePlugin(storageAccount.StoragePluginId); if (plugin == null) { throw new StoragePluginNotFoundException(storageAccount.StoragePluginId); } var streamResult = plugin.GetFileStream(url, storageAccount.Id); streamResult.FileStream = _streamFactory.MakeDownloadStream(streamResult.FileStream); return(streamResult); }
public CachedStoragePlugin(StoragePlugin pluginDescriptor, IStoragePlugin plugin) { PluginDescriptor = pluginDescriptor; Plugin = plugin; }
public ForExpression Storage(IStoragePlugin plugin) { _pluginConfiguration.Register(plugin); return(this); }
public void SetPlugin(int pluginId, IStoragePlugin storagePlugin) { string cacheKey = GetStorageCacheKey(pluginId); Type pluginType = storagePlugin.GetType(); CacheService.Set(cacheKey, pluginType); }
public ActionResult GetFolder(int id, string path) { FolderModel model = null; var resultAction = Condition() .DoIfNotAjax(() => View(model)) .DoIfAjax(() => Json(new AjaxResult { MainPanelHtml = this.RenderViewToString("~/Views/StorageAccount/Controls/StorageAccountFolderControl.ascx", model) }, JsonRequestBehavior.AllowGet)); StorageAccount account = _storageAccountService.Load(id); if (account == null) { ModelState.AddModelError("notfound", ValidationResources.StorageAccountNotFoundError); return(resultAction); } Identity identity = (Identity)HttpContext.User.Identity; if (identity.UserId != account.UserId) { ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError); return(resultAction); } #warning call service not plugin dirrectly IStoragePlugin storagePlugin = _storagePluginsService.GetStoragePlugin(account.StoragePluginId); if (storagePlugin == null) { ModelState.AddModelError("storage_plugin", ValidationResources.StoragePluginNotFoundError); return(resultAction); } StorageFolderResult queryModel = null; try { queryModel = storagePlugin.QueryStorage(id, path); } catch (PluginException ex) { ModelState.AddModelError("storage_plugin", GetErrorMessage(ex.ErrorCode)); if (ex.ErrorCode == PluginErrorCodes.PluginError) { Logger.Error("Storage plugin error", ex); } return(resultAction); } catch (Exception ex) { ModelState.AddModelError("storage_plugin", ErrorResources.PluginError); Logger.Error("Storage plugin error", ex); return(resultAction); } model = new FolderModel() { Content = queryModel, StorageAccount = account }; return(resultAction); }
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { NameValueCollection form = controllerContext.HttpContext.Request.Form; if (!form.AllKeys.Contains(Constants.StorageAccountIdFormKey)) { bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError); return(null); } string pluginFormValue = form[Constants.StorageAccountIdFormKey]; int accountId; if (!int.TryParse(pluginFormValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out accountId)) { bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError); return(null); } IStorageAccountService accountService = IocContainer.Instance.Resolve <IStorageAccountService>(); StorageAccount account = accountService.Load(accountId); if (account == null) { bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError); return(null); } IStoragePluginsService storageService = IocContainer.Instance.Resolve <IStoragePluginsService>(); IStoragePlugin storagePlugin = storageService.GetStoragePlugin(account.StoragePluginId); if (storagePlugin == null) { bindingContext.ModelState.AddModelError("storage_plugin", ValidationResources.StoragePluginNotFoundError); return(null); } Type modelType = storagePlugin.GetAccountConfigurationModel().GetType(); if (!String.IsNullOrEmpty(bindingContext.ModelName) && !bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName)) { if (!bindingContext.FallbackToEmptyPrefix) { return(null); } bindingContext = new ModelBindingContext { ModelMetadata = bindingContext.ModelMetadata, ModelState = bindingContext.ModelState, PropertyFilter = bindingContext.PropertyFilter, ValueProvider = bindingContext.ValueProvider }; } //object model = bindingContext.Model ?? CreateModel(controllerContext, bindingContext, bindingContext.ModelType); object model = bindingContext.Model ?? CreateModel(controllerContext, bindingContext, modelType); bindingContext = new ModelBindingContext { //ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, bindingContext.ModelType), ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, modelType), ModelName = bindingContext.ModelName, ModelState = bindingContext.ModelState, PropertyFilter = bindingContext.PropertyFilter, ValueProvider = bindingContext.ValueProvider }; if (OnModelUpdating(controllerContext, bindingContext)) { foreach (PropertyDescriptor descriptor in GetFilteredModelProperties(controllerContext, bindingContext)) { BindProperty(controllerContext, bindingContext, descriptor); } OnModelUpdated(controllerContext, bindingContext); } return(model); }