Merge lp:~adam-rpconnelly/dbversion/archive-properties into lp:dbversion

Proposed by Adam Connelly
Status: Merged
Merged at revision: 26
Proposed branch: lp:~adam-rpconnelly/dbversion/archive-properties
Merge into: lp:dbversion
Prerequisite: lp:~adam-rpconnelly/dbversion/settings
Diff against target: 708 lines (+347/-71)
10 files modified
src/DatabaseVersion.Console/DatabaseVersion.Console.csproj (+1/-1)
src/DatabaseVersion.Console/Program.cs (+32/-12)
src/DatabaseVersion.Tests/Archives/File/FileDatabaseArchiveTests.cs (+70/-6)
src/DatabaseVersion.Tests/Archives/Zip/ZipDatabaseArchiveTests.cs (+62/-6)
src/DatabaseVersion.sln (+1/-0)
src/DatabaseVersion/Archives/File/FileDatabaseArchive.cs (+26/-0)
src/DatabaseVersion/Archives/IDatabaseArchive.cs (+9/-0)
src/DatabaseVersion/Archives/Zip/ZipDatabaseArchive.cs (+125/-10)
src/DatabaseVersion/DatabaseCreator.cs (+16/-36)
src/DatabaseVersion/Property/PropertyService.cs (+5/-0)
To merge this branch: bzr merge lp:~adam-rpconnelly/dbversion/archive-properties
Reviewer Review Type Date Requested Status
dbversion committers Pending
Review via email: mp+73992@code.launchpad.net

Description of the change

