Exemplo n.º 1
0
		private void ReadPackages(IVirtualPathProvider vpp)
		{
			if (!ValidatePaths())
				return;

			lstPlugins.DisplayMember = "Name";
			lstPlugins.ValueMember = "Path";
			lstThemes.DisplayMember = "Name";
			lstThemes.ValueMember = "Path";

			lstPlugins.Items.Clear();
			lstThemes.Items.Clear();

			IEnumerable<string> dirs = Enumerable.Empty<string>();

			if (vpp.DirectoryExists("~/Plugins") || vpp.DirectoryExists("~/Themes"))
			{
				if (vpp.DirectoryExists("~/Plugins"))
				{
					dirs = dirs.Concat(vpp.ListDirectories("~/Plugins"));
				}
				if (vpp.DirectoryExists("~/Themes"))
				{
					dirs = dirs.Concat(vpp.ListDirectories("~/Themes"));
				}
			}
			else
			{
				dirs = vpp.ListDirectories("~/");
			}

			foreach (var dir in dirs)
			{
				bool isTheme = false;

				// is it a plugin?
				var filePath = vpp.Combine(dir, "Description.txt");
				if (!vpp.FileExists(filePath))
				{
					// ...no! is it a theme?
					filePath = vpp.Combine(dir, "theme.config");
					if (!vpp.FileExists(filePath))
						continue;

					isTheme = true;
				}

				try
				{
					if (isTheme)
					{
						var manifest = ThemeManifest.Create(vpp.MapPath(dir));
						lstThemes.Items.Add(new ExtensionInfo(dir, manifest.ThemeName));
					}
					else
					{
						var descriptor = PluginFileParser.ParsePluginDescriptionFile(vpp.MapPath(filePath));
						if (descriptor != null)
						{
							lstPlugins.Items.Add(new ExtensionInfo(dir, descriptor.FolderName));
						}
					}
				}
				catch
				{
					continue;
				}
			}

			if (lstPlugins.Items.Count > 0) 
			{
				tabMain.SelectedIndex = 0;
			}
			else if (lstThemes.Items.Count > 0)
			{
				tabMain.SelectedIndex = 1;
			}
		}
Exemplo n.º 2
0
 public bool dirExists(IVirtualPathProvider vfs, string virtualPath) => vfs.DirectoryExists(virtualPath);
Exemplo n.º 3
0
        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 => {
                        if (!_virtualPathProvider.DirectoryExists(virtualPath))
                        {
                            return(new List <string>());
                        }

                        if (!DisableMonitoring)
                        {
                            Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
                            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");
        }
Exemplo n.º 4
0
 public static bool IsDirectory(this IVirtualPathProvider pathProvider, string filePath)
 {
     return(pathProvider.DirectoryExists(filePath));
 }
Exemplo n.º 5
0
        private void ReadPackages(IVirtualPathProvider vpp)
        {
            if (!ValidatePaths())
            {
                return;
            }

            lstPlugins.DisplayMember = "Name";
            lstPlugins.ValueMember   = "Path";
            lstThemes.DisplayMember  = "Name";
            lstThemes.ValueMember    = "Path";

            lstPlugins.Items.Clear();
            lstThemes.Items.Clear();

            IEnumerable <string> dirs = Enumerable.Empty <string>();

            if (vpp.DirectoryExists("~/Plugins") || vpp.DirectoryExists("~/Themes"))
            {
                if (vpp.DirectoryExists("~/Plugins"))
                {
                    dirs = dirs.Concat(vpp.ListDirectories("~/Plugins"));
                }
                if (vpp.DirectoryExists("~/Themes"))
                {
                    dirs = dirs.Concat(vpp.ListDirectories("~/Themes"));
                }
            }
            else
            {
                dirs = vpp.ListDirectories("~/");
            }

            foreach (var dir in dirs)
            {
                bool isTheme = false;

                // is it a plugin?
                var filePath = vpp.Combine(dir, "Description.txt");
                if (!vpp.FileExists(filePath))
                {
                    // ...no! is it a theme?
                    filePath = vpp.Combine(dir, "theme.config");
                    if (!vpp.FileExists(filePath))
                    {
                        continue;
                    }

                    isTheme = true;
                }

                try
                {
                    if (isTheme)
                    {
                        var manifest = ThemeManifest.Create(vpp.MapPath(dir));
                        lstThemes.Items.Add(new ExtensionInfo(dir, manifest.ThemeName));
                    }
                    else
                    {
                        var descriptor = PluginFileParser.ParsePluginDescriptionFile(vpp.MapPath(filePath));
                        if (descriptor != null)
                        {
                            lstPlugins.Items.Add(new ExtensionInfo(dir, descriptor.FolderName));
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }

            if (lstPlugins.Items.Count > 0)
            {
                tabMain.SelectedIndex = 0;
            }
            else if (lstThemes.Items.Count > 0)
            {
                tabMain.SelectedIndex = 1;
            }
        }