private void TryDownloading() { if (_haveTried) { return; } _haveTried = true; if (XamlUri != null) { IWebRequestFactory iwrf = Application.Current as IWebRequestFactory; if (iwrf != null) { _loadingToken = CentralStatusManager.Instance.BeginShowEllipsisMessage("Downloading"); var f = iwrf.CreateWebRequestClient(); f.DownloadStringCompleted += OnDownloadStringCompleted; var wr = f.CreateSimpleWebRequest(XamlUri); f.DownloadStringAsync(wr); } else { OnError(); } } }
public void SetCloudSetting( string key, string value, Action <string> success, Action <Exception> failure) { // TODO: Global loading type stuff. var pushUri = PushUri; if (pushUri != null && key != null && value != null) { IWebRequestFactory iwrf = Application.Current as IWebRequestFactory; if (iwrf != null) { var client = (iwrf.CreateWebRequestClient()).GetWrappedClientTemporary(); var uri = ((IGenerate4thAndMayorUri)(Application.Current)) .Get4thAndMayorUri("/v1/push/setSetting/?uri=" + PushNotificationService.Instance.PushUri.ToString() + "&key=" + Uri.EscapeDataString(key) + "&value=" + Uri.EscapeDataString(value) , true); //var req = client.CreateSimpleWebRequest(uri); client.UploadStringCompleted += (sndr, args) => //client.DownloadStringCompleted += (sndr, args) => { AgFx.PriorityQueue.AddUiWorkItem(() => { if (!args.Cancelled && args.Error == null && success != null) { success(args.Result); } else if (args.Error != null && failure != null) { failure(args.Error); } }); }; client.UploadStringAsync(uri, string.Empty); //client.DownloadStringAsyncWithPost(req, string.Empty); } } }
private void DisconnectFromCloud() { // Remove the URI _pushSettings.PushChannelUri = null; _pushSettings.Save(); // Disconnect on the cloud side. IWebRequestFactory iwrf = Application.Current as IWebRequestFactory; if (iwrf != null) { var client = (iwrf.CreateWebRequestClient()).GetWrappedClientTemporary(); var uri = ((IGenerate4thAndMayorUri)(Application.Current)) .Get4thAndMayorUri("/v1/disconnect/?uri=" + (PushUri == null ? string.Empty : PushUri.ToString()), true); client.UploadStringAsync(uri, string.Empty); } }
private void ConnectWithTheCloud(Uri pushUri) { if (_info == null) { throw new InvalidOperationException("_info cloud data was empty."); } if (_pushSettings != null && pushUri != null) { // Store our updated URI first. _pushSettings.PushChannelUri = pushUri; _pushSettings.Save(); } System.Diagnostics.Debug.WriteLine("Push Notification Channel is now open: {0}", pushUri); string version = string.Empty; /*string deviceId; * string liveId; * GetDeviceInformation(out deviceId, out liveId);*/ /*string accent = string.Empty; * try * { * var accentColor = (Color)Application.Current.Resources["PhoneAccentColor"]; * if (accentColor != null) * { * accent = accentColor.ToString(CultureInfo.InvariantCulture); * } * } * catch * { * // timing issue? * }*/ IAppInfo iai = Application.Current as IAppInfo; if (iai != null) { version = iai.Version; } string av = version; string oat = _info.Token; string apv = string.Empty; IAppPlatformVersion iapv = Application.Current as IAppPlatformVersion; if (iapv != null) { apv = iapv.AppPlatformVersion; } string cc = _info.CheckinCount; string uc = _info.UseCount; string mfg = DeviceStatus.DeviceManufacturer + " " + DeviceStatus.DeviceName; string osv = Environment.OSVersion.Version.ToString(); IWebRequestFactory iwrf = Application.Current as IWebRequestFactory; if (iwrf != null) { var client = (iwrf.CreateWebRequestClient()).GetWrappedClientTemporary(); var uri = ((IGenerate4thAndMayorUri)(Application.Current)) .Get4thAndMayorUri(string.Format( CultureInfo.InvariantCulture, //"https://www.4thandmayor.com/v1/connect/?uri={0}&d={1}&lid={2}&oat={3}&u={4}&apv={5}&av={6}&cc={7}&uc={8}&mfg={9}&osv={10}&toast={11}&tile={12}&accent={13}", "/v1/connect/?uri={0}&oat={1}&u={2}&apv={3}&av={4}&cc={5}&uc={6}&mfg={7}&osv={8}", HttpUtility.UrlEncode(pushUri.ToString()), //deviceId, //liveId, oat, _info.UserId, apv, av, cc, uc, HttpUtility.UrlEncode(mfg), osv //_info.Toast, //_info.Tile, //HttpUtility.UrlEncode(accent) ), true); //var req = client.CreateSimpleWebRequest(uri); //client.DownloadStringCompleted += OnServiceConnectCompleted; // Try getting all active tiles. StringBuilder sb = new StringBuilder(); try { foreach (var t in ShellTile.ActiveTiles) { sb.AppendLine(t.NavigationUri.ToString()); } } catch (Exception) { } client.UploadStringAsync(uri, sb.ToString()); //client.DownloadStringAsyncWithPost(req, sb.ToString()); } }
public void Update(Action <string> callback) { IWebRequestFactory iwrf = (IWebRequestFactory)Application.Current; Debug.Assert(iwrf != null); if (LocationAssistant.Instance.LastKnownLiveLocation != null && LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Ready) { // uses the live version. var lll = LocationAssistant.Instance.LastKnownLiveLocation; double lat = lll.Latitude; double @long = lll.Longitude; PriorityQueue.AddNetworkWorkItem(() => { var cclient = iwrf.CreateWebRequestClient(); //new FourSquareWebClient(); var client = cclient.GetWrappedClientTemporary(); //var r = client.CreateSimpleWebRequest(GetServiceUri(lat, @long)); //var r = client.CreateServiceRequest(GetServiceUri(lat, @long), false /* no credentials */); client.DownloadStringCompleted += (x, xe) => { if (xe.Error != null) { // TODO: Make sure that the chain supports a EMPTY and not NULL geocode _asCoordinates = string.Format(CultureInfo.InvariantCulture, "No data connection ({0:0.000}, {1:0.000})", lat, @long); Location = _asCoordinates; callback(_lastGeocode); } else { string s = xe.Result; Action <string> cb = callback; PriorityQueue.AddWorkItem(() => ParseJson(s, cb)); } }; client.DownloadStringAsync(GetServiceUri(lat, @long)); }); } else { //LastGeocodeName = string.Empty; string s = "Location service is off or unavailable."; if (LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Initializing) { s = string.Empty; // "Finding your location..."; } if (LocationAssistant.Instance.Status == System.Device.Location.GeoPositionStatus.Ready) { s = "Looking up your address..."; } Location = s; callback(_lastGeocode); // TODO: Warning, this is not a good thing to do. ? var cb = callback; IntervalDispatcher.BeginInvoke(TimeSpan.FromSeconds(1), () => Update(cb)); } }