Beispiel #1
0
        private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire)
        {
            var entry   = new CacheEntry();
            var context = new AcquireContext <TKey>(k, entry.AddToken);

            IAcquireContext parentContext = null;

            try
            {
                // Push context
                parentContext = _cacheContextAccessor.Current;
                _cacheContextAccessor.Current = context;

                entry.Result = acquire(context);
            }
            finally
            {
                // Pop context
                _cacheContextAccessor.Current = parentContext;
            }
            entry.CompactTokens();
            return(entry);
        }
Beispiel #2
0
        private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire)
        {
            var entry   = new CacheEntry();
            var context = new AcquireContext <TKey>(k, entry.AddToken);

            IAcquireContext parentContext = null;

            try
            {
                // Push context
                parentContext = _cacheContextAccessor.Current;
                _cacheContextAccessor.Current = context;
                entry.Result = acquire(context);
                //创建缓存
                var flag = _client.ExecuteStore(StoreMode.Set, k.ToString(), entry);
            }
            finally
            {
                // Pop context
                _cacheContextAccessor.Current = parentContext;
            }
            entry.CompactTokens();
            return(entry);
        }
        // Merging occurs from multiple locations:
        // In reverse priority order: 
        // "~/Core/App_Data/Localization/<culture_name>/orchard.core.po";
        // "~/Modules/<module_name>/App_Data/Localization/<culture_name>/orchard.module.po";
        // "~/Themes/<theme_name>/App_Data/Localization/<culture_name>/orchard.theme.po";
        // "~/App_Data/Localization/<culture_name>/orchard.root.po";
        // "~/App_Data/Sites/<tenant_name>/Localization/<culture_name>/orchard.po";
        // The dictionary entries from po files that live in higher priority locations will
        // override the ones from lower priority locations during loading of dictionaries.

        // TODO: Add culture name in the po file name to facilitate usage.
        private IDictionary<string, string> LoadTranslationsForCulture(string culture, AcquireContext<string> context) {
            IDictionary<string, string> translations = new Dictionary<string, string>();
            string corePath = string.Format(CoreLocalizationFilePathFormat, culture);
            string text = _webSiteFolder.ReadFile(corePath);
            if (text != null) {
                ParseLocalizationStream(text, translations, false);
                context.Monitor(_webSiteFolder.WhenPathChanges(corePath));
            }

            foreach (var module in _extensionManager.AvailableExtensions()) {
                if (DefaultExtensionTypes.IsModule(module.ExtensionType)) {
                    string modulePath = string.Format(ModulesLocalizationFilePathFormat, module.Id, culture);
                    text = _webSiteFolder.ReadFile(modulePath);
                    if (text != null) {
                        ParseLocalizationStream(text, translations, true);
                        context.Monitor(_webSiteFolder.WhenPathChanges(modulePath));
                    }
                }
            }

            foreach (var theme in _extensionManager.AvailableExtensions()) {
                if (DefaultExtensionTypes.IsTheme(theme.ExtensionType)) {
                    string themePath = string.Format(ThemesLocalizationFilePathFormat, theme.Id, culture);
                    text = _webSiteFolder.ReadFile(themePath);
                    if (text != null) {
                        ParseLocalizationStream(text, translations, true);
                        context.Monitor(_webSiteFolder.WhenPathChanges(themePath));
                    }
                }
            }

            string rootPath = string.Format(RootLocalizationFilePathFormat, culture);
            text = _webSiteFolder.ReadFile(rootPath);
            if (text != null) {
                ParseLocalizationStream(text, translations, true);
                context.Monitor(_webSiteFolder.WhenPathChanges(rootPath));
            }

            string tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture);
            text = _webSiteFolder.ReadFile(tenantPath);
            if (text != null) {
                ParseLocalizationStream(text, translations, true);
                context.Monitor(_webSiteFolder.WhenPathChanges(tenantPath));
            }

            return translations;
        }
 private void MonitorContentDefinitionSignal(AcquireContext <string> ctx)
 {
     ctx.Monitor(_signals.When(ContentDefinitionSignal));
 }
 private void MonitorContentDefinitionSignal(AcquireContext<string> ctx) {
     ctx.Monitor(_signals.When(ContentDefinitionSignal));
 }
