public static List <ServiceOfferDesc> FindOffer(OfferRegistry offers, ServiceProperty[] search, int count, int tries, int interval) { OrbServices orb = OrbServices.GetSingleton(); List <ServiceOfferDesc> found = new List <ServiceOfferDesc>(); for (int i = 0; i < tries; i++) { found.Clear(); Thread.Sleep(interval * 1000); ServiceOfferDesc[] services = offers.findServices(search); if (services.Length > 0) { foreach (ServiceOfferDesc offerDesc in services) { try { if (!orb.non_existent(offerDesc.service_ref)) { found.Add(offerDesc); } } catch (Exception) { // não adiciona essa oferta } } } if (found.Count >= count) { return(found); } } StringBuilder buffer = new StringBuilder(); foreach (ServiceOfferDesc desc in found) { String name = GetProperty(desc.properties, "openbus.offer.entity"); String login = GetProperty(desc.properties, "openbus.offer.login"); buffer.AppendFormat("\n - {0} ({1})", name, login); } String msg = String .Format( "Não foi possível encontrar ofertas: found ({0}) expected({1}) tries ({2}) time ({3}){4}", found.Count, count, tries, tries * interval, buffer); throw new InvalidOperationException(msg); }
/// <summary> /// Filtra ofertas e retorna somente as que se encontram responsivas. /// Qualquer erro encontrado ao tentar acessar uma oferta faz com que não /// seja inclusa no conjunto retornado, inclusive erros NO_PERMISSION com /// minor code NoLogin. /// </summary> /// <param name="offers">Ofertas a ser verificadas por responsividade.</param> /// <returns>Conjunto de ofertas responsivas no momento do teste.</returns> public static ServiceOfferDesc[] FilterWorkingOffers( IEnumerable <ServiceOfferDesc> offers) { OrbServices orb = OrbServices.GetSingleton(); IList <ServiceOfferDesc> working = new List <ServiceOfferDesc>(); foreach (ServiceOfferDesc offerDesc in offers) { try { if (!orb.non_existent(offerDesc.service_ref)) { working.Add(offerDesc); } } catch (Exception) { // não adiciona essa oferta } } return(working.ToArray()); }