public MigrationExectutionSummary ExecuteMigrations(IList <string> migrationNames) { var result = new MigrationExectutionSummary(); foreach (var recipeFile in GetAvailableRecipeFiles()) { var migrationName = GetMigrationNameFromFileName(recipeFile); if (migrationNames.Contains(migrationName)) { var mappedPath = _virtualPathProvider.MapPath(recipeFile); var executionId = _importExportService.Import(File.ReadAllText(mappedPath)); //var recipeJournal = _recipeJournal.GetRecipeJournal(executionId); //result.Messages.AddRange(recipeJournal.Messages.Select(m=>string.Format("Recipe Content Migration Provider: Migration: {0}. {1}", migrationName, m))); //if (recipeJournal.Status == RecipeStatus.Complete) { // result.SuccessfulMigrations.Add(migrationName); //} //else{ // result.FailedMigrations.Add(migrationName); //} } } return(result); }
string IWebSiteFolder.ReadFile(string virtualPath, bool actualContent) { if (!_virtualPathProvider.FileExists(virtualPath)) { return(null); } if (actualContent) { var physicalPath = _virtualPathProvider.MapPath(virtualPath); using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read)) { using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } } else { using (var stream = _virtualPathProvider.OpenFile(virtualPath)) { using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } } }
public string ReadFile(string virtualPath, bool actualContent) { if (!virtualPathProvider.FileExists(virtualPath)) { return(null); } if (actualContent) { var physicalPath = virtualPathProvider.MapPath(virtualPath); using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read)) { using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } } using (var stream = virtualPathProvider.OpenFile(Normalize(virtualPath))) { using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } }
public IEnumerable <AppInfo> GetApps(IAppHost host) { string hostDirPath = _virtualPathProvider.MapPath(string.Format("~/{0}/", host.DirName)); DirectoryInfo directory = new DirectoryInfo(hostDirPath); if (!directory.Exists) { return(Enumerable.Empty <AppInfo>()); } Stack <AppInfo> aSet = new Stack <AppInfo>(); IEnumerable <string> enabledapps = _appStateManager.EnabledAppIds(); foreach (DirectoryInfo dir in directory.GetDirectories()) { DirectoryInfo[] appbin = dir.GetDirectories("bin", SearchOption.TopDirectoryOnly); if (appbin.Length != 1) { continue; } string basicAssemblyPath = Path.Combine(Path.Combine(Path.Combine(hostDirPath, dir.Name), "bin"), dir.Name + ".dll"); if (_memoryAppInfo.ContainsKey(basicAssemblyPath)) { aSet.Push(_memoryAppInfo[basicAssemblyPath]); } else { Assembly assembly, resourcesAssembly; AppInfo app = LoadApp(host, basicAssemblyPath, out assembly, out resourcesAssembly); if (app != null) { app.IsEnable = false; foreach (string item in enabledapps) { if (string.Equals(item, app.Id)) { app.IsEnable = true; break; } } if (!_appInfoDic.ContainsKey(app)) { Assembly[] assemblies = new Assembly[] { assembly, app.IsEnable ? resourcesAssembly : null }; _appInfoDic.Add(app, assemblies); } _memoryAppInfo.Add(basicAssemblyPath, app); aSet.Push(app); } } } return(aSet); }
/// <summary> /// Tries to install the package /// </summary> /// <param name="package">The package to install</param> /// <param name="packageRepository">The repository</param> /// <param name="location">The virtual location of the package file, usually <c>~/App_Data</c></param> /// <param name="applicationPath">The virtual app root path, usually <c>~/</c></param> /// <returns>An instance of <see cref="PackageInfo"/> type</returns> protected PackageInfo InstallPackage(IPackage package, IPackageRepository packageRepository, string location, string applicationPath) { bool previousInstalled; // 1. See if extension was previous installed and backup its folder if so try { previousInstalled = BackupExtensionFolder(package.ExtensionFolder(), package.ExtensionId()); } catch (Exception exception) { throw new SmartException(T("Admin.Packaging.BackupError"), exception); } if (previousInstalled) { // 2. If extension is installed, need to un-install first try { UninstallExtensionIfNeeded(package); } catch (Exception exception) { throw new SmartException(T("Admin.Packaging.UninstallError"), exception); } } var packageInfo = ExecuteInstall(package, packageRepository, location, applicationPath); // check if the new package is compatible with current cloudCommerce version var descriptor = package.GetExtensionDescriptor(packageInfo.Type); if (descriptor != null) { packageInfo.ExtensionDescriptor = descriptor; if (!PluginManager.IsAssumedCompatible(descriptor.MinAppVersion)) { if (previousInstalled) { // restore the previous version RestoreExtensionFolder(package.ExtensionFolder(), package.ExtensionId()); } else { // just uninstall the new package Uninstall(package.Id, _virtualPathProvider.MapPath("~\\")); } var msg = T("Admin.Packaging.IsIncompatible", cloudCommerceVersion.CurrentFullVersion); _logger.Error(msg); throw new SmartException(msg); } } return(packageInfo); }
public string ReadFile(string virtualPath, bool actualContent) { if (!_virtualPathProvider.FileExists(virtualPath)) { return(null); } if (actualContent) { var physicalPath = _virtualPathProvider.MapPath(virtualPath); return(File.ReadAllText(physicalPath)); } else { return(_virtualPathProvider.ReadFile(Normalize(virtualPath))); } }
private void ExecuteOutSql(string path) { var sqlPath = _virtualPathProvider.MapPath(path); var fs = new FileStream(sqlPath, FileMode.Open); var sr = new StreamReader(fs); var sql = sr.ReadToEnd(); _schemaBuilder.ExecuteSql(sql); }
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 override void ExtensionActivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension) { string sourceFileName = _virtualPathProvider.MapPath(GetAssemblyPath(extension)); // Copy the assembly if it doesn't exist or if it is older than the source file. bool copyAssembly = !_assemblyProbingFolder.AssemblyExists(extension.Id) || File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(extension.Id); if (copyAssembly) { ctx.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(extension.Id, sourceFileName)); // We need to restart the appDomain if the assembly is loaded if (_hostEnvironment.IsAssemblyLoaded(extension.Id)) { Logger.Information("ExtensionRemoved: Module \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", extension.Id); ctx.RestartAppDomain = true; } } }
private CodeCompileUnit CreateCompileUnit(string virtualPath) { var contents = GetContents(virtualPath); var unit = new CodeSnippetCompileUnit(contents); var physicalPath = _virtualPathProvider.MapPath(virtualPath); if (!string.IsNullOrEmpty(physicalPath)) { unit.LinePragma = new CodeLinePragma(physicalPath, 1); } return(unit); }
protected PackageInfo InstallPackage(IPackage package, IPackageRepository packageRepository, string location, string applicationPath) { bool previousInstalled; // 1. See if extension was previous installed and backup its folder if so try { previousInstalled = BackupExtensionFolder(package.ExtensionFolder(), package.ExtensionId()); } catch (Exception exception) { throw new OrchardException(T("Unable to backup existing local package directory."), exception); } if (previousInstalled) { // 2. If extension is installed, need to un-install first try { UninstallExtensionIfNeeded(package); } catch (Exception exception) { throw new OrchardException(T("Unable to un-install local package before updating."), exception); } } var packageInfo = ExecuteInstall(package, packageRepository, location, applicationPath); // check the new package is compatible with current Orchard version var descriptor = package.GetExtensionDescriptor(packageInfo.ExtensionType); if (descriptor != null) { if (new FlatPositionComparer().Compare(descriptor.OrchardVersion, typeof(ContentItem).Assembly.GetName().Version.ToString()) >= 0) { if (previousInstalled) { // restore the previous version RestoreExtensionFolder(package.ExtensionFolder(), package.ExtensionId()); } else { // just uninstall the new package Uninstall(package.Id, _virtualPathProvider.MapPath("~\\")); } Logger.Error(String.Format("The package is compatible with version {0} and above. Please update Orchard or install another version of this package.", descriptor.OrchardVersion)); throw new OrchardException(T("The package is compatible with version {0} and above. Please update Orchard or install another version of this package.", descriptor.OrchardVersion)); } } return(packageInfo); }
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; } }
public void OnContentLoaded(CombinatorResource resource) { var extension = Path.GetExtension(resource.AbsoluteUrl.ToString()).ToLowerInvariant(); if (extension != ".sass" && extension != ".scss") { return; } using (var compiler = new SassCompiler()) { resource.Content = compiler.Compile(_virtualPathProvider.MapPath(resource.RelativeVirtualPath).Replace("\\", @"\"), false, new List <string>()); } }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { var plocation = _virtualPathProvider.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(new ExtensionAssemblyLoader(plocation, _serviceProvider))) { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); _logger.WriteInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); } }
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 ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!ExtensionsVirtualPathPrefixes.Contains(descriptor.Location)) { return(null); } var plocation = _virtualPathProvider.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(plocation))) { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); Logger.Information("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); } }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!descriptor.Location.StartsWith("~/Core/")) { return(null); } var plocation = _virtualPathProvider.MapPath("~/Core"); using (_loaderContainer.AddLoader(new ExtensionAssemblyLoader(plocation, _serviceProvider))) { var assembly = Assembly.Load(new AssemblyName(CoreAssemblyName)); Logger.Information("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes.Where(x => IsTypeFromModule(x, descriptor)) }); } }
/// <summary> /// Uninstalls a package. /// </summary> /// <param name="packageId">The package identifier for the package to be uninstalled.</param> /// <param name="applicationPath">The application path.</param> public void Uninstall(string packageId, string applicationPath) { string solutionPath; string extensionFullPath = string.Empty; if (packageId.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme))) { extensionFullPath = _virtualPathProvider.MapPath("~/Themes/" + packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme).Length)); } else if (packageId.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module))) { extensionFullPath = _virtualPathProvider.MapPath("~/Modules/" + packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module).Length)); } if (string.IsNullOrEmpty(extensionFullPath) || !Directory.Exists(extensionFullPath)) { throw new OrchardException(T("Package not found: {0}", packageId)); } // if we can access the parent directory, and the solution is inside, NuGet-uninstall the package here if (TryGetSolutionPath(applicationPath, out solutionPath)) { // this logger is used to render NuGet's log on the notifier var logger = new NugetLogger(_notifier); var installedPackagesPath = Path.Combine(solutionPath, PackagesPath); var sourcePackageRepository = new LocalPackageRepository(installedPackagesPath); try { var project = new FileBasedProjectSystem(applicationPath) { Logger = logger }; var projectManager = new ProjectManager( sourcePackageRepository, new DefaultPackagePathResolver(installedPackagesPath), project, new ExtensionReferenceRepository(project, sourcePackageRepository, _extensionManager) ) { Logger = logger }; // add the package to the project projectManager.RemovePackageReference(packageId); } catch { // Uninstalling the package at the solution level failed } try { var packageManager = new NuGetPackageManager( sourcePackageRepository, new DefaultPackagePathResolver(applicationPath), new PhysicalFileSystem(installedPackagesPath) { Logger = logger } ) { Logger = logger }; packageManager.UninstallPackage(packageId); } catch { // Package doesnt exist anymore } } // If the package was not installed through nuget we still need to try to uninstall it by removing its directory if (Directory.Exists(extensionFullPath)) { Directory.Delete(extensionFullPath, true); } }
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 string MapPath(string virtualPath) { return(_virtualPathProvider.MapPath(virtualPath)); }
private string GetAssemblyDirectory() { var virtualPath = _virtualPathProvider.Combine("~/Modules/" + AssemblyName, "bin"); return(_virtualPathProvider.MapPath(virtualPath)); }
public LoggingConfigurationResolve(ICacheManager cacheManager, IVirtualPathProvider virtualPathProvider) { _defaultConfigurationPath = virtualPathProvider.MapPath(@"~/Config/Logging/LoggingConfig.config"); _defaultLoggingConfigurationDocument = XDocument.Load(_defaultConfigurationPath); _cacheManager = cacheManager; }
public virtual string MapPath(string relativePath) { return(_vpp.MapPath(GetVirtualPath(relativePath))); }
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; } }
private string ReadFile(string path) { path = _virtualPathProvider.MapPath(path); return(!File.Exists(path) ? null : File.ReadAllText(path)); }