private bool RestoreExtensionFolder(string extensionFolder, string extensionId) { var source = new DirectoryInfo(_virtualPathProvider.MapPath(_virtualPathProvider.Combine("~", extensionFolder, extensionId))); if (source.Exists) { var tempPath = _virtualPathProvider.Combine("~", extensionFolder, "_Backup", extensionId); string localTempPath = null; for (int i = 0; i < 1000; i++) { localTempPath = _virtualPathProvider.MapPath(tempPath) + (i == 0 ? "" : "." + i.ToString()); if (!Directory.Exists(localTempPath)) { Directory.CreateDirectory(localTempPath); break; } localTempPath = null; } if (localTempPath == null) { throw new OrchardException(T("Backup folder {0} has too many backups subfolder (limit is 1,000)", tempPath)); } var backupFolder = new DirectoryInfo(localTempPath); _folderUpdater.Restore(backupFolder, source); _notifier.Information(T("Successfully restored local package to local folder \"{0}\"", source)); return(true); } return(false); }
public override ExtensionProbeEntry Probe(ExtensionDescriptor descriptor) { if (Disabled) { return(null); } if (descriptor.Location.StartsWith("~/Themes/")) { string projectPath = virtualPathProvider.Combine(descriptor.Location, descriptor.Id + ".csproj"); // ignore themes including a .csproj in this loader if (virtualPathProvider.FileExists(projectPath)) { return(null); } var assemblyPath = virtualPathProvider.Combine(descriptor.Location, "bin", descriptor.Id + ".dll"); // ignore themes with /bin in this loader if (virtualPathProvider.FileExists(assemblyPath)) { return(null); } return(new ExtensionProbeEntry { Descriptor = descriptor, Loader = this, VirtualPath = "~/Themes/" + descriptor.Id, VirtualPathDependencies = Enumerable.Empty <string>(), }); } return(null); }
private bool RestoreExtensionFolder(string extensionFolder, string extensionId) { var virtualSource = _virtualPathProvider.Combine("~", extensionFolder, extensionId); var source = new DirectoryInfo(_virtualPathProvider.MapPath(virtualSource)); if (source.Exists) { var tempPath = _virtualPathProvider.Combine("~/App_Data", "_Backup", extensionFolder, extensionId); string localTempPath = null; for (int i = 0; i < 1000; i++) { localTempPath = _virtualPathProvider.MapPath(tempPath) + (i == 0 ? "" : "." + i.ToString()); if (!System.IO.Directory.Exists(localTempPath)) { System.IO.Directory.CreateDirectory(localTempPath); break; } localTempPath = null; } if (localTempPath == null) { throw new SmartException(T("Admin.Packaging.TooManyBackups", tempPath)); } var backupFolder = new DirectoryInfo(localTempPath); _folderUpdater.Restore(backupFolder, source); _notifier.Information(T("Admin.Packaging.RestoreSuccess", virtualSource)); return(true); } return(false); }
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)); } }
/// <summary> /// 探测。 /// </summary> /// <param name="descriptor">扩展描述符条目。</param> /// <returns>扩展探测条目。</returns> public override ExtensionProbeEntry Probe(ExtensionDescriptorEntry descriptor) { if (Disabled) { return(null); } var assembly = _buildManager.GetReferencedAssembly(descriptor.Id); if (assembly == null) { return(null); } var assemblyPath = _virtualPathProvider.Combine("~/bin", descriptor.Id + ".dll"); return(new ExtensionProbeEntry { Descriptor = descriptor, Loader = this, Priority = 100, //更高的优先级,因为在~/bin中的程序集总是优先 VirtualPath = assemblyPath, VirtualPathDependencies = new[] { assemblyPath }, }); }
public void BuildManifests(ResourceManifestBuilder builder) { var manifest = builder.Add(); manifest.DefineStyle("WorkflowsAdmin").SetUrl("orchard-workflows-admin.css").SetDependencies("~/Themes/TheAdmin/Styles/Site.css"); manifest.DefineScript("jsPlumb").SetUrl("jquery.jsPlumb-1.4.1-all-min.js").SetDependencies("jQueryUI"); // Trying to find a matching activity CSS for each activity in the extensions they come from. var resourceNamesAndPaths = _cacheManager.Get("Orchard.Workflows.ActivityResourceNames", context => { var resourceNameAndPathList = new List <Tuple <string, string> >(); foreach (var activity in _activitiesManager.Value.GetActivities()) { var assemblyName = activity.GetType().Assembly.GetName().Name; var extension = _extensionManager.GetExtension(assemblyName); if (extension == null) { continue; } var stylesPath = _virtualPathProvider.Combine(extension.VirtualPath, "Styles"); var resourceName = "WorkflowsActivity-" + activity.Name; var filename = resourceName.HtmlClassify() + ".css"; var filePath = _virtualPathProvider.Combine(_hostEnvironment.MapPath(stylesPath), filename); if (File.Exists(filePath)) { /* Since stylesheets are shapes, we don't need to create the resource with the full path to the CSS file, * because extensions can override those shapes by file name if they reference Orchard.Workflows, * even when they don't exist in Orchard.Workflows. */ resourceNameAndPathList.Add(Tuple.Create(resourceName, filename)); } } return(resourceNameAndPathList); }); foreach (var resourceNameAndPath in resourceNamesAndPaths) { manifest .DefineStyle(resourceNameAndPath.Item1) .SetUrl(resourceNameAndPath.Item2) .SetDependencies("WorkflowsAdmin"); } manifest .DefineStyle("WorkflowsActivities") .SetDependencies(resourceNamesAndPaths.Select(resourceNameAndPath => resourceNameAndPath.Item1).ToArray()); }
private void DeleteAssembly(ExtensionLoadingContext ctx, string moduleName) { var assemblyPath = _virtualPathProvider.Combine("~/bin", moduleName + ".dll"); if (_virtualPathProvider.FileExists(assemblyPath)) { ctx.DeleteActions.Add( () => { Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from bin directory (AppDomain will restart)", moduleName); File.Delete(_virtualPathProvider.MapPath(assemblyPath)); }); ctx.RestartAppDomain = true; } }
/// <summary> /// Retrieves the full path of the manifest file for a module's extension descriptor. /// </summary> /// <param name="extensionDescriptor">The module's extension descriptor.</param> /// <returns>The full path to the module's manifest file.</returns> private string GetManifestPath(ExtensionDescriptor extensionDescriptor) { string projectPath = _virtualPathProvider.Combine(extensionDescriptor.Location, extensionDescriptor.Id, "module.txt"); if (!_virtualPathProvider.FileExists(projectPath)) { return(null); } return(projectPath); }
public static string GetReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string basePath, string referenceName, string hintPath) { // Check if hint path is valid if (!string.IsNullOrEmpty(hintPath)) { if (virtualPathProvider.TryFileExists(virtualPathProvider.Combine(basePath, hintPath))) { return(hintPath); } } // Fall back to bin directory string relativePath = virtualPathProvider.Combine("bin", referenceName + ".dll"); if (virtualPathProvider.TryFileExists(virtualPathProvider.Combine(basePath, relativePath))) { return(relativePath); } return(null); }
private IEnumerable <string> GetAvailableRecipeFiles() { //go through each enabled feature- any xml files inside a folder called ContentMigrations will be discovered var features = _featureManager.GetEnabledFeatures(); foreach (var feature in features) { var migrationPath = _virtualPathProvider.Combine(feature.Extension.Location, feature.Extension.Id, "ContentMigrations", feature.Id); var mappedPath = _virtualPathProvider.MapPath(migrationPath); if (!Directory.Exists(mappedPath)) { continue; } foreach (var recipeFile in Directory.EnumerateFiles(mappedPath, "*.Recipe.xml")) { yield return(_virtualPathProvider.Combine(migrationPath, Path.GetFileName(recipeFile))); } } }
public static string GetProjectReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string projectPath, string referenceName, string hintPath) { string basePath = virtualPathProvider.GetDirectoryName(projectPath); string virtualPath = virtualPathProvider.GetReferenceVirtualPath(basePath, referenceName, hintPath); if (!string.IsNullOrEmpty(virtualPath)) { return(virtualPathProvider.Combine(basePath, virtualPath)); } return(null); }
protected virtual object CreateModelPart(SystemSetting part, MessageContext messageContext) { var host = messageContext.BaseUri.ToString(); var m = new Dictionary <string, object> { { "Title", part.Title }, { "LogoSrc", _vpp.Combine(host, part.LogoImage) }, }; return(m); }
public Assembly Load(AssemblyName assemblyName) { Project project; string name = assemblyName.FullName; if (!Project.TryGetProject(_virtualPathProvider.Combine(_path, name), out project)) { return(null); } return(_cache.Get <Assembly>(assemblyName.Name, cacheContext => { var target = new CompilationTarget( name, project.GetTargetFramework(_applicationEnvironment.RuntimeFramework).FrameworkName, _applicationEnvironment.Configuration, null); _moduleContext = new ModuleLoaderContext( _serviceProvider, project.ProjectDirectory, target.Configuration, target.TargetFramework); foreach (var lib in _moduleContext.DependencyWalker.Libraries) { _libraryManager.AddLibrary(lib.ToLibrary()); } var compilationEngineFactory = new CompilationEngineFactory( NoopWatcher.Instance, new CompilationCache()); var engine = compilationEngineFactory.CreateEngine(new CompilationEngineContext( _moduleContext.LibraryManager, _moduleContext.ProjectGraphProvider, _moduleContext.ServiceProvider, target.TargetFramework, target.Configuration)); _packageAssemblyLookup.AddLoader( _moduleContext.NuGetDependencyProvider); var p = engine.LoadProject(project, null, _assemblyLoadContextAccessor.Default); var exports = engine.RootLibraryExporter.GetExport(project.Name); foreach (var metadataReference in exports.MetadataReferences) { _libraryManager.AddMetadataReference(metadataReference); } return p; })); }
public override ExtensionProbeEntry Probe(ExtensionDescriptor descriptor) { if (Disabled) { return(null); } // Temporary - theme without own project should be under ~/themes if (descriptor.Location.StartsWith("~/Themes", StringComparison.InvariantCultureIgnoreCase)) { string projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, descriptor.Id + ".csproj"); // ignore themes including a .csproj in this loader if (_virtualPathProvider.FileExists(projectPath)) { return(null); } var assemblyPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, "bin", descriptor.Id + ".dll"); // ignore themes with /bin in this loader if (_virtualPathProvider.FileExists(assemblyPath)) { return(null); } return(new ExtensionProbeEntry { Descriptor = descriptor, Loader = this, VirtualPath = descriptor.VirtualPath, VirtualPathDependencies = Enumerable.Empty <string>(), }); } return(null); }
public override ExtensionProbeEntry Probe(ExtensionDescriptor descriptor) { if (Disabled) { return(null); } if (!string.IsNullOrEmpty(descriptor.Location) && _extensionPathsProvider.GetExtensionPaths().ThemeFolderPaths.Any(path => path.Contains(descriptor.Location))) { string projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, descriptor.Id + ".csproj"); // ignore themes including a .csproj in this loader if (_virtualPathProvider.FileExists(projectPath)) { return(null); } var assemblyPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, "bin", descriptor.Id + ".dll"); // ignore themes with /bin in this loader if (_virtualPathProvider.FileExists(assemblyPath)) { return(null); } return(new ExtensionProbeEntry { Descriptor = descriptor, Loader = this, VirtualPath = "~/Theme/" + descriptor.Id, VirtualPathDependencies = Enumerable.Empty <string>(), }); } return(null); }
/// <summary> /// 探测。 /// </summary> /// <param name="descriptor">扩展描述符条目。</param> /// <returns>扩展探测条目。</returns> public override ExtensionProbeEntry Probe(ExtensionDescriptorEntry descriptor) { if (Disabled) { return(null); } if (descriptor.Location != "~/Themes") { return(null); } var projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, descriptor.Id + ".csproj"); //如果项目文件不存在则忽略主题 if (_virtualPathProvider.FileExists(projectPath)) { return(null); } var assemblyPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, "bin", descriptor.Id + ".dll"); //如果主题包含dll文件则忽略 if (_virtualPathProvider.FileExists(assemblyPath)) { return(null); } return(new ExtensionProbeEntry { Descriptor = descriptor, Loader = this, VirtualPath = "~/Theme/" + descriptor.Id, VirtualPathDependencies = Enumerable.Empty <string>(), }); }
public FileInfo CreatePluginPackage(string path) { string virtualPath = _vpp.Combine(path, "Description.txt"); if (!_vpp.FileExists(virtualPath)) { return(null); } var descriptor = PluginFileParser.ParsePluginDescriptionFile(_vpp.MapPath(virtualPath)); if (descriptor != null) { return(CreatePluginPackage(descriptor)); } return(null); }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { var plocation = _virtualPathProvider.MapPath(_virtualPathProvider.Combine(descriptor.Location, descriptor.Id)); Project project = null; if (!Project.TryGetProject(plocation, out project)) { return(null); } var assembly = Load(project); Logger.Information("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); }
public ThemeSettingsManifest GetSettingsManifest(string themeId) { var key = String.Format("ThemeSettingsManifest-{0}", themeId); return(_cacheManager.Get(key, context => { var theme = GetTheme(themeId); var path = _virtualPathProvider.Combine(theme.Location, theme.Id, "Settings.json"); if (!_virtualPathProvider.FileExists(path)) { return null; } var json = ReadAllText(path); var settings = JsonConvert.DeserializeObject <ThemeSettingsManifest>(json); return settings; })); }
private string ResolveVirtualPath(Context context, string templateName) { var path = ((string)context[templateName]).NullEmpty() ?? templateName; if (path.IsEmpty()) { return(string.Empty); } path = path.EnsureEndsWith(".liquid"); string virtualPath; if (!path.StartsWith("~/")) { //var currentTheme = _themeContext.Value.CurrentTheme; virtualPath = _vpp.Combine("~/Themes/Basic/Views/Shared/EmailTemplates", path); } else { virtualPath = VirtualPathUtility.ToAppRelative(path); } return(virtualPath); }
private string GetAssemblyDirectory() { var virtualPath = _virtualPathProvider.Combine("~/Modules/" + AssemblyName, "bin"); return(_virtualPathProvider.MapPath(virtualPath)); }
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; } }
public void Compile(CompileExtensionContext context) { Logger.Information("Generate code for file \"{0}\"", context.VirtualPath); var moduleName = Path.GetFileNameWithoutExtension(context.VirtualPath); var dependencyDescriptor = _dependenciesFolder.GetDescriptor(moduleName); if (dependencyDescriptor == null) { return; } try { var projectFileDescriptor = _projectFileParser.Parse(context.VirtualPath); // Add source files var directory = _virtualPathProvider.GetDirectoryName(context.VirtualPath); foreach (var filename in projectFileDescriptor.SourceFilenames.Select(f => _virtualPathProvider.Combine(directory, f))) { context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename)); } var addedReferences = new HashSet <string>(StringComparer.OrdinalIgnoreCase); // Add assembly references foreach (var reference in dependencyDescriptor.References) { var referenceTemp = reference; var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName); if (loader == null) { Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName); continue; } var assembly = loader.LoadReference(reference); if (assembly == null) { Logger.Warning("Loader '{0}' could not load reference '{1}'", reference.LoaderName, reference.Name); continue; } addedReferences.Add(reference.Name); context.AssemblyBuilder.AddAssemblyReference(assembly); } _criticalErrorProvider.Clear(); // Load references specified in project file (only the ones not yet loaded) foreach (var assemblyReference in projectFileDescriptor.References) { if (addedReferences.Contains(assemblyReference.SimpleName)) { continue; } var assembly = _assemblyLoader.Load(assemblyReference.FullName); if (assembly != null) { context.AssemblyBuilder.AddAssemblyReference(assembly); } else { Logger.Error("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath); _criticalErrorProvider.RegisterErrorMessage(T( "The assembly reference '{0}' could not be loaded for module '{1}'.\r\n\r\n" + "There are generally a few ways to solve this issue:\r\n" + "1. Install any dependent module.\r\n" + "2. Remove the assembly reference from the project file if it's not needed.\r\n" + "3. Ensure the assembly reference is present in the 'bin' directory of the module.\r\n" + "4. Ensure the assembly reference is present in the 'bin' directory of the application.\r\n" + "5. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.", assemblyReference.FullName, moduleName)); throw new CoeveryCoreException(T("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath)); } } } catch (Exception e) { //Note: we need to embed the "e.Message" in the exception text because // ASP.NET build manager "swallows" inner exceptions from this method. throw new CoeveryCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, e.Message), e); } }
public virtual string Combine(params string[] paths) { return(_vpp.Combine(paths)); }
public bool HasReferencedAssembly(string name) { var assemblyPath = _virtualPathProvider.Combine("~/bin", name + ".dll"); return(_virtualPathProvider.FileExists(assemblyPath)); }
public Assembly Load(AssemblyName assemblyName) { Project project; string name = assemblyName.FullName; if (!Project.TryGetProject(_virtualPathProvider.Combine(_path, name), out project)) { return(null); } var cache = (ICache)_serviceProvider.GetService(typeof(ICache)); var target = new CompilationTarget( name, project.GetTargetFramework(_applicationEnvironment.RuntimeFramework).FrameworkName, _applicationEnvironment.Configuration, null); ModuleLoaderContext moduleContext = new ModuleLoaderContext( _serviceProvider, project.ProjectDirectory); moduleContext.DependencyWalker.Walk(name, project.Version, target.TargetFramework); var cacheContextAccessor = (ICacheContextAccessor)_serviceProvider.GetService(typeof(ICacheContextAccessor)); var loadContextFactory = (IAssemblyLoadContextFactory)_serviceProvider.GetService(typeof(IAssemblyLoadContextFactory)) ?? new AssemblyLoadContextFactory(_serviceProvider); var compiler = new InternalRoslynCompiler( cache, cacheContextAccessor, new NamedCacheDependencyProvider(), loadContextFactory, _fileWatcher, _applicationEnvironment, _serviceProvider); _orchardLibraryManager.AddAdditionalRegistrations(moduleContext.DependencyWalker.Libraries); var exports = ProjectExportProviderHelper.GetExportsRecursive( _orchardLibraryManager, moduleContext.LibraryExportProvider, new CompilationTarget(name, target.TargetFramework, target.Configuration, target.Aspect), true); _orchardLibraryManager.AddAdditionalLibraryExportRegistrations(name, exports); foreach (var dependency in project.Dependencies) { if (!_orchardLibraryManager.MetadataReferences.ContainsKey(dependency.Name)) { continue; } exports.MetadataReferences.Add(_orchardLibraryManager.MetadataReferences[dependency.Name]); } var compliationContext = compiler.CompileProject( project.ToCompilationContext(target), exports.MetadataReferences, exports.SourceReferences, () => CompositeResourceProvider.Default.GetResources(project)); var roslynProjectReference = new RoslynProjectReference(compliationContext); _orchardLibraryManager.AddMetadataReference(name, roslynProjectReference); var loadContext = _assemblyLoadContextAccessor.Default; return(roslynProjectReference.Load(loadContext)); }
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; } }