예제 #1
0
        ServicesPublishDiscoverScenarioResult ExecutePublishDiscoverScenario(ServicesPublishDiscoverParameters pubDiscoParams)
        {
            ServicesPublishDiscoverScenario scenario = new ServicesPublishDiscoverScenario(
                localWFDController,
                remoteWFDController,
                pubDiscoParams
                );
            ServicesPublishDiscoverScenarioResult scenarioResult = scenario.Execute();

            Verify.IsTrue(scenarioResult.ScenarioSucceeded);

            return(scenarioResult);
        }
        private void ExecuteInternal()
        {
            try
            {
                WiFiDirectTestLogger.Log("Beginning Publish/Discover/Connect scenario");

                // Do publish/discover(s)
                var publishDiscoverScenario = new ServicesPublishDiscoverScenario(
                    seekerTestController,
                    advertiserTestController,
                    publishDiscoveryConnectParameters.PublishDiscoverParameters
                    );
                ServicesPublishDiscoverScenarioResult publishDiscoverResults = publishDiscoverScenario.Execute();
                publishResults   = publishDiscoverResults.PublishResults;
                discoveryResults = publishDiscoverResults.DiscoveryResults;

                if (!publishDiscoverResults.ScenarioSucceeded)
                {
                    throw new Exception("Publish/Discover failed!");
                }

                // BUG: [TH2] Fix race on back-to-back discoveries
                Task.Delay(500).Wait();

                // Do all connects
                foreach (var connectPreParams in publishDiscoveryConnectParameters.ConnectParameters)
                {
                    // Need to translate indices to handles

                    if (connectPreParams.AdvertisedHandleIndex > publishResults.Count || connectPreParams.AdvertisedHandleIndex < 0)
                    {
                        throw new Exception("Bad connect parameters! Index out of range for advertiser");
                    }
                    WFDSvcWrapperHandle advertiserHandle = publishResults[connectPreParams.AdvertisedHandleIndex].AdvertiserHandle;

                    if (connectPreParams.DiscoveryResultIndex > discoveryResults.Count ||
                        connectPreParams.DiscoveryResultIndex < 0 ||
                        connectPreParams.DiscoveredHandleIndex > discoveryResults[connectPreParams.DiscoveryResultIndex].DiscoveryHandles.Count ||
                        connectPreParams.DiscoveredHandleIndex < 0)
                    {
                        throw new Exception("Bad connect parameters! Index out of range for discovered device");
                    }
                    WFDSvcWrapperHandle discoveredDevice = discoveryResults[connectPreParams.DiscoveryResultIndex].DiscoveryHandles[connectPreParams.DiscoveredHandleIndex];

                    // Now run scenario

                    ServicesConnectParameters connectParams = new ServicesConnectParameters(
                        discoveredDevice,
                        advertiserHandle,
                        connectPreParams.Options
                        );

                    var connectScenario = new ServicesConnectScenario(seekerTestController, advertiserTestController, connectParams);
                    ServicesConnectScenarioResult connectResult = connectScenario.Execute();
                    connectResults.Add(connectResult);

                    if (!connectResult.ScenarioSucceeded)
                    {
                        throw new Exception("Connect failed!");
                    }
                }

                succeeded = true;
            }
            catch (Exception e)
            {
                WiFiDirectTestLogger.Error("Caught exception while executing service publish/discover/connect scenario: {0}", e);
            }
        }