Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private static ResourceBase CreateResource(string resourceName, CultureInfo culture, string resourceLocation)
        {
            Func <string, string> fixResourceName = c => resourceName + ((c != null) ? "." + c : string.Empty) + ".resx";

            IVirtualPathProvider vpp = DI.Current.Resolve <IVirtualPathProvider>();

            // First try the file path Resource.fr-CA.resx
            string fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.ToString()));
            bool   exists           = vpp.FileExists(fullResourcePath);

            // If not found, try Resource.fr.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.TwoLetterISOLanguageName));
                exists           = vpp.FileExists(fullResourcePath);
            }

            // If nothing is found try Resource.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(null));
                exists           = vpp.FileExists(fullResourcePath);
            }

            ResourceBase resource = exists ?
                                    new ResXResource(DI.Current.Resolve <IPathResolver>().Resolve(fullResourcePath)) :
                                    new EmbeddedResource(resourceName, culture) as ResourceBase;

            return(resource);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the path to the script.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <param name="version">The version.</param>
        /// <param name="extensions">The collection of extensions.</param>
        /// <returns>The path.</returns>
        private string ProbePath(string virtualPath, string version, IEnumerable <string> extensions)
        {
            string result = null;

            Func <string, string> fixPath = path =>
            {
                string directory = _virtualPathProvider.GetDirectory(path);
                string fileName  = _virtualPathProvider.GetFile(path);

                if (!directory.EndsWith(version + Path.AltDirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
                {
                    string newDirectory = _virtualPathProvider.CombinePaths(directory, version);
                    string newPath      = newDirectory + Path.AltDirectorySeparatorChar + fileName;

                    if (_virtualPathProvider.FileExists(newPath))
                    {
                        return(newPath);
                    }
                }

                return(path);
            };

            foreach (string extension in extensions)
            {
                string changedPath    = Path.ChangeExtension(virtualPath, extension);
                string newVirtualPath = string.IsNullOrEmpty(version) ? changedPath : fixPath(changedPath);

                if (_virtualPathProvider.FileExists(newVirtualPath))
                {
                    result = newVirtualPath;
                    break;
                }
            }

            if (string.IsNullOrEmpty(result))
            {
                result = virtualPath;

                if (!_virtualPathProvider.FileExists(result))
                {
                    throw new FileNotFoundException("The specified file does not exist : '" + result + "'");
                }
            }

            // Return the virtual file.
            return(result);
        }
        public void PopulateConfiguration(CKEditorConfigContext config)
        {
            // Get CKEditor settings
            var ckSettings = Services.WorkContext.CurrentSite.As <CKEditorSettingsPart>();

            if (ckSettings != null)
            {
                if (!String.IsNullOrWhiteSpace(ckSettings.ContentsCss))
                {
                    // Push css link(s) into config
                    var currentTheme = _siteThemeService.GetSiteTheme();
                    var sheets       =
                        // Get list of stylesheets
                        ckSettings.ContentsCss.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                        // Transform to full URLs
                        .Select(sheet => string.Format("{0}/{1}/Styles/{2}", currentTheme.Location, currentTheme.Id, sheet))
                        .Where(path => _virtualPathProvider.FileExists(path)).Select(path => UrlHelper.GenerateContentUrl(path, Services.WorkContext.HttpContext)).ToList(); // Execute at this time to avoid trouble later
                    config.Add(new CKEditorConfigStringList("contentsCss", sheets));
                }
                if (!String.IsNullOrWhiteSpace(ckSettings.ExtraPlugins))
                {
                    // TODO: Plugins should add modularly from an ICKEditorPlugin interface?
                    var plugins =
                        ckSettings.ExtraPlugins;

                    config.Add(new CKEditorConfigString("extraPlugins", plugins));
                }
                // For removing standard styles if stylesheet parser is used
                if (ckSettings.ClearDefaultStyleSets)
                {
                    config.Add(new CKEditorConfigStringList("stylesSet", Enumerable.Empty <String>()));
                }
            }
        }
        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());
                    }
                }
            }
        }
