コード例 #1
0
        public async Task <bool> DeleteAllErrorLogs(List <string> CallTrace)
        {
            try
            {
                IEnumerable <CosmosDocErrorLog> result = await cosmosDBRepoErrorLog.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.Error, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                if (result.Any())
                {
                    foreach (var item in result)
                    {
                        await cosmosDBClientBase.DeleteItemAsync(item, pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                    }
                }
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }


            return(true);
        }
コード例 #2
0
 public async Task <CosmosDocFeedback> FindFeedback(Guid UserID, List <string> CallTrace)
 {
     return(await cosmosDBRepo.FindFirstItemsAsync(x => x.DocType == (int)DocTypeEnum.Feedback &&
                                                   x.UserID == UserID, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public async Task <bool> UpdateFeedbackEntity(CosmosDocFeedback tsFeedback, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(tsFeedback, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #5
0
        public async Task <List <TSFeedback> > GetAllFeedback(List <string> CallTrace)
        {
            List <TSFeedback> TsFeedbacks = new List <TSFeedback>();

            try
            {
                IEnumerable <CosmosDocFeedback> result = await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.Feedback, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                foreach (var item in result)
                {
                    TsFeedbacks.Add(item.toTSFeedback());
                }
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
            }


            return(TsFeedbacks);
        }
コード例 #6
0
        public async Task <T> GetItemAsync(T item, string pkPrefix, List <string> CallTrace)
        {
            try
            {
                string id = GetProperty(item, "ID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).ToString();

                try
                {
                    Guid g = Guid.Parse(id);
                    if (g.Equals(Guid.Empty))
                    {
                        throw new ArgumentException("ID is empty!");
                    }
                }
                catch (Exception)
                {
                    throw;
                }



                string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString());

                return(await cosmosDBRepo.GetItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(GetProperty(item, "UserID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())), ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(null);
            }
        }
コード例 #7
0
 public async Task <TSReaction> GetReaction(TSReaction tsReaction, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocReaction(tsReaction), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSReaction());
 }
コード例 #8
0
 public async Task <CosmosDocUser> FindUserByEmail(string Email, List <string> CallTrace)
 {
     return(await cosmosDBRepo.FindFirstItemsAsync(x => x.DocType == (int)DocTypeEnum.User &&
                                                   x.Email.ToLower() == Email.ToLower(),
                                                   LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #9
0
        public async Task <List <TSUserOpen> > GetLiveUsers(List <string> CallTrace)
        {
            List <TSUserOpen> r = new List <TSUserOpen>();

            try
            {
                IEnumerable <CosmosDocUser> result = await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.User && x.IsLive, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));


                foreach (var item in result)
                {
                    r.Add(item.toTSUserOpen());
                }


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

                return(new List <TSUserOpen>());
            }
        }
コード例 #10
0
 public async Task <CosmosDocUser> GetUserDoc(TSUser tsUser, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.GetItemAsync(new CosmosDocUser(tsUser), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #11
0
 public async Task <TSUser> GetUser(Guid id, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(id, id, pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSUser());
 }
コード例 #12
0
 public async Task <CosmosDocUILanguage> FindByName(string Name, List <string> CallTrace)
 {
     return(await cosmosDBRepo.FindFirstItemsAsync(x => x.DocType == (int)DocTypeEnum.UILanguage &&
                                                   x.Name.ToLower() == Name.ToLower(),
                                                   LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #13
0
 public async Task <TSUILanguage> Get(TSUILanguage tsUILanguage, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocUILanguage(tsUILanguage), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSUILanguage());
 }
コード例 #14
0
 public async Task <bool> Add(TSUILanguage tsUILanguage, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.AddItemAsync(new CosmosDocUILanguage(tsUILanguage), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #15
0
        public async Task <bool> UpdateItemAsync(T item, List <string> CallTrace)
        {
            try
            {
                await cosmosDBRepo.UpdateItemAsync(item, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

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

                return(false);
            }
        }
コード例 #16
0
        public async Task <bool> AddUser(TSUser tsUser, List <string> CallTrace)
        {
            try
            {
                CosmosDocUser newUser = new CosmosDocUser(tsUser)
                {
                    Salt = GlobalFunctions.GetSalt()
                };
                newUser.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(tsUser.Password, newUser.Salt);


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

                await CosmosAPI.cosmosDBClientCategory.AddDefaultCategory(tsUser.ID, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

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

                return(false);
            }
        }
コード例 #17
0
        public async Task <bool> DeleteItemAsync(T item, string pkPrefix, List <string> CallTrace)
        {
            try
            {
                string id = GetProperty(item, "ID", LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).ToString();


                string pkValue = PartitionKeyGenerator.Create(pkPrefix, id.ToString());

                T deleteItem = await cosmosDBRepo.GetItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));


                if (deleteItem == null)
                {
                    return(false);
                }
                else
                {
                    await cosmosDBRepo.DeleteItemAsync(id, pkValue, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

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

                return(false);
            }
        }
コード例 #18
0
        public async Task <bool> UpdateOfflineUsers(List <string> CallTrace)
        {
            try
            {
                IEnumerable <CosmosDocUser> result = await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.User && x.IsLive && x.TimeStamp < GlobalFunctions.ToUnixEpochDate(DateTime.Now.AddSeconds(-30)),
                                                                                      LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                foreach (var item in result)
                {
                    item.IsLive = false;
                    await CosmosAPI.cosmosDBClientUser.UpdateUserDoc(item, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                }
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }


            return(true);
        }
コード例 #19
0
 public async Task <bool> UpdateReaction(TSReaction tsReaction, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocReaction(tsReaction), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #20
0
        public async Task <bool> UpdateOnlineUsersCount(List <string> CallTrace)
        {
            try
            {
                int count = (await cosmosDBRepo.GetItemsAsync(x => x.DocType == (int)DocTypeEnum.User && x.IsLive, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).Count();
                await CosmosAPI.cosmosDBClientSetting.SetSetting(Guid.Empty, "LiveUsersCount", count.ToString(), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(false);
            }


            return(true);
        }
コード例 #21
0
 public async Task <bool> AddFeedback(TSFeedback tsFeedback, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.AddItemAsync(new CosmosDocFeedback(tsFeedback), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #22
0
        public async Task <bool> AddUsersBath(List <TSUser> TsUsers, List <string> CallTrace)
        {
            try
            {
                foreach (var item in TsUsers)
                {
                    CosmosDocUser a = new CosmosDocUser(item)
                    {
                        Salt = GlobalFunctions.GetSalt()
                    };
                    a.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(item.Password, a.Salt);

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



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

                return(false);
            }
        }
コード例 #23
0
 public async Task <TSFeedback> GetFeedback(TSFeedback tsFeedback, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocFeedback(tsFeedback), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSFeedback());
 }
コード例 #24
0
 public async Task <bool> UpdateUserDoc(CosmosDocUser tsUser, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(tsUser, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #25
0
        public async Task <CosmosDocFeedback> FindFeedback(string SearchCrtiteria, string column, List <string> CallTrace)
        {
            try
            {
                QueryDefinition sql = new QueryDefinition("SELECT * FROM c WHERE c.DocType = " + (int)DocTypeEnum.Feedback + " and c." + column + "='" + SearchCrtiteria + "'");

                return(await cosmosDBRepo.FindFirstItemsAsync(sql, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
            }
            catch (CosmosException ex)
            {
                await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                return(null);
            }
        }
コード例 #26
0
        public async Task <bool> UpdateUser(TSUser tsUser, bool KeepPassAndSalt, List <string> CallTrace)
        {
            try
            {
                CosmosDocUser newUser = new CosmosDocUser(tsUser);

                if (KeepPassAndSalt)
                {
                    CosmosDocUser oldUser = await GetUserDoc(tsUser, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));

                    newUser.Salt           = oldUser.Salt;
                    newUser.HashedPassword = oldUser.HashedPassword;
                }
                else
                {
                    newUser.Salt           = GlobalFunctions.GetSalt();
                    newUser.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(tsUser.Password, newUser.Salt);
                }



                await cosmosDBClientBase.UpdateItemAsync(newUser, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));


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

                return(false);
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        public async Task <bool> AddItemsBathAsync(List <T> Items, List <string> CallTrace)
        {
            try
            {
                foreach (var item in Items)
                {
                    await cosmosDBRepo.CreateItemAsync(item, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()));
                }



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

                return(false);
            }
        }
コード例 #29
0
 public async Task <bool> Update(TSUIWordNative tsUIWordNative, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocUIWordNative(tsUIWordNative), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
コード例 #30
0
 public async Task <bool> DeleteErrorLog(CosmosDocErrorLog tsErrorLog, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.DeleteItemAsync(tsErrorLog, pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }