コード例 #1
0
        public async Task <SyncObjectStatus> GetSyncStatus(IEnumerable <Tuple <string, int> > points)
        {
            SyncObjectStatus requestValue = new SyncObjectStatus();

            foreach (var point in points)
            {
                requestValue.Statuses.Add(new SyncObjectStatus.ObjectStatus()
                {
                    ObjectId = point.Item1,
                    Version  = point.Item2
                });
            }
            JObject jsonRequestObject = JObject.FromObject(requestValue);

            SyncObjectStatus deserializedValue = new SyncObjectStatus();

            try
            {
                ApiRequest api      = new ApiRequest();
                var        response = await api.HttpRequestPOST($"{_hostUrl}/routepoints/sync", jsonRequestObject.ToString(), _authToken);

                LastHttpStatusCode = api.LastHttpStatusCode;
                deserializedValue  = JsonConvert.DeserializeObject <SyncObjectStatus>(response);
            }
            catch (Exception e)
            {
                HandleError.Process("PointsApiRequest", "GetSyncStatus", e, false);
            }

            return(deserializedValue);
        }
コード例 #2
0
        public async Task <SyncObjectStatus> GetSyncStatus(IEnumerable <Tuple <string, int> > routes)
        {
            SyncObjectStatus requestValue = new SyncObjectStatus();

            foreach (var route in routes)
            {
                requestValue.Statuses.Add(new SyncObjectStatus.ObjectStatus()
                {
                    ObjectId = route.Item1,
                    Version  = route.Item2
                });
            }
            JObject jsonRequestObject = JObject.FromObject(requestValue);

            SyncObjectStatus deserializedValue = new SyncObjectStatus();

            bool requestResult = false;
            int  triesCount    = 0;

            while (!requestResult)
            {
                deserializedValue = await TryToRequestAsync(jsonRequestObject.ToString(), _authToken);

                requestResult = LastHttpStatusCode == HttpStatusCode.OK;
                if ((!requestResult) && (triesCount < 5) && (LastHttpStatusCode == HttpStatusCode.InternalServerError))//пока не пойму почему на сервере 500 при валидации пользователя
                {
                    triesCount++;
                    Thread.Sleep(30);//ToDo: останавливает основной поток, UI будет тупить, надо на таймер переделать
                }
                else
                {
                    break;
                }
            }

            return(deserializedValue);
        }