private void UpdateErrorDraftIds(List <int> DraftIds) { try { List <string> depT = new List <string>(); int i; List <EbMobileForm> FormCollection = EbPageHelper.GetOfflineForms(); foreach (EbMobileForm Form in FormCollection) { if (depT.Contains(Form.TableName)) { continue; } EbDataTable dt = Form.GetDraftIds(); foreach (EbDataRow dr in dt.Rows) { i = Convert.ToInt32(dr[0]); if (!DraftIds.Contains(i)) { Form.UpdateDraftAsSynced(Convert.ToInt32(dr[1]), i); } } } } catch (Exception ex) { EbLog.Error("UpdateErrorDraftIds: " + ex.Message); } }
private void DeleteUnwantedRecords() { try { List <EbMobileForm> FormCollection = EbPageHelper.GetOfflineForms(); foreach (EbMobileForm Form in FormCollection) { DateTime date = DateTime.UtcNow.AddDays(-7); DbParameter[] parameter = new DbParameter[] { new DbParameter { ParameterName = "@strdate", DbType = (int)EbDbTypes.String, Value = date.ToString("yyyyMMdd", CultureInfo.InvariantCulture) } }; string query = Form.GetDeleteQuery(); int rowsAffected = App.DataDB.DoNonQuery(query, parameter); EbLog.Info(rowsAffected + " row(s) deleted from " + Form.TableName + " and its lines table"); } } catch (Exception ex) { EbLog.Error(ex.Message); } }
private string GetErrorDraftIds() { List <int> draft_ids = new List <int>(); int i; try { var depT = new List <string>(); List <EbMobileForm> FormCollection = EbPageHelper.GetOfflineForms(); foreach (EbMobileForm Form in FormCollection) { if (depT.Contains(Form.TableName)) { continue; } EbDataTable dt = Form.GetDraftIds(); foreach (EbDataRow dr in dt.Rows) { i = Convert.ToInt32(dr[0]); if (!draft_ids.Contains(i)) { draft_ids.Add(i); } } } } catch (Exception ex) { EbLog.Error("GetErrorDraftIds: " + ex.Message); } return(JsonConvert.SerializeObject(draft_ids)); }
public async Task <SyncResponse> PushDataToCloud(Loader loader = null) { SyncResponse response = new SyncResponse() { Status = true }; int totalRecords = 0, failedCount = 0; try { List <EbMobileForm> FormCollection = EbPageHelper.GetOfflineForms(); WebformData webdata = new WebformData(); var depT = new List <string>(); int localid; foreach (EbMobileForm Form in FormCollection) { if (depT.Contains(Form.TableName)) { continue; } EbMobileForm DependencyForm = Form.ResolveDependency(); if (DependencyForm != null) { depT.Add(DependencyForm.TableName); } EbDataTable SourceData = Form.GetLocalData(); totalRecords += SourceData.Rows.Count; string msg = $"Pushing {Form.DisplayName} {{0}} of {SourceData.Rows.Count}"; for (int i = 0; i < SourceData.Rows.Count; i++) { if (loader != null) { Device.BeginInvokeOnMainThread(() => { loader.Message = string.Format(msg, i + 1); }); } localid = Convert.ToInt32(SourceData.Rows[i]["id"]); EbLog.Info(string.Format(msg, i + 1) + "; Local Id: " + localid); Form.UpdateRetryCount(SourceData.Rows[i]); PushResponse resp = await SendRecord(webdata, Form, SourceData, SourceData.Rows[i], i); if (resp.RowAffected <= 0) { response.Status = false; failedCount++; EbLog.Error("Push Data Failed: " + resp.Message + "; " + resp.MessageInt); } else { Form.FlagLocalRow(resp); if (DependencyForm != null)//// error submission must be consider [flow pending...] { await PushDependencyData(webdata, Form, DependencyForm, resp.RowId, resp.LocalRowId); } } } } if (response.Status) { response.Message = "Push completed"; DeleteUnwantedRecords(); } else if (failedCount > 0) { response.Message = $"{failedCount} of {totalRecords} failed to push"; } EbLog.Info(response.Message); } catch (Exception ex) { response.Status = false; response.Message = "Push failed: " + ex.Message; EbLog.Error(ex.Message); } return(response); }