void UpLoadAttendanceGPSPoints() { string cookieName = string.Empty; string cookieValue = string.Empty; var user = Common.GetCurrentUser(); var login = new RestClient(Settings.URLs.Host); //login.Authenticator = new SimpleAuthenticator("identifier", "*****@*****.**", "password", "q1234567"); login.Authenticator = new SimpleAuthenticator(@"identifier", user.username, @"password", user.password); login.CookieContainer = new CookieContainer(); var request = new RestRequest(@"auth/local", Method.POST); var response = login.Execute <User>(request); User userRes = response.Data; if (userRes == null) { RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось пройти аутентификацию!")); } cookieName = response.Cookies[0].Name; cookieValue = response.Cookies[0].Value; var queueToUpload = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate); foreach (var q in queueToUpload) { try { if ((q.type == SyncQueueType.sqtAttendanceGPSPoint) && (!q.isSync)) { var client = new RestClient(Settings.URLs.Host); //Debug.WriteLine(@"Получение информации о себе.", @"Info"); AttendanceGPSPoint attendanceGPSPoint = SyncQueueManager.GetAttendanceGPSPoint(q.fileLocation); //Attendance attendance = AttendanceManager.GetAttendance (attendanceGPSPoint.attendance); RunOnUiThread(() => progressDialog.SetMessage(string.Format(@"Загрузка GPS значений с id {0} по посещению с id:{1}", attendanceGPSPoint.id, attendanceGPSPoint.attendance))); request = new RestRequest(@"AttendanceGPSPoint/", Method.POST); request.AddCookie(cookieName, cookieValue); request.RequestFormat = DataFormat.Json; request.JsonSerializer.ContentType = @"application/json; charset=utf-8"; request.AddParameter(@"application/json; charset=utf-8", attendanceGPSPoint.ToJSON(), ParameterType.RequestBody); // attendanceResult.id = 0; // request.AddBody(attendanceResult); var respAttendanceGPSPoint = client.Execute(request); switch (respAttendanceGPSPoint.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Created: q.isSync = true; SyncQueueManager.SaveSyncQueue(q, false); // Thread.Sleep (500); RunOnUiThread(() => { progressDialog.SetMessage(string.Format(@"GPS значение с id {0} по посещению с id:{1} ЗАГРУЖЕНО!", attendanceGPSPoint.id, attendanceGPSPoint.attendance)); // RefreshContent(); }); continue; default: // Thread.Sleep (500); RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось загрузить GPS значение по посещению!")); // Thread.Sleep (1500); continue; } } } catch (Exception ex) { RunOnUiThread(() => progressDialog.SetMessage(@"Error : " + ex.Message)); // Thread.Sleep (1500); continue; } } }
void UpLoadAttendancePhotos() { string cookieName = string.Empty; string cookieValue = string.Empty; var user = Common.GetCurrentUser(); var login = new RestClient(Settings.URLs.Host); //login.Authenticator = new SimpleAuthenticator("identifier", "*****@*****.**", "password", "q1234567"); login.Authenticator = new SimpleAuthenticator(@"identifier", user.username, @"password", user.password); login.CookieContainer = new CookieContainer(); var loginReq = new RestRequest(@"auth/local", Method.POST); var loginRes = login.Execute <User>(loginReq); User userRes = loginRes.Data; if (userRes == null) { RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось пройти аутентификацию!")); } cookieName = loginRes.Cookies[0].Name; cookieValue = loginRes.Cookies[0].Value; var queueToUpload = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate); foreach (var q in queueToUpload) { try { if ((q.type == SyncQueueType.sqtAttendancePhoto) && (!q.isSync)) { //Debug.WriteLine(@"Получение информации о себе.", @"Info"); AttendancePhoto attendancePhoto = SyncQueueManager.GetAttendancePhoto(q.fileLocation); //Attendance attendance = AttendanceManager.GetAttendance (attendancePhoto.attendance); RunOnUiThread(() => progressDialog.SetMessage(string.Format(@"Загрузка фото с id {0} по посещению с id:{1}", attendancePhoto.id, attendancePhoto.attendance))); var client = new RestClient(Settings.URLs.Host); // var request = new RestRequest (@"AttendancePhoto/create?attendance={attendance}&longitude={longitude}&latitude={latitude}&stamp={stamp}", Method.POST); var request = new RestRequest(@"AttendancePhoto/create?localID={localID}&attendance={attendance}&longitude={longitude}&latitude={latitude}&subType={subType}", Method.POST); request.AddCookie(cookieName, cookieValue); request.AddUrlSegment(@"localID", attendancePhoto.id.ToString()); request.AddUrlSegment(@"attendance", attendancePhoto.attendance.ToString()); request.AddUrlSegment(@"longitude", attendancePhoto.longitude.ToString(CultureInfo.CreateSpecificCulture("en-GB"))); request.AddUrlSegment(@"latitude", attendancePhoto.latitude.ToString(CultureInfo.CreateSpecificCulture("en-GB"))); request.AddUrlSegment(@"subType", attendancePhoto.subType.ToString()); // request.AddUrlSegment(@"stamp", attendancePhoto.stamp.ToString()); request.AddFile(@"photo", File.ReadAllBytes(attendancePhoto.photoPath), Path.GetFileName(attendancePhoto.photoPath), string.Empty); var response = client.Execute(request); switch (response.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Created: // case HttpStatusCode.U q.isSync = true; SyncQueueManager.SaveSyncQueue(q, false); // Thread.Sleep (500); RunOnUiThread(() => { progressDialog.SetMessage(string.Format(@"Фото с id {0} по посещению с id:{1}"" ЗАГРУЖЕНО!", attendancePhoto.id, attendancePhoto.attendance)); // RefreshContent(); }); continue; default: // Thread.Sleep (500); RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось загрузить фото по посещению!")); // Thread.Sleep (1500); continue; } } } catch (Exception ex) { RunOnUiThread(() => progressDialog.SetMessage(@"Error : " + ex.Message)); // Thread.Sleep (1500); continue; } } }
void UpLoadAttendances() { string cookieName = string.Empty; string cookieValue = string.Empty; var user = Common.GetCurrentUser(); var login = new RestClient(Settings.URLs.Host); //login.Authenticator = new SimpleAuthenticator("identifier", "*****@*****.**", "password", "q1234567"); login.Authenticator = new SimpleAuthenticator(@"identifier", user.username, @"password", user.password); login.CookieContainer = new CookieContainer(); var request = new RestRequest(@"auth/local", Method.POST); var response = login.Execute <User>(request); User userRes = response.Data; if (userRes == null) { RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось пройти аутентификацию!")); return; } cookieName = response.Cookies[0].Name; cookieValue = response.Cookies[0].Value; var queueToUpload = (List <SyncQueue>)SyncQueueManager.GetSyncQueue(selectedDate); foreach (var q in queueToUpload) { try { if ((q.type == SyncQueueType.sqtAttendance) && (!q.isSync)) { var client = new RestClient(Settings.URLs.Host); Attendance oldAttendance = SyncQueueManager.GetAttendace(q.fileLocation); RunOnUiThread(() => progressDialog.SetMessage(string.Format(@"Загрузка посещения с id:{0}", oldAttendance.id))); request = new RestRequest(@"Attendance/", Method.POST); request.AddCookie(cookieName, cookieValue); request.RequestFormat = DataFormat.Json; request.JsonSerializer.ContentType = @"application/json; charset=utf-8"; //request.AddBody(oldAttendance); request.AddParameter(@"application/json; charset=utf-8", oldAttendance.ToJSON(), ParameterType.RequestBody); var respAttendance = client.Execute <Attendance>(request); Attendance newAttendance = respAttendance.Data; // Thread.Sleep (500); switch (respAttendance.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Created: if (AttendanceResultManager.CreateItemsForSync(oldAttendance, newAttendance) && AttendancePhotoManager.CreateItemsForSync(oldAttendance, newAttendance) && AttendanceGPSPointManager.CreateItemsForSync(oldAttendance, newAttendance) ) { q.isSync = true; SyncQueueManager.SaveSyncQueue(q, false); RunOnUiThread(() => { progressDialog.SetMessage(string.Format(@"Посещение с id:{0} ЗАГРУЖЕНО!", oldAttendance.id)); // RefreshContent (); }); } else { RunOnUiThread(() => { progressDialog.SetMessage(string.Format(@"Не удалось скорректировать данные для посещения с id:{0} ОШИБКА!", oldAttendance.id)); // RefreshContent (); }); } continue; default: // Thread.Sleep (500); RunOnUiThread(() => progressDialog.SetMessage(@"Не удалось загрузить посещение!")); // Thread.Sleep (1500); break; } } } catch (Exception ex) { RunOnUiThread(() => progressDialog.SetMessage(@"Error : " + ex.Message)); // Thread.Sleep (1500); break; } } }