public override void Monitor(ExtensionDescriptor descriptor, Action <IVolatileToken> monitor)
        {
            if (Disabled)
            {
                return;
            }

            // If the assembly exists, monitor it
            string assemblyPath = GetAssemblyPath(descriptor);

            if (assemblyPath != null)
            {
                Logger.Debug("Monitoring virtual path \"{0}\"", assemblyPath);
                monitor(_virtualPathMonitor.WhenPathChanges(assemblyPath));
                return;
            }

            // If the assembly doesn't exist, we monitor the containing "bin" folder, as the assembly
            // may exist later if it is recompiled in Visual Studio for example, and we need to
            // detect that as a change of configuration.
            var assemblyDirectory = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, "bin");

            if (_virtualPathProvider.DirectoryExists(assemblyDirectory))
            {
                Logger.Debug("Monitoring virtual path \"{0}\"", assemblyDirectory);
                monitor(_virtualPathMonitor.WhenPathChanges(assemblyDirectory));
            }
        }
Exemple #2
0
        public void MonitorExtensionsWork(Action <IVolatileToken> monitor)
        {
            Logger.Information("Start monitoring extension files...");
            // Monitor add/remove of any module/theme
            monitor(_virtualPathMonitor.WhenPathChanges("~/Modules"));
            monitor(_virtualPathMonitor.WhenPathChanges("~/Themes"));

            // Give loaders a chance to monitor any additional changes
            var extensions = _extensionManager.AvailableExtensions().Where(d => DefaultExtensionTypes.IsModule(d.ExtensionType) || DefaultExtensionTypes.IsTheme(d.ExtensionType)).ToList();

            foreach (var extension in extensions)
            {
                foreach (var loader in _loaders)
                {
                    loader.Monitor(extension, monitor);
                }
            }
            Logger.Information("Done monitoring extension files...");
        }
        private void MonitorExtensionsWork(Action <IVolatileToken> monitor)
        {
            Logger.Information("开始监控扩展文件...");
            //TODO:这边应该由扩展文件夹来提供需要监控的路径而不是固定的模块和主题
            //监控任何在 模块/主题 中的 添加/删除 动作。
            Logger.Debug("监控虚拟路径 \"{0}\"", "~/Modules");
            monitor(_virtualPathMonitor.WhenPathChanges("~/Modules"));
            Logger.Debug("监控虚拟路径 \"{0}\"", "~/Themes");
            monitor(_virtualPathMonitor.WhenPathChanges("~/Themes"));
            Logger.Debug("监控虚拟路径 \"{0}\"", "~/Templates");
            monitor(_virtualPathMonitor.WhenPathChanges("~/Templates"));

            //使用装载机来监控额外的变化。
            var extensions = _extensionManager.AvailableExtensions().ToList();

            foreach (var extension in extensions)
            {
                foreach (var loader in _loaders)
                {
                    loader.Monitor(extension, monitor);
                }
            }
            Logger.Information("完成扩展文件的监控...");
        }
        public void VirtualPathChangesTest()
        {
            try
            {
                using (var stream = File.Create(fileName))
                {
                    using (var sw = new StreamWriter(stream))
                    {
                        sw.Write(Guid.NewGuid().ToString());
                    }
                }

                var fileToken = _patchMonitor.WhenPathChanges("./");
                File.WriteAllText(fileName, Guid.NewGuid().ToString());
                //Wait for fileWatcher event fire
                Thread.Sleep(10);
                Assert.False(fileToken.IsCurrent);
                // File.SetLastWriteTime(fileName,DateTime.Now);
            }
            finally
            {
                File.Delete(fileName);
            }
        }
Exemple #5
0
        public void MonitorExtensionsWork(Action <IVolatileToken> monitor)
        {
            var locations = _extensionManager.AvailableExtensions().Select(e => e.Location).Distinct(StringComparer.InvariantCultureIgnoreCase);

            Logger.Information("Start monitoring extension files...");
            // Monitor add/remove of any module/theme
            foreach (string location in locations)
            {
                Logger.Debug("Monitoring virtual path \"{0}\"", location);
                monitor(_virtualPathMonitor.WhenPathChanges(location));
            }

            // Give loaders a chance to monitor any additional changes
            var extensions = _extensionManager.AvailableExtensions().Where(d => DefaultExtensionTypes.IsModule(d.ExtensionType) || DefaultExtensionTypes.IsTheme(d.ExtensionType)).ToList();

            foreach (var extension in extensions)
            {
                foreach (var loader in _loaders)
                {
                    loader.Monitor(extension, monitor);
                }
            }
            Logger.Information("Done monitoring extension files...");
        }
        public IVolatileToken WhenPathChanges(string path)
        {
            var virtualPath = GetVirtualPath(path);

            return(_virtualPathMonitor.WhenPathChanges(virtualPath));
        }
 public IVolatileToken WhenPathChanges(string virtualPath)
 {
     return(_virtualPathMonitor.WhenPathChanges(virtualPath));
 }
        public void Discover(ShapeTableBuilder builder)
        {
            Logger.Information("Start discovering shapes");

            var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });

            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures    = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions  = Once(activeFeatures);

            var hits = _parallelCacheContext.RunInParallel(activeExtensions, extensionDescriptor => {
                Logger.Information("Start discovering candidate views filenames");
                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => {
                    var basePath    = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                    var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
                    var fileNames   = _cacheManager.Get(virtualPath, ctx => {
                        ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
                        return(_virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection());
                    });
                    return(new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames });
                })).ToList();
                Logger.Information("Done discovering candidate views filenames");

                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
                    var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
                    return(fileNames.Select(
                               fileName => new {
                        fileName = Path.GetFileNameWithoutExtension(fileName),
                        fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
                        pathContext
                    }));
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext => {
                    var harvestShapeInfo = new HarvestShapeInfo {
                        SubPath             = fileContext.pathContext.subPath,
                        FileName            = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return(harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext }));
                });

                return(shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList());
            }).SelectMany(hits2 => hits2);


            foreach (var iter in hits)
            {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    Logger.Debug("Binding {0} as shape [{1}] for feature {2}",
                                 hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                                 iter.shapeContext.harvestShapeHit.ShapeType,
                                 featureDescriptor.Id);

                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                    .From(new Feature {
                        Descriptor = featureDescriptor
                    })
                    .BoundAs(
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }

            Logger.Information("Done discovering shapes");
        }
        // 从多个地点进行合并:
        // "~/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 IVolatileToken WhenPathChanges(string path)
 {
     return(virtualPathMonitor.WhenPathChanges(GetVirtualPath(path)));
 }