Exemplo n.º 1
0
        public static async void Timer2([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            //await CosmosAPI.cosmosDBClientError.DeleteAllErrorLogs(TodosCosmos.LocalFunctions.AddThisCaller(new List<string>(), MethodBase.GetCurrentMethod()));


            bool             b;
            CosmosDocSetting setting = await CosmosAPI.cosmosDBClientSetting.GetSetting(Guid.Empty, "DoActivityLog", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (setting != null)
            {
                if (string.IsNullOrEmpty(setting.Value))
                {
                    if (CosmosAPI.DoActivityLog)
                    {
                        CosmosAPI.DoActivityLog = false;
                    }
                }
                else
                {
                    b = bool.Parse(setting.Value);
                    if (CosmosAPI.DoActivityLog != b)
                    {
                        CosmosAPI.DoActivityLog = b;
                    }
                }
            }

            await CosmosAPI.cosmosDBClientTodo.SendTodoReminders(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));
        }
        public async Task <CosmosDocSetting> GetSetting(Guid UserID, string Key, List <string> CallTrace)
        {
            try
            {
                IEnumerable <CosmosDocSetting> result = await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.Setting &&
                                                                                         x.UserID == UserID &&
                                                                                         x.Key.ToLower() == Key.ToLower(), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));


                if (result.Count() > 0)
                {
                    return(result.FirstOrDefault());
                }
                else
                {
                    CosmosDocSetting newSetting = new CosmosDocSetting(UserID, Key, string.Empty);

                    await cosmosDBClientBase.AddItemAsync(newSetting, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                    return(newSetting);
                }
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(UserID, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(null);
            }
        }
Exemplo n.º 3
0
        public bool ReadDBSettings(List <string> CallTrace)
        {
            CosmosAPI.DoActivityLog = true;

            CosmosDocSetting setting = CosmosAPI.cosmosDBClientSetting.GetSetting(Guid.Empty, "DoActivityLog", TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;

            if (setting != null)
            {
                if (string.IsNullOrEmpty(setting.Value))
                {
                    CosmosAPI.cosmosDBClientSetting.SetSetting(Guid.Empty, "DoActivityLog", "true", TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                    if (!CosmosAPI.DoActivityLog)
                    {
                        CosmosAPI.DoActivityLog = true;
                    }
                }
                else
                {
                    bool b = setting.Value.ToLower().Equals("true");
                    if (CosmosAPI.DoActivityLog != b)
                    {
                        CosmosAPI.DoActivityLog = b;
                    }
                }
            }

            return(true);
        }
        public async Task <bool> SetSetting(Guid UserID, string Key, string Value, List <string> CallTrace)
        {
            CosmosDocSetting tsSetting = await GetSetting(UserID, Key, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

            tsSetting.Value = Value;

            return(await cosmosDBClientBase.UpdateItemAsync(tsSetting, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
        }
Exemplo n.º 5
0
        public static async Task Timer1([TimerTrigger("*/30 * * * * *")] TimerInfo myTimer, ILogger log)
        {
            CosmosDocSetting setting = await CosmosAPI.cosmosDBClientSetting.GetSetting(Guid.Empty, "LatsStatRequest", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (setting != null)
            {
                if (GlobalFunctions.ToUnixEpochDate(DateTime.Now.AddMinutes(-1)) < setting.TimeStamp)
                {
                    await CosmosAPI.cosmosDBClientUser.UpdateOfflineUsers(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                    await CosmosAPI.cosmosDBClientUser.UpdateOnlineUsersCount(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));
                }
            }
        }
        public async Task <bool> UpdateSettingCounter(Guid UserID, string KeyName, bool IncreaseOrDecrease, List <string> CallTrace)
        {
            try
            {
                CosmosDocSetting tsSetting = await GetSetting(UserID, KeyName, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                if (tsSetting != null)
                {
                    if (string.IsNullOrEmpty(tsSetting.Value))
                    {
                        if (IncreaseOrDecrease)
                        {
                            await SetSetting(UserID, KeyName, "1", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                        }
                        else
                        {
                            await SetSetting(UserID, KeyName, "-1", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                        }
                    }
                    else
                    {
                        int NewID = int.Parse(tsSetting.Value);


                        if (IncreaseOrDecrease)
                        {
                            await SetSetting(UserID, KeyName, (NewID + 1).ToString(), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                        }
                        else
                        {
                            await SetSetting(UserID, KeyName, (NewID - 1).ToString(), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                        }
                    }
                }


                return(true);
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(UserID, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }
        }
Exemplo n.º 7
0
        private async Task <int> GetStat(string name)
        {
            CosmosDocSetting setting = await CosmosAPI.cosmosDBClientSetting.GetSetting(Guid.Empty, name, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            if (setting != null)
            {
                if (string.IsNullOrEmpty(setting.Value))
                {
                    return(0);
                }
                else
                {
                    return(int.Parse(setting.Value));
                }
            }
            else
            {
                return(0);
            }
        }