Ejemplo n.º 1
0
        public static async Task DownloadUIDataAndSaveInIndexedDB()
        {
            if (!LocalData.uiTranslator.TSUIWordNativesList.Any())
            {
                LocalData.uiTranslator.TSUIWordNativesList = await WebApiFunctions.CmdGetAllUIWordNatives();
            }

            LocalData.uiTranslator.PrepareDict(await WebApiFunctions.CmdGetAllUIWordForeigns(LocalData.uiTranslator.CurrUILanguage.ID));



            if (LocalData.UsingIndexedDb)
            {
                foreach (var item in LocalData.uiTranslator.TSUIWordsPairsList)
                {
                    var newRecord = new StoreRecord <TSUIWordsPair>
                    {
                        Storename = "UILangDict" + LocalData.uiTranslator.CurrUILanguage.Code,
                        Data      = item
                    };

                    await LocalData.indexedDbManager.AddRecord(newRecord);
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task <bool> CmdGetJWT(SecureString ParUserName, SecureString ParPassword, WebApiUserTypesEnum ParWebApiUserTypesEnum = WebApiUserTypesEnum.NotAuthorized)
        {
            if (!LocalData.IsDownloadedSetupData)
            {
                LocalFunctions.AddError("Bootstrap data is not Downloaded!", MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }

            LocalData.CurrJWT = string.Empty;
            try
            {
                JwtResult tmp_jwt = await WebApiFunctions.CmdDownloadToken(ParUserName, ParPassword, ParWebApiUserTypesEnum);


                if (string.IsNullOrEmpty(tmp_jwt.ErrorMessage))
                {
                    LocalData.CurrJWT = tmp_jwt.AccessToken;
                }
                else
                {
                    LocalFunctions.AddError(tmp_jwt.ErrorMessage, MethodBase.GetCurrentMethod(), true, false);
                }
            }
            catch (Exception ex)
            {
                LocalFunctions.AddError(ex.Message, MethodBase.GetCurrentMethod(), true, false);
            }


            return(!string.IsNullOrEmpty(LocalData.CurrJWT));
        }
Ejemplo n.º 3
0
        public static async Task GetTodosAndCategories()
        {
            bool updatedCategories = false;
            bool updatedTodos      = false;

            if (!LocalData.TSCategoriesList.Any())
            {
                updatedCategories          = true;
                LocalData.TSCategoriesList = await WebApiFunctions.CmdGetAllCategories();
            }

            if (!LocalData.TsTodosList.Any())
            {
                updatedTodos          = true;
                LocalData.TsTodosList = await WebApiFunctions.CmdGetAllTodos();

                foreach (var item in LocalData.TsTodosList.Where(x => x.HasDueDate == false))
                {
                    item.DueDate = new DateTime();
                }

                foreach (var item in LocalData.TsTodosList.Where(x => x.HasRemindDate == false))
                {
                    item.RemindDate = new DateTime();
                }


                foreach (var item in LocalData.TsTodosList.Where(x => x.HasDueDate))
                {
                    item.DaysLeft = (short)(item.DueDate - ToLocalDate(DateTime.Now)).TotalDays;
                }

                for (int i = 0; i < LocalData.TsTodosList.Count; i++)
                {
                    LocalData.TsTodosList[i].N = i + 1;
                }


                foreach (var item in LocalData.TsTodosList)
                {
                    item.Category = GetCategoryName(item.CategoryID);
                }
            }


            if (updatedCategories || updatedTodos)
            {
                if (LocalData.TSCategoriesList.Any())
                {
                    for (int i = 0; i < LocalData.TSCategoriesList.Count; i++)
                    {
                        LocalData.TSCategoriesList[i].N          = i + 1;
                        LocalData.TSCategoriesList[i].TodosCount = LocalData.TsTodosList.Count(x => x.CategoryID == LocalData.TSCategoriesList[i].ID);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static string GetCategoryName(Guid CategoryID)
        {
            string result = string.Empty;

            if (!LocalData.TSCategoriesDictionary.Any())
            {
                LocalData.TSCategoriesList = WebApiFunctions.CmdGetAllCategories().Result;
            }
            else
            {
                LocalData.TSCategoriesDictionary.TryGetValue(CategoryID, out result);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static async Task <bool> Cmd_Get_PublicData()
        {
            LocalData.IsDownloadedSetupData = false;
            string a = await WebApiFunctions.Cmd_Get_Setup_Data();

            if (a.Equals("OK"))
            {
                return(true);
            }
            else
            {
                LocalFunctions.AddError(a, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static async Task <bool> CmdRegisterUser(TSUser ParTSUser)
        {
            string a = await WebApiFunctions.CmdTSUserRegister(ParTSUser);

            if (a.Equals("OK"))
            {
                LocalFunctions.Authorize(ParTSUser.UserName, ParTSUser.Password);

                return(true);
            }
            else
            {
                LocalFunctions.AddError(a, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 7
0
        public static async Task GetUILanguages()
        {
            LocalData.uiTranslator.ComboUILanguagesSelectedIndex = 1;

            if (!LocalData.uiTranslator.TSUILanguagesList.Any())
            {
                LocalData.uiTranslator.TSUILanguagesList = await WebApiFunctions.CmdGetAllUILanguages();



                if (LocalData.UsingIndexedDb)
                {
                    List <TSUILanguage> ListInIndexedDB = await LocalData.indexedDbManager.GetRecords <TSUILanguage>("UILanguages");

                    foreach (var item in LocalData.uiTranslator.TSUILanguagesList)
                    {
                        if (ListInIndexedDB is null)
                        {
                            await AddUILanguageAndStore(item);
                        }
                        else
                        {
                            if (ListInIndexedDB.Any(x => x.Code.Equals(item.Code, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (item.Version != ListInIndexedDB.Single(x => x.Code.Equals(item.Code, StringComparison.InvariantCultureIgnoreCase)).Version)
                                {
                                    var updateRecord = new StoreRecord <TSUILanguage>
                                    {
                                        Storename = "UILanguages",
                                        Data      = item
                                    };

                                    await LocalData.indexedDbManager.UpdateRecord(updateRecord);

                                    await LocalData.indexedDbManager.ClearStore("UILangDict" + item.Code);
                                }
                            }
                            else
                            {
                                await AddUILanguageAndStore(item);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static async Task <bool> CmdUserChangePassword(TSUser ParTSUser)
        {
            string a = await WebApiFunctions.CmdTSUserChangePassword(ParTSUser);

            if (a.Equals("OK"))
            {
                LocalFunctions.AddMessage("Password was changed successfully, please login again", true, false);
                LocalData.btModal.Close();
                LocalFunctions.Logout();

                return(true);
            }
            else
            {
                LocalFunctions.AddError(a, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 9
0
        public static async Task <bool> CmdCheckUserNameNotExists(string ParUserName)
        {
            TSEmail ParTSEmail = new TSEmail {
                To = ParUserName, OperationCode = 0
            };

            TSEmail tsEmail = await WebApiFunctions.CmdCheckUserNameNotExists(ParTSEmail);

            if (tsEmail.Result.Equals("OK"))
            {
                return(true);
            }
            else
            {
                LocalFunctions.AddError(tsEmail.Result, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 10
0
        public static async void Logout()
        {
            LocalData.btModal.Close();
            LocalData.btModalConfirm.Close();
            LocalData.btModalError.Close();
            LocalData.btModalMessage.Close();



            await WebApiFunctions.CmdTSUserLogout();

            LocalData.IsAuthenticated = false;
            LocalData.CurrTSUser      = new TSUser();
            LocalData.LoginLogout     = "Login";

            LocalData.IsReady = false;

            timerHelper.Stop();

            LocalData.CurrJWT = string.Empty;
            bool b = await WebApi.CmdGetJWT(LocalData.ServerNotAuthorizedUserName, LocalData.ServerNotAuthorizedUserPass, WebApiUserTypesEnum.NotAuthorized);

            LocalData.IsReady = b;


            timerHelper.OnTick = TimerTick;
            timerHelper.Start(1, 10000);

            LocalData.TSCategoriesList       = new List <TSCategoryEx>();
            LocalData.TSCategoriesDictionary = new Dictionary <Guid, string>();

            LocalData.TsTodosList = new List <TSTodoEx>();

            LocalData.currFeedback = new TSFeedback();
            LocalData.currReaction = new TSReaction();


            CmdNavigate();


            LocalData.componentBridge.InvokeRefresh();
            LocalData.compHeader.Refresh();
        }
Ejemplo n.º 11
0
        public static async Task <bool> CmdSendMail(string ParTo, EmailOperationsEnum ParEmailOperationsEnum)
        {
            TSEmail ParTSEmail = new TSEmail {
                To = ParTo, OperationCode = (int)ParEmailOperationsEnum
            };


            TSEmail tsEmail = await WebApiFunctions.CmdSendEmail(ParTSEmail);



            if (tsEmail.Result.Equals("OK"))
            {
                LocalFunctions.AddMessage("Email was sent successfully, please check inbox, code is valid for 2 minutes", true, false);
                return(true);
            }
            else
            {
                LocalFunctions.AddError(tsEmail.Result, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 12
0
        public static async Task <bool> CmdRecoverPass(string ParUserName, EmailOperationsEnum ParEmailOperationsEnum)
        {
            TSEmail ParTSEmail = new TSEmail {
                To = ParUserName, OperationCode = (int)ParEmailOperationsEnum
            };


            TSEmail tsEmail = await WebApiFunctions.CmdRecoverPass(ParTSEmail);



            if (tsEmail.Result.Equals("OK"))
            {
                LocalFunctions.AddMessage("Password recovered successfully, new password was sent to your email", true, false);
                return(true);
            }
            else
            {
                LocalFunctions.AddError(tsEmail.Result, MethodBase.GetCurrentMethod(), true, false);
                return(false);
            }
        }
Ejemplo n.º 13
0
        public async static void Authorize(string ParUserName, string ParPassword)
        {
            LocalData.CurrJWT = string.Empty;

            BlazorTimeAnalyzer.DevelopmentMode = !LocalData.ProductionOrDevelopmentMode;
            BlazorTimeAnalyzer.Reset();
            BlazorTimeAnalyzer.LogAllAddition = true;

            BlazorTimeAnalyzer.Add("A1", MethodBase.GetCurrentMethod());

            timerHelper.Stop();

            if (await WebApi.CmdGetJWT(GlobalFunctions.ConvertToSecureString(ParUserName), GlobalFunctions.ConvertToSecureString(ParPassword), WebApiUserTypesEnum.Authorized))
            {
                BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod());
                TSUser tmpTSUser = new TSUser
                {
                    UserName = ParUserName,
                    Password = ParPassword,
                };

                BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod());
                LocalData.CurrTSUser = await WebApiFunctions.CmdTSUserAuthorize(tmpTSUser);

                BlazorTimeAnalyzer.Add("A3", MethodBase.GetCurrentMethod());

                if (LocalData.CurrTSUser.UserName.ToLower().Equals("error!"))
                {
                    LocalData.AppHasGlobalError = true;
                    AddError(LocalData.CurrTSUser.FullName, MethodBase.GetCurrentMethod(), true, false);
                }
                else
                {
                    LocalData.IsAuthenticated = !LocalData.CurrTSUser.ID.Equals(Guid.Empty);

                    if (LocalData.IsAuthenticated)
                    {
                        timerHelper.OnTick = TimerTick;
                        timerHelper.Start(1, 10000);

                        BlazorTimeAnalyzer.Add("A4", MethodBase.GetCurrentMethod());
                        await WebApiFunctions.CmdGetFeedback();

                        BlazorTimeAnalyzer.Add("A5", MethodBase.GetCurrentMethod());
                        await WebApiFunctions.CmdGetReaction();

                        BlazorTimeAnalyzer.Add("A6", MethodBase.GetCurrentMethod());

                        LocalData.LoginLogout = LocalData.CurrTSUser.UserName;

                        LocalData.btModal.Close();

                        CmdNavigate("DesktopPage");

                        LocalData.EventConsumerName = "TodosPage";
                        LocalData.componentBridge.InvokeRefresh();

                        LocalData.compHeader.Refresh();

                        LocalData.AppHasGlobalError = false;
                        BlazorTimeAnalyzer.Add("A7", MethodBase.GetCurrentMethod());
                    }
                    else
                    {
                        bool b = await WebApi.CmdGetJWT(LocalData.ServerNotAuthorizedUserName, LocalData.ServerNotAuthorizedUserPass, WebApiUserTypesEnum.NotAuthorized);

                        if (b)
                        {
                            timerHelper.OnTick = TimerTick;
                            timerHelper.Start(1, 10000);
                        }

                        LocalData.AppHasGlobalError = true;
                    }
                }
            }

            BlazorTimeAnalyzer.LogAll();
        }
Ejemplo n.º 14
0
        public static async Task GetStat()
        {
            LocalData.tsStat = await WebApiFunctions.CmdGetStat();

            LocalData.compFooter.Refresh();
        }