/// <summary /// Returns an <see cref="Provisioning.Common.Data.ISiteRequestManager"/> interface for working with the SiteRequest Repository /// Custom implementations must implement <see cref="Provisioning.Common.Data.ISiteRequestManager"/> /// This member reads from your configuration file and the app setting RepositoryManagerType must be defined. /// <add key="RepositoryManagerType" value="Provisioning.Common.Data.Impl.SPSiteRequestManagerImpl, Provisioning.Common" /> /// <returns><see cref="Provisioning.Common.Data.ISiteRequestManager"/></returns> /// </summary> public ISiteRequestManager GetSiteRequestManager() { var _configManager = new ConfigManager(); var _module = _configManager.GetModuleByName(ModuleKeys.REPOSITORYMANGER_KEY); var _managerTypeString = _module.ModuleType; if (string.IsNullOrEmpty(_managerTypeString)) throw new ConfigurationErrorsException(PCResources.Exception_Template_Provider_Missing_Config_Message); try { var type = _managerTypeString.Split(','); var typeName = type[0]; var assemblyName = type[1]; var instance = (AbstractModule)Activator.CreateInstance(assemblyName, typeName).Unwrap(); if (String.IsNullOrEmpty(_module.ConnectionString)) { instance.ConnectionString = SC.ConfigurationManager.AppSettings.Get(ModuleKeys.REPOSITORYMANGER_KEY + "_connectionString"); } else { instance.ConnectionString = _module.ConnectionString; } instance.Container = _module.Container; return (ISiteRequestManager)instance; } catch(Exception _ex) { throw new DataStoreException("Exception Occured while Creating Instance" ,_ex); } }
public EmailConfig() { ConfigManager cf = new ConfigManager(); string successEmail = cf.GetAppSettingsKey(CONFIG_NEWSITETEMPLATE); string failEmail = cf.GetAppSettingsKey(CONFIG_FAILEMAILTEMPLATE); if (File.Exists(successEmail)) { using (StreamReader sr = new StreamReader(successEmail)) { this.SuccessEmailTemplate = sr.ReadToEnd(); } } else { Log.Warning("Provisioning.Common.Mail.EmailConfig", "Your Email Template doesn't exist"); } if(File.Exists(failEmail)) { using (StreamReader sr = new StreamReader(failEmail)) { this.FailureEmailTemplate = sr.ReadToEnd(); } } else { Log.Warning("Provisioning.Common.Mail.EmailConfig", "Your Email Template doesn't exist"); } }
public IMetadataManager GetManager() { var _configManager = new ConfigManager(); var _module = _configManager.GetModuleByName(ModuleKeys.METADATAMANGER_KEY); var _managerTypeString = _module.ModuleType; if (string.IsNullOrEmpty(_managerTypeString)) { var _message = "MetadataManager is missing from the configuration file. Please update the configuration file."; throw new ConfigurationErrorsException(_message); } try { var type = _managerTypeString.Split(','); var typeName = type[0]; var assemblyName = type[1]; var instance = (AbstractModule)Activator.CreateInstance(assemblyName, typeName).Unwrap(); instance.ConnectionString = _module.ConnectionString; instance.Container = _module.Container; return (IMetadataManager)instance; } catch (Exception _ex) { throw new DataStoreException("Exception occured while creating instance", _ex); } }
/// <summary> /// Returns an <see cref="Provisioning.Common.Configuration.TemplateISiteTemplateManager"/> interface. This member reads from your configuration file and the app setting TemplateProviderType and must be defined. /// Custom implementations must implement <see cref="Provisioning.Common.Configuration.TemplateISiteTemplateManager"/> /// <add key="TemplateProviderType" value="Provisioning.Common.Configuration.Template.Impl.XMLSiteTemplateManager, Provisioning.Common"/> /// </summary> /// <returns></returns> /// <exception cref="System.Configuration.ConfigurationErrorsException"></exception> /// <exception cref="Provisioning.Common.Data.FactoryException">Exception that occurs when the factory encounters an exception.</exception> public ISiteTemplateManager GetManager() { var _configManager = new ConfigManager(); var _module = _configManager.GetModuleByName(ModuleKeys.MASTERTEMPLATEPROVIDER_KEY); var _managerTypeString = _module.ModuleType; if(string.IsNullOrEmpty(_managerTypeString)) { //TODO LOG throw new ConfigurationErrorsException(PCResources.Exception_Template_Provider_Missing_Config_Message); } try { var type = _managerTypeString.Split(','); var typeName = type[0]; var assemblyName = type[1]; var instance = (AbstractModule)Activator.CreateInstance(assemblyName, typeName).Unwrap(); instance.ConnectionString = _module.ConnectionString; instance.Container = _module.Container; Log.Info("Provisioning.Common.Data.Templates", PCResources.SiteTemplate_Factory_Created_Instance, _managerTypeString); return (ISiteTemplateManager)instance; } catch (Exception _ex) { var _message = String.Format(PCResources.SiteTemplate_Factory_Created_Instance_Exception, _managerTypeString); Log.Info("Provisioning.Common.Data.Templates", _message) ; throw new FactoryException(_message, _ex); } }
public void CanParseEnvironmentTokenFromConfigManager() { ConfigManager _cm = new ConfigManager(); var _expected = "C:\\ProgramData/Resources/SiteTemplate"; var _actual = _cm.GetAppSettingsKey("ENVRTEST1"); Assert.AreEqual(_expected, _actual); }
public void CanGetModulesByKey() { ConfigManager _cm = new ConfigManager(); var module = _cm.GetModuleByName(ModuleKeys.REPOSITORYMANGER_KEY); Assert.IsNotNull(module.Name); Assert.IsNotNull(module); }
public void CanGetModulesSections() { ConfigManager _cm = new ConfigManager(); var _mes = _cm.ModulesElements; var module = _mes[ModuleKeys.REPOSITORYMANGER_KEY]; Assert.IsNotNull(_mes); }
public void CanParseEnvironmentToken() { ConfigManager _cm = new ConfigManager(); var _expected = "C:\\ProgramData/Resources/SiteTemplate"; var _actual = _cm.GetAppSettingsKey("ENVRTEST1"); Regex r = new Regex(@"(?:(?<=\().+?(?=\))|(?<=\[).+?(?=\]))"); Regex r1 = new Regex(@"\[(.*?)\]"); Match _outPut = r.Match(_actual); if(_outPut.Success) { var _env = Environment.GetEnvironmentVariable(_outPut.Value); _actual = r1.Replace(_actual, _env); } Assert.AreEqual(_expected, _actual); }
public List<SitePolicyResults> GetSitePolicies() { var _returnResults = new List<SitePolicyResults>(); ConfigManager _manager = new ConfigManager(); AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService(); var _auth = new AppOnlyAuthenticationTenant(); _auth.SiteUrl = _manager.GetAppSettingsKey("SPHost"); var _sitePolicies = _siteService.GetAvailablePolicies(); foreach(var _sitePolicyEntity in _sitePolicies) { var _policy = new SitePolicyResults(); _policy.Key = _sitePolicyEntity.Name; _policy.Value = _sitePolicyEntity.Description; _returnResults.Add(_policy); } return _returnResults; }
/// <summary> /// /// </summary> /// <param name="siteUrl"></param> public virtual bool isSiteExternalSharingEnabled(string siteUrl) { ConfigManager _manager = new ConfigManager(); var _tenantAdminUrl = _manager.GetAppSettingsKey("TenantAdminUrl"); var _returnResult = false; AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService(); _siteService.Authentication = new AppOnlyAuthenticationTenant(); _siteService.Authentication.TenantAdminUrl = _tenantAdminUrl; _siteService.UsingContext(ctx => { try { Tenant _tenant = new Tenant(ctx); SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteUrl, false); ctx.Load(_tenant); ctx.Load(_siteProps); ctx.ExecuteQuery(); var _tenantSharingCapability = _tenant.SharingCapability; var _siteSharingCapability = _siteProps.SharingCapability; if (_tenantSharingCapability != SharingCapabilities.Disabled) { if (_siteSharingCapability != SharingCapabilities.Disabled) { // Enabled _returnResult = true; } else { // Disabled _returnResult = false; } } else { // Disabled _returnResult = false; } } catch (Exception _ex) { Log.Warning("AbstractSiteProvisioningService.IsSiteExternalSharingEnabled", PCResources.SiteExternalSharing_Enabled_Error_Message, siteUrl, _ex); } }); return _returnResult; }
public void CanParseConfigWithNoEnvironmentFromConfigManager() { ConfigManager _cm = new ConfigManager(); var _expected = "Resources/SiteTemplate"; var _actual = _cm.GetAppSettingsKey("ENVRTEST2"); Assert.AreEqual(_expected, _actual); }
public SiteEditMetadata SetExternalSharing(SiteEditMetadata metadata) { try { if (!metadata.SharePointOnPremises) { string _sharingStatus = string.Empty; ConfigManager _manager = new ConfigManager(); var _tenantAdminUrl = _manager.GetAppSettingsKey("TenantAdminUrl"); AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService(); _siteService.Authentication = new AppOnlyAuthenticationTenant(); _siteService.Authentication.TenantAdminUrl = _tenantAdminUrl; SiteInformation _srInfo = new SiteInformation(); _srInfo.Url = metadata.Url; if (metadata.EnableExternalSharing) { _srInfo.EnableExternalSharing = true; _sharingStatus = "true"; } else { _srInfo.EnableExternalSharing = false; _sharingStatus = "false"; } _siteService.SetExternalSharing(_srInfo); Uri siteUri = new Uri(metadata.Url); string realm = TokenHelper.GetRealmFromTargetUrl(siteUri); string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken; using (var clientContext = TokenHelper.GetClientContextWithAccessToken(metadata.Url, accessToken)) { var _web = clientContext.Web; clientContext.Load(_web); //Update property bag as well _web.SetPropertyBagValue(SITE_PROPERTY_EXTERNAL_SHARING, _sharingStatus); metadata.Success = true; }; } } catch (Exception _ex) { var _message = string.Format("There was an error processing the request. {0}", _ex.Message); Log.Error("MetadataController.SetSiteExternalSharingStatus", "There was an error processing the request. Exception: {0}", _ex); metadata.ErrorMessage = _ex.Message; return metadata; } return metadata; }
public Models.SiteMetadata SetSiteMetadata([FromBody]string value) { ConfigManager _cfgmanager = new ConfigManager(); var _auth = new AppOnlyAuthenticationTenant(); _auth.TenantAdminUrl = _cfgmanager.GetAppSettingsKey("TenantAdminUrl"); var _request = JsonConvert.DeserializeObject<Models.SiteMetadata>(value); _request.TenantAdminUrl = _auth.TenantAdminUrl; // Transform the request var _metadataRequest = ObjectMapper.ToSiteEditMetadata(_request); _metadataRequest.Success = false; try { IMetadataFactory _factory = MetadataFactory.GetInstance(); IMetadataManager _manager = _factory.GetManager(); var _metadataResponse = _manager.SetSiteMetadata(_metadataRequest); _metadataResponse.Success = true; // Transform response var _response = ObjectMapper.ToSiteMetadata(_metadataResponse); return _response; } catch (Exception _ex) { _request.ErrorMessage = _ex.Message; OfficeDevPnP.Core.Diagnostics.Log.Error("MetadataController.SetSiteMetadata", "There was an error processing the request. Exception: {0}", _ex); return _request; } }