Beispiel #6
0
 private void MonitorSignal(AcquireContext <string> ctx)
 {
     ctx.Monitor(_signals.When(SignalName));
 }
        private XDocument BuildSitemapDocument(AcquireContext<string> ctx)
        {
            ctx.Monitor(_clock.When(TimeSpan.FromHours(1.0)));
            ctx.Monitor(_signals.When("WebAdvanced.Sitemap.XmlRefresh"));

            XNamespace xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";

            var providerContext = new DescribeSpecializedSitemapProviderContext();
            foreach (var specializedSitemapProvider in _specializedSitemapProviders) {
                specializedSitemapProvider.Describe(providerContext);
            }

            var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            var urlset = new XElement(xmlns + "urlset");

            foreach (var specializedSitemapFor in providerContext.Describes.Values) {
                urlset.Add(new XAttribute(XNamespace.Xmlns + specializedSitemapFor.NamespacePrefix, specializedSitemapFor.XNamespace));
            }

            document.Add(urlset);

            var rootUrl = GetRootPath();

            // Add filtered routes
            var routeUrls = new HashSet<string>(); // Don't include the same url twice
            var items = new List<SitemapRoute>();

            // Process routes from providers in order of high to low priority to allow custom routes
            // to be processed first and thus override content routes.
            foreach (var provider in _routeProviders.OrderByDescending(p => p.Priority)) {
                var validRoutes = provider.GetXmlRoutes().Where(r => _routeFilters.All(filter => filter.AllowUrl(r.Url))).AsEnumerable();

                foreach (var item in validRoutes) {
                    if (routeUrls.Contains(item.Url)) {
                        continue;
                    }

                    routeUrls.Add(item.Url);
                    items.Add(item);
                }
            }

            // Ensure routes with higher priority are listed first
            foreach (var item in items.OrderByDescending(i => i.Priority).ThenBy(i => i.Url)) {
                string url = item.Url;
                if (!Regex.IsMatch(item.Url, @"^\w+://.*$")) {
                    url = rootUrl + item.Url.TrimStart('/');
                }

                var element = new XElement(xmlns + "url");
                element.Add(new XElement(xmlns + "loc", url));
                element.Add(new XElement(xmlns + "changefreq", item.UpdateFrequency));
                if (item.LastUpdated.HasValue) {
                    element.Add(new XElement(xmlns + "lastmod", item.LastUpdated.Value.ToString("yyyy-MM-dd")));
                }
                var priority = (item.Priority - 1)/4.0;
                if (priority >= 0.0 && priority <= 1.0) {
                    element.Add(new XElement(xmlns + "priority", (item.Priority - 1)/4.0));
                }

                foreach (var specializedSitemapFor in providerContext.Describes.Values) {
                    var xElement = specializedSitemapFor.Process(item.ContentItem, item.Url);
                    if (xElement != null) {
                        element.Add(xElement);
                    }
                }

                urlset.Add(element);
            }

            return document;
        }
        // 从多个地点进行合并:
        // "~/Modules/<module_name>/App_Data/Localization/<culture_name>/rabbit.module.po";
        // "~/App_Data/Localization/<culture_name>/rabbit.root.po";
        // "~/App_Data/Tenants/<tenant_name>/Localization/<culture_name>/rabbit.po";
        private IDictionary <string, string> LoadTranslationsForCulture(string culture, AcquireContext <string> context)
        {
            IDictionary <string, string> translations = new Dictionary <string, string>();
            string text;

            foreach (var module in _extensionManager.AvailableExtensions())
            {
                if (module.ExtensionType != "Module")
                {
                    continue;
                }

                var modulePath = string.Format(ModulesLocalizationFilePathFormat, module.Id, culture);
                text = ReadFile(modulePath);

                if (text == null)
                {
                    continue;
                }

                ParseLocalizationStream(text, translations, true);

                if (DisableMonitoring)
                {
                    continue;
                }

                Logger.Debug("监控虚拟路径 \"{0}\"", modulePath);
                context.Monitor(_virtualPathMonitor.WhenPathChanges(modulePath));
            }

            var rootPath = string.Format(RootLocalizationFilePathFormat, culture);

            text = ReadFile(rootPath);
            if (text != null)
            {
                ParseLocalizationStream(text, translations, true);
                if (!DisableMonitoring)
                {
                    Logger.Debug("监控虚拟路径 \"{0}\"", rootPath);
                    context.Monitor(_virtualPathMonitor.WhenPathChanges(rootPath));
                }
            }

            var tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture);

            text = ReadFile(tenantPath);

            if (text == null)
            {
                return(translations);
            }

            ParseLocalizationStream(text, translations, true);

            if (DisableMonitoring)
            {
                return(translations);
            }

            Logger.Debug("监控虚拟路径 \"{0}\"", tenantPath);
            context.Monitor(_virtualPathMonitor.WhenPathChanges(tenantPath));

            return(translations);
        }
        // 从多个地点进行合并:
        // "~/Modules/<module_name>/App_Data/Localization/<culture_name>/rabbit.module.po";
        // "~/App_Data/Localization/<culture_name>/rabbit.root.po";
        // "~/App_Data/Tenants/<tenant_name>/Localization/<culture_name>/rabbit.po";
        private IDictionary<string, string> LoadTranslationsForCulture(string culture, AcquireContext<string> context)
        {
            IDictionary<string, string> translations = new Dictionary<string, string>();
            string text;
            foreach (var module in _extensionManager.AvailableExtensions())
            {
                if (module.ExtensionType != "Module")
                    continue;

                var modulePath = string.Format(ModulesLocalizationFilePathFormat, module.Id, culture);
                text = ReadFile(modulePath);

                if (text == null)
                    continue;

                ParseLocalizationStream(text, translations, true);

                if (DisableMonitoring)
                    continue;

                Logger.Debug("监控虚拟路径 \"{0}\"", modulePath);
                context.Monitor(_virtualPathMonitor.WhenPathChanges(modulePath));
            }

            var rootPath = string.Format(RootLocalizationFilePathFormat, culture);
            text = ReadFile(rootPath);
            if (text != null)
            {
                ParseLocalizationStream(text, translations, true);
                if (!DisableMonitoring)
                {
                    Logger.Debug("监控虚拟路径 \"{0}\"", rootPath);
                    context.Monitor(_virtualPathMonitor.WhenPathChanges(rootPath));
                }
            }

            var tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture);
            text = ReadFile(tenantPath);

            if (text == null)
                return translations;

            ParseLocalizationStream(text, translations, true);

            if (DisableMonitoring)
                return translations;

            Logger.Debug("监控虚拟路径 \"{0}\"", tenantPath);
            context.Monitor(_virtualPathMonitor.WhenPathChanges(tenantPath));

            return translations;
        }
 public void MonitorCacheChangedSignal(AcquireContext<string> ctx, int hashCode)
 {
     // Immediately invalidated the cache
     ctx.Monitor(_signals.When("CombinatorSignal"));
     _signals.Trigger("CombinatorSignal");
 }
