// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using Migration.Scripts.Data.Exceptions;
namespace Migration.Scripts.Data
{
///
/// Class that provides methods for the upgrading a for a specific version.
///
public abstract class UpgradeScript
{
private readonly string fromVersion;
private readonly string toVersion;
///
/// Creates a new instance of the class.
///
/// The source version.
/// The target version.
/// Thrown when:
///
/// - is empty or null,
/// - is empty or null,
///
protected UpgradeScript(string fromVersion, string toVersion)
{
if (string.IsNullOrEmpty(fromVersion))
{
throw new ArgumentException(@"FromVersion must have a value.", nameof(fromVersion));
}
if (string.IsNullOrEmpty(toVersion))
{
throw new ArgumentException(@"ToVersion must have a value.", nameof(toVersion));
}
this.fromVersion = fromVersion;
this.toVersion = toVersion;
}
///
/// The source version of .
///
/// The version.
public string FromVersion()
{
return fromVersion;
}
///
/// The target version of .
///
/// The version.
public string ToVersion()
{
return toVersion;
}
///
/// Uses to upgrade to .
///
/// The source file to upgrade from.
/// The target file to upgrade to.
/// Thrown when:
///
/// - is null,
/// - is null.
///
/// Thrown when executing query failed.
public void Upgrade(IVersionedFile source, IVersionedFile target)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
PerformUpgrade(source, target);
}
protected abstract void PerformUpgrade(IVersionedFile source, IVersionedFile target);
}
}