public async Task <bool> SyncFromServer(int method) { timeStart = DateTime.Now; totalRowInserted = 0; totalRowUpdated = 0; Debug.WriteLine("Sync Invoice From Server Started!"); if (Settings.LastSyncInvoice != 0) { await SyncToServer(method); } var response = await restClient.GetStringAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_GET_INVOICE(CurrentUserName, Settings.CurrentPassword, Settings.LastSyncInvoice)); if (!string.IsNullOrWhiteSpace(response) && !response.Equals("[]")) { ProcessData(response); } else { SetLastSyncInvoice(); } Debug.WriteLine("Sync Invoice Time: " + DateTime.Now.Subtract(timeStart).TotalSeconds); Debug.WriteLine("Total Invoice Inserted: " + totalRowInserted); Debug.WriteLine("Total Invoice Updated: " + totalRowUpdated); Debug.WriteLine("Sync Invoice From Server Ended!"); return(await Task.FromResult(true)); }
public async Task <bool> SyncFromServer(int method) { timeStart = DateTime.Now; totalRowInserted = 0; totalRowUpdated = 0; Debug.WriteLine("Sync Product From Server Started!"); var response = await restClient.GetStringAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_GET_PRODUCTS(CurrentUserName, Settings.CurrentPassword, Settings.LastSyncInvoice)); if (!string.IsNullOrWhiteSpace(response) && !response.Equals("[]") && !(response.Contains("SUCCESS\":\"No result") || response.Equals("{\"SUCCESS\":\"No result\"}"))) { ProcessData(response); } else { SetLastSyncProduct(); } Debug.WriteLine("Sync Product Time: " + DateTime.Now.Subtract(timeStart).TotalSeconds); Debug.WriteLine("Total Product Inserted: " + totalRowInserted); Debug.WriteLine("Total Product Updated: " + totalRowUpdated); Debug.WriteLine("Sync Product From Server Ended!"); return(await Task.FromResult(true)); }
public async Task <bool> AssignToMe(int interventionId) { var response = await restClient.GetAsync(ApiURI.URL_BASE(Settings.CurrentAccount) + ApiURI.URL_SET_INTERVENTION_ASSIGN(Settings.CurrentUserName, Settings.CurrentPassword, interventionId)); var content = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var result = JsonConvert.DeserializeObject <JObject>(content); if (result != null) { if (result.GetValue("MESSAGE") != null) { Debug.WriteLine("Assiggn Intervention successed: " + content); return(await Task.FromResult(true)); } else if (result.GetValue("ERROR") != null) { Debug.WriteLine("Intervention already assigned: " + content); return(await Task.FromResult(false)); } } throw new Exception(content); } else { Debug.WriteLine("Assiggn Intervention failed: " + content); throw new Exception(content); } }
public async Task <List <Intervention> > GetHistory(int interventionId) { var response = await restClient.GetAsync(ApiURI.URL_BASE(Settings.CurrentAccount) + ApiURI.URL_GET_INTERVENTION_HISTORY(Settings.CurrentUserName, Settings.CurrentPassword, interventionId)); var content = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var result = JsonConvert.DeserializeObject <InterventionHistoryRespone>(content); if (result != null) { List <Intervention> interventions = new List <Intervention>(); if (result.Interventions != null) { foreach (var intRes in result.Interventions) { interventions.Add(new Intervention(intRes)); } } return(interventions); } } else { Debug.WriteLine("Get Intervention History failed: " + content); return(null); } return(null); }
public async Task <bool> SyncFromServer(int method) { timeStart = DateTime.Now; totalRowInserted = 0; totalRowUpdated = 0; int page = 0; Debug.WriteLine("Sync Issue From Server Started!"); if (!Settings.LastSyncIssue.Equals("0")) { await SyncToServerAsync(method); var url = ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_GET_ISSUE(CurrentUserName, Settings.CurrentPassword, page, Settings.LastSyncIssue); var response = await restClient.GetStringAsync(url); if (!string.IsNullOrWhiteSpace(response) && !response.Equals("[]")) { ProcessData(response); page++; //page increase } else { SetLastSyncIssue(); //NeedToSync = false; } Debug.WriteLine("Sync Issue Time: " + DateTime.Now.Subtract(timeStart).TotalSeconds); Debug.WriteLine("Total Issue Inserted: " + totalRowInserted); Debug.WriteLine("Total Issue Updated: " + totalRowUpdated); Debug.WriteLine("Sync Issue From Server Ended!"); return(await Task.FromResult(true)); } bool NeedToSync = true; while (NeedToSync) { var response = await restClient.GetStringAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_GET_ISSUE(CurrentUserName, Settings.CurrentPassword, page, Settings.LastSyncIssue)); if (!string.IsNullOrWhiteSpace(response) && !response.Equals("[]")) { ProcessData(response); page++; //page increase } else { SetLastSyncIssue(); NeedToSync = false; } } Debug.WriteLine("Sync Issue Time: " + DateTime.Now.Subtract(timeStart).TotalSeconds); Debug.WriteLine("Total Issue Inserted: " + totalRowInserted); Debug.WriteLine("Total Issue Updated: " + totalRowUpdated); Debug.WriteLine("Sync Issue From Server Ended!"); return(await Task.FromResult(true)); }
public async Task <bool> SyncFromServer(int method) { timeStart = DateTime.Now; totalRowInserted = 0; totalRowUpdated = 0; Debug.WriteLine("Sync Equipment From Server Started!"); if (!Settings.LastSyncEquipment.Equals("0")) { await SyncToServer(method); } int page = 0; bool NeedToSync = true; Debug.WriteLine("Sync Equipment To Server Started!"); while (NeedToSync) { string url = ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_GET_EQUIPMENT(CurrentUserName, Settings.CurrentPassword, page, Settings.LastSyncEquipment); Debug.WriteLine("url: " + url); var response = await restClient.GetStringAsync(url); Debug.WriteLine("Response Invoice: " + response); if (!string.IsNullOrWhiteSpace(response) && !response.Equals("[]")) { ProcessData(response); page++; } else { SetLastSyncEquipmnet(); NeedToSync = false; } } Debug.WriteLine("Sync Invoice Time: " + DateTime.Now.Subtract(timeStart).TotalSeconds); Debug.WriteLine("Total Invoice Inserted: " + totalRowInserted); Debug.WriteLine("Total Invoice Updated: " + totalRowUpdated); Debug.WriteLine("Sync Invoice From Server Ended!"); return(await Task.FromResult(true)); }
public async Task <bool> SyncToServer(int method) { var invoices = App.LocalDb.Table <Invoice>().Where(inv => inv.UserId == CurrentUser.Id && inv.IsToSync).ToArray(); var invoices_lines = App.LocalDb.Table <InvoiceProduct>().Where(ip => ip.UserId == CurrentUser.Id && ip.IsToSync).ToArray(); JObject @params = new JObject(); if (invoices.LongLength > 0) { @params.Add(new JProperty("invoices", JArray.FromObject(invoices).RemoveEmptyChildren(invoices.FirstOrDefault()?.PropertyIgnore))); } if (invoices_lines.LongLength > 0) { @params.Add(new JProperty("invoices_lines", JArray.FromObject(invoices_lines).RemoveEmptyChildren(invoices_lines.FirstOrDefault()?.PropertyIgnore))); } if (@params.Count > 0) { @params.Add(new JProperty("api_version", ApiURI.API_MOBILE_TO_SERVER_VERSION)); @params.Add(new JProperty("appVersion", ApiURI.APP_VERSION)); } else { return(await Task.FromResult(true)); } var response = await restClient.PostAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_SET_INVOICE(CurrentUserName, Settings.CurrentPassword), @params); var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("RESPONSE: " + responseContent); if (response.IsSuccessStatusCode) { var result = JsonConvert.DeserializeObject <SetSyncInvoiceResponse>(responseContent, App.DefaultDeserializeSettings); if (result != null && result.Success.Equals("OK")) { foreach (var inv in invoices) { if (result.Invoices.FirstOrDefault(c => ((c.ServerId > 0 && c.ServerId == inv.ServerId) || Guid.TryParse(c.AppId, out Guid id) && inv.Id.Equals(id))) is Models.SetSync.InvoiceResponse invr && invr.ServerId > 0) { var invoice = inv.DeepCopy(); App.LocalDb.Delete(inv); invoice.ServerId = invr.ServerId; invoice.InvoiceNumber = invr.InvoiceNumber; //invoice.SynchronizationDate = DateTime.Now; invoice.IsToSync = false; App.LocalDb.Insert(invoice); if (App.LocalDb.Table <MediaLink>().FirstOrDefault(mdl => !mdl.FkColumnAppliId.Equals(Guid.Empty) && mdl.FkColumnAppliId.Equals(inv.Id)) is MediaLink mediaLink) { mediaLink.FkColumnServerId = invr.ServerId; App.LocalDb.Update(mediaLink); } } else { inv.IsToSync = false; //inv.SynchronizationDate = DateTime.Now; App.LocalDb.Update(inv); } //UPDATE MEDIA HERE } foreach (var invl in invoices_lines) { if (result.InvoicesLines.FirstOrDefault(a => ((a.ServerId > 0 && a.ServerId == invl.ServerId) || Guid.TryParse(a.AppId, out Guid id) && invl.Id.Equals(id))) is Models.SetSync.InvoiceLineResponse invlr && invlr.ServerId > 0) { var invoiceProduct = invl.DeepCopy(); App.LocalDb.Delete(invl); invoiceProduct.ServerId = invlr.ServerId; //invoiceProduct.SynchronizationDate = DateTime.Now; invoiceProduct.IsToSync = false; App.LocalDb.Insert(invoiceProduct); }
public async Task <bool> SyncToServerAsync(int method) { var issues = App.LocalDb.Table <Issue>().Where(iss => iss.UserId == CurrentUser.Id && iss.IsToSync).ToArray(); var issue_replys = App.LocalDb.Table <IssueLink>().Where(issr => issr.UserId == CurrentUser.Id && issr.IsToSync).ToArray(); JObject @params = new JObject(); if (issues.LongLength > 0) { @params.Add(new JProperty("issues", JArray.FromObject(issues).RemoveEmptyChildren(issues.FirstOrDefault()?.PropertyIgnore))); } if (issue_replys.LongLength > 0) { @params.Add(new JProperty("issues_lines", JArray.FromObject(issue_replys).RemoveEmptyChildren(issue_replys.FirstOrDefault()?.PropertyIgnore))); } if (@params.Count > 0) { @params.Add(new JProperty("api_version", "2")); @params.Add(new JProperty("appVersion", ApiURI.APP_VERSION)); } else { return(await Task.FromResult(true)); } var response = await restClient.PostAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_SET_ISSUE(CurrentUserName, Settings.CurrentPassword), @params); var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("RESPONSE: " + responseContent); if (response.IsSuccessStatusCode) { var result = JsonConvert.DeserializeObject <SetIssueResponse>(responseContent, App.DefaultDeserializeSettings); if (result != null && result.Success.Equals("OK")) { foreach (var issue in issues) { if (result.Issues.FirstOrDefault(c => ((c.ServerId > 0 && c.ServerId == issue.ServerId) || Guid.TryParse(c.AppId, out Guid id) && issue.Id.Equals(id))) is Models.SetSync.IssueResponse issresponse && issresponse.ServerId > 0) { var iss = issue.DeepCopy(); App.LocalDb.Delete(issue); iss.ServerId = issresponse.ServerId; iss.UserId = CurrentUser.Id; //invoice.SynchronizationDate = DateTime.Now; iss.IsToSync = false; iss.CodeId = issresponse.CodeId; App.LocalDb.Insert(iss); } else { issue.IsToSync = false; //inv.SynchronizationDate = DateTime.Now; App.LocalDb.Update(issue); } } foreach (var invl in issue_replys) { if (result.IssuesLines.FirstOrDefault(a => ((a.ServerId > 0 && a.ServerId == invl.ServerId) || Guid.TryParse(a.AppId, out Guid id) && invl.Id.Equals(id))) is Models.SetSync.IssueLineResponse invlr && invlr.ServerId > 0) { var issueLink = invl.DeepCopy(); App.LocalDb.Delete(invl); issueLink.ServerId = invlr.ServerId; //invoiceProduct.SynchronizationDate = DateTime.Now; issueLink.IsToSync = false; App.LocalDb.Insert(issueLink); }
public async Task <bool> SyncToServer(int method) { try { var equipments = App.LocalDb.Table <Equipment>().Where(inv => inv.UserId == CurrentUser.Id && inv.IsToSync).ToArray(); var interventions_euipments = App.LocalDb.Table <LinkInterventionEquipment>().Where(lie => lie.UserId == CurrentUser.Id && lie.IsToSync).ToArray(); JObject @params = new JObject(); if (equipments.LongLength > 0) { @params.Add(new JProperty("equipments", JArray.FromObject(equipments).RemoveEmptyChildren(equipments.FirstOrDefault()?.PropertyIgnore))); } if (interventions_euipments.LongLength > 0) { @params.Add(new JProperty("equipements_links", JArray.FromObject(interventions_euipments).RemoveEmptyChildren(interventions_euipments.FirstOrDefault()?.PropertyIgnore))); } if (@params.Count > 0) { @params.Add(new JProperty("api_version", ApiURI.API_MOBILE_TO_SERVER_VERSION)); @params.Add(new JProperty("appVersion", ApiURI.APP_VERSION)); } else { return(await Task.FromResult(true)); } var response = await restClient.PostAsync(ApiURI.URL_BASE(CurrentAccount) + ApiURI.URL_SET_EQUIPMENT(CurrentUserName, Settings.CurrentPassword), @params); var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("RESPONSE: " + responseContent); if (response.IsSuccessStatusCode) { var result = JsonConvert.DeserializeObject <SetSyncEquipment>(responseContent, App.DefaultDeserializeSettings); if (result != null && result.Success.Equals("OK")) { foreach (var inv in equipments) { if (result.Equipements.FirstOrDefault(c => ((c.ServerId > 0 && c.ServerId == inv.ServerId) || Guid.TryParse(c.AppId, out Guid id) && inv.Id.Equals(id))) is EquipmentResponse invr && invr.ServerId > 0) { var equipment = inv.DeepCopy(); App.LocalDb.Delete(inv); equipment.ServerId = invr.ServerId; equipment.CodeId = invr.CodeId; //invoice.SynchronizationDate = DateTime.Now; equipment.IsToSync = false; App.LocalDb.Insert(equipment); } else { inv.IsToSync = false; //inv.SynchronizationDate = DateTime.Now; App.LocalDb.Update(inv); } } /* * foreach (var invl in interventions_euipments) * { * if (result.InvoicesLines.FirstOrDefault(a => ((a.ServerId > 0 && a.ServerId == invl.ServerId) || Guid.TryParse(a.AppId, out Guid id) && invl.Id.Equals(id))) is Models.SetSync.InvoiceLineResponse invlr && invlr.ServerId > 0) * { * var invoiceProduct = invl.DeepCopy(); * App.LocalDb.Delete(invl); * invoiceProduct.ServerId = invlr.ServerId; * //invoiceProduct.SynchronizationDate = DateTime.Now; * invoiceProduct.IsToSync = false; * App.LocalDb.Insert(invoiceProduct); * } * else * { * invl.IsToSync = false; * //invl.SynchronizationDate = DateTime.Now; * App.LocalDb.Update(invl); * } * }*/ Debug.WriteLine("SET_SYNC_Equipment Successed!"); } }
public async Task <LoginResponse> Login(string account, string userName, string password) { var result = await restClient.GetStringAsync <LoginResponse>(ApiURI.URL_BASE(account) + ApiURI.URL_GET_LOGIN(userName, password)); return(await Task.FromResult(result)); }