Beispiel #11
0
        private XDocument BuildSitemapDocument(AcquireContext <string> ctx)
        {
            ctx.Monitor(_clock.When(TimeSpan.FromHours(1.0)));
            ctx.Monitor(_signals.When("WebAdvanced.Sitemap.XmlRefresh"));

            XNamespace xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";

            var providerContext = new DescribeSpecializedSitemapProviderContext();

            foreach (var specializedSitemapProvider in _specializedSitemapProviders)
            {
                specializedSitemapProvider.Describe(providerContext);
            }

            var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            var urlset   = new XElement(xmlns + "urlset");

            foreach (var specializedSitemapFor in providerContext.Describes.Values)
            {
                urlset.Add(new XAttribute(XNamespace.Xmlns + specializedSitemapFor.NamespacePrefix, specializedSitemapFor.XNamespace));
            }

            document.Add(urlset);

            var rootUrl = GetRootPath();

            // Add filtered routes
            var routeUrls = new HashSet <string>(); // Don't include the same url twice
            var items     = new List <SitemapRoute>();

            // Process routes from providers in order of high to low priority to allow custom routes
            // to be processed first and thus override content routes.
            foreach (var provider in _routeProviders.OrderByDescending(p => p.Priority))
            {
                var validRoutes = provider.GetXmlRoutes().Where(r => _routeFilters.All(filter => filter.AllowUrl(r.Url))).AsEnumerable();

                foreach (var item in validRoutes)
                {
                    if (routeUrls.Contains(item.Url))
                    {
                        continue;
                    }

                    routeUrls.Add(item.Url);
                    items.Add(item);
                }
            }

            // Ensure routes with higher priority are listed first
            foreach (var item in items.OrderByDescending(i => i.Priority).ThenBy(i => i.Url))
            {
                string url = item.Url;
                if (!Regex.IsMatch(item.Url, @"^\w+://.*$"))
                {
                    url = rootUrl + item.Url.TrimStart('/');
                }

                var element = new XElement(xmlns + "url");
                element.Add(new XElement(xmlns + "loc", url));
                element.Add(new XElement(xmlns + "changefreq", item.UpdateFrequency));
                if (item.LastUpdated.HasValue)
                {
                    element.Add(new XElement(xmlns + "lastmod", item.LastUpdated.Value.ToString("yyyy-MM-dd")));
                }
                var priority = (item.Priority - 1) / 4.0;
                if (priority >= 0.0 && priority <= 1.0)
                {
                    element.Add(new XElement(xmlns + "priority", (item.Priority - 1) / 4.0));
                }

                foreach (var specializedSitemapFor in providerContext.Describes.Values)
                {
                    var xElement = specializedSitemapFor.Process(item.ContentItem, item.Url);
                    if (xElement != null)
                    {
                        element.Add(xElement);
                    }
                }

                urlset.Add(element);
            }

            return(document);
        }
        private IDictionary <string, string> LoadTranslationsForCulture(string culture, AcquireContext <string> context)
        {
            IDictionary <string, string> result = new Dictionary <string, string>();

            var translations = _localizationService.GetTranslations(culture);

            foreach (var t in translations)
            {
                var    scope     = t.Context;
                var    id        = t.Key;
                string scopedKey = (scope + "|" + id).ToLowerInvariant();
                if (!result.ContainsKey(scopedKey))
                {
                    result.Add(scopedKey, t.Translation);
                }
                else
                {
                    result[scopedKey] = t.Translation;
                }
            }

            return(result);
        }
