Example #1
0
        private async Task ImportSolutionData(EbMobileSolutionData solutionData)
        {
            if (solutionData == null)
            {
                return;
            }

            EbDataSet importData = solutionData.GetOfflineData();

            DBService.Current.ImportData(importData);
            UpdateErrorDraftIds(solutionData.DraftIds);

            await Store.SetJSONAsync(AppConst.APP_COLLECTION, solutionData.Applications);

            await SetLocationInfo(solutionData.Locations);
            await SetCurrentUser(solutionData.CurrentUser);
            await SetSolutionObject(solutionData.CurrentSolution);
            await SetImagesInPdf(solutionData.Images);

            if (solutionData.ProfilePages != null && solutionData.ProfilePages.Count > 0)
            {
                await Store.SetJSONAsync(AppConst.EXTERNAL_PAGES, solutionData.ProfilePages);

                ExternalMobilePages = solutionData.ProfilePages;
            }

            if (CurrentApplication != null)
            {
                CurrentApplication = solutionData.Applications.Find(item => item.AppId == CurrentApplication.AppId);
                MobilePages        = CurrentApplication?.MobilePages;
                WebObjects         = CurrentApplication?.WebObjects;
                await Store.SetJSONAsync(AppConst.CURRENT_APP, CurrentApplication);
            }
        }
Example #2
0
        private async Task <(bool, bool, string)> UpdateLastSyncInfo(EbMobileSolutionData solutionData, LastSyncInfo syncInfo, string appVersion)
        {
            string msg = null;
            bool   leaveLastSyncTsCheck = false, incorrectDate = false, maintenanceMode = false;

            if (solutionData.MetaData != null)
            {
                if (solutionData.MetaData.TryGetValue(AppConst.maintenance_msg, out object val) && val != null)
                {
                    msg             = val.ToString();
                    maintenanceMode = true;
                }
                else if (solutionData.MetaData.TryGetValue(AppConst.session_expired, out object val2) && bool.TryParse(val2.ToString(), out bool b) && b)
                {
                    msg             = AppConst.session_expired;
                    maintenanceMode = true;
                }
                else if (solutionData.MetaData.TryGetValue(AppConst.leave_ts_check, out object val3) && bool.TryParse(val3.ToString(), out bool st) && st)
                {
                    EbLog.Warning("Last sync ts check avoided");
                    leaveLastSyncTsCheck = true;
                }

                if (solutionData.MetaData.TryGetValue(AppConst.app_version, out object val4) && val4 != null)
                {
                    syncInfo.LatestAppVersion = val4.ToString();
                }
                else
                {
                    syncInfo.LatestAppVersion = null;
                }
            }
            else
            {
                syncInfo.LatestAppVersion = null;
            }

            if (!(solutionData.last_sync_ts > DateTime.Now.Subtract(new TimeSpan(0, 2, 0)) &&
                  solutionData.last_sync_ts < DateTime.Now.Add(new TimeSpan(0, 3, 0))) && !leaveLastSyncTsCheck)
            {
                incorrectDate = true;
                EbLog.Warning("Device date time is incorrect. Server time: " + solutionData.last_sync_ts);
                if (msg == null)
                {
                    msg = "Device date time is incorrect";
                }
            }

            if (msg != null)
            {
                EbLog.Warning(msg);
            }

            syncInfo.PullSuccess = false;
            syncInfo.IsLoggedOut = false;
            syncInfo.SolnId      = App.Settings.Sid;
            await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, syncInfo);

            return(incorrectDate, maintenanceMode, msg);
        }
Example #3
0
        public async Task Navigate(EbMobileSolutionData data)
        {
            if (data.Applications != null)
            {
                if (Utils.IsFreshStart)
                {
                    await App.Navigation.NavigateAsync(new WelcomPage(data));
                }
                else
                {
                    if (data.Applications.Count == 1)
                    {
                        AppData appdata = data.Applications[0];

                        await Store.SetJSONAsync(AppConst.CURRENT_APP, appdata);

                        App.Settings.CurrentApplication = appdata;
                        App.Settings.MobilePages        = appdata.MobilePages;
                        App.Settings.WebObjects         = appdata.WebObjects;

                        App.RootMaster = new RootMaster();
                        Application.Current.MainPage = App.RootMaster;
                    }
                    else
                    {
                        await App.Navigation.NavigateAsync(new MyApplications());
                    }
                }
            }
        }
