Esempio n. 1
0
        public void Add(NavigationInfo navigation)
        {
            var hb = GetHyperlinkButtonFor(navigation);

            if (hb == null)
            {
                hb = navigation.AsHyperlinkButton();
                //first check if there is a mapped Uri for this navigation uri
                var    uri     = (this.ContentFrame.UriMapper as UriMapper).UriMappings.FirstOrDefault(x => x.Uri.OriginalString.Equals(navigation.NavigationUri));
                string pattern = navigation.NavigationUri;
                if (uri != null)
                {
                    pattern = uri.MappedUri.ToString();
                }
                NavigationAuthRule authRule = new NavigationAuthRule()
                {
                    UriPattern = string.Concat("^", pattern, "$")
                };
                if (navigation.Deny.Count > 0)
                {
                    authRule.Parts.Add(new Deny()
                    {
                        Users = navigation.GetDeniedRolesAsString()
                    });
                }
                if (navigation.Allow.Count > 0)
                {
                    authRule.Parts.Add(new Allow()
                    {
                        Users = navigation.GetAllowedRolesAsString()
                    });
                }
                NavigationAuthorizer _authorizer = GetAuthorizer();
                _authorizer.Rules.Add(authRule);
                LinksStackPanel.Children.Add(GetDivider());
                LinksStackPanel.Children.Add(hb);
            }
            else
            {
                throw new System.ArgumentException("Link already exists for NavigationInfo", "navigation");
            }
        }