public static async Task <bool> PostLocationArray(bool isStartPushPin = false) { try { int maxCount = Globals.TagList.Count; int index = Globals.PostedLocationIndex; //these variables are needed as global values may change in other async parallel calls int count = maxCount - index; if (maxCount != 0 && count != 0) { GeoReference.GeoTags objGeoTags = GetGeotagsObject(count); for (int i = index; i < maxCount; i++) { objGeoTags.Alt.Add(Globals.TagList[i].Alt); objGeoTags.Lat.Add(Globals.TagList[i].Lat.ToString()); objGeoTags.Long.Add(Globals.TagList[i].Long.ToString()); objGeoTags.IsSOS.Add(Globals.TagList[i].IsSOS); objGeoTags.TS.Add(Globals.TagList[i].TimeStamp.Ticks); objGeoTags.Spd.Add(Globals.TagList[i].Speed); objGeoTags.Accuracy.Add(Globals.TagList[i].Accuracy); } string result = string.Empty; using (MemoryStream mem = new MemoryStream()) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GeoReference.GeoTags)); ser.WriteObject(mem, objGeoTags); string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length); WebClient webClient = new WebClient(); webClient.Headers["Content-type"] = "application/json;"; webClient.Headers["AuthID"] = Globals.User.LiveAuthId; webClient.Encoding = Encoding.UTF8; result = await webClient.UploadStringTask(new Uri(Constants.PostMyLocationUrl), data); if (Globals.AddOrUpdateValue("DeactivateTime", DateTimeOffset.Now)) { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; settings.Save(); } } Globals.PostedLocationIndex = maxCount; } return(true); } catch { return(false); } }
private static GeoReference.GeoTags GetGeotagsObject(int LocCount) { if (string.IsNullOrEmpty(Globals.CurrentProfile.SessionToken)) { App.MyProfiles.SaveCurrentProfileSetting(ProfileViewModel.ProfileSetting.SessionToken, Guid.NewGuid().ToString()); } GeoReference.GeoTags objGeoTags = new GeoReference.GeoTags(); objGeoTags.Alt = new ObservableCollection <string>(); objGeoTags.Lat = new ObservableCollection <string>(); objGeoTags.Long = new ObservableCollection <string>(); objGeoTags.IsSOS = new ObservableCollection <bool>(); objGeoTags.TS = new ObservableCollection <long>(); objGeoTags.Id = Globals.CurrentProfile.SessionToken; objGeoTags.LocCnt = LocCount; objGeoTags.PID = Convert.ToInt64(Globals.CurrentProfile.ProfileId); objGeoTags.Spd = new ObservableCollection <int>(); objGeoTags.Accuracy = new ObservableCollection <double>(); return(objGeoTags); }