当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.Localization类代码示例

本文整理汇总了C#中Sdl.Web.Common.Configuration.Localization的典型用法代码示例。如果您正苦于以下问题:C# Localization类的具体用法?C# Localization怎么用?C# Localization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Localization类属于Sdl.Web.Common.Configuration命名空间,在下文中一共展示了Localization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetContextNavigationLinks

        /// <summary>
        /// Gets Navigation Links for the context navigation panel for the given request URL path.
        /// </summary>
        /// <param name="requestUrlPath">The request URL path.</param>
        /// <param name="localization">The Localization.</param>
        /// <returns>The Navigation Links.</returns>
        public virtual NavigationLinks GetContextNavigationLinks(string requestUrlPath, Localization localization)
        {
            using (new Tracer(requestUrlPath, localization))
            {
                // Find the context Sitemap Item; start with Sitemap root.
                SitemapItem contextSitemapItem = GetNavigationModel(localization);
                if (requestUrlPath.Contains("/"))
                {
                    while (contextSitemapItem.Items != null)
                    {
                        SitemapItem matchingChildSg = contextSitemapItem.Items.FirstOrDefault(i => i.Type == SitemapItem.Types.StructureGroup && requestUrlPath.StartsWith(i.Url, StringComparison.InvariantCultureIgnoreCase));
                        if (matchingChildSg == null)
                        {
                            // No matching child SG found => current contextSitemapItem reflects the context SG.
                            break;
                        }
                        contextSitemapItem = matchingChildSg;
                    }
                }

                if (contextSitemapItem.Items == null)
                {
                    throw new DxaException(string.Format("Context SitemapItem has no child items: {0}", contextSitemapItem));
                }

                return new NavigationLinks
                {
                    Items = contextSitemapItem.Items.Where(i => i.Visible).Select(i => i.CreateLink(localization)).ToList()
                };
            }
        }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:37,代码来源:StaticNavigationProvider.cs

示例2: GetContextClaims

        /// <summary>
        /// Gets the context claims. Either all context claims or for a given aspect name.
        /// </summary>
        /// <param name="aspectName">The aspect name. If <c>null</c> all context claims are returned.</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>A dictionary with the claim names in format aspectName.propertyName as keys.</returns>
        public IDictionary<string, object> GetContextClaims(string aspectName, Localization localization)
        {
            using (new Tracer(aspectName))
            {
                string claimNamePrefix = ContextClaimPrefix;
                if (!string.IsNullOrEmpty(aspectName))
                {
                    claimNamePrefix += aspectName + ":";
                }

                IDictionary<string, object> result = new Dictionary<string, object>();
                foreach (KeyValuePair<Uri, object> claim in AmbientDataContext.CurrentClaimStore.GetAll())
                {
                    string claimName = claim.Key.ToString();
                    if (!claimName.StartsWith(claimNamePrefix))
                    {
                        continue;
                    }
                    string propertyName = claimName.Substring(ContextClaimPrefix.Length).Replace(':', '.');
                    result.Add(propertyName, claim.Value);
                }

                return result;
            }
        }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:31,代码来源:AdfContextClaimsProvider.cs

示例3: SetupParameters

 protected override NameValueCollection SetupParameters(SearchQuery searchQuery, Localization localization)
 {
     NameValueCollection parameters = base.SetupParameters(searchQuery, localization);
     // We use the highlighting feature to autogenerate a Summary if no Summary is present in the search index.
     parameters["hl"] = "true";
     return parameters;
 }
开发者ID:RAJMITTAL,项目名称:dxa-modules,代码行数:7,代码来源:SolrProvider.cs

