public Message Subscribe(string[] parameters, MessageEvent e) { if (!parameters.Any()) { return(new Message("/subscribe [feed]")); } try { var subscribed = col.Find(x => e.GetEndpoint().Item1 == x.endpoint_type && e.GetEndpoint().Item2 == x.endpoint_num ); if (subscribed.Any(x => x.feed == parameters[0])) { return(new Message("already subscribed")); } FeedReader.ReadAsync(parameters[0]).ContinueWith( (f, o) => col.Insert(new Subscription { endpoint_type = e.GetEndpoint().Item1, endpoint_num = e.GetEndpoint().Item2, feed = parameters[0], last_id = "" }) , null ); } catch { return(new Message("failed to subscribe")); } return(new Message("subscribed")); }
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); }
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); }
/// <summary> /// Añade un fichero mp3 a la BD /// </summary> /// <param name="fichero"></param> /// <returns></returns> public static FicheroMP3 AddFicheroMP3(FicheroMP3 fichero) { LiteDB.LiteCollection <FicheroMP3> ficheros = db.GetCollection <FicheroMP3>("ficheros"); ficheros.Insert(fichero); ficheros.EnsureIndex(f => f.Usuario); Logger.Log("Añadido fichero a la Base de datos"); return(fichero); }
public void Insert(string w, string d, string user) { col.Insert(new Item { keyword = w, reply = d, contributor = user, time = DateTime.Now }); }
private void button1_Click(object sender, EventArgs e) { UserForm uform = new UserForm(); if (uform.ShowDialog() == DialogResult.OK) { KnowledgeBase.Usuario usuario = KnowledgeBase.ManipulationFunctions.GenKey(uform.Username); if (!(usuario is null)) { usuarios.Insert(usuario); } MessageBox.Show("Usuario agregado con éxito, por favor conéctese usando su clave privada"); } }
private void button3_Click(object sender, EventArgs e) { if (currentUser is null) { MessageBox.Show("Debe loggearse primero"); return; } ArticleForm af = new ArticleForm(); if (af.ShowDialog() == DialogResult.OK) { var art = KnowledgeBase.ManipulationFunctions.MakeArticle(af.Titulo, af.Contenido, cryptoProvider, currentUser); articulos.Insert(art); loadArticles(); } }
public static Market GetOrCreate(LiteDB.LiteCollection <Market> marketDB, ulong marketId, bool insertIfNew = false) { var market = marketDB.GetById(marketId); if (market == null) { market = new Market { MarketId = marketId, Transactions = new List <Transaction>(), Listings = new Dictionary <string, List <Listing> >() }; if (insertIfNew) { marketDB.Insert(market); } } return(market); }