public override void SetPreviousVersion(DBXml dbXml, Dictionary <string, string> previousVersions) { base.SetPreviousVersion(dbXml, previousVersions); foreach (var objectVersion in previousVersions) { if (objectVersion.Key.Length > 0) { var row = dbXml.FindRow(r => r.Element("_commReq") != null && r.Element("_commReq").Value == objectVersion.Key); if (row != null) { row.AddElement("version", objectVersion.Value); } } } }
/// <summary> /// Generates the changeset - diff beetween two snapshots. /// </summary> /// <param name="commSnapshot">The snapshot from other branch.</param> /// <param name="dbSnapshot">The snapshot created from database.</param> /// <returns>Generated xml changeset.</returns> public virtual DBXml GenerateChangeset(DBXml commSnapshot, DBXml dbSnapshot) { DBXml result = new DBXml(commSnapshot); Dictionary <string, string> previousVersion = GetPreviousVersion(result); RemovePreviousVersion(result); IEnumerable <DBRow> resultEntries = result.Tables.SelectMany(table => table.Rows); if (dbSnapshot == null) { var eTables = new List <DBTable>(); foreach (var table in result.Tables) { if (table.HasRows == false) { eTables.Add(table); } } foreach (var table in eTables) { table.Remove(); } return(MarkAsInserted(resultEntries).First().Table.Document); } IEnumerable <DBRow> dbEntries = dbSnapshot.Tables.SelectMany(table => table.Rows).Where(row => row.HasAction == false); List <DBRow> unmodifiedEntries = new List <DBRow>(); foreach (DBRow entry in resultEntries) { DBRow match = dbSnapshot.FindRow(entry); if (match != null) { //entry.Action != DBRowState.Delete - niestety musialem dolozyc ten warunek gdyz ciezko jest dogadac sie z chlopakami // by entry przy delete tez zawieraly wersje if (entry.Action != DBRowState.Delete && entry.IsTheSameAs(match)) { if (entry.Action == null) { unmodifiedEntries.Add(entry); } else if (entry.Action == DBRowState.Insert) { entry.SetAction(DBRowState.Update); } } else if (entry.Action == null) { entry.Element("version").Name = "_version"; entry.SetAction(DBRowState.Update); } match.Remove(); } else if (entry.Action == null) { entry.SetAction(DBRowState.Insert); } } if (previousVersion != null) // && result.Table(MainObjectTag).FirstRow().Element("version") == null { SetPreviousVersion(result, previousVersion); //result.Table(MainObjectTag).FirstRow().AddElement("version", previousVersion); } // remove unmodified entries from result unmodifiedEntries.ForEach(entry => entry.Remove()); foreach (DBRow entry in dbEntries) { entry.SetAction(DBRowState.Delete); } result.AddTable(from table in dbSnapshot.Tables where table.HasRows select table); var emptyTables = new List <DBTable>(); foreach (var table in result.Tables) { if (table.HasRows == false) { emptyTables.Add(table); } } foreach (var table in emptyTables) { table.Remove(); } return(result); }