public bool InstallSamplePackage(string packageFilePath) { if (!File.Exists(packageFilePath)) { return(false); // do nothing } //get temporary directory to extract the package var tempDirectory = _localFileProvider.GetTemporaryDirectory(); try { //first extract the zip _localFileProvider.ExtractArchive(packageFilePath, tempDirectory); //now copy the image files to the uploads directory var wwwroot = ServerHelper.MapPath("~/", true); var uploadsDirectory = _localFileProvider.CombinePaths(wwwroot, "content", "Uploads"); var sourceFilesDirectory = _localFileProvider.CombinePaths(tempDirectory, "images"); var files = _localFileProvider.GetFiles(sourceFilesDirectory); foreach (var file in files) { //copy the file var fileName = _localFileProvider.GetFileName(file); _localFileProvider.CopyFile(file, Path.Combine(uploadsDirectory, fileName)); } //sql path if any var sqlFile = _localFileProvider.CombinePaths(tempDirectory, "data.sql"); if (File.Exists(sqlFile)) { var sql = _localFileProvider.ReadAllText(sqlFile); //execute the query file using (EntitySet.Query(sql, null)) { } } //delete the temporary directory _localFileProvider.DeleteDirectory(tempDirectory, true); return(true); } catch (Exception ex) { _logger.Log <InstallationService>(LogLevel.Error, ex.Message, ex); return(false); } finally { _localFileProvider.DeleteDirectory(tempDirectory, true); } }
public IActionResult Index() { var databaseSettings = DependencyResolver.Resolve <IDatabaseSettings>(); var areTableInstalled = DatabaseManager.IsDatabaseInstalled(databaseSettings); if (areTableInstalled) { return(RedirectToRoute(RouteNames.Home)); } //read the license var license = _localFileProvider.ReadAllText(ServerHelper.MapPath("~/App_Data/Install/license.txt")); return(R.Success.With("license", license).Result); }
private ThemeInfo GetThemeInfo(DirectoryInfo directoryInfo) { var themeConfigPath = _localFileProvider.CombinePaths(_themeDirectory, directoryInfo.Name, "config.json"); if (_localFileProvider.FileExists(themeConfigPath)) { var configJson = _localFileProvider.ReadAllText(themeConfigPath); var themeInfo = _dataSerializer.DeserializeAs <ThemeInfo>(configJson); var imagePath = _localFileProvider.CombinePaths(_themeDirectory, directoryInfo.Name, "Assets", "theme.jpg"); //do we have an image file? if (_localFileProvider.FileExists(imagePath)) { themeInfo.ThumbnailUrl = $"/{directoryInfo.Name}/assets/theme.jpg"; } themeInfo.DirectoryName = directoryInfo.Name; return(themeInfo); } return(null); }