コード例 #1
0
 public void GetConfigurationUsesjsConf_PrefixAsDefault()
 {
     var data = Utils.FilterAppSettings("jsConf_");
     var jsm = new JsConfigurationScriptManager();
     var script = jsm.GetScript(data);
     Assert.IsTrue(script.Contains(@"{""test1"":1};"));
 }
コード例 #2
0
 public void GetConfigurationFailsIfnotPrefixPresent()
 {
     var data = Utils.FilterAppSettings("conf_");
     var jsm = new JsConfigurationScriptManager();
     var script = jsm.GetScript(data);
     Assert.IsFalse(script.Contains(@"""test3"""));
 }
コード例 #3
0
 public void GetConfigurationReturnsStringsProperly()
 {
     var data = Utils.FilterAppSettings("conf_");
     var jsm = new JsConfigurationScriptManager {Prefix = "conf_"};
     var script = jsm.GetScript(data);
     Assert.IsTrue(script.StartsWith("var ServerConfigurations = "));
     Assert.IsTrue(script.Contains(@"{""test3"":""hello""};"));
 }
コード例 #4
0
 public void GetConfigurationReturnsOk()
 {
     var data = Utils.FilterAppSettings("jsConf_");
     var jsm = new JsConfigurationScriptManager();
     var script = jsm.GetScript(data);
     Assert.IsTrue(script.StartsWith("var ServerConfigurations = "));
     Assert.IsTrue(script.Contains(@"{""test1"":1};"));
 }
コード例 #5
0
 public void GetConfigurationCustomReturnsCustonNames()
 {
     const string JS_PREFIX = "jsConf_";
     var data = Utils.FilterAppSettings(JS_PREFIX);
     var jsm = new JsConfigurationScriptManager { Prefix = JS_PREFIX, VariableName = "MyVar"};
     var script = jsm.GetScript(data);
     Assert.IsTrue(script.StartsWith("var MyVar = "));
     Assert.IsTrue(script.Contains(@"{""test1"":1};"));
 }
コード例 #6
0
 private static void AddDataCodeFromConfig(StringBuilder builder, string prefix, string varName)
 {
     var jsm = new JsConfigurationScriptManager {
         Prefix = prefix,
         VariableName = varName,
         VarIsMainVar = false
     };
     var codes = Utils.FilterAppSettings(jsm.Prefix);
     builder.Append(jsm.GetScript(codes));
 }
コード例 #7
0
        public JavaScriptResult GetConfiguration()
        {
            //1. we set the prefix of the AppSettings that we're going to export.
            var jsPrefix = Utils.GetString("JsConfPrefix");
            //2. we use our utility method in order to retrieve the key/value pairs.
            var data = Utils.FilterAppSettings(jsPrefix);
            //3. we instantiate our JsConfigurationScriptManager (typically we'll use DI and maybe use it through the controller)
            var jsm = new JsConfigurationScriptManager();
            //4. we create the script
            var script = jsm.GetScript(data);
            //5. we expose the script
            return JavaScript(script);

            /* RETURN VALUE   ****************************************************************************************************

            var ServerConfigurations = {  'maxContactItems': 50,  'maxAddressItems': 50 };

            - The default variable name is ServerConfigurations.

            *********************************************************************************************************************/
        }
コード例 #8
0
        public JavaScriptResult GetConfigurationCustom()
        {
            //1. we set the prefix of the AppSettings that we're going to export.
            const string JS_PREFIX = "jsConf_";
            //2. we use our utility method in order to retrieve the key/value pairs.
            var data = Utils.FilterAppSettings(JS_PREFIX);
            //3. we instantiate our JsConfigurationScriptManager (typically we'll use DI and maybe use it through the controller)
            var jsm = new JsConfigurationScriptManager { Prefix = JS_PREFIX, VariableName = "MyVar", ExposeRelativePath = true};
            //4. we create the script
            var script = jsm.GetScript(data);
            //5. we expose the script
            return JavaScript(script);

            /* RETURN VALUE   ****************************************************************************************************

            var Myvar = {  'maxContactItems': 50,  'maxAddressItems': 50,  'relPath':'/' };

            - The variable name has been defined by us.
            - If you forget to inform the prefix when instantiating the JsConfigurationScriptManager, the prefix will appear
              in the property names.
            - relPath exposes the relative path of the app.

            *********************************************************************************************************************/
        }