Example #1
0
        public async Task GetRsopOfReachableComputers()
        {
            clearOldRsops();
            List <OrganizationalUnit> allOUs = await unitOfWork.OrganizationalUnitRepository.GetAllEntities();

            List <ADDomain> allDomains = await unitOfWork.ADDomainRepository.GetAllEntities();

            List <int?> collectedSiteIds = new List <int?>();

            foreach (OrganizationalUnit OU in allOUs)
            {
                collectedSiteIds.Clear();

                var domain = allDomains.Find(x => x.ADDomainId == OU.ADDomainRefId);

                if (OU.Computers != null)
                {
                    OU.HasReachableComputer = false;
                    foreach (var computer in OU.Computers)
                    {
                        if (!collectedSiteIds.Contains(computer.SiteRefId) && pingService.IsPingable(computer.IpAddress))
                        {
                            computer.PingSuccessful = true;
                            unitOfWork.ComputerRepository.Update(computer);

                            OU.HasReachableComputer = true;
                            unitOfWork.OrganizationalUnitRepository.Update(OU);

                            collectedSiteIds.Add(computer.SiteRefId);

                            getRSoP(computer.ComputerName + "." + domain.Name,
                                    OU.OrganizationalUnitsId, computer.SiteRefId,
                                    System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                        }
                    }
                    await unitOfWork.SaveChangesAsync();
                }
            }
        }