/// <summary> /// Retrieve the configuration for the specified business event. /// </summary> /// <param name="businessEvent">The business event to get the configuration for</param> /// <returns>The business event's configuration. </returns> public BusinessEventTypeConfiguration GetBusinessEventTypeConfiguration(string businessEvent) { IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); string adminWebUrl = hierarchicalConfig.GetByKey <string>(Constants.SubSiteCreationConfigSiteKey, ConfigLevel.CurrentSPFarm); if (string.IsNullOrEmpty(adminWebUrl)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigSiteNotFoundMessage, Constants.SubSiteCreationConfigSiteKey)); } using (SPSite site = new SPSite(adminWebUrl)) { using (SPWeb adminWeb = site.OpenWeb()) { SPList businessEventSiteTemplateList = adminWeb.Lists[Constants.BusinessEventTypeConfigListName]; CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder(); camlQueryBuilder.AddEqual(FieldIds.BusinessEventFieldId, businessEvent); SPListItemCollection items = businessEventSiteTemplateList.GetItems(camlQueryBuilder.Build()); if (items.Count > 0) { return(ListItemFieldMapper.CreateEntity(items[0])); } else { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigDataNotFoundMessage, businessEvent)); } } } }
private string GetPartnerSiteDirectoryUrlConfigSetting() { // Read the PartnerSiteDirectoryUrl from the Hierarchical config. This value is stored at the SPFarm level, because // there can only be 1 PartnerSiteDirectory in our environment. Therefor it doesn't make sense to override this setting // at different levels. IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); return(hierarchicalConfig.GetByKey <string>(Constants.PartnerSiteDirectoryUrlConfigKey, ConfigLevel.CurrentSPFarm)); }
/// <summary> /// Initializes a new instance of the <see cref="EventLogLogger"/> class. /// </summary> public EventLogLogger() { IHierarchicalConfig config = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); // Assume default event soruce eventSource = DefaultEventSource; if (SPContext.Current == null) { // There is no SharePoint context: Get the config from the farm. if (config.ContainsKey(Constants.EventSourceNameConfigKey, ConfigLevel.CurrentSPFarm)) { eventSource = config.GetByKey <string>(Constants.EventSourceNameConfigKey, ConfigLevel.CurrentSPFarm); } } else { // There is a SharePoint context. Get the config from the current SPWeb if (config.ContainsKey(Constants.EventSourceNameConfigKey)) { eventSource = config.GetByKey <string>(Constants.EventSourceNameConfigKey); } } }
public PartnerPromotionRepository() { // Get the URL of the Web that holds the partnerpromotions. This value is set by the PromotionsWebFeatureReceiver when // this feature is activated on a particular Web. IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); string partnerPromotionWebUrl = hierarchicalConfig.GetByKey <string>(PartnerPromotionRepositoryUrlConfigKey); Initialize(partnerPromotionWebUrl); //Important to retrieve ID value of SPListItem so that //modifications to entity can be persisted back into SPListItem ListItemFieldMapper.AddMapping(ProductSkuFieldId, "Sku"); ListItemFieldMapper.AddMapping(PromotionImageFieldId, "Image"); ListItemFieldMapper.AddMapping(PromotionNameFieldId, "PromotionName"); ListItemFieldMapper.AddMapping(PromotionDescriptionFieldId, "Description"); ListItemFieldMapper.AddMapping(WindowsMediaFieldId, "Media"); }
private SiteMapNode BuildSiteMapSynchronized() { SiteMapNode siteMapRootNode = null; try { // Get the XML that holds all the sitemapnodes from the config store. The default value for this is set by the // ContosoGlobalNavFeatureReceiver. Because the SiteMapProvider is instantiated only once per WebApplication, // the configsetting is also only read from the Current SPWebApplication or above. // Note, The IHierarchicalConfig interface is used to read config settings in a hierarchical way. The IConfigManager // interface is used to write config settings to a particular location. IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); string siteMapXml = hierarchicalConfig.GetByKey <string>(Constants.SiteMapXmlConfigKey, ConfigLevel.CurrentSPWebApplication); if (string.IsNullOrEmpty(siteMapXml)) { logger.LogToOperations("SiteMap Xml value retrieved from configuration ws null or empty."); return(null); } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(siteMapXml); XmlNode rootXmlNode = xmlDocument.SelectSingleNode("/siteMap/siteMapNode"); if (rootXmlNode == null) { logger.LogToOperations("Can not find siteMapNode in navigation xml."); return(null); } siteMapRootNode = BuildSiteMapTree(rootXmlNode); } catch (Exception ex) { logger.LogToOperations(ex, "Could not build up the sitemap from setting in HierarchicalConfig.", 0, EventLogEntryType.Error, null); throw; } return(siteMapRootNode); }
/// <summary> /// Inserts a new item into the "Sub Site Creation Request List". Calling this method will trigger /// the "Sub Site Creation Workflow". /// </summary> /// <param name="request">The request entity containing necessary information to successfully run the Sub Site Creation Workflow.</param> public void AddSubSiteCreationRequest(SubSiteCreationRequest request) { if (request == null) { throw new SubSiteCreationException(Constants.TheSubSiteCreationRequestWasNullMessage); } else if (string.IsNullOrEmpty(request.BusinessEvent)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.BusinessEventProperty)); } else if (string.IsNullOrEmpty(request.EventId)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.EventIdProperty)); } else if (string.IsNullOrEmpty(request.SiteCollectionUrl)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ValueProvidedNullOrEmptyMessage, Constants.SiteCollectionUrlProperty)); } IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>(); string adminWebUrl = hierarchicalConfig.GetByKey <string>(Constants.SubSiteCreationConfigSiteKey, ConfigLevel.CurrentSPFarm); if (string.IsNullOrEmpty(adminWebUrl)) { throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, Constants.ConfigSiteNotFoundMessage, Constants.SubSiteCreationConfigSiteKey)); } using (SPSite site = new SPSite(adminWebUrl)) { using (SPWeb adminWeb = site.OpenWeb()) { SPList subSiteCreationRequests = adminWeb.Lists[Constants.SubSiteRequestsListName]; SPListItem subSiteCreationRequest = subSiteCreationRequests.Items.Add(); ListItemFieldMapper.FillSPListItemFromEntity(subSiteCreationRequest, request); subSiteCreationRequest.Update(); } } }