From: Seonah Moon Date: Mon, 9 Dec 2019 05:30:11 +0000 (+0900) Subject: [Connection][Non-ACR][Add exception handling codes for precondition] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eca987eeb94a45d20f223abd328604557d62a30a;p=test%2Ftct%2Fcsharp%2Fapi.git [Connection][Non-ACR][Add exception handling codes for precondition] Change-Id: I69688558f8588e42a26272c050b7436766079375 --- diff --git a/tct-suite-vs/Tizen.Connection.Tests/testcase/support/networkSetup.cs b/tct-suite-vs/Tizen.Connection.Tests/testcase/support/networkSetup.cs index 152a351..026aab4 100755 --- a/tct-suite-vs/Tizen.Connection.Tests/testcase/support/networkSetup.cs +++ b/tct-suite-vs/Tizen.Connection.Tests/testcase/support/networkSetup.cs @@ -16,11 +16,39 @@ namespace networkUtils public class networkSetup { private static int MAX_SCAN_TRY = 3; + private static WiFiConnectionState connectionState = WiFiConnectionState.Disconnected; private networkSetup() { } + private static void EventHandlerConnectionStateChangedCBState(object sender, ConnectionStateChangedEventArgs e) + { + connectionState = e.State; + Tizen.Log.Info(Globals.LogTag, "ConnectionState is changed: " + connectionState.ToString()); + } + + private static async Task waitConnecting() + { + int count = 0; + while (true) + { + await Task.Delay(1000); + count++; + if (connectionState == WiFiConnectionState.Connected) + { + Tizen.Log.Info(Globals.LogTag, "Connected"); + break; + } + + if (count == 30) + { + Tizen.Log.Info(Globals.LogTag, "connecting timeout is reached"); + break; + } + } + } + public static async Task ForgetCurrentAP() { Tizen.Log.Info(Globals.LogTag, "networkSetup.ForgetCurrentAP"); @@ -130,16 +158,31 @@ namespace networkUtils ap.SecurityInformation.SetPassphrase(WiFiPass); } + WiFiManager.ConnectionStateChanged += EventHandlerConnectionStateChangedCBState; + try { await ap.ConnectAsync(); Tizen.Log.Info(Globals.LogTag, "Connected"); } + catch (NowInProgressException) + { + Tizen.Log.Info(Globals.LogTag, "Connecting.."); + await waitConnecting(); + } catch (System.Exception e) { - Tizen.Log.Info(Globals.LogTag, "Exception during Wi-Fi Association: " + e); - await ap.ConnectAsync(); + if (WiFiManager.ConnectionState == WiFiConnectionState.Connected) + { + Tizen.Log.Info(Globals.LogTag, "Already connected"); + } + else + { + Tizen.Log.Info(Globals.LogTag, "Exception during Wi-Fi Association: " + e); + await ap.ConnectAsync(); + } } + WiFiManager.ConnectionStateChanged -= EventHandlerConnectionStateChangedCBState; } // ConnectWiFi() } }