Ejemplo n.º 1
0
        public virtual SitePolicyEntity GetAppliedSitePolicy()
        {
            SitePolicyEntity _appliedSitePolicy = null;

            UsingContext(ctx =>
            {
                var _web           = ctx.Web;
                _appliedSitePolicy = _web.GetAppliedSitePolicy();
            });
            return(_appliedSitePolicy);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the site policy with the given name
        /// </summary>
        /// <param name="web">Web to operate on</param>
        /// <param name="sitePolicy">Site policy to fetch</param>
        /// <returns>A <see cref="SitePolicyEntity"/> object holding the fetched policy</returns>
        public static SitePolicyEntity GetSitePolicyByName(this Web web, string sitePolicy)
        {
            List <SitePolicyEntity> policies = web.GetSitePolicies();

            if (policies.Count > 0)
            {
                SitePolicyEntity policy = policies.FirstOrDefault(p => p.Name == sitePolicy);
                return(policy);
            }
            else
            {
                return(null);
            }
        }
        public virtual SitePolicyEntity GetAppliedSitePolicy()
        {
            Log.Info("AbstractSiteProvisioningService.GetAppliedSitePolicy", "Entering GetAppliedSitePolicy");
            SitePolicyEntity _appliedSitePolicy = null;

            UsingContext(ctx =>
            {
                Stopwatch _timespan = Stopwatch.StartNew();
                var _web            = ctx.Web;
                _appliedSitePolicy  = _web.GetAppliedSitePolicy();

                _timespan.Stop();
                Log.TraceApi("SharePoint", "AbstractSiteProvisioningService.IsTenantExternalSharingEnabled", _timespan.Elapsed);
            });
            return(_appliedSitePolicy);
        }
Ejemplo n.º 4
0
        public SiteProfile GetSiteProfile(ClientContext ctx)
        {
            var _siteProfile = new SiteProfile()
            {
                CustomProperties = this.GetCustomProfileProperties(ctx),
                ExpirationDate   = ctx.Web.GetSiteExpirationDate()
            };

            SitePolicyEntity _sitePolicy = ctx.Web.GetAppliedSitePolicy();

            if (_sitePolicy != null)
            {
                _siteProfile.SitePolicy = _sitePolicy.Name;
            }

            return(_siteProfile);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            cc = spContext.CreateUserClientContextForSPHost();

            // define initial script, needed to render the chrome control
            string script = @"
            function chromeLoaded() {
                $('body').show();
            }

            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'
                };

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);
                chromeNavigation.setVisible(true);
            }";

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);

            if (!Page.IsPostBack)
            {
                //Scenario 1

                //Get site expiration and closure dates
                if (cc.Web.HasSitePolicyApplied())
                {
                    lblSiteExpiration.Text = String.Format("The expiration date for the site is {0}", cc.Web.GetSiteExpirationDate());
                    lblSiteClosure.Text    = String.Format("The closure date for the site is {0}", cc.Web.GetSiteCloseDate());
                }
                else
                {
                    lblSiteExpiration.Text = String.Format("The expiration date for the site is {0}", "not defined");
                    lblSiteClosure.Text    = String.Format("The closure date for the site is {0}", "not defined");
                }

                //List the defined policies
                List <SitePolicyEntity> policies = cc.Web.GetSitePolicies();
                string policiesString            = "";
                foreach (var policy in policies)
                {
                    policiesString += String.Format("{0} ({1}) <BR />", policy.Name, policy.Description);
                }
                lblSitePolicies.Text = policiesString;

                //Show the assigned policy
                SitePolicyEntity appliedPolicy = cc.Web.GetAppliedSitePolicy();
                if (appliedPolicy != null)
                {
                    lblAppliedPolicy.Text = String.Format("{0} ({1})", appliedPolicy.Name, appliedPolicy.Description);
                }
                else
                {
                    lblAppliedPolicy.Text = "No policy has been applied";
                }

                //Scenario 2

                //Fill the policies combo
                foreach (var policy in policies)
                {
                    if (appliedPolicy == null || !policy.Name.Equals(appliedPolicy.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        drlPolicies.Items.Add(policy.Name);
                    }
                }
                btnApplyPolicy.Enabled = drlPolicies.Items.Count > 0;
            }
        }