Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public ThemeInfo GetActiveTheme()
        {
            var defaultThemeDirectoryName = "Default";

            if (!DatabaseManager.IsDatabaseInstalled())
            {
                return(GetThemeInfo(new DirectoryInfo(defaultThemeDirectoryName)));
            }
            var generalSettings = DependencyResolver.Resolve <GeneralSettings>();

            if (_cachedThemeInfo != null && _cachedThemeInfo.DirectoryName == generalSettings.ActiveTheme)
            {
                return(_cachedThemeInfo);
            }
            var themeDirectoryName = generalSettings.ActiveTheme;

            if (themeDirectoryName.IsNullEmptyOrWhiteSpace())
            {
                themeDirectoryName = defaultThemeDirectoryName;
            }
            //does theme directory exist
            var themePath = GetThemePath(themeDirectoryName);

            if (!_localFileProvider.DirectoryExists(themePath))
            {
                //reset theme path to default
                themePath = GetThemePath(defaultThemeDirectoryName);
            }
            _cachedThemeInfo = GetThemeInfo(new DirectoryInfo(themePath));

            //load if there are any templates
            var templatesDirectory = _localFileProvider.CombinePaths(themePath, "Views", "Templates");

            if (_localFileProvider.DirectoryExists(templatesDirectory))
            {
                //get all the files
                var templateFiles = _localFileProvider.GetFiles(templatesDirectory, "*.html");
                foreach (var templateFile in templateFiles)
                {
                    var fileName = _localFileProvider.GetFileNameWithoutExtension(templateFile);
                    _cachedThemeInfo.Templates.TryAdd(fileName, $"Templates/{fileName}");
                }
            }
            return(_cachedThemeInfo);
        }