private DatabaseHistory GetDatabaseHistory(int deviceID, string databaseName) { // The database name might have invalid characters for a URL // (like in C:\\COMMON\\common.sqlite), so it's base64 encoded at the client, // and we decode it here. string db_name = Encoding.UTF8.GetString(Convert.FromBase64String(databaseName)); Database db = new Database(); DatabaseHistory d = db.GetDatabaseHistory(deviceID, db_name); return(d); }
public int AddDatabaseMigration(DatabaseHistory dHistory) { //var dh = db.DatabaseHistories.FirstOrDefault(f => f.SiteId == dHistory.SiteId); //if (dh == null) //{ // db.DatabaseHistories.Add(dHistory); //} //else //{ // dh.FbConnectionStringUsed = dHistory.FbConnectionStringUsed; // dh.InstitutionName = dHistory.InstitutionName; // dh.LastMigrationDate = DateTime.Now; // dh.MigrationLog = dHistory.MigrationLog; // Array.ForEach(dHistory.PatientHistories.ToArray(), p => AddPatientMigration(p, dh.SiteId)); // Array.ForEach(dHistory.TableHistories.ToArray(), t => AddTableMigration(t, dh.SiteId)); //} db.DatabaseHistories.Add(dHistory); return(db.SaveChanges()); }
public void LogMigration() { DateTime date = DateTime.Now; var dh = new DatabaseHistory { FbConnectionStringUsed = MigrationVariables.FbConnectionString, InstitutionName = ahelper.GetAllCorporationInfo().Where(c => c.SiteId == MigrationVariables.CurrentSiteId).Select(s => s.Site_Name).FirstOrDefault(), LastMigrationDate = date, MigrationLog = MappingStatistics.ExportToLog(), SiteId = MigrationVariables.CurrentSiteId }; Array.ForEach(MigrationVariables.FirebirdTableNames.ToArray(), t => { if (dh.TableHistories.Any(a => string.Equals(a.TableName, t, StringComparison.CurrentCultureIgnoreCase))) { var th = dh.TableHistories.First(f => string.Equals(f.TableName, t, StringComparison.CurrentCultureIgnoreCase)); th.FirebirdRecordCount = +MappingStatistics.MappingStats.Where(w => string.Equals(w.FBTableName, t, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.FBRecordCount).FirstOrDefault(); th.MigratedRecordCount = +MappingStatistics.MappingStats.Where(w => string.Equals(w.FBTableName, t, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.CompletedMappingsCount).FirstOrDefault(); } else { dh.TableHistories.Add(new TableHistory { TableName = t, LastMigrationDate = date, FirebirdRecordCount = MappingStatistics.MappingStats.Where(w => string.Equals(w.FBTableName, t, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.FBRecordCount).FirstOrDefault(), MigratedRecordCount = MappingStatistics.MappingStats.Where(w => string.Equals(w.FBTableName, t, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.CompletedMappingsCount).FirstOrDefault() }); } }); Array.ForEach(TransactionManager.DatabaseContext.Patients.ToArray(), p => { var pat = MemoryMappings.GetAllPatientInfo().FirstOrDefault(f => f.Item3 == p.UserId); if (pat != null) { dh.PatientHistories.Add(new PatientHistory { BirthDate = p.DateofBirth, FirebirdPatientId = pat.Item2, Firstname = p.Firstname, Lastname = p.Lastname, SqlUserId = pat.Item3, MigrationDate = date, }); } }); Array.ForEach(TransactionManager.DatabaseContext.UserAuthentications.ToArray(), p => { var userInfo = ahelper.GetAspUserInfo(p.Username); Guid legId = (userInfo == null) ? Guid.Empty : userInfo.UserId; dh.UserHistories.Add(new UserHistory { SqlUserId = p.UserId, MigrationDate = date, Username = p.Username, LegacyUserId = legId }); }); AddDatabaseMigration(dh); }