-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDataMigration7000003.cs
More file actions
80 lines (71 loc) · 2.84 KB
/
DataMigration7000003.cs
File metadata and controls
80 lines (71 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2009-2013 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
//
// File: DataMigration7000003.cs
// Responsibility: shaneyfelt
//
// <remarks>
// </remarks>
using System.Collections.Generic;
using System.Xml.Linq;
namespace SIL.LCModel.DomainServices.DataMigration
{
/// ----------------------------------------------------------------------------------------
/// <summary>
/// Migrate data from 7000002 to 7000003.
///
/// Changes all StFootnotes to ScrFootnotes
/// </summary>
/// ----------------------------------------------------------------------------------------
internal class DataMigration7000003 : IDataMigration
{
#region IDataMigration Members
/// ------------------------------------------------------------------------------------
/// <summary>
/// Changes all StFootnotes to ScrFootnotes
/// </summary>
/// <param name="domainObjectDtoRepository">
/// Repository of all CmObject DTOs available for one migration step.
/// </param>
/// <remarks>
/// The method must add/remove/update the DTOs to the repository,
/// as it adds/removes objects as part of it work.
///
/// Implementors of this interface should ensure the Repository's
/// starting model version number is correct for the step.
/// Implementors must also increment the Repository's model version number
/// at the end of its migration work.
///
/// The method also should normally modify the xml string(s)
/// of relevant DTOs, since that string will be used by the main
/// data migration calling client (ie. BEP).
/// </remarks>
/// ------------------------------------------------------------------------------------
public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000002);
var footnotesToChangeClasses = new List<DomainObjectXMLDTO>();
foreach (var footnote in domainObjectDtoRepository.AllInstancesSansSubclasses("StFootnote"))
{
XElement footnoteEl = XElement.Parse(footnote.Xml);
footnoteEl.Attribute("class").Value = "ScrFootnote";
// Add the empty ScrFootnote element to the ScrFootnote
footnoteEl.Add(new XElement("ScrFootnote"));
// Update the object XML
footnote.Xml = footnoteEl.ToString();
footnote.Classname = "ScrFootnote";
footnotesToChangeClasses.Add(footnote);
}
// Udate the repository
var startingStructure = new ClassStructureInfo("StText", "StFootnote");
var endingStructure = new ClassStructureInfo("StFootnote", "ScrFootnote");
foreach (var changedPara in footnotesToChangeClasses)
domainObjectDtoRepository.Update(changedPara,
startingStructure,
endingStructure);
DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
}
#endregion
}
}