예제 #1
0
        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));
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
 public IEnumerable<SettingModel> GetSettings(SettingStore store, int objectId)
 {
     //will authenticate
     return (from setting in GetSettingsFromStore(store)
             where setting.ObjecId == objectId
             select DataToModel(setting));
 }
예제 #4
0
 public IEnumerable <SettingModel> GetSettings(SettingStore store, int objectId)
 {
     //will authenticate
     return(from setting in GetSettingsFromStore(store)
            where setting.ObjecId == objectId
            select DataToModel(setting));
 }
예제 #5
0
        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();
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
 public IHttpActionResult GetByDirectory(SettingStore store)
 {
     try
     {
         return Ok<SettingModel[]>(controller.GetSettings(store).ToArray());
     }
     catch (Exception ex)
     {
         return Error(ex);
     }
 }
예제 #8
0
 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);
     }
 }
예제 #9
0
        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);
        }
예제 #10
0
        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;
        }
예제 #11
0
        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);
        }
예제 #12
0
 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 });
 }
예제 #13
0
 public void SaveSetting(SettingStore store, SettingModel setting)
 {
     SaveSettings(store, new[] { setting });
 }
예제 #14
0
 public IEnumerable <SettingModel> GetSettings(SettingStore store)
 {
     //will authenticate
     return(from setting in GetSettingsFromStore(store)
            select DataToModel(setting));
 }
예제 #15
0
 public void SaveSetting(SettingStore store, SettingModel setting)
 {
     SaveSettings(store, new[] { setting });
 }
예제 #16
0
 public IEnumerable<SettingModel> GetSettings(SettingStore store)
 {
     //will authenticate
     return (from setting in GetSettingsFromStore(store)
             select DataToModel(setting));
 }
예제 #17
0
 public IHttpActionResult SaveSettings(SettingStore store, IEnumerable<SettingModel> value)
 {
     try
     {
         controller.SaveSettings(store, value);
         return Ok();
     }
     catch (Exception ex)
     {
         return Error(ex);
     }
 }
예제 #18
0
        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;
        }
예제 #19
0
        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);
        }
예제 #20
0
 public IHttpActionResult GetSettting(SettingStore store, string key, int objectId)
 {
     try
     {
         return Ok(controller.GetSetting(store, key, objectId));
     }
     catch (Exception ex)
     {
         return Error(ex);
     }
 }
예제 #21
0
        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();
            }
        }