示例4: BuildEntityModel

        public void BuildEntityModel(ref EntityModel entityModel, IComponentPresentation cp, Localization localization)
        {
            using (new Tracer(entityModel, cp, localization))
            {
                IFieldSet contextExpressionsFieldSet;
                if (cp.ExtensionData == null || !cp.ExtensionData.TryGetValue(Constants.ContextExpressionsKey, out contextExpressionsFieldSet))
                {
                    // No Context Expressions found; nothing to do.
                    return;
                }

                ContextExpressionConditions conditions = new ContextExpressionConditions();
                IField includeField;
                if (contextExpressionsFieldSet.TryGetValue("Include", out includeField))
                {
                    conditions.Include = includeField.Values.ToArray();
                }
                IField excludeField;
                if (contextExpressionsFieldSet.TryGetValue("Exclude", out excludeField))
                {
                    conditions.Exclude = excludeField.Values.ToArray();
                }

                entityModel.SetExtensionData(Constants.ContextExpressionsKey, conditions);
            }
        }
开发者ID:sdl,项目名称:dxa-modules,代码行数:26,代码来源:ContextExpressionModelBuilder.cs

示例5: GetXpmMarkup

        /// <summary>
        /// Gets the rendered XPM markup
        /// </summary>
        /// <param name="localization">The context Localization.</param>
        /// <returns>The XPM markup.</returns>
        public override string GetXpmMarkup(Localization localization)
        {
            if (XpmMetadata == null)
            {
                return string.Empty;
            }

            string cmsUrl;
            object cmsUrlValue;
            if (XpmMetadata.TryGetValue("CmsUrl", out cmsUrlValue))
            {
                cmsUrl = (string) cmsUrlValue;
            }
            else
            {
                cmsUrl = localization.GetConfigValue("core.cmsurl");
            }
            if (cmsUrl.EndsWith("/"))
            {
                // remove trailing slash from cmsUrl if present
                cmsUrl = cmsUrl.Remove(cmsUrl.Length - 1);
            }

            return string.Format(
                _xpmPageSettingsMarkup,
                XpmMetadata["PageID"],
                XpmMetadata["PageModified"],
                XpmMetadata["PageTemplateID"],
                XpmMetadata["PageTemplateModified"]
                ) + 
                string.Format(_xpmPageScript, cmsUrl);
        }
开发者ID:jsuurd,项目名称:dxa-web-application-dotnet,代码行数:37,代码来源:PageModel.cs

示例6: ResolveLink

        /// <summary>
        /// Resolves a link URI (TCM URI or site URL) to a normalized site URL.
        /// </summary>
        /// <param name="sourceUri">The source URI (TCM URI or site URL)</param>
        /// <param name="resolveToBinary">Specifies whether a link to a Multimedia Component should be resolved directly to its Binary (<c>true</c>) or as a regular Component link.</param>
        /// <param name="localization">The context Localization (optional, since the TCM URI already contains a Publication ID, but this allows resolving in a different context).</param>
        /// <returns>The resolved URL.</returns>
        public string ResolveLink(string sourceUri, bool resolveToBinary = false, Localization localization = null)
        {
            if (sourceUri == null)
            {
                return null;
            }

            string url;
            if (sourceUri.StartsWith("tcm:"))
            {
                TcmUri tcmUri = new TcmUri(sourceUri);
                url = ResolveLink(tcmUri, resolveToBinary, localization);
            }
            else
            {
                url = sourceUri;
            }

            // Strip off default extension / page name
            if (url != null && url.EndsWith(Constants.DefaultExtension))
            {
                url = url.Substring(0, url.Length - Constants.DefaultExtension.Length);
                if (url.EndsWith("/" + Constants.DefaultExtensionLessPageName))
                {
                    url = url.Substring(0, url.Length - Constants.DefaultExtensionLessPageName.Length);
                }
            }
            return url;
        }
开发者ID:trivident,项目名称:dxa-web-application-dotnet,代码行数:36,代码来源:DefaultLinkResolver.cs

