Beispiel #1
0
        public FileInfo CreateThemePackage(string virtualPath)
        {
            //string virtualPath = "~/Themes/{0}".FormatInvariant(themeName);

            var manifest = ThemeManifest.Create(_vpp.MapPath(virtualPath));

            if (manifest != null)
            {
                return(CreateThemePackage(manifest));
            }

            return(null);
        }
        private void ThemeFolderRenamed(string name, string fullPath, string oldName, string oldFullPath)
        {
            TryRemoveManifest(oldName);

            var di = new DirectoryInfo(fullPath);

            try
            {
                var newManifest = ThemeManifest.Create(di.FullName);
                if (newManifest != null)
                {
                    this.AddThemeManifest(newManifest);
                    Debug.WriteLine("Changed theme manifest for '{0}'".FormatCurrent(name));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERR - Could not touch theme manifest '{0}': {1}".FormatCurrent(name, ex.Message));
            }
        }
        private void LoadThemes()
        {
            var folder          = EngineContext.Current.Resolve <IWebSiteFolder>();
            var virtualBasePath = _cfg.ThemeBasePath;

            foreach (var path in folder.ListDirectories(virtualBasePath))
            {
                try
                {
                    var manifest = ThemeManifest.Create(CommonHelper.MapPath(path), virtualBasePath);
                    if (manifest != null)
                    {
                        _themes.TryAdd(manifest.ThemeName, manifest);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("ERR - unable to create manifest for theme '{0}': {1}".FormatCurrent(path, ex.Message));
                }
            }
        }
Beispiel #4
0
        internal static ExtensionDescriptor GetExtensionDescriptor(this IPackage package, string extensionType)
        {
            bool isTheme = extensionType.IsCaseInsensitiveEqual("Theme");

            IPackageFile packageFile = package.GetFiles().FirstOrDefault(file =>
            {
                var fileName = Path.GetFileName(file.Path);
                return(fileName != null && fileName.Equals(isTheme ? "theme.config" : "Description.txt", StringComparison.OrdinalIgnoreCase));
            });

            ExtensionDescriptor descriptor = null;

            if (packageFile != null)
            {
                var filePath = packageFile.EffectivePath;
                if (filePath.HasValue())
                {
                    filePath = Path.Combine(HostingEnvironment.MapPath("~/"), filePath);
                    if (isTheme)
                    {
                        var themeManifest = ThemeManifest.Create(Path.GetDirectoryName(filePath));
                        if (themeManifest != null)
                        {
                            descriptor = themeManifest.ConvertToExtensionDescriptor();
                        }
                    }
                    else                     // is a Plugin
                    {
                        var pluginDescriptor = PluginFileParser.ParsePluginDescriptionFile(filePath);
                        if (pluginDescriptor != null)
                        {
                            descriptor = pluginDescriptor.ConvertToExtensionDescriptor();
                        }
                    }
                }
            }

            return(descriptor);
        }
        private void ThemeConfigChanged(string name, string fullPath)
        {
            var di = new DirectoryInfo(Path.GetDirectoryName(fullPath));

            try
            {
                var newManifest = ThemeManifest.Create(di.FullName);
                if (newManifest != null)
                {
                    this.AddThemeManifest(newManifest);
                    Debug.WriteLine("Changed theme manifest for '{0}'".FormatCurrent(name));
                }
                else
                {
                    // something went wrong (most probably no 'theme.config'): remove the manifest
                    TryRemoveManifest(di.Name);
                }
            }
            catch (Exception ex)
            {
                TryRemoveManifest(di.Name);
                Debug.WriteLine("ERR - Could not touch theme manifest '{0}': {1}".FormatCurrent(name, ex.Message));
            }
        }
        public ActionResult UploadPackage(FormCollection form, string returnUrl = "")
        {
            if (returnUrl.IsEmpty())
            {
                returnUrl = _services.WebHelper.GetUrlReferrer();
            }

            bool isTheme = false;

            try
            {
                var file = Request.Files["packagefile"];
                if (file != null && file.ContentLength > 0)
                {
                    var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName))
                                                ? StandardPermissionProvider.ManageThemes
                                                : StandardPermissionProvider.ManagePlugins;

                    if (!_services.Permissions.Authorize(requiredPermission))
                    {
                        return(AccessDeniedView());
                    }

                    if (!Path.GetExtension(file.FileName).IsCaseInsensitiveEqual(".nupkg"))
                    {
                        NotifyError(T("Admin.Packaging.NotAPackage"));
                        return(Redirect(returnUrl));
                    }

                    var location = CommonHelper.MapPath("~/App_Data");
                    var appPath  = CommonHelper.MapPath("~/");

                    if (isTheme)
                    {
                        // avoid getting terrorized by IO events
                        _themeRegistry.Value.StopMonitoring();
                    }

                    var packageInfo = _packageManager.Install(file.InputStream, location, appPath);

                    if (isTheme)
                    {
                        // create manifest
                        if (packageInfo != null)
                        {
                            var manifest = ThemeManifest.Create(packageInfo.ExtensionDescriptor.Path);
                            if (manifest != null)
                            {
                                _themeRegistry.Value.AddThemeManifest(manifest);
                            }
                        }

                        // SOFT start IO events again
                        _themeRegistry.Value.StartMonitoring(false);
                    }
                }
                else
                {
                    NotifyError(T("Admin.Common.UploadFile"));
                    return(Redirect(returnUrl));
                }

                if (!isTheme)
                {
                    _services.WebHelper.RestartAppDomain();
                }
                NotifySuccess(T("Admin.Packaging.InstallSuccess"));
                return(Redirect(returnUrl));
            }
            catch (Exception exc)
            {
                NotifyError(exc);
                return(Redirect(returnUrl));
            }
        }
