Пример #1
0
        /// <summary>
        /// Gets the view configuration.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="viewLocations">Locations where view files can be found.</param>
        /// <returns>Config for the given view if such config exists.</returns>
        protected DesignerViewConfigModel GetViewConfig(string view, IEnumerable <string> viewLocations)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (viewLocations == null)
            {
                throw new ArgumentNullException("viewLocations");
            }

            foreach (var viewLocation in viewLocations)
            {
                var expectedConfigFileName = viewLocation + "/" + DesignerViewPrefix + view + ".json";

                if (VirtualPathManager.FileExists(expectedConfigFileName))
                {
                    var fileStream = VirtualPathManager.OpenFile(expectedConfigFileName);

                    using (var streamReader = new StreamReader(fileStream))
                    {
                        var text = streamReader.ReadToEnd();
                        var designerViewConfigModel = new JavaScriptSerializer().Deserialize <DesignerViewConfigModel>(text);

                        this.PopulateComponentsScriptReferences(designerViewConfigModel);

                        return(designerViewConfigModel);
                    }
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Resolves the layout virtual path and ensures that file exist on the specified location.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <returns>
        /// If the provided template is not in pure MVC mode returns null.
        /// If the provided template is in pure MVC mode returns virtual path like "~/SfLayouts/some_title.master" and ensures that this path is pointing to existing resource.
        /// Otherwise returns null.
        /// </returns>
        public virtual string GetVirtualPath(Pages.Model.IPageTemplate template)
        {
            if (template.GetTemplateFramework() != PageTemplateFramework.Mvc)
            {
                return(null);
            }

            var hasTitle = template as IHasTitle;

            if (hasTitle == null)
            {
                return(null);
            }

            string templateTitle     = hasTitle.GetTitle();
            var    virtualBuilder    = this.CreateLayoutVirtualPathBuilder();
            var    layoutVirtualPath = virtualBuilder.BuildPathFromTitle(templateTitle);
            var    doesLayoutExist   = VirtualPathManager.FileExists(layoutVirtualPath);

            if (!doesLayoutExist)
            {
                layoutVirtualPath = null;
            }

            return(layoutVirtualPath);
        }
Пример #3
0
        /// <summary>
        /// Populates the script references.
        /// </summary>
        /// <param name="widgetName">Name of the widget.</param>
        /// <param name="viewConfigs">The view configs.</param>
        protected void PopulateScriptReferences(string widgetName, IEnumerable <KeyValuePair <string, DesignerViewConfigModel> > viewConfigs)
        {
            var packagesManager = new PackageManager();
            var packageName     = packagesManager.GetCurrentPackage();

            var designerWidgetName = FrontendManager.ControllerFactory.GetControllerName(typeof(DesignerController));

            var viewScriptReferences = new List <string>(this.views.Count());

            foreach (var view in this.views)
            {
                var scriptFileName = this.GetViewScriptFileName(view);
                var scriptPath     = this.GetScriptPath(scriptFileName, widgetName, packageName);
                if (VirtualPathManager.FileExists(scriptPath))
                {
                    viewScriptReferences.Add(this.GetScriptReferencePath(widgetName, scriptFileName));
                }
                else
                {
                    scriptPath = this.GetScriptPath(scriptFileName, designerWidgetName, packageName);
                    if (VirtualPathManager.FileExists(scriptPath))
                    {
                        viewScriptReferences.Add(this.GetScriptReferencePath(designerWidgetName, scriptFileName));
                    }
                }
            }

            var configuredScriptReferences = viewConfigs
                                             .Where(c => c.Value.Scripts != null)
                                             .SelectMany(c => c.Value.Scripts);

            this.scriptReferences = viewScriptReferences
                                    .Union(configuredScriptReferences)
                                    .Distinct();
        }
Пример #4
0
        public void RegisterVirtualPaths_CurrentAssembly_VirtualPathAndRouteRegistered()
        {
            Assembly       assembly     = Assembly.GetExecutingAssembly();
            PathDefinition vpDefinition = null;

            var initializer = new DummyInitializer();

            using (new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                ObjectFactory.Container.RegisterType <IResourceResolverStrategy, DummyResolverStrategy>(new ContainerControlledLifetimeManager());

                var strategy = (DummyResolverStrategy)ObjectFactory.Container.Resolve <IResourceResolverStrategy>();
                strategy.ExistsMock = (def, vp) =>
                {
                    vpDefinition = def;
                    return(true);
                };

                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();

                initializer.RegisterVirtualPathsPublic(new[] { assembly });

                VirtualPathManager.FileExists("~/" + FrontendManager.VirtualPathBuilder.GetVirtualPath(assembly));
            }

            Assert.AreNotEqual(0, RouteTable.Routes.Count, "No routes were registered.");
            Assert.IsNotNull(RouteTable.Routes.OfType <Route>().FirstOrDefault(r => r.Url == "Frontend-Assembly/Telerik.Sitefinity.Frontend.Test/{*Params}"));
            Assert.IsNotNull(vpDefinition, "Virtual path definition was not found.");
            Assert.AreEqual(vpDefinition.ResourceLocation, assembly.CodeBase, "The resolved virtual path definition was not expected.");
        }
Пример #5
0
        private string GetViewFilePath(string view, IEnumerable <string> viewLocations, Dictionary <string, string> viewFilesMappings)
        {
            // If view file mapping exists return it
            if (viewFilesMappings != null && viewFilesMappings.ContainsKey(view))
            {
                return(viewFilesMappings[view]);
            }

            // Search all locations for the view
            IEnumerable <string> viewExtensions = new string[] { "aspx", "ascx", "master", "cshtml", "vbhtml" };

            foreach (var viewLocation in viewLocations)
            {
                foreach (var viewExtension in viewExtensions)
                {
                    var expectedViewFileName = string.Format("{0}{1}{2}.{3}", viewLocation, DesignerViewPrefix, view, viewExtension);
                    if (VirtualPathManager.FileExists(expectedViewFileName))
                    {
                        return(expectedViewFileName);
                    }
                }
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// Gets the default template.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        private string GetDefaultTemplate(string path)
        {
            var templateText = string.Empty;

            if (VirtualPathManager.FileExists(path))
            {
                var fileStream = VirtualPathManager.OpenFile(path);

                using (var streamReader = new StreamReader(fileStream))
                {
                    templateText = streamReader.ReadToEnd();
                }
            }

            return(templateText);
        }
Пример #7
0
        private static string GetResourceOrMinified(string resourceKey)
        {
            if (!ResourceHelper.IsDebugMode)
            {
                var extensionIndex = resourceKey.LastIndexOf(".js");
                if (extensionIndex > 0 && !resourceKey.Contains(".min.js"))
                {
                    var minFilePath          = resourceKey.Insert(extensionIndex, ".min");
                    var minPathWithoutParams = resourceKey.Substring(0, extensionIndex) + ".min.js";

                    if (VirtualPathManager.FileExists(minPathWithoutParams) || VirtualPathManager.FileExists(minFilePath))
                    {
                        resourceKey = minFilePath;
                    }
                }
            }

            return(resourceKey);
        }
Пример #8
0
        /// <summary>
        /// Creates and populates the user profiles.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="profileProperties">A dictionary containing the profile properties.</param>
        protected virtual void CreateUserProfiles(User user, IDictionary <string, string> profileProperties)
        {
            if (string.IsNullOrEmpty(this.ProfileBindings))
            {
                if (!VirtualPathManager.FileExists(RegistrationModel.ProfileBindingsFile))
                {
                    return;
                }

                var fileStream = VirtualPathManager.OpenFile(RegistrationModel.ProfileBindingsFile);
                using (var streamReader = new StreamReader(fileStream))
                {
                    this.ProfileBindings = streamReader.ReadToEnd();
                }
            }

            var profiles           = new JavaScriptSerializer().Deserialize <List <ProfileBindingsContract> >(this.ProfileBindings);
            var userProfileManager = UserProfileManager.GetManager();

            using (new ElevatedModeRegion(userProfileManager))
            {
                foreach (var profileBinding in profiles)
                {
                    var userProfile = userProfileManager.CreateProfile(user, profileBinding.ProfileType);
                    foreach (var property in profileBinding.Properties)
                    {
                        var value = profileProperties.GetValueOrDefault(property.Name);
                        userProfile.SetValue(property.FieldName, value);
                    }

                    userProfileManager.RecompileItemUrls(userProfile);
                }

                userProfileManager.SaveChanges();
            }
        }