Пример #1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            var _web = _ctx.Web;
           
            var _division = Request.Form["selectDivision"].ToString();
            var _updateDivision = string.Compare(this.lblDivision.Text, _division, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateDivision)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_DIVISION, _division);
            }

            var _region = Request.Form["selectRegions"].ToString();
            var _updateRegion = string.Compare(this.lblRegion.Text, _region, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateRegion)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_REGION, _region);
            }

            var _function = Request.Form["selectFunction"].ToString();
            var _updateFunction = string.Compare(this.lblFunction.Text, _function, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateFunction)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_FUNCTION, _function);
            }

            var _sitePolicyName = Request.Form["BusinessImpact"].ToString();
            var _updateSitePolicy = String.Compare(this.lblSitePolicy.Text, _sitePolicyName, StringComparison.InvariantCultureIgnoreCase) != 0;
            if(_updateSitePolicy)
            {
                AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
                var _auth = new AppOnlyAuthenticationSite();
                _auth.SiteUrl = this.Url.Value;
                _siteService.Authentication = _auth;
                _siteService.SetSitePolicy(_sitePolicyName);

            }

            Response.Redirect(this.Url.Value);
        }
Пример #2
0
        private void SetUXAvailableSitePolicy()
        {
            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
            var _auth = new AppOnlyAuthenticationSite();
            _auth.SiteUrl = this.Url.Value;
            _siteService.Authentication = _auth;

            var _sitePolicies = _siteService.GetAvailablePolicies();
            foreach (var _sitePolicyEntity in _sitePolicies)
            {
                this.BusinessImpact.Items.Add(_sitePolicyEntity.Name);
            }

            var _appliedSitePolicy = _siteService.GetAppliedSitePolicy();
            if(_appliedSitePolicy != null)
            {
                this.lblSitePolicy.Text = _appliedSitePolicy.Name;
                var _expirationDate = _ctx.Web.GetSiteExpirationDate();
                this.lblExpirationDate.Text = _expirationDate == DateTime.MinValue ? String.Format("{0}", "None") : String.Format("{0}", _expirationDate);
            }
            else
            {
                this.lblSitePolicy.Text = string.Format("{0}", "None");
                this.lblExpirationDate.Text = String.Format("{0}", "None");
            }
        }
Пример #3
0
        public SiteEditMetadata SetSitePolicy(SiteEditMetadata metadata)
        {
            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
            var _auth = new AppOnlyAuthenticationSite();
            _auth.SiteUrl = metadata.Url;
            _siteService.Authentication = _auth;

            var _appliedSitePolicy = _siteService.GetAppliedSitePolicy();           
                        
            if (_appliedSitePolicy != null)
            {
                var _updateSitePolicy = String.Compare(metadata.SitePolicy, _appliedSitePolicy.Name, StringComparison.InvariantCultureIgnoreCase) != 0;
                if (_updateSitePolicy)
                {
                    _siteService.SetSitePolicy(metadata.AppliedSitePolicyName);
                }

                // Get applied site policy data
                Uri siteUri = new Uri(metadata.Url);
                string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
                string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

                using (var ctx = TokenHelper.GetClientContextWithAccessToken(metadata.Url, accessToken))
                {
                    var _web = ctx.Web;
                    var _expDate = ctx.Web.GetSiteExpirationDate();

                    metadata.AppliedSitePolicy = _appliedSitePolicy;
                    metadata.AppliedSitePolicyName = metadata.AppliedSitePolicy.Name;
                    metadata.AppliedSitePolicyExpirationDate = _expDate == DateTime.MinValue ? String.Format("{0}", "None") : String.Format("{0}", _expDate);

                };                
            }
            else
            {
                _siteService.SetSitePolicy(metadata.SitePolicy);
                metadata.AppliedSitePolicyName = metadata.SitePolicy;
            }
            return metadata;
        }