Example #4
0
        protected async Task AfterLoginSuccess(ApiAuthResponse resp, string username, LoginType loginType, Loader loader)
        {
            try
            {
                await Service.UpdateAuthInfo(resp, username);

                await Service.UpdateLastUser(username, loginType);

                EbMobileSolutionData data = await App.Settings.GetSolutionDataAsync(loader);

                IsBusy = true;

                if (App.Settings.Vendor.AllowNotifications)
                {
                    await NotificationService.Instance.UpdateNHRegistration();
                }

                if (data != null)
                {
                    await Service.Navigate(data);
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("Exception at after login :: " + ex.Message);
            }
        }
        public WelcomPage(EbMobileSolutionData data)
        {
            InitializeComponent();

            solData = data;

            UserName       = App.Settings.UserDisplayName;
            SolutionLogo   = CommonServices.GetLogo(App.Settings.Sid);
            BindingContext = this;
        }
Example #6
0
 private void MergeObjectsInSolutionData(EbMobileSolutionData New, List <AppData> OldApps)
 {
     if (OldApps == null)
     {
         return;
     }
     foreach (AppData app in New.Applications)
     {
         foreach (MobilePagesWraper wraper in app.MobilePages)
         {
             if (string.IsNullOrEmpty(wraper.Json))
             {
                 foreach (AppData _app in OldApps)
                 {
                     MobilePagesWraper _w = _app.MobilePages.Find(e => e.RefId == wraper.RefId);
                     if (_w != null)
                     {
                         wraper.Json = _w.Json;
                         break;
                     }
                 }
             }
         }
         foreach (WebObjectsWraper wraper in app.WebObjects)
         {
             if (string.IsNullOrEmpty(wraper.Json))
             {
                 foreach (AppData _app in OldApps)
                 {
                     WebObjectsWraper _w = _app.WebObjects.Find(e => e.RefId == wraper.RefId);
                     if (_w != null)
                     {
                         wraper.Json = _w.Json;
                         break;
                     }
                 }
             }
         }
     }
 }
        public async Task <List <AppData> > UpdateDataAsync(Loader loader)
        {
            List <AppData> apps = null;

            loader.IsVisible = true;
            loader.Message   = "Refreshing...";
            try
            {
                EbMobileSolutionData data = await App.Settings.GetSolutionDataAsync(loader);

                if (data != null)
                {
                    apps = data.Applications;
                    Utils.Toast("Refreshed");
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("Failed to get solution data :: " + ex.Message);
            }
            loader.IsVisible = false;
            return(apps);
        }
Example #8
0
        public async Task <EbMobileSolutionData> GetSolutionDataAsync(Loader loader)
        {
            if (App.Settings.SyncInProgress)
            {
                EbLog.Info(App.Settings.Sid + ": Sync in progress...");
                return(null);
            }
            App.Settings.SyncInProgress = true;
            EbLog.BackupLogFiles();
            EbMobileSolutionData solutionData = null;
            bool flag = false;

            try
            {
                loader.Message = "Sync started...";
                EbLog.Info("Sync started...");

                LocalDBServie service  = new LocalDBServie();
                SyncResponse  response = await service.PushDataToCloud(loader);

                if (response.Status)
                {
                    loader.Message = string.Empty;
                }
                else
                {
                    loader.Message = response.Message + " \n";
                }

                loader.Message += "Fetching data from server...";
                EbLog.Info("Fetching data from server...");

                RestClient client = new RestClient(App.Settings.RootUrl)
                {
                    Timeout = ApiConstants.TIMEOUT_IMPORT
                };
                RestRequest request = new RestRequest(ApiConstants.GET_SOLUTION_DATAv2, Method.POST);

                request.AddHeader(AppConst.BTOKEN, App.Settings.BToken);
                request.AddHeader(AppConst.RTOKEN, App.Settings.RToken);
                Dictionary <string, object> metaDict = new Dictionary <string, object>();
                metaDict.Add(AppConst.draft_ids, GetErrorDraftIds());
                INativeHelper helper = DependencyService.Get <INativeHelper>();
                metaDict.Add(AppConst.app_version, helper.AppVersion);
                metaDict.Add(AppConst.device_id, helper.DeviceId);
                request.AddParameter(AppConst.metadata, JsonConvert.SerializeObject(metaDict));

                IRestResponse resp = await client.ExecuteAsync(request);

                if (resp.IsSuccessful)
                {
                    loader.Message = "Processing pulled data...";

                    LastSyncInfo syncInfo = App.Settings.SyncInfo;
                    if (syncInfo == null)
                    {
                        syncInfo = new LastSyncInfo();
                    }
                    solutionData = JsonConvert.DeserializeObject <EbMobileSolutionData>(resp.Content);

                    (bool incorrectDate, bool maintenanceMode, string msg) = await UpdateLastSyncInfo(solutionData, syncInfo, helper.AppVersion);

                    if (!maintenanceMode)
                    {
                        await ImportSolutionData(solutionData);

                        loader.Message = "Importing latest document ids...";
                        EbLog.Info("Importing latest document ids...");
                        if (await GetLatestAutoId(solutionData.Applications))
                        {
                            if (!incorrectDate)
                            {
                                syncInfo.LastSyncTs        = solutionData.last_sync_ts;
                                syncInfo.LastOfflineSaveTs = solutionData.last_sync_ts;
                            }
                            else
                            {
                                Utils.Toast(msg);
                            }

                            syncInfo.PullSuccess = true;
                            await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, syncInfo);

                            flag = true;
                        }
                        else
                        {
                            Utils.Toast("Failed to import latest doc ids");
                        }
                    }
                    else
                    {
                        Utils.Toast(msg);
                        syncInfo.PullSuccess = true;
                        await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, syncInfo);
                    }
                }
                else
                {
                    Utils.Toast(response.Message ?? "Sync failed");
                    EbLog.Warning(response.Message ?? "Sync failed");
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("Error on [GetSolutionData] request" + ex.Message);
                Utils.Toast(ex.Message);
            }
            loader.IsVisible            = false;
            App.Settings.SyncInProgress = false;
            return(flag ? solutionData : null);
        }
Example #9
0
        //version 2
        public async Task <SyncResponse> GetSolutionDataAsyncV2(Loader loader)
        {
            EbLog.BackupLogFiles();
            SyncResponse resp   = new SyncResponse();
            RestClient   client = new RestClient(App.Settings.RootUrl)
            {
                Timeout = ApiConstants.TIMEOUT_IMPORT
            };
            RestRequest request = new RestRequest(ApiConstants.GET_SOLUTION_DATAv2, Method.POST);

            request.AddHeader(AppConst.BTOKEN, App.Settings.BToken);
            request.AddHeader(AppConst.RTOKEN, App.Settings.RToken);

            Dictionary <string, object> metaDict = new Dictionary <string, object>();
            LastSyncInfo syncInfo = App.Settings.SyncInfo;

            if (syncInfo == null)
            {
                syncInfo = new LastSyncInfo();
            }

            if (syncInfo.LastSyncTs != DateTime.MinValue)
            {
                metaDict.Add(AppConst.last_sync_ts, syncInfo.LastSyncTs);
            }
            metaDict.Add(AppConst.draft_ids, GetErrorDraftIds());
            INativeHelper helper = DependencyService.Get <INativeHelper>();

            metaDict.Add(AppConst.app_version, helper.AppVersion);
            metaDict.Add(AppConst.device_id, helper.DeviceId);
            request.AddParameter(AppConst.metadata, JsonConvert.SerializeObject(metaDict));

            EbMobileSolutionData solutionData = null;

            try
            {
                IRestResponse response = await client.ExecuteAsync(request);

                if (response.IsSuccessful)
                {
                    Device.BeginInvokeOnMainThread(() => { loader.Message = "Processing pulled data..."; });

                    solutionData = JsonConvert.DeserializeObject <EbMobileSolutionData>(response.Content);

                    (bool incorrectDate, bool maintenanceMode, string msg) = await UpdateLastSyncInfo(solutionData, syncInfo, helper.AppVersion);

                    resp.Message = msg;

                    if (!maintenanceMode)
                    {
                        List <AppData> oldAppData = Store.GetJSON <List <AppData> >(AppConst.APP_COLLECTION);
                        MergeObjectsInSolutionData(solutionData, oldAppData);
                        await ImportSolutionData(solutionData);

                        Device.BeginInvokeOnMainThread(() => { loader.Message = "Importing latest document ids..."; });
                        EbLog.Info("Importing latest document ids...");
                        if (await GetLatestAutoId(solutionData.Applications))
                        {
                            if (!incorrectDate)
                            {
                                syncInfo.LastSyncTs        = solutionData.last_sync_ts;
                                syncInfo.LastOfflineSaveTs = solutionData.last_sync_ts;
                            }
                            resp.Status          = true;
                            syncInfo.PullSuccess = true;
                            await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, syncInfo);

                            EbLog.Info("[GetSolutionDataAsyncV2] api success");
                        }
                        else
                        {
                            resp.Message = "Failed to import latest doc ids";
                        }
                    }
                    else
                    {
                        syncInfo.PullSuccess = true;
                        await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, syncInfo);
                    }
                }
                else
                {
                    //callback?.Invoke(response.ResponseStatus);
                    resp.Message = "Pull failed. Try after sometime.";
                    EbLog.Info("[GetSolutionData] api failure, callback invoked");
                }
            }
            catch (Exception ex)
            {
                resp.Message = "Exception: " + ex.Message;
                EbLog.Error("Error on [GetSolutionData] request" + ex.Message);
            }
            return(resp);
        }