コード例 #1
0
ファイル: ConfigurationProvider.cs プロジェクト: 2sic/2sxc
        // note: not sure yet where the best place for this method is, so it's here for now
        // will probably move again some day
        internal static ValueCollectionProvider GetConfigProviderForModule(int moduleId, SexyContent.App app, SxcInstance sxc)
        {
            var portalSettings = PortalSettings.Current;

            var provider = new SxcValueCollectionProvider(sxc);

            // only add these in running inside an http-context. Otherwise leave them away!
            if (HttpContext.Current != null)
            {
                var request = HttpContext.Current.Request;

                // new
                NameValueCollection paramList = new NameValueCollection();
                if(sxc?.Parameters != null)
                    foreach (var pair in sxc.Parameters)
                        paramList.Add(pair.Key, pair.Value);
                else
                    paramList = request.QueryString;
                provider.Sources.Add("querystring", new FilteredNameValueCollectionPropertyAccess("querystring", paramList));
                // old
                // provider.Sources.Add("querystring", new FilteredNameValueCollectionPropertyAccess("querystring", request.QueryString));
                provider.Sources.Add("server", new FilteredNameValueCollectionPropertyAccess("server", request.ServerVariables));
                provider.Sources.Add("form", new FilteredNameValueCollectionPropertyAccess("form", request.Form));
            }

            // Add the standard DNN property sources if PortalSettings object is available
            if (portalSettings != null)
            {
                var dnnUsr = portalSettings.UserInfo;
                var dnnCult = Thread.CurrentThread.CurrentCulture;
                var dnn = new TokenReplaceDnn(app, moduleId, portalSettings, dnnUsr);
                var stdSources = dnn.PropertySources;
                foreach (var propertyAccess in stdSources)
                    provider.Sources.Add(propertyAccess.Key,
                        new ValueProviderWrapperForPropertyAccess(propertyAccess.Key, propertyAccess.Value, dnnUsr, dnnCult));
            }

            provider.Sources.Add("app", new AppPropertyAccess("app", app));

            // add module if it was not already added previously
            if (!provider.Sources.ContainsKey("module"))
            {
                var modulePropertyAccess = new StaticValueProvider("module");
                modulePropertyAccess.Properties.Add("ModuleID", moduleId.ToString(CultureInfo.InvariantCulture));
                provider.Sources.Add(modulePropertyAccess.Name, modulePropertyAccess);
            }
            return provider;
            //return _valueCollectionProvider;
        }
コード例 #2
0
        public void ValueProvider_StaticValueProvider()
        {
            var sv = new StaticValueProvider("Demo");
            sv.Properties.Add("Alpha", "found");
            sv.Properties.Add("Bravo", "found it too");
            sv.Properties.Add("Child:Grandchild", "found");

            bool found = false;

            Assert.IsTrue(sv.Has("Alpha"));
            Assert.IsTrue(sv.Has("alpha")); // true now that caps don't matter
            Assert.IsTrue(sv.Has("Bravo"));
            Assert.IsFalse(sv.Has("Charlie"));
            Assert.IsTrue(sv.Get("Alpha", "", ref found) == "found");
            Assert.IsTrue(sv.Get("Bravo", "", ref found) == "found it too");
            Assert.IsTrue(sv.Get("Child:Grandchild", "", ref found) == "found");
            Assert.IsTrue(sv.Get("Child", "", ref found) == null);
        }
