internal static bool Synchronize() { log.Info("Uruchomiono program z opcją \"synchronize\""); if (!IisIntegration.CheckBeforeSynchronization) { return(false); } UpdatePermanentList(); List <EntityIpDomain> compareList = Lists.Zip(GetListFromFile(permanentFileName), Ims.GetList()); List <EntityIpDomain> iisList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant); List <EntityIpDomain> compToIms = Lists.GetDifference(compareList, iisList); List <EntityIpDomain> imsToComp = Lists.GetDifference(iisList, compareList); if ((compToIms.Count > 0) || (imsToComp.Count > 0)) { IisIntegration.UpdateIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant, compareList); string ErrorDescription = string.Format("Dodane do IMS adresy: {0}. Usunięte w IMS adresy: {1}", Lists.ToString(compToIms), Lists.ToString(imsToComp)); Console.WriteLine(ErrorDescription); log.Info(ErrorDescription); } log.Info("Zakończono synchronizację."); return(true); }
internal static void AddFromArg(string hostIp) { try { ErrorDescription = string.Empty; List <EntityIpDomain> newList = new List <EntityIpDomain>(); List <EntityIpDomain> currentList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant); string ip = ParseAddress.GetLine(hostIp.Replace("\"", "").Replace(" ", "")); if (!string.IsNullOrEmpty(ip)) { Result result = IisIntegration.SetIpSecurityPropertySingle(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant, ip, out currentList, out newList); switch (result) { case Result.Failure: Console.WriteLine(ErrorDescription = string.Format("Błąd podczas importu adresu IP: {0}", ip)); log.Error(ErrorDescription); break; case Result.NotExist: break; case Result.Exist: Console.WriteLine(ErrorDescription = string.Format("Adres IP: \"{0}\" już jest dodany do listy relay.", ip)); log.Info(ErrorDescription); break; case Result.OK: Console.WriteLine(ErrorDescription = string.Format("Zaimportowano adres IP: \"{0}\"", ip)); log.Info(ErrorDescription); break; } } else { Console.WriteLine(ErrorDescription = string.Format("Nieprawidłowy format adresu: \"{0}\"", ip)); log.Error(ErrorDescription); } } catch (Exception ex) { ErrorDescription = string.Format("Nie udało się dodać adresu IP: {0}", ex.Message); Console.WriteLine(ErrorDescription); log.Error(ErrorDescription); } }
internal static void ImportFromFile(string myFileName) { int validLines = 0; int counter = 0; List <EntityIpDomain> list = GetListFromFile(myFileName); if (list.Count > 0) { ErrorDescription = string.Empty; List <EntityIpDomain> newList = new List <EntityIpDomain>(); List <EntityIpDomain> currentList = IisIntegration.GetIpSecurityPropertyArray(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant); foreach (var ip in list) { counter++; Result result = IisIntegration.SetIpSecurityPropertySingle(IisIntegration.METABASE, MethodName.Get, MethodArgument.IPSecurity, Member.IPGrant, ip.IpDomain, out currentList, out newList); switch (result) { case Result.Failure: Console.WriteLine(ErrorDescription = string.Format("Wiersz nr {0} - błąd podczas importu adresu IP: \"{1}\"", counter, ip.IpDomain)); log.Error(ErrorDescription); break; case Result.NotExist: break; case Result.Exist: Console.WriteLine(ErrorDescription = string.Format("Wiersz nr {0} - urządzenie o adresie IP: \"{1}\" już jest dodana do listy relay.", counter, ip.IpDomain)); log.Info(ErrorDescription); break; case Result.OK: Console.WriteLine(ErrorDescription = string.Format("Wiersz nr {0} - pomyślnie zaimportowano adres IP: \"{1}\" do listy relay.", counter, ip.IpDomain)); log.Info(ErrorDescription); validLines++; break; } } } Console.WriteLine(string.Format("Wykonano import z pliku: {0}", myFileName)); Console.WriteLine(string.Format(" Odczytano wierszy: {0}", counter)); Console.WriteLine(string.Format("Zaimportowanych adresów: {0}", validLines)); log.Info(string.Format("Odczytanych wierszy: {0}. Zaimportowanych adresów: {1}", counter, validLines)); }