// Copyright (C) Stichting Deltares 2017. 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 Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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 Core.Common.Util;
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 or
/// is invalid.
/// A valid path:
///
/// - is not empty or null,
/// - does not consist out of only whitespace characters,
/// - does not contain an invalid character,
/// - does not end with a directory or path separator (empty file name).
///
/// Thrown when upgrading failed.
public void Upgrade(string sourceLocation, string targetLocation)
{
if (!IOUtils.IsValidFilePath(sourceLocation))
{
throw new ArgumentException($@"'{sourceLocation}' is not a valid file path.", nameof(sourceLocation));
}
if (!IOUtils.IsValidFilePath(targetLocation))
{
throw new ArgumentException($@"'{targetLocation}' is not a valid file path.", nameof(targetLocation));
}
PerformUpgrade(sourceLocation, targetLocation);
}
///
/// Performs the upgrade on .
///
/// The source file to upgrade from.
/// The target file to upgrade to.
/// The and has been verified in .
/// Thrown when upgrading failed.
protected abstract void PerformUpgrade(string sourceLocation, string targetLocation);
}
}