/// <summary>Initializes a new instance of <see cref="EmailSettings"/>.</summary> /// <param name="reader">The XmlReader containing the setting details.</param> public EmailSettings(XmlReader reader) { if (reader.IsEmptyElement == false) { reminderDaysInput = reader.GetAttribute("ReminderDays"); EmailOnSubmitOff = SlkSettings.BooleanAttribute(reader, "EmailOnSubmitOff"); DefaultEmailingOn = SlkSettings.BooleanAttribute(reader, "DefaultEmailingOn"); reader.Read(); while (reader.Name != "EmailSettings") { switch (reader.Name) { case "NewAssignment": NewAssignment = new EmailDetails(reader); break; case "CancelAssignment": CancelAssignment = new EmailDetails(reader); break; case "SubmitAssignment": SubmitAssignment = new EmailDetails(reader); break; case "ReactivateAssignment": ReactivateAssignment = new EmailDetails(reader); break; case "ReturnAssignment": ReturnAssignment = new EmailDetails(reader); break; case "CollectAssignment": CollectAssignment = new EmailDetails(reader); break; case "AssignmentReminder": AssignmentReminder = new EmailDetails(reader); break; default: reader.Read(); break; } } } // Do not Move off end element }
/// <summary>Initializes a new instance of <see cref="DropBoxSettings"/>.</summary> /// <param name="reader">The XmlReader containing the setting details.</param> public DropBoxSettings(XmlReader reader) { // Default the location Location = DropBoxLocation.SubSite; string location = reader.GetAttribute("Location"); if (string.IsNullOrEmpty(location) == false) { Location = (DropBoxLocation)Enum.Parse(typeof(DropBoxLocation), location, true); } Url = reader.GetAttribute("Url"); UseOfficeWebApps = SlkSettings.BooleanAttribute(reader, "UseOfficeWebApps"); OpenOfficeInIpadApp = SlkSettings.BooleanAttribute(reader, "OpenOfficeInIpadApp"); OpenSubmittedInSameWindow = SlkSettings.BooleanAttribute(reader, "OpenSubmittedInSameWindow"); }
private static SlkSettings LoadSettings(SlkSPSiteMapping mapping, SPSite site, XmlSchema xmlSchema) { // create a LearningStore. Read is in privileged scope so irrelevant what key is. // Cannot use current user as may be be called in a page PreInit event when it's not necessarily valid string learningStoreKey = "SHAREPOINT\\System"; LearningStore learningStore = new LearningStore(mapping.DatabaseConnectionString, learningStoreKey, ImpersonationBehavior.UseOriginalIdentity); // read the SLK Settings file from the database into <settings> SlkSettings settings; using (LearningStorePrivilegedScope privilegedScope = new LearningStorePrivilegedScope()) { LearningStoreJob job = learningStore.CreateJob(); LearningStoreQuery query = learningStore.CreateQuery(Schema.SiteSettingsItem.ItemTypeName); query.AddColumn(Schema.SiteSettingsItem.SettingsXml); query.AddColumn(Schema.SiteSettingsItem.SettingsXmlLastModified); query.AddCondition(Schema.SiteSettingsItem.SiteGuid, LearningStoreConditionOperator.Equal, mapping.SPSiteGuid); job.PerformQuery(query); DataRowCollection dataRows = job.Execute <DataTable>().Rows; if (dataRows.Count != 1) { throw new SafeToDisplayException(SlkCulture.GetResources().SlkSettingsNotFound, site.Url); } DataRow dataRow = dataRows[0]; string settingsXml = (string)dataRow[0]; DateTime settingsXmlLastModified = ((DateTime)dataRow[1]); using (StringReader stringReader = new StringReader(settingsXml)) { XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.Schemas.Add(xmlSchema); xmlSettings.ValidationType = ValidationType.Schema; using (XmlReader xmlReader = XmlReader.Create(stringReader, xmlSettings)) { settings = new SlkSettings(xmlReader, settingsXmlLastModified); } } } return(settings); }
/// <summary>Get the anonymous store.</summary> /// <param name="site">The site to get the settings for.</param> /// <returns></returns> public static AnonymousSlkStore GetStore(SPSite site) { Guid siteId = site.ID; // set <httpContext> to the current HttpContext (null if none) HttpContext httpContext = HttpContext.Current; // if an AnonymousSlkStore corresponding to <spSiteGuid> is cached, retrieve it, otherwise // create one string cacheItemName = null; AnonymousSlkStore anonymousSlkStore; if (httpContext != null) { cacheItemName = String.Format(CultureInfo.InvariantCulture, "SlkStore_{0}", siteId); anonymousSlkStore = (AnonymousSlkStore)httpContext.Cache.Get(cacheItemName); if (anonymousSlkStore != null) { return(anonymousSlkStore); } } // set <mapping> to the SlkSPSiteMapping corresponding to <siteId>; if no such // mapping, exists, a SafeToDisplayException is thrown SlkSPSiteMapping mapping = SlkSPSiteMapping.GetRequiredMapping(site); // load "SlkSettings.xsd" from a resource into <xmlSchema> XmlSchema xmlSchema; using (StringReader schemaStringReader = new StringReader(SlkCulture.GetDefaultResources().SlkSettingsSchema)) { xmlSchema = XmlSchema.Read(schemaStringReader, delegate(object sender2, ValidationEventArgs e2) { // ignore warnings (already displayed when SLK Settings file was uploaded) }); } SlkSettings settings = null; try { settings = LoadSettings(mapping, site, xmlSchema); } catch (SqlException) { // Try again in case temporary error try { settings = LoadSettings(mapping, site, xmlSchema); } catch (SqlException e) { SlkCulture culture = new SlkCulture(CultureInfo.InvariantCulture); SlkStore.LogError(culture.Resources.SlkSettingsSqlErrorLoad + " {0}", culture, e); throw new SafeToDisplayException(culture.Resources.SlkSettingsSqlErrorLoad); } } // create and (if possible) cache the new AnonymousSlkStore object anonymousSlkStore = new AnonymousSlkStore(siteId, mapping, settings); DateTime cacheExpirationTime = DateTime.Now.AddSeconds(HttpContextCacheTime); if (httpContext != null) { httpContext.Cache.Add(cacheItemName, anonymousSlkStore, null, cacheExpirationTime, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); } return(anonymousSlkStore); }
/////////////////////////////////////////////////////////////////////////////////////////////// // Public Methods // /// <summary> /// Initializes an instance of this class. /// </summary> /// /// <param name="spSiteGuid">The value to use to initialize the <c>SPSiteGuid</c> property. /// </param> /// /// <param name="mapping">The value to use to initialize the <c>Mapping</c> property. /// </param> /// /// <param name="settings">The value to use to initialize the <c>Settings</c> property. /// </param> /// public AnonymousSlkStore(Guid spSiteGuid, SlkSPSiteMapping mapping, SlkSettings settings) { m_spSiteGuid = spSiteGuid; m_mapping = mapping; m_settings = settings; }
static void UpdateSlkSettings(string connectionString, Guid spSiteGuid, string settingsFileContents, string defaultSettingsFileContents) { // make sure we can access LearningStore; while we're at it, find out if there's a row // corresponding to this SPSite in the SiteSettingsItem table LearningStore learningStore = new LearningStore(connectionString, "", true); LearningStoreJob job = learningStore.CreateJob(); LearningStoreQuery query = learningStore.CreateQuery(Schema.SiteSettingsItem.ItemTypeName); query.AddColumn(Schema.SiteSettingsItem.SettingsXml); query.AddCondition(Schema.SiteSettingsItem.SiteGuid, LearningStoreConditionOperator.Equal, spSiteGuid); job.PerformQuery(query); DataRowCollection results = job.Execute <DataTable>().Rows; if (results.Count == 0) { // this SPSite isn't listed in the SiteSettingsItem table, so we need to add a row if (settingsFileContents == null) { settingsFileContents = defaultSettingsFileContents; } } else { object currentSettingsFileContents = results[0][Schema.SiteSettingsItem.SettingsXml]; if ((currentSettingsFileContents == null) || (currentSettingsFileContents is DBNull) || (((string)currentSettingsFileContents).Length == 0)) { // the SLK Settings for this SPSite are missing, so we need to add them if (settingsFileContents == null) { settingsFileContents = defaultSettingsFileContents; } } } // upload the SLK Settings file if needed if (settingsFileContents != null) { // load "SlkSettings.xsd" from a resource into <xmlSchema> XmlSchema xmlSchema; using (StringReader schemaStringReader = new StringReader(SlkCulture.GetDefaultResources().SlkSettingsSchema)) { xmlSchema = XmlSchema.Read(schemaStringReader, delegate(object sender2, ValidationEventArgs e2) { // ignore warnings (already displayed when SLK Settings file was uploaded) }); } // validate <settingsFileContents> using (StringReader stringReader = new StringReader(settingsFileContents)) { XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.Schemas.Add(xmlSchema); xmlSettings.ValidationType = ValidationType.Schema; using (XmlReader xmlReader = XmlReader.Create(stringReader, xmlSettings)) { try { SlkSettings settings = new SlkSettings(xmlReader, DateTime.MinValue); } catch (SlkSettingsException ex) { throw new SafeToDisplayException(LoadCulture(spSiteGuid).Resources.SlkSettingsFileError, ex.Message); } } } // store <settingsFileContents> in the database job = learningStore.CreateJob(); Dictionary <string, object> uniqueProperties = new Dictionary <string, object>(); uniqueProperties.Add(Schema.SiteSettingsItem.SiteGuid, spSiteGuid); Dictionary <string, object> updateProperties = new Dictionary <string, object>(); updateProperties.Add(Schema.SiteSettingsItem.SettingsXml, settingsFileContents); updateProperties.Add(Schema.SiteSettingsItem.SettingsXmlLastModified, DateTime.Now.ToUniversalTime()); job.AddOrUpdateItem(Schema.SiteSettingsItem.ItemTypeName, uniqueProperties, updateProperties); job.Execute(); } }