Beispiel #1
0
        public void SaveRankModel(Dictionary <string, RankModel> dict)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            LiteDB.LiteDatabase liteDatabase = new LiteDB.LiteDatabase(this.DbLite);
            LiteDB.LiteCollection <RankModel> liteCollection = liteDatabase.GetCollection <RankModel>("博客园排行");
            int count = 0;

            foreach (KeyValuePair <string, RankModel> itemRank in dict)
            {
                count++;
                LiteDB.BsonValue bsonValue = new LiteDB.BsonValue(itemRank.Value.Url);
                RankModel        model     = liteCollection.FindById(bsonValue);
                if (model == null)
                {
                    bsonValue = liteCollection.Insert(itemRank.Value);
                }
                else
                {
                }
            }
            liteDatabase.Dispose();
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
        }
Beispiel #2
0
        public async void SaveBlogModel(List <BlogModel> blogModels, string collectionName)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            LiteDB.LiteDatabase liteDatabase = new LiteDB.LiteDatabase(this.DbLite);
            LiteDB.LiteCollection <BlogModel> liteCollection = liteDatabase.GetCollection <BlogModel>(collectionName.RepleaceBrackets());
            int count = 0;

            foreach (BlogModel blogModel in blogModels)
            {
                count++;
                LiteDB.BsonValue bsonValue = new LiteDB.BsonValue(blogModel.PostUrl);
                BlogModel        model     = liteCollection.FindById(bsonValue);
                if (model == null)
                {
                    blogModel.HtmlContent = await this.Get(blogModel.PostUrl);

                    blogModel.HtmlContent = blogModel.HtmlContent?.RepleaceBrackets()?.Sub();
                    bsonValue             = liteCollection.Insert(blogModel);
                }
                else
                {
                }
            }
            liteDatabase.Dispose();
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
        }
        public static LiteDB.BsonValue Index(this LiteDB.BsonValue source, int index)
        {
            if (source is LiteDB.BsonArray array)
            {
                return(array.RawValue[index]);
            }

            throw new NotSupportedException();
        }
        public static LiteDB.BsonValue Index(this LiteDB.BsonValue source, string key)
        {
            if (source is LiteDB.BsonDocument doc)
            {
                return(doc.RawValue.GetOrDefault(key, LiteDB.BsonValue.Null));
            }

            throw new NotSupportedException();
        }
 public static void WriteIndex(this LiteDB.BsonValue source, string key, LiteDB.BsonValue value)
 {
     if (source is LiteDB.BsonDocument doc)
     {
         doc.RawValue[key] = value ?? LiteDB.BsonValue.Null;
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Beispiel #6
0
        public string Get(string query)
        {
            LiteDB.BsonDocument document = _database.GetCollection("game").Find(LiteDB.Query.EQ("STRING", query)).Where(x => x[_culture] != null).FirstOrDefault();

            LiteDB.BsonValue value = null;

            if (document != null)
            {
                value = document[_culture];
            }

            if (value == null)
            {
                value = _database.GetCollection("game").Find(LiteDB.Query.EQ("STRING", query)).Where(x => x["EN"] != null).First()["EN"];
            }

            return(value.AsString);
        }
Beispiel #7
0
            /// <summary>
            /// Receive string, convert to Chat, Save to db, Convert to Chatloader, return as string.
            /// </summary>
            /// <param name="incoming"></param>
            /// <returns></returns>
            internal static string ProcessMessage(Chat chat)
            {
                //send notification
                try
                {
                    LiteDB.BsonValue newID = contextLite.Chat.Insert(chat);

                    Push.SendChatNotification(chat);
                    //ChatLoader loader = ChatLoader(chat);
                    Chat returnChat = contextLite.Chat.FindById(newID);
                    return(JsonConvert.SerializeObject(returnChat));
                }
                catch (Exception ex)
                {
                    System.Threading.Tasks.Task forget_error = hubcontext.Error(ex);
                    return(JsonConvert.SerializeObject(new Chat()
                    {
                    }));
                }
            }