示例7: CdConfigLocalizationResolver

        /// <summary>
        /// Initializes a new <see cref="CdConfigLocalizationResolver"/> instance.
        /// </summary>
        public CdConfigLocalizationResolver()
        {
            using (new Tracer())
            {
                string cdDynamicConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\config\cd_dynamic_conf.xml");
                XDocument cdDynamicConfigDoc = XDocument.Load(cdDynamicConfigPath);

                // sorting Publications by Path in decending order so default Path ("/" or "") is last in list
                // using Path of first Host element found in a Publication, assuming the Paths of all of these Host elements will be equal
                XElement publicationsElement = cdDynamicConfigDoc.Descendants("Publications").First();
                IOrderedEnumerable<XElement> publicationElements = publicationsElement.Elements("Publication").OrderByDescending(e => e.Element("Host").Attribute("Path").Value);
                foreach (XElement publicationElement in publicationElements)
                {
                    string publicationId = publicationElement.Attribute("Id").Value;

                    // there could be multiple Host elements per Publication, add them all
                    foreach (XElement hostElement in publicationElement.Elements("Host"))
                    {
                        Uri baseUrl = GetBaseUrl(hostElement);
                        Localization localization;
                        if (!_knownLocalizations.TryGetValue(publicationId, out localization))
                        {
                            localization = new Localization
                            {
                                LocalizationId = publicationId,
                                Path = hostElement.Attribute("Path").Value
                            };
                            _knownLocalizations.Add(publicationId, localization);
                        }
                        _urlToLocalizationMapping.Add(new KeyValuePair<Uri, Localization>(baseUrl, localization));
                    }
                }
            }
        }
开发者ID:tgfl-tom,项目名称:dxa-web-application-dotnet,代码行数:37,代码来源:CdConfigLocalizationResolver.cs

示例8: TestFixture

        static TestFixture()
        {
            // TODO: Retrieve Localization Info from CM (?)

            _parentLocalization = new Localization
            {
                LocalizationId = "1065",
                Path = "/autotest-parent"
            };

            _childLocalization = new Localization
            {
                LocalizationId = "1066",
                Path = "/autotest-child"
            };

            _testLocalizations = new[] { _parentLocalization, _childLocalization };

            ArticleDcpEntityId = "9712-9711";
            ArticlePageUrlPath = "/autotest-parent/test_article_page.html";
            Tsi1278PageUrlPath = "/autotest-parent/tsi-1278_trådløst.html";
            Tsi1278StaticContentItemUrlPath = "/autotest-parent/Images/trådløst_tcm1065-9791.jpg";

            TestRegistration.RegisterCoreViewModels();
        }
开发者ID:trivident,项目名称:dxa-web-application-dotnet,代码行数:25,代码来源:TestFixture.cs

示例9: IncludeEntity

        /// <summary>
        /// Determines whether a given Entity Model should be included based on the conditions specified on the Entity Model and the context.
        /// </summary>
        /// <param name="entity">The Entity Model to be evaluated.</param>
        /// <param name="localization">The context Localization</param>
        /// <returns><c>true</c> if the Entity should be included.</returns>
        public bool IncludeEntity(EntityModel entity, Localization localization)
        {
            using (new Tracer(entity))
            {
                object ceExtensionData;
                if (entity.ExtensionData == null || !entity.ExtensionData.TryGetValue(Constants.ContextExpressionsKey, out ceExtensionData))
                {
                    // No Context Expressions defined for Entity: just include it.
                    return true;
                }
                ContextExpressionConditions ceConditions = (ContextExpressionConditions) ceExtensionData;

                IDictionary<string, object> contextClaims = GetCachedContextClaims(localization);

                if (!EvaluateContextExpressionClaims(ceConditions.Include, true, contextClaims))
                {
                    Log.Debug("Include Context Expression conditions are not satisfied; suppressing Entity [{0}].", entity);
                    return false;
                }
                if (!EvaluateContextExpressionClaims(ceConditions.Exclude, false, contextClaims))
                {
                    Log.Debug("Exclude Context Expression conditions are not satisfied; suppressing Entity [{0}].", entity);
                    return false;
                }

                Log.Debug("All resolved Context Expression conditions are satisfied; keeping Entity [{0}].", entity);
                return true;
            }
        }
