コード例 #1
0
ファイル: DataCleanup.cs プロジェクト: theopenem/Toems
        public void AutoArchivePolicies()
        {
            Logger.Debug("Policy Archive Started");
            var servicePolicy = new ServicePolicy();
            var allPolicies   = _uow.PolicyRepository.Get(x => !x.Archived);

            foreach (var policy in allPolicies)
            {
                if (policy.AutoArchiveType == EnumPolicy.AutoArchiveType.AfterXdays)
                {
                    int intArchiveDays;
                    if (!int.TryParse(policy.AutoArchiveSub, out intArchiveDays))
                    {
                        continue;
                    }

                    if (intArchiveDays <= 0)
                    {
                        continue;
                    }

                    var dateCutOff = DateTime.UtcNow - TimeSpan.FromDays(intArchiveDays);

                    if (policy.StartDate < dateCutOff && policy.StartDate > _utcCutoff)
                    {
                        servicePolicy.DeactivatePolicy(policy.Id);
                        servicePolicy.ArchivePolicy(policy.Id);
                    }
                }
                else if (policy.AutoArchiveType == EnumPolicy.AutoArchiveType.WhenComplete)
                {
                    var groupsWithThisPolicy = servicePolicy.GetPolicyGroups(policy.Id);
                    var memberIds            = new List <int>();
                    foreach (var group in groupsWithThisPolicy)
                    {
                        var groupMembers = new ServiceGroup().GetGroupMembers(group.Id);
                        memberIds.AddRange(groupMembers.Select(member => member.Id));
                    }
                    var distinctMembers = memberIds.Distinct().ToList();
                    if (!distinctMembers.Any())
                    {
                        continue;
                    }
                    var successCount = _uow.PolicyHistoryRepository.Get(x => x.PolicyId == policy.Id && x.Result == EnumPolicyHistory.RunResult.Success).ToList().GroupBy(x => x.ComputerId).Count();
                    if (successCount == distinctMembers.Count)
                    {
                        servicePolicy.DeactivatePolicy(policy.Id);
                        servicePolicy.ArchivePolicy(policy.Id);
                    }
                }
            }
        }
コード例 #2
0
ファイル: PolicyController.cs プロジェクト: theopenem/Toems
        public DtoActionResult DeactivatePolicy(int id)
        {
            var policy = _policyServices.GetPolicy(id);
            var result = _policyServices.DeactivatePolicy(id);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            if (result.Success)
            {
                var auditLog = new EntityAuditLog();
                auditLog.ObjectType = "Policy";
                auditLog.ObjectId   = result.Id;
                auditLog.ObjectName = policy.Name;
                auditLog.ObjectJson = JsonConvert.SerializeObject(policy);
                auditLog.UserId     = _userId;
                auditLog.AuditType  = EnumAuditEntry.AuditType.DeactivatePolicy;
                _auditLogService.AddAuditLog(auditLog);
            }
            return(result);
        }