Beispiel #1
0
        public virtual void TestGetProperties(AppSettingsType type)
        {
            String propertyValue = ConfigurationManager.AppSettings["not-exist"];

            Assert.Null(propertyValue);

            IConfigurationManager           manager        = CreateManager(type);
            PropertyConfig <String, String> propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>()
                                                             .SetKey("not-exist").Build();
            IProperty <String, String> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("not-exist2")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("default", property.Value);

            if (type == AppSettingsType.AppConfig)
            {
                return;
            }

            propertyConfig = ConfigurationProperties.NewConfigBuilder <String, String>().SetKey("exist")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok", property.Value);
        }
 public void Clear(AppSettingsType type)
 {
     using (var db = new LiteDatabase(_database))
     {
         db.DropCollection(GetTableNameFromType(type));
     }
 }
 public IEnumerable <AppSetting> GetAll(AppSettingsType type)
 {
     using (var db = new LiteDatabase(_database))
     {
         var collection = db.GetCollection <AppSetting>(GetTableNameFromType(type));
         return(collection.FindAll());
     }
 }
 public void Remove(string filePath, AppSettingsType type)
 {
     using (var db = new LiteDatabase(_database))
     {
         var collection = db.GetCollection <AppSetting>(GetTableNameFromType(type));
         collection.Delete(x => x.FilePath == filePath);
     }
 }
Beispiel #5
0
        protected virtual IConfigurationManager CreateManager(AppSettingsType type)
        {
            AppSettingsConfigurationSourceConfig sourceConfig = StringPropertySources.NewAppSettingsSourceConfigBuilder()
                                                                .SetName("appsettings").SetType(type).Build();
            AppSettingsConfigurationSource source        = StringPropertySources.NewAppSettingsSource(sourceConfig);
            ConfigurationManagerConfig     managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("test")
                                                           .AddSource(1, source).Build();

            Console.WriteLine("manager config: " + managerConfig + "\n");
            return(ConfigurationManagers.NewManager(managerConfig));
        }
        private string GetTableNameFromType(AppSettingsType type)
        {
            switch (type)
            {
            case AppSettingsType.Creator:
                return("CreatorSettings");

            case AppSettingsType.Simulator:
                return("SimulatorSettings");

            default:
                return("OtherSettings");
            }
        }
        public void Add(AppSetting settings, AppSettingsType type)
        {
            using (var db = new LiteDatabase(_database))
            {
                var collection = db.GetCollection <AppSetting>(GetTableNameFromType(type));
                var record     = collection.FindOne(x => x.FilePath == settings.FilePath);
                if (record != null)
                {
                    return;
                }

                collection.Insert(settings);
            }
        }
Beispiel #8
0
        static T ReadByKey <T>(AppSettingsType appSettingsType)
        {
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Values != null &&
                localSettings.Values.ContainsKey(GetKeyName(appSettingsType)))
            {
                var result = localSettings.Values[GetKeyName(appSettingsType)];
                if (result != null &&
                    result is T)
                {
                    return((T)result);
                }
            }

            return(default);
 public virtual Builder SetType(AppSettingsType type)
 {
     Config.Type = type;
     return(this);
 }
Beispiel #10
0
        public Dictionary <string, string> GetConfigurationsRequestInternal(AppSettingsType appSettingsType, IDictionary <string, PropertyInfo> settings)
        {
            var result = new Dictionary <string, string>();

            var isFromAdminPortal = appSettingsType == AppSettingsType.Webapp;
            var returnAllKeys     = SessionAs <AuthUserSession>().HasPermission(RoleName.SuperAdmin);
            var isTaxiHailPro     = _serverSettings.ServerData.IsTaxiHailPro;

            foreach (var setting in settings)
            {
                var sendToClient          = false;
                var customizableByCompany = false;
                var attributes            = setting.Value.GetCustomAttributes(false);

                // Check if we have to return this setting to the mobile client
                var sendToClientAttribute = attributes.OfType <SendToClientAttribute>().FirstOrDefault();
                if (sendToClientAttribute != null)
                {
                    sendToClient = !isFromAdminPortal;
                }

                // Check if we have to return this setting to the company settings of admin section
                var customizableByCompanyAttribute = attributes.OfType <CustomizableByCompanyAttribute>().FirstOrDefault();
                if (customizableByCompanyAttribute != null)
                {
                    if (isTaxiHailPro)
                    {
                        // company is taxihail pro, no need to check for taxihail pro attribute on setting, we know we return it
                        customizableByCompany = isFromAdminPortal;
                    }
                    else
                    {
                        var requiresTaxiHailProAttribute = attributes.OfType <RequiresTaxiHailPro>().FirstOrDefault();
                        if (requiresTaxiHailProAttribute == null)
                        {
                            customizableByCompany = isFromAdminPortal;
                        }
                    }
                }

                if (returnAllKeys ||                                    // in the case of superadmin
                    sendToClient ||                                     // send to mobile client
                    customizableByCompany)                              // company settings in admin section
                {
                    var settingValue = _serverSettings.ServerData.GetNestedPropertyValue(setting.Key);

                    string settingStringValue = settingValue == null ? string.Empty : settingValue.ToString();
                    if (settingStringValue.IsBool())
                    {
                        // Needed because ToString() returns False instead of false
                        settingStringValue = settingStringValue.ToLower();
                    }

                    result.Add(setting.Key, settingStringValue);
                }
            }

            // Order results alphabetically
            return(result.OrderBy(s => s.Key)
                   .ToDictionary(s => s.Key, s => s.Value));
        }