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(); }
public static void Connect(string collectionName, string domain = "localhost", uint port = 27017) { if (Collection != null) { throw new TraceLogStateException("Connection already established."); } client = new MongoClient($"mongodb://{domain}:{port}"); //just to update the description state var databases = client.ListDatabases(); if (client.Cluster.Description.State == ClusterState.Disconnected) { throw new TraceLogStateException("Local db is unreachable."); } var database = client.GetDatabase(Dns.GetHostName()); Collection = database.GetCollection <Log>(collectionName); LogBuffer[] Buffers = new LogBuffer[NumberOfBuffers]; for (int i = 0; i < NumberOfBuffers; i++) { Buffers[i] = new LogBuffer(); } Arbiter = new Arbiter <LogBuffer>(Buffers); Arbiter.OnAllResourcesFilled += Arbiter_OnAllResourcesFilled; timer = new Timer(FlushInterval.TotalMilliseconds); timer.AutoReset = false; timer.Elapsed += Timer_Elapsed; timer.Start(); }
/// <summary> /// Transfers asynchronously all the logs from the buffer into the database. /// </summary> public async static Task FlushAsync() { if (Collection == null) { new TraceStateException("No connection has been created."); } List <Log> b = new List <Log>(); for (int i = 0; i < Buffers.Length; i++) { b.AddRange(Buffers[i].Logs); } if (b.Count == 0) { return; } await Collection.InsertManyAsync(b); Buffers = new LogBuffer[NumberOfBuffers]; for (int i = 0; i < NumberOfBuffers; i++) { Buffers[i] = new LogBuffer(); } }
/// <summary> /// Writes the log into the buffer. /// </summary> /// <param name="log">The log to be saved.</param> public static void Write(Log log) { if (Collection == null) { new TraceStateException("No connection has been created."); } Semaphore.WaitOne(); LogBuffer freeBuffer = null; lock (critSec) { //TODO //Find a way to do this quicker freeBuffer = Buffers.FirstOrDefault(b => !b.InUse && !b.Full); if (freeBuffer == null) { Flush(); //After the flush, every buffer is free. So take the first freeBuffer = Buffers[0]; } else { freeBuffer.InUse = true; } } freeBuffer.Add(log); freeBuffer.InUse = false; Semaphore.Release(); }
public static void Connect(string collectionName) { if (Collection != null) { throw new TraceStateException("Connection already established."); } client = new MongoClient("mongodb://localhost:27017"); //just to update the description state //var databases = client.ListDatabases(); //if (client.Cluster.Description.State == ClusterState.Disconnected) // throw new TraceStateException("Local db is unreachable."); var database = client.GetDatabase(Dns.GetHostName()); Collection = database.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(); }
public static void Write(Log log) { //if (client == null || client.Cluster.Description.State == ClusterState.Disconnected) // throw new TraceStateException("No connection to local db."); LogBuffer freeBuffer = Arbiter.Wait(); freeBuffer.Add(log); Arbiter.Release(freeBuffer); }
public static void Write(Log log) { if (client == null) { throw new TraceStateException("No connection to local db."); } LogBuffer freeBuffer = Arbiter.Wait(); freeBuffer.Add(log); Arbiter.Release(freeBuffer); }
public static void Connect(string collectionName) { if (Collection != null) { throw new TraceStateException("Connection already established."); } ArangoDatabase.ChangeSetting(s => { s.Database = "test"; s.Url = "http://localhost:8529"; // you can set other settings if you need s.Credential = new NetworkCredential("root", ""); s.SystemDatabaseCredential = new NetworkCredential("root", ""); }); client = ArangoDatabase.CreateWithSetting(); //client.CreateDatabase(Dns.GetHostName()); //just to update the description state var databases = client.ListDatabases(); if (client.Connection == null) { throw new TraceStateException("Local db is unreachable."); } //client.CreateCollection("logggs"); Collection = client.Collection(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(); }
public static void Connect(string dbName, string collName) { if (Collection != null) { new TraceStateException("Connection already established."); } var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase(dbName); Collection = database.GetCollection <Log>(collName); Semaphore = new Semaphore(NumberOfBuffers, NumberOfBuffers); Buffers = new LogBuffer[NumberOfBuffers]; for (int i = 0; i < NumberOfBuffers; i++) { Buffers[i] = new LogBuffer(); } }
public static void Connect(string collectionName) { if (Collection != null) { throw new TraceStateException("Connection already established."); } client = new MyCouchClient("http://*****:*****@localhost:5984", "test"); //just to update the description state var databases = client.Database.GetAsync(); if (client.Connection == null) { throw new TraceStateException("Local db is unreachable."); } Collection = client.Entities; 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(); }