// 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 log4net; using Ringtoets.Common.Service.Properties; namespace Ringtoets.Common.Service { /// /// This class defines helper methods for performing calculations. /// public static class CalculationServiceHelper { private static readonly ILog log = LogManager.GetLogger(typeof(CalculationServiceHelper)); /// /// Logs messages as errors. /// /// The format for the message. /// The messages to log. public static void LogMessagesAsError(string format, params string[] errorMessages) { foreach (var errorMessage in errorMessages) { log.ErrorFormat(format, errorMessage); } } /// /// Logs messages as warnings. /// /// The messages to log. public static void LogMessagesAsWarning(params string[] warningMessages) { foreach (var waningMessage in warningMessages) { log.Warn(waningMessage); } } /// /// Logs the begin time of the validation. /// /// The name of the object being validated. public static void LogValidationBeginTime(string name) { log.Info(string.Format(Resources.Validation_Subject_0_started_Time_1_, name, DateTimeService.CurrentTimeAsString)); } /// /// Logs the end time of the validation. /// /// The name of the object being validated. public static void LogValidationEndTime(string name) { log.Info(string.Format(Resources.Validation_Subject_0_ended_Time_1_, name, DateTimeService.CurrentTimeAsString)); } /// /// Logs the begin time of the calculation. /// /// The name of the calculation being started. public static void LogCalculationBeginTime(string name) { log.Info(string.Format(Resources.Calculation_Subject_0_started_Time_1_, name, DateTimeService.CurrentTimeAsString)); } /// /// Logs the end time of the calculation. /// /// The name of the calculation that has ended. public static void LogCalculationEndTime(string name) { log.Info(string.Format(Resources.Calculation_Subject_0_ended_Time_1_, name, DateTimeService.CurrentTimeAsString)); } /// /// Determines whether an error has occurred during the calculation. /// /// The canceled state of the calculation. /// Indicator if there is already an exception thrown in the calculation. /// The contents of the last error file. /// true when a calculation isn't canceled, has not already thrown an exception and /// is set. false otherwise. public static bool ErrorOccurred(bool canceled, bool exceptionThrown, string lastErrorFileContent) { return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); } } }