//LockedDate will be displayed in first&second notification email //Extend LockedDate to no earlier than the email sent date if needed to avoid confusion private void ExtendOutdatedLockedDate(SiteInformation site) { var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); if (site.ComplianceState.LockedDate < now) { var lockDate = DateTime.MinValue; if (!site.ComplianceState.FirstLockNotificationSent) { lockDate = now.AddDays(GovernanceWorkflowHelper.FirstLockNotificationDays); } else if (!site.ComplianceState.SecondLockNotificationSent) { lockDate = now.AddDays(GovernanceWorkflowHelper.SecondLockNotificationDays); } if (lockDate == DateTime.MinValue) { return; } site.ComplianceState.LockedDate = lockDate; if (site.ComplianceState.ExpireDate < lockDate) { site.ComplianceState.ExpireDate = lockDate; } } }
public virtual void Process(SiteInformation site) { var state = site.ComplianceState; var lockDate = GovernanceWorkflowHelper.GetCurrentBusinessTime() .AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["DefaultFirstLockNotificationDays"])); if (state.LockedDate > lockDate || state.LockedDate == DateTime.MinValue) { state.LockedDate = lockDate; } }
public override bool IsCompliant(SiteInformation site) { var expiredDate = GetExpiredDate(site); var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); if ((expiredDate - now).TotalDays <= GovernanceWorkflowHelper.FirstLockNotificationDays) { return(false); } return(true); }
public virtual void Enforce(SiteInformation site, bool supressEmail) { var state = site.ComplianceState; //If site is locked, then will not send any lock notification email, instead of sending delete email. if (site.ComplianceState.IsLocked && !site.ComplianceState.DeleteNotificationSent) { SetNotifyDeleteState(site); } if (GovernanceWorkflowHelper.NeedNotifyLock(state.LockedDate, state)) { ExtendOutdatedLockedDate(site); //Extend the LockedDate if it is earlier than current date } else if (GovernanceWorkflowHelper.NeedNotifyDelete(state.LockedDate, state)) { ExtendOutdatedDeleteDate(site); //Extend the DeleteDate if it is earlier than current date } if (state.IsCompliant) { ChangeComplianceStateToDefault(site); } var tenant = new Tenant(TenentClientContext); if (GovernanceWorkflowHelper.NeedNotifyLock(state.LockedDate, state)) { Notifiy(site, TenentClientContext, supressEmail); Log.Info(GetType().Name, "Notify Lock for site {0}", site.Url); } else if (GovernanceWorkflowHelper.NeedLock(state.LockedDate, state)) { tenant.SetSiteLockState(site.Url, SiteLockState.NoAccess, true); site.ComplianceState.IsLocked = true; Log.Info(GetType().Name, "Site {0} was locked", site.Url); } else if (GovernanceWorkflowHelper.NeedNotifyDelete(state.LockedDate, state)) { Notifiy(site, TenentClientContext, supressEmail); Log.Info(GetType().Name, "Notify Delete for site {0}", site.Url); } else if (GovernanceWorkflowHelper.NeedDelete(state.LockedDate)) { //set a flag to let us know that the site is deleted by Governance Job //site.DeletedBy = AutoSiteDeleteBy.GovernanceJob; tenant.DeleteSiteCollection(site.Url, true); //Set a value to indicate that the site was just deleted site.ComplianceState.DeleteDate = DateTime.MaxValue; Log.Info(GetType().Name, "Site {0} was deleted", site.Url); } TenentClientContext.ExecuteQueryRetry(); }
//DeleteDate will be displayed in delete notification email //Extend DeleteDate to no earlier than the email sent date if needed to avoid confusion private void ExtendOutdatedDeleteDate(SiteInformation site) { var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); if (site.ComplianceState.LockedDate.AddDays(GovernanceWorkflowHelper.DeleteDays - 7) < now) { var lockDate = now.AddDays(-GovernanceWorkflowHelper.DeleteNotificationDays); site.ComplianceState.LockedDate = lockDate; if (site.ComplianceState.ExpireDate < lockDate) { site.ComplianceState.ExpireDate = lockDate; } } }
public override void Process(SiteInformation site) { var state = site.ComplianceState; var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); var expiredDate = GetExpiredDate(site); if (state.LockedDate > expiredDate || (DateTime.MinValue == state.LockedDate && !state.IsCompliant)) { state.LockedDate = expiredDate; } if (DateTime.MinValue == state.ExpireDate) { state.ExpireDate = expiredDate; } }
private void RunGovernancePolicy(SiteInformation site) { var plan = PolicyProvider.GetGovernancePlan(site); site.ComplianceState.LastCheckDate = GovernanceWorkflowHelper.GetCurrentBusinessTime(); site.ComplianceState.IsCompliant = true; var isSiteDeleted = false; try { foreach (var policy in plan.PolicyCollection) { if (isSiteDeleted) { break; } var isLifeCyclePolicy = policy is LifeCyclePolicy; var isCompliant = policy.IsCompliant(site); if (!isCompliant) { site.ComplianceState.IsCompliant = false; } if (!isCompliant || isLifeCyclePolicy) { policy.Process(site); } if (site.ComplianceState.DeleteDate == DateTime.MaxValue) { isSiteDeleted = true; break; } } } catch (Exception e) { Log.Error("sps", "Policy Checking Error {0}", e); } }
private void SetNotifyDeleteState(SiteInformation site) { var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); if (site.ComplianceState.IsLocked && (!site.ComplianceState.FirstLockNotificationSent || !site.ComplianceState.SecondLockNotificationSent)) { if (!site.ComplianceState.FirstLockNotificationSent) { site.ComplianceState.FirstLockNotificationSent = true; site.ComplianceState.FirstLockNotificationSentDate = now; site.ComplianceState.SecondLockNotificationSent = true; site.ComplianceState.SecondLockNotificationSentDate = now; } else if (!site.ComplianceState.SecondLockNotificationSent) { site.ComplianceState.SecondLockNotificationSent = true; site.ComplianceState.SecondLockNotificationSentDate = now; } } ExtendOutdatedDeleteDate(site); }
public DateTime GetExpiredDate(SiteInformation site) { var ret = site.ComplianceState.ExpireDate; if (!ret.Equals(DateTime.MinValue)) { return(ret); } var lease = GetDefaultLifeTimeInMonth(site); var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); ret = site.CreatedDate; while (true) { if (ret > now) { break; } ret = ret.AddMonths(lease); } return(ret); }
public void SetNotifyFlag(SiteInformation site) { if (site == null) { throw new ArgumentNullException("site"); } var now = GovernanceWorkflowHelper.GetCurrentBusinessTime(); if (!site.ComplianceState.FirstLockNotificationSent) { site.ComplianceState.FirstLockNotificationSent = true; site.ComplianceState.FirstLockNotificationSentDate = now; } else if (!site.ComplianceState.SecondLockNotificationSent) { site.ComplianceState.SecondLockNotificationSent = true; site.ComplianceState.SecondLockNotificationSentDate = now; } else if (!site.ComplianceState.DeleteNotificationSent) { site.ComplianceState.DeleteNotificationSent = true; site.ComplianceState.DeleteNotificationSentDate = now; } }