/// <summary> /// Does this web have a site policy applied? /// </summary> /// <param name="web">Web to operate on</param> /// <returns>True if a policy has been applied, false otherwise</returns> private static async Task <bool> HasSitePolicyAppliedImplementation(this Web web) { var hasSitePolicyApplied = ProjectPolicy.DoesProjectHavePolicy(web.Context, web); await web.Context.ExecuteQueryRetryAsync(); return(hasSitePolicyApplied.Value); }
/// <summary> /// Gets a list of the available site policies /// </summary> /// <param name="web">Web to operate on</param> /// <returns>A list of <see cref="SitePolicyEntity"/> objects</returns> public static List <SitePolicyEntity> GetSitePolicies(this Web web) { ClientObjectList <ProjectPolicy> sitePolicies = ProjectPolicy.GetProjectPolicies(web.Context, web); web.Context.Load(sitePolicies); web.Context.ExecuteQueryRetry(); List <SitePolicyEntity> policies = new List <SitePolicyEntity>(); if (sitePolicies != null && sitePolicies.Count > 0) { foreach (var policy in sitePolicies) { policies.Add(new SitePolicyEntity { Name = policy.Name, Description = policy.Description, EmailBody = policy.EmailBody, EmailBodyWithTeamMailbox = policy.EmailBodyWithTeamMailbox, EmailSubject = policy.EmailSubject }); } } return(policies); }
static void Main(string[] args) { string siteCollectionUrl = ""; string relativeSiteUrl = ""; // Get the site and web info Console.WriteLine("Site Policy E-mail Changer"); Console.WriteLine("Enter the Site Collection URL: "); siteCollectionUrl = Console.ReadLine(); Console.WriteLine("Enter the relative Site URL: "); relativeSiteUrl = Console.ReadLine(); // Return the currently applied Site Policy ClientContext context = new ClientContext(siteCollectionUrl); Site site = context.Site; Web web = site.OpenWeb(relativeSiteUrl); ProjectPolicy policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(context, web); context.Load(policy, p => p.Name, p => p.Description, p => p.EmailSubject, p => p.EmailBody, p => p.EmailBodyWithTeamMailbox); context.ExecuteQuery(); // Display the current Site Policy properties and pause Console.WriteLine(String.Format("Policy Name is: {0}", policy.Name)); Console.WriteLine(String.Format("Policy Description is: {0}", policy.Description)); Console.WriteLine(String.Format("Policy E-mail Subject is: {0}", policy.EmailSubject)); Console.WriteLine(String.Format("Policy E-mail Body is: {0}", policy.EmailBody)); Console.WriteLine(String.Format("Policy E-mail Body (with Site Mailbox) is: {0}", policy.EmailBodyWithTeamMailbox)); Console.WriteLine(); Console.ReadLine(); // Edit the Site Policy E-mail properties policy.EmailSubject = "Contoso Site Deletion Notice"; policy.EmailBody = "The Contoso site <!--{SiteUrl}--> is set to expire on <!--{SiteDeleteDate}-->. If you have any questions or concerns, please contact your admin."; policy.EmailBodyWithTeamMailbox = "The Contoso site <!--{SiteUrl}--> associated with Site Mailbox <!--{TeamMailboxID}--> is set to expire on <!--{SiteDeleteDate}-->. If you have any questions or concerns, please contact your admin."; policy.SavePolicy(); context.ExecuteQuery(); // Refetch the edited Site Policy from the server policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(context, web); context.Load(policy, p => p.Name, p => p.Description, p => p.EmailSubject, p => p.EmailBody, p => p.EmailBodyWithTeamMailbox); context.ExecuteQuery(); // Display the new Site Policy properties and pause Console.WriteLine(String.Format("Policy Name is: {0}", policy.Name)); Console.WriteLine(String.Format("Policy Description is: {0}", policy.Description)); Console.WriteLine(String.Format("Policy E-mail Subject is NOW: {0}", policy.EmailSubject)); Console.WriteLine(String.Format("Policy E-mail Body is NOW : {0}", policy.EmailBody)); Console.WriteLine(String.Format("Policy E-mail Body (with Site Mailbox) is NOW: {0}", policy.EmailBodyWithTeamMailbox)); Console.ReadLine(); }
/// <summary> /// Check if a site is closed /// </summary> /// <param name="web">Web to operate on</param> /// <returns>True if site is closed, false otherwise</returns> private static async Task <bool> IsClosedBySitePolicyImplementation(this Web web) { var isClosed = ProjectPolicy.IsProjectClosed(web.Context, web); await web.Context.ExecuteQueryRetryAsync(); return(isClosed.Value); }
/// <summary> /// Check if a site is closed /// </summary> /// <param name="web">Web to operate on</param> /// <returns>True if site is closed, false otherwise</returns> public static bool IsClosedBySitePolicy(this Web web) { var isClosed = ProjectPolicy.IsProjectClosed(web.Context, web); web.Context.ExecuteQueryRetry(); return(isClosed.Value); }
private static async Task <SitePolicyEntity> GetAppliedSitePolicyImplementation(this Web web) #endif { #if ONPREMISES if (web.HasSitePolicyAppliedImplementation()) #else if (await web.HasSitePolicyAppliedImplementation()) #endif { var policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(web.Context, web); web.Context.Load(policy, p => p.Name, p => p.Description, p => p.EmailSubject, p => p.EmailBody, p => p.EmailBodyWithTeamMailbox); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif return(new SitePolicyEntity { Name = policy.Name, Description = policy.Description, EmailBody = policy.EmailBody, EmailBodyWithTeamMailbox = policy.EmailBodyWithTeamMailbox, EmailSubject = policy.EmailSubject }); } else { return(null); } }
/// <summary> /// Does this web have a site policy applied? /// </summary> /// <param name="web">Web to operate on</param> /// <returns>True if a policy has been applied, false otherwise</returns> public static bool HasSitePolicyApplied(this Web web) { ClientResult <bool> hasSitePolicyApplied = ProjectPolicy.DoesProjectHavePolicy(web.Context, web); web.Context.ExecuteQueryRetry(); return(hasSitePolicyApplied.Value); }
private static async Task <bool> ApplySitePolicyImplementation(this Web web, string sitePolicy) #endif { var result = false; var sitePolicies = ProjectPolicy.GetProjectPolicies(web.Context, web); web.Context.Load(sitePolicies); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif if (sitePolicies != null && sitePolicies.Count > 0) { var policyToApply = sitePolicies.FirstOrDefault(p => p.Name == sitePolicy); if (policyToApply != null) { ProjectPolicy.ApplyProjectPolicy(web.Context, web, policyToApply); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif result = true; } } return(result); }
private static async Task <List <SitePolicyEntity> > GetSitePoliciesImplementation(this Web web) #endif { var sitePolicies = ProjectPolicy.GetProjectPolicies(web.Context, web); web.Context.Load(sitePolicies); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif var policies = new List <SitePolicyEntity>(); if (sitePolicies != null && sitePolicies.Count > 0) { foreach (var policy in sitePolicies) { policies.Add(new SitePolicyEntity { Name = policy.Name, Description = policy.Description, EmailBody = policy.EmailBody, EmailBodyWithTeamMailbox = policy.EmailBodyWithTeamMailbox, EmailSubject = policy.EmailSubject }); } } return(policies); }
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(); } } } }
/// <summary> /// Gets the site policy that currently is applied /// </summary> /// <param name="web">Web to operate on</param> /// <returns>A <see cref="SitePolicyEntity"/> object holding the applied policy</returns> public static SitePolicyEntity GetAppliedSitePolicy(this Web web) { if (web.HasSitePolicyApplied()) { ProjectPolicy policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(web.Context, web); web.Context.Load(policy, p => p.Name, p => p.Description, p => p.EmailSubject, p => p.EmailBody, p => p.EmailBodyWithTeamMailbox); web.Context.ExecuteQueryRetry(); return(new SitePolicyEntity { Name = policy.Name, Description = policy.Description, EmailBody = policy.EmailBody, EmailBodyWithTeamMailbox = policy.EmailBodyWithTeamMailbox, EmailSubject = policy.EmailSubject }); } else { return(null); } }
private void UpdateprojectPolicy(string poli, ProjectPolicy policy, DateTime date) { policy.content = poli; policy.modified_at = date; _insendluEntities.Entry(policy).State = System.Data.Entity.EntityState.Modified; _insendluEntities.SaveChanges(); }
/// <summary> /// Open a site, if it has a site policy applied and is currently closed /// </summary> /// <param name="web"></param> /// <returns>True if site was opened, false otherwise</returns> public static bool SetOpenBySitePolicy(this Web web) { if (web.HasSitePolicyApplied() && IsClosedBySitePolicy(web)) { ProjectPolicy.OpenProject(web.Context, web); web.Context.ExecuteQueryRetry(); return(true); } return(false); }
/// <summary> /// Open a site, if it has a site policy applied and is currently closed /// </summary> /// <param name="web"></param> /// <returns>True if site was opened, false otherwise</returns> private static async Task <bool> SetOpenBySitePolicyImplementation(this Web web) { if (await web.HasSitePolicyAppliedImplementation() && await web.IsClosedBySitePolicyImplementation()) { ProjectPolicy.OpenProject(web.Context, web); await web.Context.ExecuteQueryRetryAsync(); return(true); } return(false); }
private static async Task <bool> IsClosedBySitePolicyImplementation(this Web web) #endif { var isClosed = ProjectPolicy.IsProjectClosed(web.Context, web); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif return(isClosed.Value); }
/// <summary> /// Gets the site expiration date /// </summary> /// <param name="web">Web to operate on</param> /// <returns>DateTime value holding the expiration date, DateTime.MinValue in case there was no policy applied</returns> public static DateTime GetSiteExpirationDate(this Web web) { if (web.HasSitePolicyApplied()) { var expirationDate = ProjectPolicy.GetProjectExpirationDate(web.Context, web); web.Context.ExecuteQueryRetry(); return(expirationDate.Value); } else { return(DateTime.MinValue); } }
/// <summary> /// Gets the site closure date /// </summary> /// <param name="web">Web to operate on</param> /// <returns>DateTime value holding the closure date, DateTime.MinValue in case there was no policy applied</returns> public static DateTime GetSiteCloseDate(this Web web) { if (web.HasSitePolicyApplied()) { ClientResult <DateTime> closeDate = ProjectPolicy.GetProjectCloseDate(web.Context, web); web.Context.ExecuteQueryRetry(); return(closeDate.Value); } else { return(DateTime.MinValue); } }
private int GetDpw(string content, long projId) { var dpw = new ProjectPolicy() { created_at = DateTime.Now, modified_at = DateTime.Now, policy_number = content, proj_id = (int)projId }; _insendluEntities.ProjectPolicies.Add(dpw); return(_insendluEntities.SaveChanges()); }
/// <summary> /// Gets the site expiration date /// </summary> /// <param name="web">Web to operate on</param> /// <returns>DateTime value holding the expiration date, DateTime.MinValue in case there was no policy applied</returns> private static async Task <DateTime> GetSiteExpirationDateImplementation(this Web web) { if (await web.HasSitePolicyAppliedImplementation()) { var expirationDate = ProjectPolicy.GetProjectExpirationDate(web.Context, web); await web.Context.ExecuteQueryRetryAsync(); return(expirationDate.Value); } else { return(DateTime.MinValue); } }
private int GetProjectPolicy(string content, long projId) { var policy = new ProjectPolicy { content = content, created_at = DateTime.Now, modified_at = DateTime.Now, proj_id = (int)projId }; _insendluEntities.ProjectPolicies.Add(policy); TryCatch(); return((int)policy.id); }
private static async Task <bool> SetOpenBySitePolicyImplementation(this Web web) #endif { #if ONPREMISES if (web.HasSitePolicyAppliedImplementation() && IsClosedBySitePolicyImplementation(web)) #else if (await web.HasSitePolicyAppliedImplementation() && await web.IsClosedBySitePolicyImplementation()) #endif { ProjectPolicy.OpenProject(web.Context, web); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif return(true); } return(false); }
private static async Task <DateTime> GetSiteCloseDateImplementation(this Web web) #endif { #if ONPREMISES if (web.HasSitePolicyAppliedImplementation()) #else if (await web.HasSitePolicyAppliedImplementation()) #endif { var closeDate = ProjectPolicy.GetProjectCloseDate(web.Context, web); #if ONPREMISES web.Context.ExecuteQueryRetry(); #else await web.Context.ExecuteQueryRetryAsync(); #endif return(closeDate.Value); } else { return(DateTime.MinValue); } }
/// <summary> /// Apply a policy to a site /// </summary> /// <param name="web">Web to operate on</param> /// <param name="sitePolicy">Policy to apply</param> /// <returns>True if applied, false otherwise</returns> public static bool ApplySitePolicy(this Web web, string sitePolicy) { bool result = false; ClientObjectList <ProjectPolicy> sitePolicies = ProjectPolicy.GetProjectPolicies(web.Context, web); web.Context.Load(sitePolicies); web.Context.ExecuteQueryRetry(); if (sitePolicies != null && sitePolicies.Count > 0) { ProjectPolicy policyToApply = sitePolicies.FirstOrDefault(p => p.Name == sitePolicy); if (policyToApply != null) { ProjectPolicy.ApplyProjectPolicy(web.Context, web, policyToApply); web.Context.ExecuteQueryRetry(); result = true; } } return(result); }
private int GetProjectAnalysis(string projAnalysis, long newId) { var projectAnalysis = new ProjectPolicy() { created_at = DateTime.Now, modified_at = DateTime.Now, policy_number = "", name = "Policy Name Here", proj_id = (int)newId }; _insendluEntities.ProjectPolicies.Add(projectAnalysis); try { _insendluEntities.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } return((int)projectAnalysis.id); }