Added support for storing properties inside the file and zip archives.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'samples/classic-sample.zip'
2Binary files samples/classic-sample.zip 1970-01-01 00:00:00 +0000 and samples/classic-sample.zip 2011-09-04 10:36:23 +0000 differ
3=== modified file 'src/DatabaseVersion.Console/DatabaseVersion.Console.csproj'
4--- src/DatabaseVersion.Console/DatabaseVersion.Console.csproj 2011-09-04 10:36:23 +0000
5+++ src/DatabaseVersion.Console/DatabaseVersion.Console.csproj 2011-09-04 10:36:23 +0000
6@@ -22,7 +22,7 @@
7 <DefineConstants>DEBUG;TRACE</DefineConstants>
8 <ErrorReport>prompt</ErrorReport>
9 <WarningLevel>4</WarningLevel>
10- <Commandlineparameters>-c "Server=localhost;Database=library;User ID=adam;Password=adam;" -a /home/adam/bzr/dbversion/settings/samples/classic-sample</Commandlineparameters>
11+ <Commandlineparameters>-c "Server=localhost;Database=library;User ID=adam;Password=adam;" -a /home/adam/bzr/dbversion/archive-properties/samples/classic-sample.zip</Commandlineparameters>
12 </PropertyGroup>
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
14 <PlatformTarget>x86</PlatformTarget>
15
16=== modified file 'src/DatabaseVersion.Console/Program.cs'
17--- src/DatabaseVersion.Console/Program.cs 2011-09-04 10:36:23 +0000
18+++ src/DatabaseVersion.Console/Program.cs 2011-09-04 10:36:23 +0000
19@@ -1,3 +1,5 @@
20+using dbversion.Archives;
21+
22 namespace dbversion.Console
23 {
24 using System;
25@@ -26,20 +28,41 @@
26
27 try
28 {
29+ var archive = GetArchive(arguments, container);
30 var propertyService = container.GetExportedValue<IPropertyService>();
31 propertyService.SetDefaultProperties();
32 MergeSavedProperties(container, propertyService);
33+ propertyService.Merge(archive.Properties);
34 OverwritePropertiesFromArguments(propertyService, arguments);
35
36- creator.LoadArchive(arguments.Archive);
37- creator.Create(arguments.Version, new ConsoleTaskExecuter());
38- } catch (VersionNotFoundException e)
39- {
40- System.Console.WriteLine(e.Message);
41- } catch (TaskExecutionException e)
42- {
43- System.Console.WriteLine(e.Message);
44- }
45+ creator.Create(archive, arguments.Version, new ConsoleTaskExecuter());
46+ }
47+ catch (VersionNotFoundException e)
48+ {
49+ System.Console.WriteLine(e.Message);
50+ }
51+ catch (TaskExecutionException e)
52+ {
53+ System.Console.WriteLine(e.Message);
54+ }
55+ }
56+
57+ private static IDatabaseArchive GetArchive(Arguments arguments, CompositionContainer container)
58+ {
59+ IDatabaseArchiveFactory archiveFactory = GetArchiveFactory(arguments.Archive, container);
60+ if (archiveFactory == null)
61+ {
62+ throw new InvalidOperationException("Unknown archive type");
63+ }
64+
65+ return archiveFactory.Create(arguments.Archive);
66+ }
67+
68+ private static IDatabaseArchiveFactory GetArchiveFactory(string archivePath, CompositionContainer container)
69+ {
70+ var archiveFactories = container.GetExportedValues<IDatabaseArchiveFactory>();
71+ // TODO: Throw UnknownArchiveTypeException if no handlers found
72+ return archiveFactories.First(f => f.CanCreate(archivePath));
73 }
74
75 private static Arguments ParseArguments(ref string[] args)
76@@ -84,9 +107,6 @@
77
78 private static void OverwritePropertiesFromArguments(IPropertyService propertyService, Arguments arguments)
79 {
80-// propertyService.Add(new Property { Key = "hibernate.connection.provider", Value = "NHibernate.Connection.DriverConnectionProvider" });
81-// propertyService.Add(new Property { Key = "hibernate.connection.driver_class", Value = "NHibernate.Driver.SqlClientDriver" });
82-// propertyService.Add(new Property { Key = "hibernate.dialect", Value = "NHibernate.Dialect.MsSql2008Dialect" });
83 propertyService.Add(new Property { Key = "hibernate.connection.connection_string", Value = arguments.ConnectionString });
84 }
85
86
87=== modified file 'src/DatabaseVersion.Tests/Archives/File/FileDatabaseArchiveTests.cs'
88--- src/DatabaseVersion.Tests/Archives/File/FileDatabaseArchiveTests.cs 2011-08-29 18:40:26 +0000
89+++ src/DatabaseVersion.Tests/Archives/File/FileDatabaseArchiveTests.cs 2011-09-04 10:36:23 +0000
90@@ -14,6 +14,8 @@
91 using Moq;
92 using dbversion.Archives;
93 using dbversion.Version;
94+ using dbversion.Property;
95+ using dbversion.Utils;
96
97 public class FileDatabaseArchiveTests : IDisposable
98 {
99@@ -84,16 +86,16 @@
100
101 DatabaseVersion version1 = new DatabaseVersion(new NumericVersion(1), "_1" + Path.DirectorySeparatorChar + "database.xml", null);
102 DatabaseVersion version2 = new DatabaseVersion(new NumericVersion(2), "_2" + Path.DirectorySeparatorChar + "database.xml", null);
103-
104+
105 this.manifestReader.Setup(
106 m => m.Read(It.IsAny<Stream>(),
107- string.Format("{1}{0}{2}{0}{3}", Path.DirectorySeparatorChar, this.testDirectory.FullName, "_1", "database.xml"),
108- It.IsAny<IDatabaseArchive>()))
109+ string.Format("{1}{0}{2}{0}{3}", Path.DirectorySeparatorChar, this.testDirectory.FullName, "_1", "database.xml"),
110+ It.IsAny<IDatabaseArchive>()))
111 .Returns(version1);
112 this.manifestReader.Setup(
113- m => m.Read(It.IsAny<Stream>(),
114+ m => m.Read(It.IsAny<Stream>(),
115 string.Format("{1}{0}{2}{0}{3}", Path.DirectorySeparatorChar, this.testDirectory.FullName, "_2", "database.xml"),
116- It.IsAny<IDatabaseArchive>()))
117+ It.IsAny<IDatabaseArchive>()))
118 .Returns(version2);
119
120 FileDatabaseArchive archive = new FileDatabaseArchive(testDirectory.FullName, this.manifestReader.Object);
121@@ -105,7 +107,69 @@
122 Assert.Contains(version1, versions);
123 Assert.Contains(version2, versions);
124 }
125-
126+
127+ [Fact]
128+ public void ShouldLoadPropertiesFromPropertiesFile()
129+ {
130+ // Arrange
131+ this.testDirectory = FileUtil.CreateTempDirectory();
132+
133+ PropertyCollection expectedProperties = new PropertyCollection();
134+ expectedProperties.Properties.Add(new Property { Key = "property1", Value = "property1.value" });
135+ expectedProperties.Properties.Add(new Property { Key = "property2", Value = "property2.value" });
136+
137+ using (FileStream stream = new FileStream(Path.Combine(this.testDirectory.FullName, PropertyService.PropertyFileName), FileMode.Create))
138+ {
139+ XmlSerializer.Serialize(expectedProperties).CopyTo(stream);
140+ }
141+
142+ var archive = new FileDatabaseArchive(this.testDirectory.FullName, this.manifestReader.Object);
143+
144+ // Act
145+ var properties = archive.Properties;
146+
147+ // Assert
148+ Assert.Equal("property1.value", properties.Single(p => p.Key == "property1").Value);
149+ Assert.Equal("property2.value", properties.Single(p => p.Key == "property2").Value);
150+ }
151+
152+ [Fact]
153+ public void ShouldReturnEmptyPropertiesIfNoPropertiesFileExists()
154+ {
155+ // Arrange
156+ this.testDirectory = FileUtil.CreateTempDirectory();
157+
158+ var archive = new FileDatabaseArchive(this.testDirectory.FullName, this.manifestReader.Object);
159+
160+ // Act
161+ var properties = archive.Properties;
162+
163+ // Assert
164+ Assert.Empty(properties);
165+ }
166+
167+ [Fact]
168+ public void ShouldReturnEmptyPropertiesIfNoPropertiesExistInFile()
169+ {
170+ // Arrange
171+ this.testDirectory = FileUtil.CreateTempDirectory();
172+
173+ PropertyCollection expectedProperties = new PropertyCollection();
174+
175+ using (FileStream stream = new FileStream(Path.Combine(this.testDirectory.FullName, PropertyService.PropertyFileName), FileMode.Create))
176+ {
177+ XmlSerializer.Serialize(expectedProperties).CopyTo(stream);
178+ }
179+
180+ var archive = new FileDatabaseArchive(this.testDirectory.FullName, this.manifestReader.Object);
181+
182+ // Act
183+ var properties = archive.Properties;
184+
185+ // Assert
186+ Assert.Empty(properties);
187+ }
188+
189 public void Dispose()
190 {
191 if (this.testDirectory != null)
192
193=== modified file 'src/DatabaseVersion.Tests/Archives/Zip/ZipDatabaseArchiveTests.cs'
194--- src/DatabaseVersion.Tests/Archives/Zip/ZipDatabaseArchiveTests.cs 2011-08-29 18:40:26 +0000
195+++ src/DatabaseVersion.Tests/Archives/Zip/ZipDatabaseArchiveTests.cs 2011-09-04 10:36:23 +0000
196@@ -1,15 +1,21 @@
197 namespace dbversion.Tests.Archives.Zip
198 {
199- using Xunit;
200- using Ionic.Zip;
201- using Moq;
202- using dbversion.Manifests;
203- using dbversion.Archives.Zip;
204 using System.IO;
205 using System.Linq;
206+
207+ using dbversion.Archives;
208+ using dbversion.Archives.Zip;
209+ using dbversion.Manifests;
210 using dbversion.Tests.Utils;
211- using dbversion.Archives;
212+ using dbversion.Utils;
213 using dbversion.Version;
214+ using dbversion.Property;
215+
216+ using Ionic.Zip;
217+
218+ using Moq;
219+
220+ using Xunit;
221
222 public class ZipDatabaseArchiveTests
223 {
224@@ -37,5 +43,55 @@
225 Assert.Equal(2, archive.Versions.Count());
226 }
227 }
228+
229+ [Fact]
230+ public void ShouldLoadPropertiesFromArchive()
231+ {
232+ // Arrange
233+ string path = Path.GetTempFileName();
234+ using (var zipFile = new ZipFile())
235+ {
236+ var tempDir = FileUtil.CreateTempDirectory();
237+ var propertiesFileName = Path.Combine(tempDir.FullName, "properties.xml");
238+ using (var stream = File.Create(propertiesFileName))
239+ {
240+ var propertyCollection = new PropertyCollection();
241+ propertyCollection.Properties.Add(new Property { Key = "property1", Value = "property1.value" });
242+ propertyCollection.Properties.Add(new Property { Key = "property2", Value = "property2.value" });
243+ XmlSerializer.Serialize(propertyCollection).CopyTo(stream);
244+ }
245+
246+ zipFile.AddFile(propertiesFileName, "/");
247+ zipFile.Save(path);
248+ }
249+
250+ var archive = new ZipDatabaseArchive(path, new Mock<ManifestReader>().Object);
251+
252+ // Act
253+ var properties = archive.Properties;
254+
255+ // Assert
256+ Assert.Equal("property1.value", properties.Single(p => p.Key == "property1").Value);
257+ Assert.Equal("property2.value", properties.Single(p => p.Key == "property2").Value);
258+ }
259+
260+ [Fact]
261+ public void ShouldHaveEmptyPropertiesIfNoPropertiesFileExists()
262+ {
263+ // Arrange
264+ string path = Path.GetTempFileName();
265+ using (var zipFile = new ZipFile())
266+ {
267+ zipFile.Save(path);
268+ }
269+
270+ var archive = new ZipDatabaseArchive(path, new Mock<ManifestReader>().Object);
271+
272+ // Act
273+ var properties = archive.Properties;
274+
275+ // Assert
276+ Assert.Empty(properties);
277+ }
278 }
279 }
280
281=== modified file 'src/DatabaseVersion.sln'
282--- src/DatabaseVersion.sln 2011-09-04 10:36:23 +0000
283+++ src/DatabaseVersion.sln 2011-09-04 10:36:23 +0000
284@@ -71,6 +71,7 @@
285 $2.WhileBraceForcement = AddBraces
286 $2.UsingBraceForcement = AddBraces
287 $2.FixedBraceForcement = AddBraces
288+ $2.PlaceElseOnNewLine = True
289 $2.BeforeMethodDeclarationParentheses = False
290 $2.BeforeMethodCallParentheses = False
291 $2.BeforeConstructorDeclarationParentheses = False
292
293=== modified file 'src/DatabaseVersion/Archives/File/FileDatabaseArchive.cs'
294--- src/DatabaseVersion/Archives/File/FileDatabaseArchive.cs 2011-08-29 18:40:26 +0000
295+++ src/DatabaseVersion/Archives/File/FileDatabaseArchive.cs 2011-09-04 10:36:23 +0000
296@@ -8,6 +8,8 @@
297 using System.ComponentModel.Composition;
298
299 using dbversion.Manifests;
300+ using dbversion.Property;
301+ using dbversion.Utils;
302 using dbversion.Version;
303
304 /// <summary>
305@@ -34,6 +36,7 @@
306 this.ArchivePath = archivePath;
307 this.manifestReader = manifestReader;
308 this.ParseManifests();
309+ this.LoadProperties();
310 }
311
312 /// <summary>
313@@ -56,6 +59,12 @@
314 private set;
315 }
316
317+ public IEnumerable<Property> Properties
318+ {
319+ get;
320+ private set;
321+ }
322+
323 /// <summary>
324 /// Gets the file at the specified path from the archive.
325 /// </summary>
326@@ -117,5 +126,22 @@
327 string filePath = Path.Combine(manifestFile.Directory.Name, scriptFileName);
328 return filePath;
329 }
330+
331+ private void LoadProperties()
332+ {
333+ FileInfo propertiesFile = new FileInfo(Path.Combine(this.ArchivePath, PropertyService.PropertyFileName));
334+ if (propertiesFile.Exists)
335+ {
336+ using (var stream = propertiesFile.OpenRead())
337+ {
338+ var propertyCollection = XmlSerializer.DeSerialize<PropertyCollection>(stream);
339+ this.Properties = propertyCollection.Properties;
340+ }
341+ }
342+ else
343+ {
344+ this.Properties = Enumerable.Empty<Property>();
345+ }
346+ }
347 }
348 }
349
350=== modified file 'src/DatabaseVersion/Archives/IDatabaseArchive.cs'
351--- src/DatabaseVersion/Archives/IDatabaseArchive.cs 2011-08-29 18:40:26 +0000
352+++ src/DatabaseVersion/Archives/IDatabaseArchive.cs 2011-09-04 10:36:23 +0000
353@@ -6,6 +6,7 @@
354 using System.Text;
355 using System.IO;
356
357+ using dbversion.Property;
358 using dbversion.Version;
359
360 /// <summary>
361@@ -24,6 +25,14 @@
362 IEnumerable<IDatabaseVersion> Versions { get; }
363
364 /// <summary>
365+ /// Gets the properties stored in the archive.
366+ /// </summary>
367+ /// <value>
368+ /// The properties.
369+ /// </value>
370+ IEnumerable<Property> Properties { get; }
371+
372+ /// <summary>
373 /// Gets the file at the specified path.
374 /// </summary>
375 /// <param name="path">The path relative to the root of the archive.</param>
376
377=== modified file 'src/DatabaseVersion/Archives/Zip/ZipDatabaseArchive.cs'
378--- src/DatabaseVersion/Archives/Zip/ZipDatabaseArchive.cs 2011-08-29 18:40:26 +0000
379+++ src/DatabaseVersion/Archives/Zip/ZipDatabaseArchive.cs 2011-09-04 10:36:23 +0000
380@@ -1,23 +1,47 @@
381 namespace dbversion.Archives.Zip
382 {
383- using Ionic.Zip;
384+ using System;
385 using System.IO;
386 using System.Linq;
387 using System.ComponentModel.Composition;
388 using System.Collections.Generic;
389
390 using dbversion.Manifests;
391+ using dbversion.Property;
392+ using dbversion.Utils;
393 using dbversion.Version;
394
395+ using Ionic.Zip;
396+
397+ /// <summary>
398+ /// A database archive that stores its files in a zip file.
399+ /// </summary>
400 [Export(typeof(IDatabaseArchive))]
401 public class ZipDatabaseArchive : IDatabaseArchive
402 {
403 #region Fields
404+
405+ /// <summary>
406+ /// The manifest reader.
407+ /// </summary>
408 private readonly IManifestReader manifestReader;
409+
410+ /// <summary>
411+ /// The versions contained in the archive.
412+ /// </summary>
413 private readonly List<IDatabaseVersion> versions = new List<IDatabaseVersion>();
414
415 #endregion
416
417+ /// <summary>
418+ /// Initializes a new instance of the <see cref="dbversion.Archives.Zip.ZipDatabaseArchive"/> class.
419+ /// </summary>
420+ /// <param name='path'>
421+ /// The path to the archive.
422+ /// </param>
423+ /// <param name='manifestReader'>
424+ /// The manifest reader.
425+ /// </param>
426 public ZipDatabaseArchive(string path, IManifestReader manifestReader)
427 {
428 Validate.NotEmpty(() => path);
429@@ -26,26 +50,57 @@
430 this.ArchivePath = path;
431 this.manifestReader = manifestReader;
432
433- using (ZipFile zipfile = new ZipFile(path))
434+ using (ZipFile zipFile = new ZipFile(path))
435 {
436- foreach (ZipEntry entry in zipfile.Where(e => e.FileName.EndsWith("database.xml")))
437- {
438- this.ParseManifest(entry);
439- }
440+ this.ParseManifests(zipFile);
441+ this.LoadProperties(zipFile);
442 }
443 }
444
445+ /// <summary>
446+ /// Gets the archive path.
447+ /// </summary>
448+ /// <value>
449+ /// The archive path.
450+ /// </value>
451 public string ArchivePath
452 {
453 get;
454 private set;
455 }
456
457- public System.Collections.Generic.IEnumerable<IDatabaseVersion> Versions
458+ /// <summary>
459+ /// Gets the versions contained in the archive.
460+ /// </summary>
461+ /// <value>
462+ /// The versions.
463+ /// </value>
464+ public IEnumerable<IDatabaseVersion> Versions
465 {
466 get { return this.versions; }
467 }
468
469+ /// <summary>
470+ /// Gets the properties set in the archive.
471+ /// </summary>
472+ /// <value>
473+ /// The properties.
474+ /// </value>
475+ public IEnumerable<Property> Properties
476+ {
477+ get;
478+ private set;
479+ }
480+
481+ /// <summary>
482+ /// Gets the specified file from the archive.
483+ /// </summary>
484+ /// <param name='path'>
485+ /// The path to the file.
486+ /// </param>
487+ /// <returns>
488+ /// The file or null if the file does not exist.
489+ /// </returns>
490 public System.IO.Stream GetFile(string path)
491 {
492 using (ZipFile zipFile = new ZipFile(this.ArchivePath))
493@@ -65,11 +120,58 @@
494 return null;
495 }
496
497+ /// <summary>
498+ /// Returns whether the archive contains the specified version.
499+ /// </summary>
500+ /// <param name='version'>
501+ /// The version to look for.
502+ /// </param>
503+ /// <returns>
504+ /// true if the archive contains the version, false otherwise.
505+ /// </returns>
506 public bool ContainsVersion(object version)
507 {
508 return this.Versions.FirstOrDefault(v => object.Equals(v.Version, version)) != null;
509 }
510
511+ /// <summary>
512+ /// Gets the script path.
513+ /// </summary>
514+ /// <param name='manifestPath'>
515+ /// The manifest path.
516+ /// </param>
517+ /// <param name='scriptFileName'>
518+ /// The script file name.
519+ /// </param>
520+ /// <returns>
521+ /// The script path.
522+ /// </returns>
523+ public string GetScriptPath(string manifestPath, string scriptFileName)
524+ {
525+ string filePath = Path.Combine(Path.GetDirectoryName(manifestPath), scriptFileName);
526+ return filePath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
527+ }
528+
529+ /// <summary>
530+ /// Parses the manifests contained in the zip file.
531+ /// </summary>
532+ /// <param name='zipFile'>
533+ /// The zip file.
534+ /// </param>
535+ private void ParseManifests(ZipFile zipFile)
536+ {
537+ foreach (ZipEntry entry in zipFile.Where(e => e.FileName.EndsWith("database.xml")))
538+ {
539+ this.ParseManifest(entry);
540+ }
541+ }
542+
543+ /// <summary>
544+ /// Parses the manifest.
545+ /// </summary>
546+ /// <param name='entry'>
547+ /// The zip entry containing the manifest.
548+ /// </param>
549 private void ParseManifest(ZipEntry entry)
550 {
551 MemoryStream stream = new MemoryStream();
552@@ -80,10 +182,23 @@
553 this.versions.Add(this.manifestReader.Read(stream, entry.FileName, this));
554 }
555
556- public string GetScriptPath(string manifestPath, string scriptFileName)
557+ /// <summary>
558+ /// Loads the properties.
559+ /// </summary>
560+ /// <param name='zipFile'>
561+ /// The zip file to load the properties from.
562+ /// </param>
563+ private void LoadProperties(ZipFile zipFile)
564 {
565- string filePath = Path.Combine(Path.GetDirectoryName(manifestPath), scriptFileName);
566- return filePath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
567+ if (zipFile.ContainsEntry(PropertyService.PropertyFileName))
568+ {
569+ var propertiesFile = zipFile.Single(p => p.FileName == PropertyService.PropertyFileName);
570+ this.Properties = XmlSerializer.DeSerialize<PropertyCollection>(propertiesFile.OpenReader()).Properties;
571+ }
572+ else
573+ {
574+ this.Properties = Enumerable.Empty<Property>();
575+ }
576 }
577 }
578 }
579
580=== modified file 'src/DatabaseVersion/DatabaseCreator.cs'
581--- src/DatabaseVersion/DatabaseCreator.cs 2011-09-04 10:36:23 +0000
582+++ src/DatabaseVersion/DatabaseCreator.cs 2011-09-04 10:36:23 +0000
583@@ -46,15 +46,9 @@
584 set;
585 }
586
587- public IDatabaseArchive Archive
588- {
589- get;
590- private set;
591- }
592-
593- public void Create(string version)
594- {
595- this.Create(version, new SimpleTaskExecuter());
596+ public void Create(IDatabaseArchive archive, string version)
597+ {
598+ this.Create(archive, version, new SimpleTaskExecuter());
599 }
600
601 /// <summary>
602@@ -67,7 +61,7 @@
603 /// <exception cref="TaskExecutionException">
604 /// Thrown if an error occurs while executing one of the tasks in the archive.
605 /// </exception>
606- public void Create(string version, ITaskExecuter executer)
607+ public void Create(IDatabaseArchive archive, string version, ITaskExecuter executer)
608 {
609 using (var sessionFactory = this.SessionFactoryProvider.CreateSessionFactory())
610 {
611@@ -89,21 +83,22 @@
612 object targetVersion;
613 if (string.IsNullOrEmpty(version))
614 {
615- targetVersion = this.Archive.Versions
616+ targetVersion = archive.Versions
617 .OrderByDescending(v => v.Version, this.VersionProvider.GetComparer())
618 .First()
619 .Version;
620- } else
621+ }
622+ else
623 {
624 targetVersion = this.VersionProvider.CreateVersion(version);
625 }
626
627- if (!this.Archive.ContainsVersion(targetVersion))
628+ if (!archive.ContainsVersion(targetVersion))
629 {
630 throw new Version.VersionNotFoundException(targetVersion);
631 }
632
633- this.AddTasksToExecuter(executer, currentVersion, targetVersion);
634+ this.AddTasksToExecuter(archive, executer, currentVersion, targetVersion);
635
636 executer.ExecuteTasks(session);
637
638@@ -113,20 +108,9 @@
639 }
640 }
641
642- public void LoadArchive(string archivePath)
643- {
644- IDatabaseArchiveFactory archiveFactory = this.GetArchiveFactory(archivePath);
645- if (archiveFactory == null)
646- {
647- throw new InvalidOperationException("Unknown archive type");
648- }
649-
650- this.Archive = archiveFactory.Create(archivePath);
651- }
652-
653- private void AddTasksToExecuter(ITaskExecuter executer, VersionBase currentVersion, object targetVersion)
654- {
655- IEnumerable<IDatabaseVersion > versionsToExecute = this.Archive.Versions
656+ private void AddTasksToExecuter(IDatabaseArchive archive, ITaskExecuter executer, VersionBase currentVersion, object targetVersion)
657+ {
658+ IEnumerable<IDatabaseVersion > versionsToExecute = archive.Versions
659 .OrderBy(v => v.Version, this.VersionProvider.GetComparer())
660 .Where(
661 v =>
662@@ -147,7 +131,8 @@
663 executer.AddTask(task);
664 currentVersion.AddTask(task);
665 }
666- } else
667+ }
668+ else
669 {
670 executer.AddTask(task);
671 v.Version.AddTask(task);
672@@ -159,18 +144,13 @@
673 if (updating)
674 {
675 executer.AddTask(new InsertVersionTask(this.VersionProvider, currentVersion));
676- } else
677+ }
678+ else
679 {
680 executer.AddTask(new InsertVersionTask(this.VersionProvider, v.Version));
681 }
682 }
683 }
684 }
685-
686- private IDatabaseArchiveFactory GetArchiveFactory(string archivePath)
687- {
688- // TODO: Throw UnknownArchiveTypeException if no handlers found
689- return this.ArchiveFactories.First(f => f.CanCreate(archivePath));
690- }
691 }
692 }
693
694=== modified file 'src/DatabaseVersion/Property/PropertyService.cs'
695--- src/DatabaseVersion/Property/PropertyService.cs 2011-09-04 10:36:23 +0000
696+++ src/DatabaseVersion/Property/PropertyService.cs 2011-09-04 10:36:23 +0000
697@@ -11,6 +11,11 @@
698 public class PropertyService : IPropertyService
699 {
700 /// <summary>
701+ /// The name of the properties file.
702+ /// </summary>
703+ public const string PropertyFileName = "properties.xml";
704+
705+ /// <summary>
706 /// The properties.
707 /// </summary>
708 private readonly Dictionary<string, Property> properties = new Dictionary<string, Property>();

Subscribers

People subscribed via source and target branches

to all changes: