示例#1
0
        static void Main(string[] args)
        {
            string      json    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sposettings.json");
            SPOSettings setting = SPOSettings.GetSettings(json);

            using (ClientContext context = GetClientContext(setting))
            {
                Web web          = context.Web;
                var sitePolicies = ProjectPolicy.GetProjectPolicies(context, web);
                context.Load(sitePolicies);
                context.ExecuteQuery();


                if (sitePolicies != null && sitePolicies.Count > 0)
                {
                    var policy = sitePolicies.FirstOrDefault(p => p.Name == setting.PolicyName);
                    if (policy != null)
                    {
                        ProjectPolicy.ApplyProjectPolicy(context, web, policy);
                        context.ExecuteQuery();

                        ProjectPolicy.CloseProject(context, web);
                        context.ExecuteQuery();
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Close a site, if it has a site policy applied and is currently not closed
 /// </summary>
 /// <param name="web"></param>
 /// <returns>True if site was closed, false otherwise</returns>
 public static bool SetClosedBySitePolicy(this Web web)
 {
     if (web.HasSitePolicyApplied() && !IsClosedBySitePolicy(web))
     {
         ProjectPolicy.CloseProject(web.Context, web);
         web.Context.ExecuteQueryRetry();
         return(true);
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Close a site, if it has a site policy applied and is currently not closed
        /// </summary>
        /// <param name="web"></param>
        /// <returns>True if site was closed, false otherwise</returns>
        private static async Task <bool> SetClosedBySitePolicyImplementation(this Web web)
        {
            if (await web.HasSitePolicyAppliedImplementation() && !await web.IsClosedBySitePolicyImplementation())
            {
                ProjectPolicy.CloseProject(web.Context, web);
                await web.Context.ExecuteQueryRetryAsync();

                return(true);
            }
            return(false);
        }
示例#4
0
        private static async Task <bool> SetClosedBySitePolicyImplementation(this Web web)
#endif
        {
#if ONPREMISES
            if (web.HasSitePolicyAppliedImplementation() && !IsClosedBySitePolicyImplementation(web))
#else
            if (await web.HasSitePolicyAppliedImplementation() && !await web.IsClosedBySitePolicyImplementation())
#endif
            {
                ProjectPolicy.CloseProject(web.Context, web);
#if ONPREMISES
                web.Context.ExecuteQueryRetry();
#else
                await web.Context.ExecuteQueryRetryAsync();
#endif
                return(true);
            }
            return(false);
        }