/// <summary>Loads SLK configuration information from WSS and LearningStore, in a form that's /// suitable for copying to Configure.aspx form fields. </summary> /// /// <param name="spSiteGuid">The GUID of the SPSite to retrieve configuration information /// from.</param> /// /// <returns>An AdministrationConfiguration.</returns> /// /// <remarks> /// This method is static so it can used outside the context of IIS. Only SharePoint /// administrators can perform this function. /// </remarks> /// /// <exception cref="SafeToDisplayException"> /// An error occurred that can be displayed to a browser user. /// </exception> /// public static AdministrationConfiguration LoadConfiguration(Guid spSiteGuid) { AdministrationConfiguration configuration = new AdministrationConfiguration(spSiteGuid); // only SharePoint administrators can perform this action CheckPermissions(); // set <mapping> to the mapping between <spSiteGuid> and the LearningStore connection // information for that SPSite SlkSPSiteMapping mapping = SlkSPSiteMapping.GetMapping(spSiteGuid); // set "out" parameters based on <mappingExists> and <mapping> if (mapping != null) { // the mapping exists -- set "out" parameters based on <mapping> configuration.DatabaseServer = mapping.DatabaseServer; configuration.DatabaseName = mapping.DatabaseName; configuration.InstructorPermission = mapping.InstructorPermission; configuration.LearnerPermission = mapping.LearnerPermission; // The below given condition will be true only during the migration of SLK from // 'SLK without Observer role' to 'SLK with Observer role' implementation if (mapping.ObserverPermission == null) { mapping.ObserverPermission = LoadCulture(spSiteGuid).Resources.DefaultSlkObserverPermissionName; } configuration.ObserverPermission = mapping.ObserverPermission; } else { SlkCulture siteCulture = LoadCulture(spSiteGuid); AppResourcesLocal adminResources = SlkCulture.GetResources(); configuration.IsNewConfiguration = true; mapping = SlkSPSiteMapping.CreateMapping(spSiteGuid); // the mapping doesn't exist -- set "out" parameters to default values SPWebService adminWebService = SlkAdministration.GetAdminWebService(); configuration.DatabaseServer = adminWebService.DefaultDatabaseInstance.Server.Address; configuration.DatabaseName = adminResources.DefaultSlkDatabaseName; mapping.DatabaseServer = configuration.DatabaseServer; mapping.DatabaseName = configuration.DatabaseName; configuration.InstructorPermission = siteCulture.Resources.DefaultSlkInstructorPermissionName; configuration.LearnerPermission = siteCulture.Resources.DefaultSlkLearnerPermissionName; configuration.ObserverPermission = siteCulture.Resources.DefaultSlkObserverPermissionName; } // set "out" parameters that need to be computed bool createDatabaseResult = false; SlkUtilities.ImpersonateAppPool(delegate() { createDatabaseResult = !DatabaseExists(mapping.DatabaseServerConnectionString, mapping.DatabaseName); }); configuration.CreateDatabase = createDatabaseResult; return(configuration); }
/// <summary> /// Saves SLK configuration information. This method accepts information in a form that's /// compatible with Configure.aspx form fields. /// </summary> /// /// <param name="spSiteGuid">The GUID of the SPSite being configured.</param> /// /// <param name="databaseServer">The name of the database server to associate with the /// specified SPSite. By default, integrated authentication is used to connect to the /// database; to use a SQL Server user ID and password instead, append the appropriate /// connection string information to the database server name -- for example, instead of /// "MyServer", use "MyServer;user id=myacct;password=mypassword". For security reasons, /// integrated authentication is strongly recommended.</param> /// /// <param name="databaseName">The name of the database to associate with the specified /// SPSite. This database must exist if <paramref name="schemaToCreateDatabase"/> is /// <c>null</c>, and must not exist if <paramref name="schemaToCreateDatabase"/> is /// non-<c>null</c>, otherwise an error message is returned.</param> /// /// <param name="schemaToCreateDatabase">If non-<c>null</c>, this is the SlkSchema.sql file /// containing the schema of the database, and an SLK database named /// <paramref name="databaseName"/> is created using this schema. If <c>null</c>, /// <paramref name="databaseName"/> specifies an existing database.</param> /// /// <param name="instructorPermission">The name of the SharePoint permission that /// identifies instructors.</param> /// /// <param name="learnerPermission">The name of the SharePoint permission that /// identifies learners.</param> /// /// <param name="observerPermission">The name of the SharePoint permission that /// identifies observers.</param> /// /// <param name="createPermissions">If <c>true</c>, the permissions specified by /// <paramref name="instructorPermission"/> and <paramref name="learnerPermission"/> /// are added to the root SPWeb of the specified SPSite (if they don't already /// exist).</param> /// /// <param name="settingsFileContents">If not <c>null</c>, this is the contents of a SLK /// Settings file to associate with this SPSite. If <c>null</c>, the previous SLK /// Settings file is used if one exists, or the default SLK settings file is used if a /// database is being created.</param> /// /// <param name="defaultSettingsFileContents">The contents of the default SLK Settings file. /// Must not be <n>null</n>.</param> /// /// <param name="appPoolAccountName">The name of the application pool account; for example, /// "NT AUTHORITY\NETWORK SERVICE". If <n>null</n>, then the current Windows identity is /// used, or, if the current identity is impersonated, the original Windows identity is /// used.</param> /// /// <remarks> /// This method is static so it can used outside the context of IIS. Only SharePoint /// administrators can perform this function. /// </remarks> /// /// <exception cref="SafeToDisplayException"> /// An error occurred that can be displayed to a browser user. /// </exception> /// public static void SaveConfiguration(Guid spSiteGuid, string databaseServer, string databaseName, string schemaToCreateDatabase, string instructorPermission, string learnerPermission, string observerPermission, bool createPermissions, string settingsFileContents, string defaultSettingsFileContents, string appPoolAccountName) { CheckParameters(databaseServer, databaseName, instructorPermission, learnerPermission, observerPermission, defaultSettingsFileContents); // only SharePoint administrators can perform this action CheckPermissions(); // set <mapping> to the mapping between <spSiteGuid> and the LearningStore connection information for that SPSite SlkSPSiteMapping mapping = SlkSPSiteMapping.GetMapping(spSiteGuid); if (mapping == null) { mapping = SlkSPSiteMapping.CreateMapping(spSiteGuid); } mapping.DatabaseServer = databaseServer; mapping.DatabaseName = databaseName; mapping.InstructorPermission = instructorPermission; mapping.LearnerPermission = learnerPermission; mapping.ObserverPermission = observerPermission; if (mapping.IsDirty) { mapping.Update(); } // create the database if specified if (schemaToCreateDatabase != null) { CreateDatabase(mapping, databaseName, appPoolAccountName, schemaToCreateDatabase); } // create permissions if specified if (createPermissions) { SlkCulture culture = LoadCulture(spSiteGuid); // create the permissions if they don't exist yet CreatePermission(spSiteGuid, instructorPermission, culture.Resources.SlkInstructorPermissionDescription, 0); CreatePermission(spSiteGuid, learnerPermission, culture.Resources.SlkLearnerPermissionDescription, 0); CreatePermission(spSiteGuid, observerPermission, culture.Resources.SlkObserverPermissionDescription, 0); } UpdateSlkSettings(mapping.DatabaseConnectionString, spSiteGuid, settingsFileContents, defaultSettingsFileContents); }