Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Registers the types and resolvers related to the layouts functionality.
        /// </summary>
        public virtual void Initialize()
        {
            ObjectFactory.Container.RegisterType <ILayoutResolver, LayoutResolver>(new ContainerControlledLifetimeManager());
            ObjectFactory.Container.RegisterType <IVirtualFileResolver, LayoutMvcPageResolver>("PureMvcPageResolver", new ContainerControlledLifetimeManager(), new InjectionConstructor());

            VirtualPathManager.AddVirtualFileResolver <LayoutVirtualFileResolver>(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}{1}{2}", "~/", LayoutVirtualFileResolver.ResolverPath, "*"), typeof(LayoutVirtualFileResolver).FullName);
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void GetVirtualPath_IPageTemplate_ReturnsNull()
        {
            //Arrange
            LayoutResolver resolver = new LayoutResolver();
            DummyFrameworkSpecificPageTemplate dummyPageTemplate = new DummyFrameworkSpecificPageTemplate(PageTemplateFramework.Mvc);

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();

                VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(LayoutResolverTests.testVp, "DummyVirtualFileResolver");

                //Act
                try
                {
                    var resolvedVirtualPath = resolver.GetVirtualPath(dummyPageTemplate);

                    //Assert
                    Assert.IsNull(resolvedVirtualPath, "Resolved VirtualPath should be null.");
                }
                finally
                {
                    VirtualPathManager.RemoveVirtualFileResolver(LayoutResolverTests.testVp);
                }
            }
        }
