private async Task PushDependencyData(WebformData webdata, EbMobileForm sourceForm, EbMobileForm dependencyForm, int liveId, int localId) { try { string RefColumn = $"{sourceForm.TableName}_id"; string query = string.Format(StaticQueries.STARFROM_TABLE_WDEP, dependencyForm.GetQuery(), dependencyForm.TableName, RefColumn, localId); EbDataTable dt = App.DataDB.DoQuery(query); if (dt.Rows.Any()) { SingleTable SingleTable = new SingleTable(); for (int i = 0; i < dt.Rows.Count; i++) { FillLiveId(dt, dt.Rows[i], liveId, RefColumn); PushResponse resp = await SendRecord(webdata, dependencyForm, dt, dt.Rows[i], i); if (resp.RowAffected <= 0) { continue; } dependencyForm.FlagLocalRow(resp); } } } catch (Exception ex) { EbLog.Error("SyncServices.PushDependencyData---" + ex.Message); } }
private void GetLinesEnabledData(int localid, EbMobileForm form, WebformData formData) { try { Dictionary <string, EbMobileControl> controls = form.ChildControls.ToControlDictionary(); foreach (var ctrl in controls.Values) { if (ctrl is ILinesEnabled Ilines) { SingleTable st = new SingleTable(); formData.MultipleTables.Add(Ilines.TableName, st); EbDataTable data = Ilines.GetLocalData(form.TableName, localid); foreach (var dr in data.Rows) { SingleRow row = new SingleRow { LocId = Convert.ToInt32(dr["eb_loc_id"]) }; row.Columns.AddRange(Ilines.GetColumnValues(data.Columns, dr)); st.Add(row); } } } } catch (Exception ex) { EbLog.Error(ex.Message); } }
private async Task <PushResponse> SendRecord(WebformData webdata, EbMobileForm Form, EbDataTable Dt, EbDataRow DataRow, int RowIndex) { PushResponse response = null; try { ClearWebFormData(webdata); SingleTable SingleTable = new SingleTable(); int localid = Convert.ToInt32(DataRow["id"]); SingleRow row = this.GetRow(Form, Dt, DataRow, RowIndex); SingleTable.Add(row); webdata.MultipleTables.Add(Form.TableName, SingleTable); await Form.UploadFiles(localid, webdata); this.GetLinesEnabledData(localid, Form, webdata); if (FormService.Instance == null) { new FormService(); } response = await FormService.Instance.SendFormDataAsync(null, webdata, 0, Form.WebFormRefId, row.LocId); response.LocalRowId = localid; } catch (Exception ex) { EbLog.Error("SyncServices.PushRow---" + ex.Message); } return(response); }
public static EbMobileForm ResolveDependency(this EbMobileForm sourceForm) { try { EbMobilePage autogenvis = EbPageHelper.GetPage(sourceForm.AutoGenMVRefid); if (autogenvis != null) { string linkref = (autogenvis.Container as EbMobileVisualization).LinkRefId; if (!string.IsNullOrEmpty(linkref)) { EbMobilePage linkpage = EbPageHelper.GetPage(linkref); if (linkpage != null && linkpage.Container is EbMobileVisualization viz) { EbMobilePage innerlink = EbPageHelper.GetPage(viz.LinkRefId); if (innerlink != null && innerlink.Container is EbMobileForm mf) { return(mf); } } } } } catch (Exception ex) { EbLog.Info("Failed to resolve form dependencies"); EbLog.Error(ex.Message); } return(null); }
public async Task <EbDataSet> GetFormLocalDataAsync(EbMobileForm form, int rowid) { EbDataSet ds = new EbDataSet(); try { //only to remove the warning await Task.Delay(1); EbDataTable masterData = App.DataDB.DoQuery($"SELECT * FROM {form.TableName} WHERE id = {rowid};"); masterData.TableName = form.TableName; ds.Tables.Add(masterData); foreach (var pair in form.ControlDictionary) { if (pair.Value is ILinesEnabled) { string linesQuery = $"SELECT * FROM {(pair.Value as ILinesEnabled).TableName} WHERE {form.TableName}_id = {rowid};"; EbDataTable linesData = App.DataDB.DoQuery(linesQuery); linesData.TableName = (pair.Value as ILinesEnabled).TableName; ds.Tables.Add(linesData); } } } catch (Exception ex) { EbLog.Error(ex.Message); } return(ds); }
public static void Initialize(EbMobileForm form, FormMode mode) { Instance = new EbFormHelper { controls = form.ControlDictionary }; Instance.evaluator.SetVariable("form", new EbFormEvaluator(mode, form.ControlDictionary)); Instance.dependencyMap = new ControlDependencyMap(); Instance.dependencyMap.Init(form.ControlDictionary); }
private SingleRow GetRow(EbMobileForm Form, EbDataTable Dt, EbDataRow DataRow, int RowIndex) { SingleRow row = new SingleRow { RowId = 0, IsUpdate = false, LocId = Convert.ToInt32(DataRow["eb_loc_id"]), }; row.Columns.AddRange(Form.GetColumnValues(Dt, RowIndex)); return(row); }
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); }
public static async Task <string> ValidateFormRendering(EbMobileForm form, Loader loader, EbDataRow context = null) { string failMsg = null; if (!Utils.IsNetworkReady(form.NetworkType)) { failMsg = "Not connected to internet!"; } else if (!string.IsNullOrEmpty(form.RenderValidatorRefId)) { try { if (loader != null) { loader.Message = "Validating..."; } List <Param> cParams = form.GetRenderValidatorParams(context); cParams.Add(new Param { Name = "eb_loc_id", Type = "11", Value = App.Settings.CurrentLocation.LocId.ToString() }); MobileDataResponse data = await DataService.Instance.GetDataAsync(form.RenderValidatorRefId, 0, 0, cParams, null, null, false); if (data.HasData() && data.TryGetFirstRow(1, out EbDataRow row)) { if (bool.TryParse(row[0]?.ToString(), out bool b) && b) { EbLog.Info("Form render validation return true"); } else { failMsg = form.MessageOnFailed; EbLog.Info("Form render validation return false"); } } else { failMsg = "Validation api returned empty data"; EbLog.Info("before render api returned empty row collection"); } } catch (Exception ex) { failMsg = "Exception in validation api: " + ex.Message; EbLog.Error("Error at form render validation api call"); EbLog.Info(ex.Message); } } if (failMsg == null && form.AutoSyncOnLoad && !form.RenderAsFilterDialog) { LocalDBServie service = new LocalDBServie(); if (!App.Settings.SyncInProgress) { App.Settings.SyncInProgress = true; failMsg = await service.PushData(loader); App.Settings.SyncInProgress = false; } else { failMsg = "Internal error. (SyncInProgress is true)"; EbLog.Info("ValidateFormRendering -> SyncInProgress is true"); } } return(failMsg); }