Esempio n. 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);
        }
        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));
            }
        }
        /// <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);
        }
Esempio n. 4
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);
        }
        /// <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();
            }
        }