コード例 #3
0
ファイル: TokenReplace_Test.cs プロジェクト: 2sic/eav-server
        public void TokenReplace_ComplexReplace()
        {
            var original =
                @"Select * From Users Where UserId = [QueryString:UserName||[AppSettings:DefaultUserName||0]] or UserId = [AppSettings:RootUserId] or UserId = [Parameters:TestKey:Subkey||27]
            and a token with sub-token for fallback [QueryString:Id||[Module:SubId]]
            some tests [] shouldn't capture and [ ] shouldn't capture either, + [MyName] shouldn't either nor should [ something

            and a [bad token without property] and a [Source::SubkeyWithoutKey]
            but this should [token:key] again
            Now try a token which returns a token: [AppSettings:UserNameMaybeFromUrl||Johny]";

            // Even without recurrence it should process the fallback-token at least once
            var expectedNoRecurrance =
                @"Select * From Users Where UserId = Daniel or UserId = -1 or UserId = 27
            and a token with sub-token for fallback 4567
            some tests [] shouldn't capture and [ ] shouldn't capture either, + [MyName] shouldn't either nor should [ something

            and a [bad token without property] and a [Source::SubkeyWithoutKey]
            but this should What a Token! again
            Now try a token which returns a token: [QueryString:UserName||Samantha]";

            var expectedRecurrance =
                @"Select * From Users Where UserId = Daniel or UserId = -1 or UserId = 27
            and a token with sub-token for fallback 4567
            some tests [] shouldn't capture and [ ] shouldn't capture either, + [MyName] shouldn't either nor should [ something

            and a [bad token without property] and a [Source::SubkeyWithoutKey]
            but this should What a Token! again
            Now try a token which returns a token: Daniel";

            var qs = new StaticValueProvider("QueryString");
            qs.Properties.Add("UserName", "Daniel");
            //qs.Properties.Add("Id", "7");
            var mod = new StaticValueProvider("Module");
            mod.Properties.Add("SubId", "4567");
            var appS = new StaticValueProvider("AppSettings");
            appS.Properties.Add("DefaultUserName", "Name Unknown");
            appS.Properties.Add("RootUserId", "-1");
            appS.Properties.Add("UserNameMaybeFromUrl", "[QueryString:UserName||Samantha]");
            var tok = new StaticValueProvider("token");
            tok.Properties.Add("key", "What a Token!");
            var sources = new Dictionary<string, IValueProvider>();
            sources.Add(qs.Name.ToLower(),qs);
            sources.Add(mod.Name.ToLower(), mod);
            sources.Add(appS.Name.ToLower(), appS);
            sources.Add(tok.Name.ToLower(), tok);

            TokenReplace tr = new TokenReplace(sources);
            var resultNoRecurrance = tr.ReplaceTokens(original);
            Assert.AreEqual(expectedNoRecurrance, resultNoRecurrance, "No Recurrance");
            var resultRecurrance = tr.ReplaceTokens(original, 2);
            Assert.AreEqual(expectedRecurrance, resultRecurrance, "With 2x looping");
        }
コード例 #4
0
ファイル: SexyContent.cs プロジェクト: BravoSierra/2sxc
        public ValueCollectionProvider GetConfigurationProvider(int moduleId)
        {
            if (_valueCollectionProvider == null)
            {
                var provider = new ValueCollectionProvider();

                // only add these in running inside an http-context. Otherwise leave them away!
                if (HttpContext.Current != null)
                {
                    var request = HttpContext.Current.Request;
                    provider.Sources.Add("querystring", new FilteredNameValueCollectionPropertyAccess("querystring", request.QueryString));
                    provider.Sources.Add("server", new FilteredNameValueCollectionPropertyAccess("server", request.ServerVariables));
                    provider.Sources.Add("form", new FilteredNameValueCollectionPropertyAccess("form", request.Form));
                }

                // Add the standard DNN property sources if PortalSettings object is available
                if (PS != null)
            {
                    var dnnUsr = PS.UserInfo;
                    var dnnCult = Thread.CurrentThread.CurrentCulture;
                    var dnn = new TokenReplaceDnn(App, moduleId, PS, dnnUsr);
                    var stdSources = dnn.PropertySources;
                    foreach (var propertyAccess in stdSources)
                        provider.Sources.Add(propertyAccess.Key,
                            new ValueProviderWrapperForPropertyAccess(propertyAccess.Key, propertyAccess.Value, dnnUsr, dnnCult));
                }

            provider.Sources.Add("app", new AppPropertyAccess("app", App));

                // add module if it was not already added previously
                if (!provider.Sources.ContainsKey("module"))
                {
                    var modulePropertyAccess = new StaticValueProvider("module");
            modulePropertyAccess.Properties.Add("ModuleID", moduleId.ToString(CultureInfo.InvariantCulture));
            provider.Sources.Add(modulePropertyAccess.Name, modulePropertyAccess);
                }
                _valueCollectionProvider = provider;
            }
            return _valueCollectionProvider;
        }