开发者ID:sdl,项目名称:dxa-modules,代码行数:35,代码来源:ContextExpressionEvaluator.cs

示例10: ApplyHashIfApplicable

        private static void ApplyHashIfApplicable(XmlElement linkElement, Localization localization)
        {
            string target = linkElement.GetAttribute("target").ToLower();
            if (target != "anchored")
            {
                return;
            }

            string href = linkElement.GetAttribute("href");

            bool samePage = string.Equals(href,
                    HttpContext.Current.Request.Url.AbsolutePath, // TODO: should not be using HttpContext at this level
                    StringComparison.OrdinalIgnoreCase
                    );

            string linkTitle = GetLinkTitle(linkElement, localization);

            string fragmentId = string.Empty;
            if (!string.IsNullOrEmpty(linkTitle))
            {
                fragmentId = '#' + linkTitle.Replace(" ", "_").ToLower();
            }

            linkElement.SetAttribute("href", (!samePage ? href : string.Empty) + fragmentId);
            linkElement.SetAttribute("target", !samePage ? "_top" : string.Empty);
        }
开发者ID:ginortoro,项目名称:dxa-web-application-dotnet,代码行数:26,代码来源:DefaultRichTextProcessor.cs

示例11: GetBreadcrumbNavigationLinks

        /// <summary>
        /// Gets Navigation Links for the breadcrumb trail for the given request URL path.
        /// </summary>
        /// <param name="requestUrlPath">The request URL path.</param>
        /// <param name="localization">The Localization.</param>
        /// <returns>The Navigation Links.</returns>
        public virtual NavigationLinks GetBreadcrumbNavigationLinks(string requestUrlPath, Localization localization)
        {
            using (new Tracer(requestUrlPath, localization))
            {

                int levels = requestUrlPath.Split('/').Length;

                SitemapItem currentItem = GetNavigationModel(localization); // Start with Sitemap root.
                List<Link> links = new List<Link> { currentItem.CreateLink(localization) };
                while (levels > 1 && currentItem.Items != null)
                {
                    currentItem = currentItem.Items.FirstOrDefault(i => requestUrlPath.StartsWith(i.Url, StringComparison.InvariantCultureIgnoreCase));
                    if (currentItem == null)
                    {
                        break;
                    }
                    links.Add(currentItem.CreateLink(localization));
                    levels--;
                }

                return new NavigationLinks
                {
                    Items = links
                };
            }
        }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:32,代码来源:StaticNavigationProvider.cs

