private string CreateEventId(NHibernate.IStatelessSession session, EventSummary summary, ushort Code) { int num = 0; ActiveEvent newEvt = null; string newEvtId = null; while (true) { newEvtId = $"{summary.SiteId}.{summary.DeviceName}.{Code}.{num++}"; newEvt = session.Get <ActiveEvent>(newEvtId); if (newEvt == null) { break; } } return(newEvtId); }
private void initDB() // TODO: Check if DB exists. If it exists, truncate tables and move to filling DB { // you can have a path here if you don't want the db file in the program directory string dbFile = "bodies.db"; // this bit works out the database schema to go with all the mapped classes var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(Bodies)).GetExportedTypes()); var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var config = new Configuration(); config.DataBaseIntegration(db => { db.Dialect <SQLiteDialect>(); db.Driver <SQLite20Driver>(); db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; db.IsolationLevel = System.Data.IsolationLevel.ReadCommitted; db.ConnectionString = string.Format("Data Source={0};Version=3;", dbFile); }); config.SetProperty(Environment.DefaultSchema, "EDSM"); config.AddDeserializedMapping(mappings, "test"); // Create the database from the mapped schema if it doesn't exist if (!File.Exists(dbFile)) { System.Console.WriteLine("No existing DB-file found. Creating new one."); new SchemaExport(config).Create(true, true); } // Connect to the database and open a connection we can use to read/write SchemaMetadataUpdater.QuoteTableAndColumns(config); var sessionFactory = config.BuildSessionFactory(); //_dbSession = sessionFactory.OpenSession(); _dbSession = sessionFactory.OpenStatelessSession(); // TruncateBodies(); }
private async Task RecoverEventAsync(NHibernate.IStatelessSession session, EventSummary summary, ushort Code, CancellationToken token) { int num = 0; ActiveEvent newEvt = null; string newEvtId = null; while (true) { newEvtId = $"{summary.SiteId}.{summary.DeviceName}.{Code}.{num++}"; newEvt = session.Get <ActiveEvent>(newEvtId); if (newEvt != null && newEvt.HasRecovered == false) { newEvt.RecoverTimestamp = summary.GetTimestamp(); newEvt.HasRecovered = true; await session.UpdateAsync(newEvt, token); } else if (newEvt == null) { break; } } }
/// <summary> /// BulkInsertion Will Be Done On The Table Related To The Class /// </summary> public static void BulkInsert <T>(List <T> objList) { using (NHibernate.IStatelessSession session = SessionFactory.GetNewStateLessSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { int count = objList.Count(); session.SetBatchSize(count); foreach (var item in objList) { session.Insert(item); } transaction.Commit(); } catch (Exception) { throw; } } } }