private void DoFindAllDiscovery() { Stopwatch discoveryStopwatch = new Stopwatch(); discoveryStopwatch.Start(); discoveryHandles = discoveryTestController.DiscoverServices( discoveryParameters.Query, discoveryParameters.ExpectedMatchCount > 0, discoveryParameters.ServiceInfoRequest ); discoveryStopwatch.Stop(); WiFiDirectTestLogger.Log("Services Discovery (FindAllAsync) completed in {0} ms.", discoveryStopwatch.ElapsedMilliseconds); if (discoveryHandles.Count != discoveryParameters.ExpectedMatchCount) { WiFiDirectTestLogger.Error( "Expected {0} devices but discovered {1} devices", discoveryParameters.ExpectedMatchCount, discoveryHandles.Count ); return; } if (discoveryHandles.Count > 0 && discoveryParameters.AdvertisersToMatch != null && discoveryParameters.AdvertisersToMatch.Count > 0) { WiFiDirectTestLogger.Log("Checking discovery results for expected services"); bool foundAll = true; IList <DiscoveredServiceInfo> discoveredDevices = new List <DiscoveredServiceInfo>(); foreach (var handle in discoveryHandles) { DiscoveredServiceInfo discovery = discoveryTestController.GetDiscoveredServiceInfo(handle); discoveredDevices.Add(discovery); WiFiDirectTestLogger.Log( "Discovered service: {0} with address: {1}", discovery.ServiceName, discovery.ServiceAddress.ToString() ); } int adIdx = 0; foreach (var handle in discoveryParameters.AdvertisersToMatch) { ServiceAdvertiserInfo advertiser = advertiserTestController.GetAdvertiserInfo(handle); bool found = false; // Check discovered list for match, remove for (int i = 0; i < discoveredDevices.Count; i++) { if (advertiser.ServiceName == discoveredDevices[i].ServiceName && advertiser.ServiceAddress == discoveredDevices[i].ServiceAddress) { WiFiDirectTestLogger.Log( "Found Expected Service: {0} with address: {1}", discoveredDevices[i].ServiceName, discoveredDevices[i].ServiceAddress.ToString() ); if (discoveryParameters.AdvertiserServiceInfoMatch != null && discoveryParameters.AdvertiserServiceInfoMatch.Count >= adIdx) { if (discoveryParameters.AdvertiserServiceInfoMatch[adIdx]) { WiFiDirectTestLogger.Log( "Expecting Service Info:\n\t{0}\nReceived:\n\t{1}", WiFiDirectTestUtilities.GetTruncatedString(advertiser.ServiceInfo, 32), WiFiDirectTestUtilities.GetTruncatedString(discoveredDevices[i].ServiceInfo, 32) ); if (advertiser.ServiceInfo != discoveredDevices[i].ServiceInfo) { // Allow multiple services with same name/different service info // Skip if service info match fails, will fail if no service info found continue; } } else { WiFiDirectTestLogger.Log( "Expecting No Service Info, Received:\n\t{0}", WiFiDirectTestUtilities.GetTruncatedString(discoveredDevices[i].ServiceInfo, 32) ); if ("" != discoveredDevices[i].ServiceInfo) { // Allow multiple services with same name/different service info // Skip if service info match fails, will fail if no service info found continue; } } } discoveredDevices.RemoveAt(i); found = true; break; } } if (!found) { WiFiDirectTestLogger.Error( "Did NOT Find Expected Service: {0} with address: {1}", advertiser.ServiceName, advertiser.ServiceAddress.ToString() ); foundAll = false; // Continue checking complete list } adIdx++; } if (discoveredDevices.Count > 0) { WiFiDirectTestLogger.Error("Found unexpected services!"); foundAll = false; } if (!foundAll) { return; } } succeeded = true; }