Exemplo n.º 6
0
        protected override DriverResult Editor(WidgetsContainerPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_WidgetsContainer", () => {
                var settings = part.Settings.GetModel <WidgetsContainerSettings>();

                var currentTheme = _siteThemeService.GetSiteTheme();
                var currentThemesZones = _widgetsService.GetZones(currentTheme).ToList();
                var widgetTypes = _widgetsService.GetWidgetTypeNames().ToList();
                if (!settings.UseHierarchicalAssociation)
                {
                    if (!string.IsNullOrWhiteSpace(settings.AllowedZones))
                    {
                        currentThemesZones = currentThemesZones.Where(x => settings.AllowedZones.Split(',').Contains(x)).ToList();
                    }
                    if (!string.IsNullOrWhiteSpace(settings.AllowedWidgets))
                    {
                        widgetTypes = widgetTypes.Where(x => settings.AllowedWidgets.Split(',').Contains(x)).ToList();
                    }
                }
                else if (settings.HierarchicalAssociation != null && settings.HierarchicalAssociation.Count() > 0)
                {
                    currentThemesZones = currentThemesZones.Where(ctz => settings.HierarchicalAssociation.Select(x => x.ZoneName).Contains(ctz)).ToList();
                    widgetTypes = widgetTypes.Where(w => settings.HierarchicalAssociation.Any(x => x.Widgets.Any(a => a.WidgetType == w || a.WidgetType == "All"))).ToList();
                }

                var widgets = _widgetManager.GetWidgets(part.Id, false);

                var zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
                var zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;

                var layer = _widgetsService.GetLayers().First();

                // recupero i contenuti localizzati una try è necessaria in quanto non è detto che un contenuto sia localizzato
                dynamic contentLocalizations;
                try {
                    contentLocalizations = _localizationService
                                           .GetLocalizations(part.ContentItem, VersionOptions.Latest) //the other cultures
                                           .Where(lp =>                                               //as long as a culture has been assigned
                                                  lp.Culture != null && !string.IsNullOrWhiteSpace(lp.Culture.Culture))
                                           .OrderBy(o => o.Culture.Culture)
                                           .ToList();
                } catch {
                    contentLocalizations = null;
                }

                var viewModel = New.ViewModel()
                                .CurrentTheme(currentTheme)
                                .Zones(currentThemesZones)
                                .ContentLocalizations(contentLocalizations)
                                .ZonePreviewImage(zonePreviewImage)
                                .WidgetTypes(widgetTypes)
                                .Widgets(widgets)
                                .ContentItem(part.ContentItem)
                                .LayerId(layer.Id)
                                .CloneFrom(0);

                return shapeHelper.EditorTemplate(TemplateName: "Parts.WidgetsContainer", Model: viewModel, Prefix: Prefix);
            }));
        }
Exemplo n.º 7
0
        private bool TryPath(string path, string modifier, out string result)
        {
            var directory   = virtualPathProvider.GetDirectory(path);
            var fileName    = virtualPathProvider.GetFile(path);
            var pathToProbe = modifier.HasValue() ? virtualPathProvider.CombinePaths(directory, modifier) + Path.AltDirectorySeparatorChar + fileName : path;

            result = virtualPathProvider.FileExists(pathToProbe) ? pathToProbe : null;

            return(result != null);
        }
Exemplo n.º 8
0
        /// <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 string GetAssemblyPath(ExtensionDescriptor descriptor)
        {
            var assemblyPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id, "bin",
                                                            descriptor.Id + ".dll");

            if (!_virtualPathProvider.FileExists(assemblyPath))
            {
                return(null);
            }

            return(assemblyPath);
        }
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        private string ReadFile(string fileName)
        {
            if (!fileName.StartsWith("~"))
            {
                fileName = string.Format("~/Content/{0}", fileName);
            }

            if (!provider.FileExists(fileName))
            {
                throw new FileNotFoundException(Resources.Exceptions.SpecifiedFileDoesNotExist.FormatWith(fileName));
            }

            return(provider.ReadAllText(fileName));
        }
        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;
            }
        }
Exemplo n.º 14
0
        /// <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>(),
            });
        }
