/// <summary> /// Checkes if all versions are in a row and not lower than 1. /// For example 1, 2, 3, ... is corect, but /// 2, 3, 6 is wrong, because 1, 4 and 5 is missing. /// Also checks if there is at least one version /// </summary> /// <exception cref="DLCException">if there is no method with specific version number</exception> /// <returns>true if all conditions are corect</returns> public void CheckVersions() { m_log.Debug("Cheking versions"); if (m_versionsTable.Count == 0) { throw new ArgumentOutOfRangeException("There must be at least one method with atrribute DBVersionAttribute"); } CheckVersionNumbers(); SortedDictionary <int, IDBVersionInformation> sorted = new SortedDictionary <int, IDBVersionInformation>(); IDBVersionInformation lastVersion = null; foreach (IDBVersionInformation entry in m_versionsTable.Values) { try { sorted.Add(entry.VersionAttribute.Version, entry); } catch (ArgumentException e) { lastVersion = m_versionsTable[entry.VersionAttribute.Version]; throw new DBUpdateException(string.Format( "DBVersion {0} has a Version atrribute where date is the same as " + " other db version (that is {1})", entry.VersionAttribute.ToString(), lastVersion.VersionAttribute.ToString()), e); } } }
private void CheckVersionNumbers() { IDBVersionInformation lastVersion = null; foreach (IDBVersionInformation entry in m_versionsTable.Values) { if (entry.VersionAttribute.Version < 1) { throw new DBUpdateException(string.Format("DBVersionAttribute number is less than 1 for method {0}", entry.VersionAttribute.ToString())); } if (lastVersion != null) { if (entry.VersionAttribute.Version <= lastVersion.VersionAttribute.Version) { throw new DBUpdateException(string.Format( "DBVersion {0} has a Version atrribute where version number " + "is less or equalthan the previous db version (that is {1})", entry.VersionAttribute.ToString(), lastVersion.VersionAttribute.ToString())); } } lastVersion = entry; } }
/// <summary> /// Creates instance of DBVersion or DBCoreVersion in database according to DBHistory atrribute /// </summary> public void CreateVersionInDB(IDBVersionInformation info) { DBVersion dbVersion = new DBVersion(); dbVersion.Comment = info.VersionAttribute.Comment; dbVersion.Date = info.VersionAttribute.Date; dbVersion.VersionNr = info.VersionAttribute.Version; dbVersion.Save(); }
public DBVersionRepository AddVersions(IDBVersionInformation info) { try { m_versionsTable.Add(info.VersionAttribute.Version, info); } catch (ArgumentException ex) { IDBVersionInformation last = m_versionsTable[info.VersionAttribute.Version]; throw new DBUpdateException(string.Format( "Could not add DBVersion {0} to list," + " because there is already a version with that date (that is {1}). " + "HOW TO FIX: check dates of these DBVersions, you'll find two with the same dates.", info, last), ex); } return(this); }
/// <summary> /// Returns the top-version registered in DBVersionSystem /// by date /// </summary> /// <returns></returns> public int GetMaxVersion() { int max = 0; foreach (IDBVersionInformation entry in m_versionsTable.Values) { if (entry.VersionAttribute.Version > max) { max = entry.VersionAttribute.Version; } } // if (max.Equals(DateTime.MinValue)) // return 0; IDBVersionInformation info = m_versionsTable[max]; if (info == null) { throw new ArgumentNullException("Could not get max version. Error in code"); } return(info.VersionAttribute.Version); }
public DBVersionRepository AddVersions(IDBVersionInformation info) { try { m_versionsTable.Add(info.VersionAttribute.Version, info); } catch (ArgumentException ex) { IDBVersionInformation last = m_versionsTable[info.VersionAttribute.Version]; throw new DBUpdateException(string.Format( "Could not add DBVersion {0} to list," + " because there is already a version with that date (that is {1}). " + "HOW TO FIX: check dates of these DBVersions, you'll find two with the same dates.", info, last), ex); } return this; }