protected RemoteDataStore() { _writeTimeoutMinutes = 5; _mostRecentSuccessfulWriteTime = null; _writeOnPowerConnect = true; _requireWiFi = true; _requireCharging = true; _requiredBatteryChargeLevelPercent = 20; _alertUserWhenBackgrounded = true; _userNotificationMessage = "Please open this notification to submit your data."; #if DEBUG || UI_TESTING WriteDelayMS = 10000; // 10 seconds...so we can see debugging output quickly #else WriteDelayMS = 1000 * 60 * 60; // every 60 minutes #endif _powerConnectionChanged = async(sender, connected) => { if (connected) { if (_writeOnPowerConnect) { SensusServiceHelper.Get().Logger.Log("Writing to remote on power connect signal.", LoggingLevel.Normal, GetType()); _powerConnectWriteCancellationToken = new CancellationTokenSource(); await WriteLocalDataStoreAsync(_powerConnectWriteCancellationToken.Token); } } else { // cancel any prior write attempts resulting from AC power connection _powerConnectWriteCancellationToken?.Cancel(); } }; _wifiConnectionChanged = async(sender, args) => { if (args.IsConnected) { if (WriteOnWifiConnect) { SensusServiceHelper.Get().Logger.Log("Writing to remote on Wifi connect signal.", LoggingLevel.Normal, GetType()); _wifiConnectWriteCancellationToken = new CancellationTokenSource(); await WriteLocalDataStoreAsync(_wifiConnectWriteCancellationToken.Token); } } else { // cancel any prior write attempts resulting from Wifi connection _wifiConnectWriteCancellationToken?.Cancel(); } }; }
/// <summary> /// Sets the connection changed event. /// </summary> /// <param name="connectivityChangedEventHandler">Connectivity changed event handler.</param> public static void SetOnConnectionChangedEvent(ConnectivityChangedEventHandler connectivityChangedEventHandler) { CrossConnectivity.Current.ConnectivityChanged -= connectivityChangedEventHandler; CrossConnectivity.Current.ConnectivityChanged += connectivityChangedEventHandler; }