Exemplo n.º 15
0
        private void DeleteAssembly(ExtensionLoadingContext ctx, string moduleName)
        {
            var assemblyPath = _virtualPathProvider.Combine("~/bin", moduleName + ".dll");

            if (!_virtualPathProvider.FileExists(assemblyPath))
            {
                return;
            }
            ctx.DeleteActions.Add(
                () =>
            {
                Logger.Information("ExtensionRemoved: 从 bin 目录删除程序集 \"{0}\"(AppDomain将重新启动)", moduleName);
                _virtualPathProvider.DeleteFile(assemblyPath);
            });
            ctx.RestartAppDomain = true;
        }
Exemplo n.º 16
0
        public ActionResult Index(int?layerId)
        {
            ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();

            if (currentTheme == null)
            {
                Services.Notifier.Error(T("To manage widgets you must have a theme enabled."));
                return(RedirectToAction("Index", "Admin", new { area = "Dashboard" }));
            }

            IEnumerable <LayerPart> layers = _widgetsService.GetLayers().ToList();

            if (!layers.Any())
            {
                Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site."));
                return(RedirectToAction("AddLayer"));
            }

            LayerPart currentLayer = layerId == null
                ? layers.FirstOrDefault()
                : layers.FirstOrDefault(layer => layer.Id == layerId);

            if (currentLayer == null && layerId != null)   // Incorrect layer id passed
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

            IEnumerable <string> allZones           = _widgetsService.GetZones();
            IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme);

            string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
            string zonePreviewImage     = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;

            dynamic viewModel = Shape.ViewModel()
                                .CurrentTheme(currentTheme)
                                .CurrentLayer(currentLayer)
                                .Layers(layers)
                                .Widgets(_widgetsService.GetWidgets())
                                .Zones(currentThemesZones)
                                .OrphanZones(allZones.Except(currentThemesZones))
                                .OrphanWidgets(_widgetsService.GetOrphanedWidgets())
                                .ZonePreviewImage(zonePreviewImage);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)viewModel));
        }
Exemplo n.º 17
0
        //public ITestModel CreateTestModelFor(BaseEntity entity, string modelPrefix)
        //{
        //    return new TestDrop(entity, modelPrefix);
        //   }

        private string ReadTemplateFileInternal(string virtualPath)
        {
            if (virtualPath.IsEmpty())
            {
                return(string.Empty);
            }

            if (!_vpp.FileExists(virtualPath))
            {
                throw new FileNotFoundException($"Include file '{virtualPath}' does not exist.");
            }

            using (var stream = _vpp.OpenFile(virtualPath))
            {
                return(stream.AsString());
            }
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 protected SkinsManifest GetSkinsManifest()
 {
     if (_skinsManifest == null)
     {
         _skinsManifest = new SkinsManifest();
         var themePath = GetThemePath();
         // find the manifest
         var manifestFile = PathCombine(themePath, "skinsconfig.json");
         if (_virtualPathProvider.FileExists(manifestFile))
         {
             using (var manifestStream = _virtualPathProvider.OpenFile(manifestFile)) {
                 using (var reader = new StreamReader(manifestStream)) {
                     _skinsManifest = JsonConvert.DeserializeObject <SkinsManifest>(reader.ReadToEnd());
                 }
             }
         }
     }
     return(_skinsManifest);
 }
Exemplo n.º 20
0
        public string GetLocalResourceContent(CombinatorResource resource)
        {
            var relativeVirtualPath = resource.RelativeVirtualPath;

            // Maybe TryFileExists would be better?
            if (!_virtualPathProvider.FileExists(relativeVirtualPath))
            {
                throw new OrchardException(T("Local resource file not found under {0}", relativeVirtualPath));
            }

            string content;

            using (var stream = _virtualPathProvider.OpenFile(relativeVirtualPath))
            {
                content = new StreamReader(stream).ReadToEnd();
            }

            return(content);
        }
Exemplo n.º 21
0
        private string ReadFile(string fileName)
        {
            if (fileName.IndexOf("://") < 0)
            {
                fileName = fileName.StartsWith("~/", StringComparison.OrdinalIgnoreCase) ? fileName : PathHelper.CombinePath(WebAssetDefaultSettings.StyleSheetFilesPath, fileName);
            }

            if (!fileName.StartsWith("~"))
            {
                fileName = string.Format("~/Content/{0}", fileName);
            }

            if (!provider.FileExists(fileName))
            {
                throw new FileNotFoundException(Resources.TextResource.SpecifiedFileDoesNotExist.FormatWith(fileName));
            }

            return(provider.ReadAllText(fileName));
        }
Exemplo n.º 22
0
        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;
            }));
        }
