コード例 #1
0
        private void CreateCachedChatAndAdd(IChat chat, uint chatId, SqlDatabase <CachedChat> database)
        {
            using (var memoryStream = ConvertChatToMemoryStream(chat))
            {
                CachedChat cachedChat = null;
                if (chat is Chat)
                {
                    cachedChat = new CachedChat
                    {
                        Id            = chatId,
                        IsChat        = true,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                else
                {
                    cachedChat = new CachedChat
                    {
                        Id            = chatId,
                        IsChat        = false,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                //Additional check to prevent overwritng a channel without a access hash
                if (chat is Channel)
                {
                    var channel = chat as Channel;
                    if (channel.AccessHash == 0)
                    {
                        return;
                    }
                }

                var dbChat = database.Store.Where(x => x.Id == chatId).FirstOrDefault();
                if (dbChat != null)
                {
                    cachedChat.Pts = dbChat.Pts;
                    database.Store.Delete(x => x.Id == chatId);
                    database.Add(cachedChat);
                }
                else
                {
                    database.Add(cachedChat);
                }
            }
        }
コード例 #2
0
        private void CreateCachedChatAndAdd(IChat chat, uint chatId, SqlDatabase<CachedChat> database)
        {
            using (var memoryStream = ConvertChatToMemoryStream(chat))
            {
                CachedChat cachedChat = null;
                if (chat is Chat)
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        isChat = true,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                else
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        isChat = false,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }

                var dbUser = database.Store.Where(x => x.Id == chatId).FirstOrDefault();
                if (dbUser != null)
                {
                    database.Store.Delete(x => x.Id == chatId);
                    database.Add(cachedChat);
                }
                else
                {
                    database.Add(cachedChat);
                }
            }
        }
コード例 #3
0
        private void CreateCachedChatAndAdd(IChat chat, uint chatId, SqlDatabase<CachedChat> database)
        {
            using (var memoryStream = ConvertChatToMemoryStream(chat))
            {
                CachedChat cachedChat = null;
                if (chat is Chat)
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        IsChat = true,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                else 
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        IsChat = false,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                //Additional check to prevent overwritng a channel without a access hash
                if (chat is Channel)
                {
                    var channel = chat as Channel;
                    if (channel.AccessHash == 0)
                    {
                        return;
                    }
                }

                var dbChat = database.Store.Where(x => x.Id == chatId).FirstOrDefault();
                if (dbChat != null)
                {
                    cachedChat.Pts = dbChat.Pts;
                    database.Store.Delete(x => x.Id == chatId);
                    database.Add(cachedChat);
                }
                else
                {
                    database.Add(cachedChat);
                }
            }

        }