private IEnumerable <SettingData> GetSettingsFromStore(SettingStore store) { if (store == null || string.IsNullOrWhiteSpace(store.ApplicationName) || string.IsNullOrWhiteSpace(store.DirectoryName)) { throw new SettingsStoreException("Invalid path"); } if (!Auth.AllowReadDirectory(store.ApplicationName, store.DirectoryName)) { throw new SettingsAuthorizationException(AuthorizationScope.Directory, AuthorizationLevel.Read, store.DirectoryName, Auth.CurrentIdentity.Id); } var version = Store.GetVersion(store.ApplicationName, store.Version); if (version == null) { throw new SettingsNotFoundException(store.Version.ToString()); } var directory = Store.GetDirectory(store.ApplicationName, store.DirectoryName); if (version == null) { throw new SettingsNotFoundException(store.DirectoryName); } return(Store.Context.Settings.Where(s => s.VersionId == version.Id && s.DirectoryId == directory.Id)); }
public void DeleteSetting(SettingStore store, SettingModel setting) { var currentSettings = GetSettingsFromStore(store); using (TransactionScope scope = TransactionScopeFactory.CreateReaduncommited()) { if (setting == null || string.IsNullOrWhiteSpace(setting.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_NO_KEY); } var existing = currentSettings.SingleOrDefault(s => s.Equals(setting)); if (existing != null) { if (Auth.AllowDeleteSetting(store.ApplicationName, store.DirectoryName)) { Store.Context.Settings.Remove(existing); } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Write, store.DirectoryName, Auth.CurrentIdentity.Id); } } else { throw new SettingsNotFoundException(setting.Key); } Store.Save(); scope.Complete(); } }
public IEnumerable<SettingModel> GetSettings(SettingStore store, int objectId) { //will authenticate return (from setting in GetSettingsFromStore(store) where setting.ObjecId == objectId select DataToModel(setting)); }
public IEnumerable <SettingModel> GetSettings(SettingStore store, int objectId) { //will authenticate return(from setting in GetSettingsFromStore(store) where setting.ObjecId == objectId select DataToModel(setting)); }
public void SaveSettings(SettingStore store, IEnumerable <SettingModel> settings) { var currentSettings = GetSettingsFromStore(store); using (TransactionScope scope = TransactionScopeFactory.CreateReaduncommited()) { foreach (var item in settings) { if (item == null || string.IsNullOrWhiteSpace(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_NO_KEY); } var existingOrNew = currentSettings.SingleOrDefault(s => s.Equals(item)); if (existingOrNew != null) { if (Auth.AllowriteSetting(store.ApplicationName, store.DirectoryName)) { existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.SettingValue = item.Value; existingOrNew.Modified = DateTime.UtcNow; } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Write, store.DirectoryName, Auth.CurrentIdentity.Id); } } else { if (Auth.AllowCreateSetting(store.ApplicationName, store.DirectoryName)) { if (!NameValidator.ValidateKey(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_INVALID_KEY); } existingOrNew = CreateDataForStore(store); existingOrNew.SettingKey = item.Key.Trim().Replace(" ", " "); existingOrNew.SettingValue = item.Value; existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.Created = DateTime.Now; existingOrNew.ObjecId = item.ObjectId; Store.Context.Settings.Add(existingOrNew); } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Create, store.DirectoryName, Auth.CurrentIdentity.Id); } } } Store.Save(); scope.Complete(); } }
public IHttpActionResult GetByDirectory(SettingStore store) { try { return Ok<SettingModel[]>(controller.GetSettings(store).ToArray()); } catch (Exception ex) { return Error(ex); } }
public IHttpActionResult DeleteKey(string applicationName, int version, string directory, int objectId, string key) { try { SettingStore store = new SettingStore(applicationName, version, directory); controller.DeleteSetting(store, new SettingModel { Key = key, ObjectId = objectId }); return Ok(); } catch (Exception ex) { return Error(ex); } }
public SettingModel GetSetting(SettingStore store, string settingKey, int objectId) { //will authenticate var value = (from setting in GetSettingsFromStore(store) where (setting.SettingKey == settingKey) && setting.ObjecId == objectId select DataToModel(setting)).SingleOrDefault(); if (value == null) { throw new SettingsNotFoundException(settingKey); } return(value); }
public SettingModel GetSetting(SettingStore store, string settingKey, int objectId) { //will authenticate var value = (from setting in GetSettingsFromStore(store) where (setting.SettingKey == settingKey) && setting.ObjecId == objectId select DataToModel(setting)).SingleOrDefault(); if (value == null) { throw new SettingsNotFoundException(settingKey); } return value; }
private SettingData CreateDataForStore(SettingStore store) { //Must be authenticated SettingData data = new SettingData(); var version = Store.GetVersion(store.ApplicationName, store.Version); if (version == null) { throw new SettingsStoreException(Constants.ERROR_VERION_UNKNOWN); } var directory = Store.GetDirectory(store.ApplicationName, store.DirectoryName); if (directory == null) { throw new SettingsStoreException(Constants.ERROR_DIRECTORY_UNKOWN); } data.DirectoryId = directory.Id; data.VersionId = version.Id; data.ObjecId = 0; return(data); }
public IHttpActionResult SaveSetting(string applicationName, int version, string directory, int objectId, string key, [FromBody]string value) { var store = new SettingStore(applicationName, version, directory); return SaveSetting(store, new SettingModel { Key = key, Value = value, ObjectId = objectId }); }
public void SaveSetting(SettingStore store, SettingModel setting) { SaveSettings(store, new[] { setting }); }
public IEnumerable <SettingModel> GetSettings(SettingStore store) { //will authenticate return(from setting in GetSettingsFromStore(store) select DataToModel(setting)); }
public IEnumerable<SettingModel> GetSettings(SettingStore store) { //will authenticate return (from setting in GetSettingsFromStore(store) select DataToModel(setting)); }
public IHttpActionResult SaveSettings(SettingStore store, IEnumerable<SettingModel> value) { try { controller.SaveSettings(store, value); return Ok(); } catch (Exception ex) { return Error(ex); } }
private SettingData CreateDataForStore(SettingStore store) { //Must be authenticated SettingData data = new SettingData(); var version = Store.GetVersion(store.ApplicationName, store.Version); if (version == null) { throw new SettingsStoreException(Constants.ERROR_VERION_UNKNOWN); } var directory = Store.GetDirectory(store.ApplicationName, store.DirectoryName); if (directory == null) { throw new SettingsStoreException(Constants.ERROR_DIRECTORY_UNKOWN); } data.DirectoryId = directory.Id; data.VersionId = version.Id; data.ObjecId = 0; return data; }
private IEnumerable<SettingData> GetSettingsFromStore(SettingStore store) { if (store == null || string.IsNullOrWhiteSpace(store.ApplicationName) || string.IsNullOrWhiteSpace(store.DirectoryName)) { throw new SettingsStoreException("Invalid path"); } if (!Auth.AllowReadDirectory(store.ApplicationName, store.DirectoryName)) { throw new SettingsAuthorizationException(AuthorizationScope.Directory, AuthorizationLevel.Read, store.DirectoryName, Auth.CurrentIdentity.Id); } var version = Store.GetVersion(store.ApplicationName, store.Version); if (version == null) { throw new SettingsNotFoundException(store.Version.ToString()); } var directory = Store.GetDirectory(store.ApplicationName, store.DirectoryName); if (version == null) { throw new SettingsNotFoundException(store.DirectoryName); } return Store.Context.Settings.Where(s => s.VersionId == version.Id && s.DirectoryId == directory.Id); }
public IHttpActionResult GetSettting(SettingStore store, string key, int objectId) { try { return Ok(controller.GetSetting(store, key, objectId)); } catch (Exception ex) { return Error(ex); } }
public void SaveSettings(SettingStore store, IEnumerable<SettingModel> settings) { var currentSettings = GetSettingsFromStore(store); using (TransactionScope scope = TransactionScopeFactory.CreateReaduncommited()) { foreach (var item in settings) { if (item == null || string.IsNullOrWhiteSpace(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_NO_KEY); } var existingOrNew = currentSettings.SingleOrDefault(s => s.Equals(item)); if (existingOrNew != null) { if (Auth.AllowriteSetting(store.ApplicationName, store.DirectoryName)) { existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.SettingValue = item.Value; existingOrNew.Modified = DateTime.UtcNow; } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Write, store.DirectoryName, Auth.CurrentIdentity.Id); } } else { if (Auth.AllowCreateSetting(store.ApplicationName, store.DirectoryName)) { if (!NameValidator.ValidateKey(item.Key)) { throw new SettingsStoreException(Constants.ERROR_SETTING_INVALID_KEY); } existingOrNew = CreateDataForStore(store); existingOrNew.SettingKey = item.Key.Trim().Replace(" ", " "); existingOrNew.SettingValue = item.Value; existingOrNew.SettingInfo = item.Info; existingOrNew.SettingTypeInfo = item.TypeInfo; existingOrNew.Created = DateTime.Now; existingOrNew.ObjecId = item.ObjectId; Store.Context.Settings.Add(existingOrNew); } else { throw new SettingsAuthorizationException(AuthorizationScope.Setting, AuthorizationLevel.Create, store.DirectoryName, Auth.CurrentIdentity.Id); } } } Store.Save(); scope.Complete(); } }