Exemplo n.º 23
0
        protected override DriverResult Editor(WidgetsContainerPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_WidgetsContainer", () => {
                var currentTheme = _siteThemeService.GetSiteTheme();
                var currentThemesZones = _widgetsService.GetZones(currentTheme).ToList();
                var widgetTypes = _widgetsService.GetWidgetTypeNames().ToList();
                var widgets = _widgetManager.GetWidgets(part.Id, VersionOptions.Latest);
                var zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
                var zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;
                var layer = _widgetsService.GetLayers().First();

                var viewModel = New.ViewModel()
                                .CurrentTheme(currentTheme)
                                .Zones(currentThemesZones)
                                .ZonePreviewImage(zonePreviewImage)
                                .WidgetTypes(widgetTypes)
                                .Widgets(widgets)
                                .ContentItem(part.ContentItem)
                                .LayerId(layer.Id);

                return shapeHelper.EditorTemplate(TemplateName: "Parts.WidgetsContainer", Model: viewModel, Prefix: Prefix);
            }));
        }
Exemplo n.º 24
0
 public bool FileExists(string virtualPath)
 {
     return(_virtualPathProvider.FileExists(virtualPath));
 }
Exemplo n.º 25
0
 public void FileExists_ReturnCorrectValue()
 {
     Provider.RootDirectory.CreateFile("File1.ext", "");
     Assert.That(Provider.FileExists("/File1.ext"), Is.True);
     Assert.That(Provider.FileExists("/xFiles"), Is.False);
 }
Exemplo n.º 26
0
        public ActionResult Index(int?layerId, string culture)
        {
            ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();

            if (currentTheme == null)
            {
                Services.Notifier.Error(T("To manage widgets you must have a theme enabled."));
                return(RedirectToAction("Index", "Admin", new { area = "Dashboard" }));
            }

            IEnumerable <LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList();

            if (!layers.Any())
            {
                Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site."));
                return(RedirectToAction("AddLayer"));
            }

            LayerPart currentLayer = layerId == null
                                     // look for the "Default" layer, or take the first if it doesn't exist
                ? layers.FirstOrDefault(x => x.Name == "Default") ?? layers.FirstOrDefault()
                : layers.FirstOrDefault(layer => layer.Id == layerId);

            if (currentLayer == null && layerId != null)   // Incorrect layer id passed
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

            IEnumerable <string> allZones           = _widgetsService.GetZones();
            IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme);

            string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
            string zonePreviewImage     = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;

            var widgets = _widgetsService.GetWidgets();

            if (!String.IsNullOrWhiteSpace(culture))
            {
                widgets = widgets.Where(x => {
                    if (x.Has <ILocalizableAspect>())
                    {
                        return(String.Equals(x.As <ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase));
                    }

                    return(false);
                }).ToList();
            }

            var viewModel = Shape.ViewModel()
                            .CurrentTheme(currentTheme)
                            .CurrentLayer(currentLayer)
                            .CurrentCulture(culture)
                            .Layers(layers)
                            .Widgets(widgets)
                            .Zones(currentThemesZones)
                            .Cultures(_cultureManager.ListCultures())
                            .OrphanZones(allZones.Except(currentThemesZones))
                            .OrphanWidgets(_widgetsService.GetOrphanedWidgets())
                            .ZonePreviewImage(zonePreviewImage);

            return(View(viewModel));
        }
Exemplo n.º 27
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 static bool IsFile(this IVirtualPathProvider pathProvider, string filePath)
 {
     return(pathProvider.FileExists(filePath));
 }
Exemplo n.º 29
0
 public bool fileExists(IVirtualPathProvider vfs, string virtualPath) => vfs.FileExists(virtualPath);
Exemplo n.º 30
0
        public bool HasReferencedAssembly(string name)
        {
            var assemblyPath = _virtualPathProvider.Combine("~/bin", name + ".dll");

            return(_virtualPathProvider.FileExists(assemblyPath));
        }
Exemplo n.º 31
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;
            }
        }