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 static void Connect(string collectionName) { if (Collection != null) { throw new TraceStateException("Connection already established."); } client = new LiteDB.LiteDatabase(@"MyData.db"); //just to update the description state var databases = client.GetCollectionNames(); if (client == null) { throw new TraceStateException("Local db is unreachable."); } Collection = client.GetCollection <Log>(collectionName); Buffers = new LogBuffer[NumberOfBuffers]; for (int i = 0; i < NumberOfBuffers; i++) { Buffers[i] = new LogBuffer(); } Arbiter = new Arbiter2(Buffers); //I create a new delegate in order to call a method with a Conditional Attribute Arbiter.OnAllBuffersFilled += delegate { Flush(); }; timer = new Timer(2000); timer.AutoReset = true; timer.Elapsed += delegate { Timer_Elapsed(null, null); }; timer.Start(); }
/// <summary> /// Actualiza un fichero mp3 ya existente /// </summary> /// <param name="fichero"></param> /// <returns></returns> public static FicheroMP3 ActualizaFicheroMP3(FicheroMP3 fichero) { LiteDB.LiteCollection <FicheroMP3> ficheros = db.GetCollection <FicheroMP3>("ficheros"); ficheros.Update(fichero); Logger.Log("Actualizado fichero en la Base de datos"); return(fichero); }
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 UserList(LiteDB.LiteCollection <KnowledgeBase.Usuario> usuarios) { InitializeComponent(); foreach (var u in usuarios.FindAll()) { userBox.Items.Add(u); } }
/// <summary> /// Devuelve una lista de todos los ficheros MP3 entre 2 fechas (opcionales) de un usuario concreto /// </summary> /// <param name="usuario"></param> /// <param name="desde"></param> /// <param name="hasta"></param> /// <returns></returns> public static IEnumerable <FicheroMP3> GetLista(String usuario, DateTime?desde, DateTime?hasta) { LiteDB.LiteCollection <FicheroMP3> ficheros = db.GetCollection <FicheroMP3>("ficheros"); IEnumerable <FicheroMP3> listaTemporal = ficheros.Find(f => f.Usuario == usuario); if (desde != null) { listaTemporal = listaTemporal.Where(f => f.FechaRecepcion >= desde.Value); } if (hasta != null) { listaTemporal = listaTemporal.Where(f => f.FechaRecepcion <= hasta.Value); } Logger.Log("Obtenida lista de la Base de datos"); return(listaTemporal); }
public editDataForm(string alias) { InitializeComponent(); db = new LSPMDatabase(Properties.Settings.Default.pwdHash); LiteDB.LiteCollection <LSPMData> col = db.getDBCollection(); col.EnsureIndex(x => x.lAlias); editable = col.FindOne(x => x.lAlias.Equals(alias)); aliasInput.Text = editable.lAlias; userInput.Text = editable.lUser; passwordInput.Text = editable.lPass; userAccessCheck.Checked = editable.lUserFastAccess; passwordAccessCheck.Checked = editable.lPasswordFastAccess; markColor(editable.lDataIcon); }
private void button4_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Wiki database|*.db"; if (ofd.ShowDialog() == DialogResult.OK) { litedb = new LiteDB.LiteDatabase(ofd.FileName); usuarios = litedb.GetCollection <KnowledgeBase.Usuario>("usuarios"); usuarios.EnsureIndex(x => x.Id); usuarios.EnsureIndex(x => x.Nombre); usuarios.EnsureIndex(x => x.Public_key); articulos = litedb.GetCollection <KnowledgeBase.Articulo>("articulos"); articulos.EnsureIndex(x => x.Id); articulos.EnsureIndex(x => x.Signature); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; } }
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); }
/// <summary> /// Devuelve la transcripción de un fichero mp3 a partir de su usuario y su id. El usuario se usa por seguridad. /// </summary> /// <param name="usuario"></param> /// <param name="id"></param> /// <returns></returns> public static RespuestaTranscripcion GetTranscripcion(String usuario, Int32 id) { Logger.Log("Solicitada transcripción de la Base de datos"); LiteDB.LiteCollection <FicheroMP3> ficheros = db.GetCollection <FicheroMP3>("ficheros"); FicheroMP3 fichero = ficheros.Find(f => f.Usuario == usuario && f.Id == id).FirstOrDefault(); if (fichero == null) { return(new RespuestaTranscripcion() { Codigo = -1, Transcripcion = null }); } else if (fichero.Estado == FicheroMP3.EstadosFicheroMP3.Realizada) { return(new RespuestaTranscripcion() { Codigo = 0, Transcripcion = fichero.Transcripcion }); } else if (fichero.Estado == FicheroMP3.EstadosFicheroMP3.Error) { return(new RespuestaTranscripcion() { Codigo = -2, Transcripcion = null }); } else { return(new RespuestaTranscripcion() { Codigo = -3, Transcripcion = null }); } }