Beispiel #13
0
        IDictionary<int, ILdapDirectory> DirectoriesAcquirer(AcquireContext<object> context)
        {
            context.Monitor(signals.When(context.Key));

            var encryptionService = orchardServices.WorkContext.Resolve<IEncryptionService>();

            var directories = orchardServices.ContentManager.List<LdapDirectoryPart>("LdapDirectory");
            return directories.ToDictionary(
                d => d.Id,
                // returning a detached LdapDirectoryPart object
                d => (ILdapDirectory)new CachedLdapDirectory
                {
                    Id = d.Id,
                    Enabled = d.Enabled,
                    Name = d.Name,
                    Server = d.Server,
                    ServiceAccountPasswordGetter = () => PasswordUtils.DecodePassword(d.Record.ServiceAccountPassword, encryptionService, () => null),
                    ServiceAccountUserName = d.ServiceAccountUserName,
                    BaseDn = d.BaseDn,
                    UserEmailAttribute = d.UserEmailAttribute,
                    UserFilter = d.UserFilter,
                    UserNameAttribute = d.UserNameAttribute,
                    UserObjectClass = d.UserObjectClass,
                    UserPasswordAttribute = d.UserPasswordAttribute,
                    UserMemberOf = d.UserMemberOf,
                    UserObjectCategory = d.UserObjectCategory,
                    UpdatePeriod = d.UpdatePeriod
                });
        }
Beispiel #14
0
 private void MonitorSignal(AcquireContext<string> ctx) {
     ctx.Monitor(_signals.When(SignalName));
 }
        private IDictionary<string, string> LoadTranslationsForCulture(string culture, AcquireContext<string> context)
        {
            IDictionary<string, string> result = new Dictionary<string, string>();

              var translations = _localizationService.GetTranslations(culture);
              foreach (var t in translations)
              {
            var scope = t.Context;
            var id = t.Key;
            string scopedKey = (scope + "|" + id).ToLowerInvariant();
            if (!result.ContainsKey(scopedKey))
            {
              result.Add(scopedKey, t.Translation);
            }
            else
            {
              result[scopedKey] = t.Translation;
            }
              }

              return result;
        }
