Esempio n. 1
0
   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");
       }
       
   }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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;
        }
Esempio n. 5
0
 public void CanParseConfigWithNoEnvironmentFromConfigManager()
 {
     ConfigManager _cm = new ConfigManager();
     var _expected = "Resources/SiteTemplate";
     var _actual = _cm.GetAppSettingsKey("ENVRTEST2");
     Assert.AreEqual(_expected, _actual);
 }
Esempio n. 6
0
 public void CanParseEnvironmentTokenFromConfigManager()
 {
     ConfigManager _cm = new ConfigManager();
     var _expected = "C:\\ProgramData/Resources/SiteTemplate";
     var _actual = _cm.GetAppSettingsKey("ENVRTEST1");
     Assert.AreEqual(_expected, _actual);
 }
Esempio n. 7
0
        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;

        }
Esempio n. 8
0
        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;
            }
        }