using System;
using System.Collections.Generic;
using Core.Common.Base.Storage;
using log4net;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Service.Exceptions;
namespace Ringtoets.Integration.Service.Merge
{
///
/// Service which provides a from a file.
///
public class AssessmentSectionProviderService : IAssessmentSectionProvider
{
private readonly ILog log = LogManager.GetLogger(typeof(AssessmentSectionProviderService));
private readonly IStoreProject storage;
///
/// Creates a new instance of
///
/// Class responsible to storing and loading the application project.
/// Thrown when is null.
public AssessmentSectionProviderService(IStoreProject projectStorage)
{
if (projectStorage == null)
{
throw new ArgumentNullException(nameof(projectStorage));
}
storage = projectStorage;
}
public IEnumerable GetAssessmentSections(string filePath)
{
RingtoetsProject openedProject;
try
{
openedProject = (RingtoetsProject) storage.LoadProject(filePath);
}
catch (StorageException e)
{
string exceptionMessage = e.Message;
log.Error(exceptionMessage, e.InnerException);
throw new AssessmentSectionProviderException(exceptionMessage, e);
}
return openedProject?.AssessmentSections;
}
}
}