Beispiel #16
0
        // Merging occurs from multiple locations:
        // In reverse priority order:
        // "~/Core/App_Data/Localization/<culture_name>/orchard.core.po";
        // "~/Modules/<module_name>/App_Data/Localization/<culture_name>/orchard.module.po";
        // "~/Themes/<theme_name>/App_Data/Localization/<culture_name>/orchard.theme.po";
        // "~/App_Data/Localization/<culture_name>/orchard.root.po";
        // "~/App_Data/Sites/<tenant_name>/Localization/<culture_name>/orchard.po";
        // The dictionary entries from po files that live in higher priority locations will
        // override the ones from lower priority locations during loading of dictionaries.

        // TODO: Add culture name in the po file name to facilitate usage.
        private IDictionary <string, string> LoadTranslationsForCulture(string culture, AcquireContext <string> context)
        {
            IDictionary <string, string> translations = new Dictionary <string, string>();
            string corePath = string.Format(CoreLocalizationFilePathFormat, culture);
            string text     = _webSiteFolder.ReadFile(corePath);

            if (text != null)
            {
                _localizationStreamParser.ParseLocalizationStream(text, translations, false);
                if (!DisableMonitoring)
                {
                    Logger.Debug("Monitoring virtual path \"{0}\"", corePath);
                    context.Monitor(_webSiteFolder.WhenPathChanges(corePath));
                }
            }

            foreach (var module in _extensionManager.AvailableExtensions())
            {
                if (DefaultExtensionTypes.IsModule(module.ExtensionType))
                {
                    string modulePath = string.Format(ModulesLocalizationFilePathFormat, module.VirtualPath, culture);
                    text = _webSiteFolder.ReadFile(modulePath);
                    if (text != null)
                    {
                        _localizationStreamParser.ParseLocalizationStream(text, translations, true);

                        if (!DisableMonitoring)
                        {
                            Logger.Debug("Monitoring virtual path \"{0}\"", modulePath);
                            context.Monitor(_webSiteFolder.WhenPathChanges(modulePath));
                        }
                    }
                }
            }

            foreach (var theme in _extensionManager.AvailableExtensions())
            {
                if (DefaultExtensionTypes.IsTheme(theme.ExtensionType))
                {
                    string themePath = string.Format(ThemesLocalizationFilePathFormat, theme.VirtualPath, culture);
                    text = _webSiteFolder.ReadFile(themePath);
                    if (text != null)
                    {
                        _localizationStreamParser.ParseLocalizationStream(text, translations, true);

                        if (!DisableMonitoring)
                        {
                            Logger.Debug("Monitoring virtual path \"{0}\"", themePath);
                            context.Monitor(_webSiteFolder.WhenPathChanges(themePath));
                        }
                    }
                }
            }

            string rootPath = string.Format(RootLocalizationFilePathFormat, culture);

            text = _webSiteFolder.ReadFile(rootPath);
            if (text != null)
            {
                _localizationStreamParser.ParseLocalizationStream(text, translations, true);
                if (!DisableMonitoring)
                {
                    Logger.Debug("Monitoring virtual path \"{0}\"", rootPath);
                    context.Monitor(_webSiteFolder.WhenPathChanges(rootPath));
                }
            }

            string tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture);

            text = _webSiteFolder.ReadFile(tenantPath);
            if (text != null)
            {
                _localizationStreamParser.ParseLocalizationStream(text, translations, true);
                if (!DisableMonitoring)
                {
                    Logger.Debug("Monitoring virtual path \"{0}\"", tenantPath);
                    context.Monitor(_webSiteFolder.WhenPathChanges(tenantPath));
                }
            }

            return(translations);
        }
 public void MonitorCacheChangedSignal(AcquireContext <string> ctx, int hashCode)
 {
     // Immediately invalidated the cache
     ctx.Monitor(_signals.When("CombinatorSignal"));
     _signals.Trigger("CombinatorSignal");
 }