Ejemplo n.º 8
0
        public void GetVirtualPath_InvalidCharacters_ReturnsCleanVirtualPath()
        {
            //Arrange
            string         dirtyTitle       = "Some<>*Test:?Title";
            string         cleanVirtualPath = "~/SfLayouts/Some_Test_Title.master";
            string         resolvedVirtualPath;
            LayoutResolver resolver = new LayoutResolver();

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(),
                                                                                    new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();
                VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(LayoutResolverTests.testVp, "DummyVirtualFileResolver");

                var dummyPageTemplate = new DummyPageTemplateWithTitle(PageTemplateFramework.Mvc, dirtyTitle);

                //Act
                try
                {
                    resolvedVirtualPath = resolver.GetVirtualPath(dummyPageTemplate);

                    //Assert
                    Assert.AreEqual(cleanVirtualPath, resolvedVirtualPath, "GetVirtualPath method doesn't return correct string.");
                }
                finally
                {
                    VirtualPathManager.RemoveVirtualFileResolver(LayoutResolverTests.testVp);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Registers the types and resolvers related to the layouts functionality.
        /// </summary>
        public virtual void Initialize()
        {
            ObjectFactory.Container.RegisterType <ILayoutResolver, LayoutResolver>(new ContainerControlledLifetimeManager());

            VirtualPathManager.AddVirtualFileResolver <LayoutVirtualFileResolver>("~/" + LayoutVirtualFileResolver.ResolverPath + "*",
                                                                                  typeof(LayoutVirtualFileResolver).FullName);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticFilesModule" /> class.
        /// </summary>
        /// <param name="fileSystemPath">The file system path.</param>
        /// <param name="headers">The headers to set in every request.</param>
        /// <param name="additionalPaths">The additional paths.</param>
        /// <param name="useDirectoryBrowser">if set to <c>true</c> [use directory browser].</param>
        /// <param name="cacheMappedPaths">if set to <c>true</c>, [cache mapped paths].</param>
        /// <exception cref="ArgumentException">Path ' + fileSystemPath + ' does not exist.</exception>
        public StaticFilesModule(
            string fileSystemPath,
            Dictionary <string, string> headers         = null,
            Dictionary <string, string> additionalPaths = null,
            bool useDirectoryBrowser = false,
            bool cacheMappedPaths    = true)
        {
            if (!Directory.Exists(fileSystemPath))
            {
                throw new ArgumentException($"Path '{fileSystemPath}' does not exist.");
            }

            _virtualPathManager = new VirtualPathManager(Path.GetFullPath(fileSystemPath), useDirectoryBrowser, cacheMappedPaths);

            DefaultDocument = DefaultDocumentName;
            UseGzip         = true;
#if DEBUG
            // When debugging, disable RamCache
            UseRamCache = false;
#else
            UseRamCache = true;
#endif

            headers?.ForEach(DefaultHeaders.Add);
            additionalPaths?.ForEach((virtualPath, physicalPath) =>
            {
                if (virtualPath != "/")
                {
                    RegisterVirtualPath(virtualPath, physicalPath);
                }
            });

            AddHandler(ModuleMap.AnyPath, HttpVerbs.Head, (context, ct) => HandleGet(context, ct, false));
            AddHandler(ModuleMap.AnyPath, HttpVerbs.Get, (context, ct) => HandleGet(context, ct));
        }
Ejemplo n.º 11
0
        private static void Bootstrapper_Initialized(object sender, ExecutedEventArgs e)
        {
            if (e.CommandName == "Bootstrapped")
            {
                VirtualPathManager.AddVirtualFileResolver <FormsVirtualRazorResolver>(FormsVirtualRazorResolver.Path + "*", "MvcFormsResolver");

                Initializer.UnregisterTemplatableControl();
                Initializer.AddFieldsToToolbox();
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Registers the types and resolvers related to the layouts functionality.
        /// </summary>
        public virtual void Initialize()
        {
            ObjectFactory.Container.RegisterType <ILayoutResolver, LayoutResolver>(new ContainerControlledLifetimeManager());
            ObjectFactory.Container.RegisterType <IVirtualFileResolver, LayoutMvcPageResolver>("PureMvcPageResolver", new ContainerControlledLifetimeManager(), new InjectionConstructor());

            VirtualPathManager.AddVirtualFileResolver <LayoutVirtualFileResolver>(string.Format(System.Globalization.CultureInfo.InvariantCulture, "~/{0}*", LayoutVirtualFileResolver.ResolverPath), typeof(LayoutVirtualFileResolver).FullName);
            ObjectFactory.Container.RegisterType <PageRouteHandler, MvcPageRouteHandler>();
            ObjectFactory.Container.RegisterType <PageEditorRouteHandler, MvcPageEditorRouteHandler>();
            ObjectFactory.Container.RegisterType <TemplateEditorRouteHandler, MvcTemplateEditorRouteHandler>();
            System.Web.Routing.RouteTable.Routes.Insert(1, new System.Web.Routing.Route("Sitefinity/Versioning/{itemId}/{VersionNumber}", ObjectFactory.Resolve <MvcVersioningRouteHandler>()));
        }
Ejemplo n.º 13
0
        private void RegisterAssemblyPaths(Assembly assembly)
        {
            var assemblyName = assembly.GetName();
            var virtualPath  = FrontendManager.VirtualPathBuilder.GetVirtualPath(assembly);

            VirtualPathManager.AddVirtualFileResolver <ResourceResolver>("~/" + virtualPath + "*", assemblyName.Name,
                                                                         assemblyName.CodeBase);

            SystemManager.RegisterRoute(assemblyName.Name, new Route(virtualPath + "{*Params}", new RouteHandler <ResourceHttpHandler>()),
                                        assemblyName.Name, requireBasicAuthentication: false);
        }
Ejemplo n.º 14
0
        private static Dictionary <string, ScriptDependencyConfigModel> InitializeComponentsDefinitions()
        {
            var assemblyPath = FrontendManager.VirtualPathBuilder.GetVirtualPath(typeof(ComponentsDependencyResolver).Assembly);
            var filename     = "client-components/components-definitions.json";

            var fileStream = VirtualPathManager.OpenFile("~/" + assemblyPath + filename);

            using (var streamReader = new StreamReader(fileStream))
            {
                var text = streamReader.ReadToEnd();
                return((new JavaScriptSerializer()).Deserialize <Dictionary <string, ScriptDependencyConfigModel> >(text));
            }
        }
Ejemplo n.º 15
0
 private void ConfigManager_Executed(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
 {
     if (args.CommandName == "SaveSection")
     {
         var section = args.CommandArguments as VirtualPathSettingsConfig;
         if (section != null)
         {
             // Reset the VirtualPathManager whenever we save the VirtualPathConfig section.
             // This is needed so that our prefixes for the widget templates in the module assembly are taken into account.
             VirtualPathManager.Reset();
         }
     }
 }
Ejemplo n.º 16
0
        internal static string AppendVersion(string contentPath)
        {
            if (contentPath.EndsWith(".js") || contentPath.Contains(".js?"))
            {
                var hash = VirtualPathManager.GetFileHash(contentPath, null);
                if (hash != null)
                {
                    var bytes         = Encoding.UTF8.GetBytes(hash);
                    var base64version = Convert.ToBase64String(bytes);
                    contentPath = UrlTransformations.AppendParam(contentPath, VersionQueryParam, base64version);
                }
            }

            return(contentPath);
        }
Ejemplo n.º 17
0
        public void PopulateScriptReferences_ViewsCollection_ConstructScriptReferencesCollection()
        {
            // TODO: Reduce class coupling
            // Arrange
            string widgetName = "Dummy";
            var    views      = new List <string>();

            views.Add("DesignerView.someViewName");
            var designerViewConfigs = this.CreateDummyDesignerViewConfigModel();

            using (var objFactory = new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(), new InjectionConstructor(typeof(XmlConfigProvider).Name));
                ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>();
                Config.RegisterSection <VirtualPathSettingsConfig>();
                Config.RegisterSection <ControlsConfig>();
                Config.RegisterSection <ResourcesConfig>();

                using (var factoryReg = new ControllerFactoryRegion <DummyControllerFactory>())
                {
                    factoryReg.Factory.ControllerRegistry["Dummy"]    = typeof(DummyController);
                    factoryReg.Factory.ControllerRegistry["Designer"] = typeof(DesignerController);

                    var fileResolverPrefix = "~/Frontend-Assembly";
                    VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(fileResolverPrefix + "*", "DummyVirtualFileResolver");

                    var dummyModel = new DummyDesignerModel(views, new List <string>(), widgetName, Guid.Empty, "someViewName");

                    try
                    {
                        // Act
                        dummyModel.PopulateScriptReferencesPublic(widgetName, designerViewConfigs);
                    }
                    finally
                    {
                        VirtualPathManager.RemoveVirtualFileResolver(fileResolverPrefix);
                        VirtualPathManager.Reset();
                    }

                    // Assert
                    Assert.AreEqual(4, dummyModel.ScriptReferences.Count(), "The script count is not as expected.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains("Mvc/Scripts/Dummy/designerview-someviewname.js"), "ScriptReferences doesn't contain scripts for the view.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script1), "ScriptReferences doesn't contain expected scripts.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script2), "ScriptReferences doesn't contain expected scripts.");
                    Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script3), "ScriptReferences doesn't contain expected scripts.");
                }
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        private void RegisterAssemblyPaths(Assembly assembly)
        {
            var assemblyName = assembly.GetName();
            var virtualPath  = FrontendManager.VirtualPathBuilder.GetVirtualPath(assembly);

            VirtualPathManager.AddVirtualFileResolver <ResourceResolver>(
                string.Format(CultureInfo.InvariantCulture, "~/{0}*", virtualPath),
                assemblyName.Name,
                assemblyName.CodeBase);

            SystemManager.RegisterRoute(
                assemblyName.Name,
                new Route(
                    virtualPath + "{*Params}",
                    new GenericRouteHandler <ResourceHttpHandler>(() => new ResourceHttpHandler(virtualPath))),
                assemblyName.Name,
                requireBasicAuthentication: false);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Generates the view configuration if its missing from the file system.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="viewLocations">Locations where view files can be found.</param>
        /// <param name="viewFilesMappings">Map of the view file location for each view.</param>
        /// <returns>Config for the given view.</returns>
        protected DesignerViewConfigModel GenerateViewConfig(string view, IEnumerable <string> viewLocations, Dictionary <string, string> viewFilesMappings)
        {
            var viewFilePath = this.GetViewFilePath(view, viewLocations, viewFilesMappings);

            if (!string.IsNullOrEmpty(viewFilePath))
            {
                using (var fileStream = VirtualPathManager.OpenFile(viewFilePath))
                {
                    var components = ComponentsDependencyResolver.ExtractComponents(fileStream);
                    var scripts    = ComponentsDependencyResolver.GetScripts(components, null);

                    // If view that exists has been parsed and no components are used in it - no point in cycling trough the other views
                    return(new DesignerViewConfigModel()
                    {
                        Scripts = scripts, Components = components, IsGenerated = true
                    });
                }
            }

            return(null);
        }
Ejemplo n.º 22
0
        private static string GenerateVirtualPath(string path)
        {
            var virtualPathConfig      = Telerik.Sitefinity.Configuration.Config.Get <VirtualPathSettingsConfig>();
            VirtualPathElement element = null;

            virtualPathConfig.VirtualPaths.TryGetValue("~/SFAkismet/*", out element);
            if (element == null)
            {
                var jobsModuleVirtualPathConfig = new VirtualPathElement(virtualPathConfig.VirtualPaths)
                {
                    VirtualPath      = "~/SFAkismet/*",
                    ResolverName     = "EmbeddedResourceResolver",
                    ResourceLocation = "AkismetModule"
                };
                virtualPathConfig.VirtualPaths.Add(jobsModuleVirtualPathConfig);
                ConfigManager.GetManager().SaveSection(virtualPathConfig);
                VirtualPathManager.Reset();
            }

            return("~/SFAkismet/" + path);
        }
Ejemplo n.º 23
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();
            }
        }