static private SetAppSetting ( string key, object value ) : void | ||
key | string | |
value | object | |
return | void |
bool checkForGPSUsage() { var gpsOK = MessageBox.Show(Strings.WelcomeAskGPSBody1 + Environment.NewLine + Strings.WelcomeAskGPSBody2, Strings.WelcomeAskGPSHeader, MessageBoxButton.OKCancel); if (MessageBoxResult.OK == gpsOK) { gpsAllowed = true; } else { gpsAllowed = false; } App.SetAppSetting("settings_use_GPS", gpsAllowed); return(gpsAllowed); }
private void connectCar2Go() { var car2GoGetTokenEndpoint = "https://www.car2go.com/api/reqtoken"; var oauthRequest = new OAuthRequest { CallbackUrl = "oob", ConsumerKey = FreeCarsCredentials.Car2Go.ConsumerKey, ConsumerSecret = FreeCarsCredentials.Car2Go.SharedSecred, Method = "GET", RequestUrl = car2GoGetTokenEndpoint, SignatureMethod = OAuthSignatureMethod.HmacSha1, Type = OAuthRequestType.RequestToken, Version = "1.0", }; var requestParameters = oauthRequest.GetAuthorizationQuery(); var requestUrl = new Uri(car2GoGetTokenEndpoint + "?" + requestParameters, UriKind.Absolute); var webClient = new WebClient(); webClient.DownloadStringCompleted += delegate(object client, DownloadStringCompletedEventArgs arguments) { string[] results = { }; if (null != arguments.Error) { return; } var authorizeUrl = new Uri("https://www.car2go.com/api/authorize?" + arguments.Result, UriKind.Absolute); results = arguments.Result.Split(new string[] { "&" }, StringSplitOptions.None); App.SetAppSetting("car2go.oauth_token_secret", results[1].Split(new char[] { '=' })[1]); App.SetAppSetting("car2go.oauth_request_token", results[0].Split(new char[] { '=' })[1]); //(string)IsolatedStorageSettings.ApplicationSettings["current_map_city"] if (App.IsCertified) { c2gAuthBrowser.Dispatcher.BeginInvoke(() => { c2gAuthBrowser.Visibility = Visibility.Visible; c2gAuthBrowser.Navigate(authorizeUrl); }); } else { verifierPanel.Visibility = Visibility.Visible; var authBrowserTask = new WebBrowserTask { Uri = authorizeUrl, }; c2gScrollViewer.ScrollToVerticalOffset(c2gScrollViewer.ActualHeight); authBrowserTask.Show(); } }; webClient.DownloadStringAsync(requestUrl); }
private void OnCar2goCitySelected(object sender, SelectionChangedEventArgs e) { try { var selectedItem = (sender as ListPicker).SelectedItem as Car2GoLocation; if (0 == selectedItem.locationId) { try { IsolatedStorageSettings.ApplicationSettings.Remove("car2goSelectedCity"); IsolatedStorageSettings.ApplicationSettings.Save(); } catch (Exception) { } } else { App.SetAppSetting("car2goSelectedCity", selectedItem.locationName); } } catch (NullReferenceException) { } }
void OnMyPositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e) { if (GeoPositionStatus.Ready != ((GeoCoordinateWatcher)sender).Status) { return; } cw.Stop(); App.SetAppSetting("my_last_location", e.Position); ShowMeAtLocation(e.Position.Location); SDKAdControl.Latitude = e.Position.Location.Latitude; SDKAdControl.Longitude = e.Position.Location.Longitude; try { if ((bool)IsolatedStorageSettings.ApplicationSettings["settings_allow_analytics"]) { FlurryWP7SDK.Api.SetLocation(e.Position.Location.Latitude, e.Position.Location.Longitude, (float)e.Position.Location.HorizontalAccuracy); } } catch (KeyNotFoundException) { } }
private void getC2GAccessToken(string[] tokenData) { var car2GoGetTokenEndpoint = "https://www.car2go.com/api/accesstoken"; var oauthRequest = new OAuthRequest() { CallbackUrl = "oob", ConsumerKey = FreeCarsCredentials.Car2Go.ConsumerKey, ConsumerSecret = FreeCarsCredentials.Car2Go.SharedSecred, Method = "GET", RequestUrl = car2GoGetTokenEndpoint, SignatureMethod = OAuthSignatureMethod.HmacSha1, Token = tokenData[0], TokenSecret = (string)App.GetAppSetting("car2go.oauth_token_secret"), //TokenSecret = tokenData[1], Type = OAuthRequestType.AccessToken, Verifier = tokenData[1], Version = "1.0", }; var requestParameters = oauthRequest.GetAuthorizationQuery(); var requestUrl = new Uri(car2GoGetTokenEndpoint + "?" + requestParameters, UriKind.Absolute); var webClient = new WebClient(); webClient.DownloadStringCompleted += (client, arguments) => { if (null != arguments.Error) { MessageBox.Show(Strings.SettingsPageCar2GoAuthFailed); return; } var results = arguments.Result.Split(new char[] { '&' }, StringSplitOptions.None); App.SetAppSetting("car2go.oauth_token", results[0].Split(new char[] { '=' })[1]); App.SetAppSetting("car2go.oauth_token_secret", results[1].Split(new char[] { '=' })[1]); App.SetAppSetting("car2go.oauth_token_timestamp", DateTime.UtcNow); CheckCar2GoApiAccess(); }; webClient.DownloadStringAsync(requestUrl); }
private void OnSaveMulticityCredentials(object sender, RoutedEventArgs e) { App.SetAppSetting("multicity.username", multicityUsernameTextbox.Text); App.SetAppSetting("multicity.password", multicityPasswordbox.Password); }
private void SaveToggleSwitch(string setting, bool?isChecked) { App.SetAppSetting(setting, isChecked); }
private void OnSaveDriveNowCredentials(object sender, RoutedEventArgs e) { App.SetAppSetting("driveNow.username", driveNowUsernameTextbox.Text); App.SetAppSetting("driveNow.password", driveNowPasswordbox.Password); }
private void CheckCar2GoApiAccess() { c2gAuthText.Text = Strings.SettingsPageCar2GoAuthStatusNotConnected; var oauth_timestamp = (DateTime?)App.GetAppSetting("car2go.oauth_token_timestamp"); if (null == oauth_timestamp) { App.ClearAppSetting("car2go.oauth_token"); App.ClearAppSetting("car2go.oauth_token_secret"); } else if (((DateTime)oauth_timestamp).AddDays(90.0).CompareTo(DateTime.UtcNow) <= 0) { c2gAuthText.Text = Strings.SettingsPageCar2GoAuthExpired; App.ClearAppSetting("car2go.oauth_token"); App.ClearAppSetting("car2go.oauth_token_secret"); } var oauth_token = (string)App.GetAppSetting("car2go.oauth_token"); var oauth_token_secret = (string)App.GetAppSetting("car2go.oauth_token_secret"); if (null != oauth_token && null != oauth_token_secret) { getCar2GoAccounts( oauth_token, oauth_token_secret, delegate(object client, DownloadStringCompletedEventArgs arguments) { string[] results = { }; if (null == arguments.Error) { //results = arguments.Result.Split(new char[] { '&' }, StringSplitOptions.None); using (Stream resultStream = Helpers.GenerateStreamFromString(arguments.Result)) { var serializer = new DataContractJsonSerializer(typeof(ResultAccounts)); var resultAccounts = (ResultAccounts)serializer.ReadObject(resultStream); switch (resultAccounts.ReturnValue.Code) { case 0: c2gAuthText.Text = String.Format( Strings.SettingsPageCar2GoAuthStatusOK, new string[] { resultAccounts.Account[0].Description, Car2Go.City }); App.SetAppSetting("car2go.oauth_account_id", resultAccounts.Account[0].AccountId); break; case 1: goto default; case 2: goto default; case 3: goto default; default: c2gAuthText.Text = String.Format( Strings.SettingsPageCar2GoAuthStatusError, new string[] { Car2Go.City }); break; } ShowConnectCar2GoApiButton = Visibility.Collapsed; disconnectCar2GoApi.Visibility = Visibility.Visible; DisconnectCar2GoApiButtonV = Visibility.Visible; verifierPanel.Visibility = Visibility.Collapsed; } } client = null; } ); } ShowConnectCar2GoApiButton = Visibility.Visible; DisconnectCar2GoApiButtonV = Visibility.Collapsed; disconnectCar2GoApi.Visibility = Visibility.Collapsed; }
private void RefreshPOIsOnMap() { if (refreshDelay >= DateTime.Now) { var bw = new BackgroundWorker(); bw.DoWork += (sender, args) => { Thread.Sleep(100); RefreshPOIsOnMap(); }; bw.RunWorkerAsync(); return; } if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke(RefreshPOIsOnMap); return; } ((App)Application.Current).RefreshPOIs(); if (IsolatedStorageSettings.ApplicationSettings.Contains("car2goSelectedCity")) { if ("autodetect" != ((string)IsolatedStorageSettings.ApplicationSettings["car2goSelectedCity"]).ToLower()) { return; } } var usCultureInfo = new CultureInfo("en-US"); var latitude = map.Center.Latitude.ToString(usCultureInfo.NumberFormat); var longitude = map.Center.Longitude.ToString(usCultureInfo.NumberFormat); var reverseGeocode = new ReverseGeocode(true); reverseGeocode.Updated += delegate(object o, EventArgs args) { var response = (o as ReverseGeocode).Results; var localityName = ""; if (null != response) { if ("" == localityName) { foreach (var address_component in response.SelectMany(result => result.address_components.Where( address_component => address_component.types.Contains("locality") && address_component.types.Contains("political")))) { localityName = address_component.long_name.ToLower(); break; } } } if ((IsolatedStorageSettings.ApplicationSettings.Contains("current_map_city") && ((string)IsolatedStorageSettings.ApplicationSettings["current_map_city"] != localityName)) || !IsolatedStorageSettings.ApplicationSettings.Contains("current_map_city")) { App.SetAppSetting("current_map_city", localityName); ((App)Application.Current).RootFrame.Dispatcher.BeginInvoke(() => { try { (App.Current.Resources["car2go"] as Car2Go).LoadPOIs(); } catch { } }); } }; reverseGeocode.QueryAsync(latitude, longitude, "DE"); }