示例12: ResolveLocalization

        /// <summary>
        /// Resolves a matching <see cref="Localization"/> for a given URL.
        /// </summary>
        /// <param name="url">The URL to resolve.</param>
        /// <returns>A <see cref="Localization"/> instance which base URL matches that of the given URL.</returns>
        /// <exception cref="DxaUnknownLocalizationException">If no matching Localization can be found.</exception>
        public override Localization ResolveLocalization(Uri url)
        {
            using (new Tracer(url))
            {
                string urlLeftPart = url.GetLeftPart(UriPartial.Path);

                // TODO PERF: to optimize caching, we could only take the first part of the URL path (e.g. one or two levels)
                int espaceIndex = urlLeftPart.IndexOf("%");
                if (espaceIndex > 0)
                {
                    // TODO: This is a work-around for a bug in SDL Web 8 Publication Mapping: URLs with escaped characters don't resolve properly (CRQ-1585).
                    // Therefore we truncate the URL at the first escaped character for now (assuming that the URL is still specific enough to resolve the right Publication).
                    urlLeftPart = urlLeftPart.Substring(0, espaceIndex);
                }

                IPublicationMapping mapping = null;
                try
                {
                    // NOTE: we're not using UrlToLocalizationMapping here, because we may match too eagerly on a base URL when there is a matching mapping with a more specific URL.
                    mapping = _mappingsRetriever.GetPublicationMapping(urlLeftPart);
                }
                catch (Exception ex)
                {
                    // CIL throws Sdl.Web.Delivery.Service.InvalidResourceException if the mapping cannot be resolved.
                    // We don't have a direct reference to Sdl.Web.Delivery.Service, so we just check the type name
                    if (ex.GetType().FullName != "Sdl.Web.Delivery.Service.InvalidResourceException")
                    {
                        throw;
                    }
                    Log.Debug("Exception occurred in DynamicMappingsRetriever.GetPublicationMapping('{0}'):\n{1}", urlLeftPart, ex.ToString());
                    // Let mapping be null, we'll handle it below.
                }
                if (mapping == null || mapping.Port != url.Port.ToString()) // See CRQ-1195
                {
                    throw new DxaUnknownLocalizationException(string.Format("No matching Localization found for URL '{0}'", urlLeftPart));
                }

                Localization result;
                lock (KnownLocalizations)
                {
                    string localizationId = mapping.PublicationId.ToString();
                    if (!KnownLocalizations.TryGetValue(localizationId, out result))
                    {
                        result = new Localization
                        {
                            LocalizationId = localizationId,
                            Path = mapping.Path
                        };
                        KnownLocalizations.Add(localizationId, result);
                    }
                }

                result.EnsureInitialized();
                return result;
            }
        }
开发者ID:jsuurd,项目名称:dxa-web-application-dotnet,代码行数:62,代码来源:CdApiLocalizationResolver.cs

示例13: ExtractSyndicationFeedItems

 /// <summary>
 /// Extracts syndication feed items.
 /// </summary>
 /// <param name="localization">The context <see cref="Localization"/>.</param>
 /// <returns>A single syndication feed item containing information extracted from this <see cref="Teaser"/>.</returns>
 public IEnumerable<SyndicationItem> ExtractSyndicationFeedItems(Localization localization)
 {
     Link link = Link;
     if (link == null && Media != null)
     {
         // If the Teaser doesn't have a Link, but does have Media, create a Link from its Media.
         link = new Link { Url = Media.Url };
     }
     return new[] { CreateSyndicationItem(Headline, Text, link, Date, localization) };
 }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:15,代码来源:Teaser.cs

示例14: SchemaSemantics

        /// <summary>
        /// Initializes a new instance of the <see cref="SchemaSemantics"/> class.
        /// </summary>
        /// <param name="prefix">Vocabulary prefix</param>
        /// <param name="entity">Entity name</param>
        /// <param name="localization">The context Localization (used to determine <see cref="Vocab"/>).</param>
        public SchemaSemantics(string prefix, string entity, Localization localization)
        {
            Prefix = prefix;
            Entity = entity;

            if (localization != null)
            {
                Initialize(localization);
            }
        }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:16,代码来源:SchemaSemantics.cs

示例15: GetPrefix

 /// <summary>
 /// Gets prefix for semantic vocabulary.
 /// </summary>
 /// <param name="vocab">Vocabulary name</param>
 /// <param name="loc">The localization</param>
 /// <returns>Prefix for this semantic vocabulary</returns>
 public static string GetPrefix(string vocab, Localization loc)
 {
     SemanticVocabulary semanticVocabulary = loc.GetSemanticVocabularies().FirstOrDefault(sv => sv.Vocab == vocab);
     if (semanticVocabulary == null)
     {
         throw new DxaException(
             string.Format("No vocabulary defined for '{0}' in Localization [{1}]. {2}", vocab, loc, Constants.CheckSettingsUpToDate)
             );
     }
     return semanticVocabulary.Prefix;
 }
开发者ID:sdl,项目名称:dxa-web-application-dotnet,代码行数:17,代码来源:SemanticMapping.cs


注:本文中的Sdl.Web.Common.Configuration.Localization类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。