Beispiel #7
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;
            }
        }
        public ActionResult UploadPackage(string returnUrl = "")
        {
            var    isTheme  = false;
            var    success  = false;
            string message  = null;
            string tempFile = "";

            try
            {
                var file = Request.ToPostedFileResult();
                if (file != null)
                {
                    var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName))
                        ? Permissions.Configuration.Theme.Upload
                        : Permissions.Configuration.Plugin.Upload;

                    if (!Services.Permissions.Authorize(requiredPermission))
                    {
                        message = T("Admin.AccessDenied.Description");
                        return(Json(new { success, file.FileName, message }));
                    }

                    if (!file.FileExtension.IsCaseInsensitiveEqual(".nupkg"))
                    {
                        return(Json(new { success, file.FileName, T("Admin.Packaging.NotAPackage").Text, returnUrl }));
                    }

                    var location = CommonHelper.MapPath("~/App_Data");
                    var appPath  = CommonHelper.MapPath("~/");

                    if (isTheme)
                    {
                        // Avoid getting terrorized by IO events.
                        _themeRegistry.Value.StopMonitoring();
                    }

                    var packageInfo = _packageManager.Install(file.Stream, location, appPath);

                    if (isTheme)
                    {
                        // Create manifest.
                        if (packageInfo != null)
                        {
                            var manifest = ThemeManifest.Create(packageInfo.ExtensionDescriptor.Path);
                            if (manifest != null)
                            {
                                _themeRegistry.Value.AddThemeManifest(manifest);
                            }
                        }

                        // SOFT start IO events again.
                        _themeRegistry.Value.StartMonitoring(false);
                    }
                }
                else
                {
                    return(Json(new { success, file.FileName, T("Admin.Common.UploadFile").Text, returnUrl }));
                }

                if (!isTheme)
                {
                    message = T("Admin.Packaging.InstallSuccess").Text;
                    Services.WebHelper.RestartAppDomain();
                }
                else
                {
                    message = T("Admin.Packaging.InstallSuccess.Theme").Text;
                }

                success = true;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                Logger.Error(ex);
            }

            return(Json(new { success, tempFile, message, returnUrl }));
        }
Beispiel #9
0
        public ActionResult UploadPackage(FormCollection form, string returnUrl = "")
        {
            var isTheme = false;

            try
            {
                var file = Request.Files["packagefile"].ToPostedFileResult();
                if (file != null)
                {
                    var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName))
                        ? Permissions.Configuration.Theme.Upload
                        : Permissions.Configuration.Plugin.Upload;

                    if (!Services.Permissions.Authorize(requiredPermission))
                    {
                        return(AccessDeniedView());
                    }

                    if (!file.FileExtension.IsCaseInsensitiveEqual(".nupkg"))
                    {
                        NotifyError(T("Admin.Packaging.NotAPackage"));
                        return(RedirectToReferrer(returnUrl));
                    }

                    var location = CommonHelper.MapPath("~/App_Data");
                    var appPath  = CommonHelper.MapPath("~/");

                    if (isTheme)
                    {
                        // Avoid getting terrorized by IO events.
                        _themeRegistry.Value.StopMonitoring();
                    }

                    var packageInfo = _packageManager.Install(file.Stream, location, appPath);

                    if (isTheme)
                    {
                        // Create manifest.
                        if (packageInfo != null)
                        {
                            var manifest = ThemeManifest.Create(packageInfo.ExtensionDescriptor.Path);
                            if (manifest != null)
                            {
                                _themeRegistry.Value.AddThemeManifest(manifest);
                            }
                        }

                        // SOFT start IO events again.
                        _themeRegistry.Value.StartMonitoring(false);
                    }
                }
                else
                {
                    NotifyError(T("Admin.Common.UploadFile"));
                    return(RedirectToReferrer(returnUrl));
                }

                if (!isTheme)
                {
                    Services.WebHelper.RestartAppDomain();
                }

                NotifySuccess(T("Admin.Packaging.InstallSuccess"));
            }
            catch (Exception ex)
            {
                NotifyError(ex);
                Logger.Error(ex);
            }

            return(RedirectToReferrer(returnUrl));
        }