コード例 #1
0
        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);
            }
        }