Skip to content

Instantly share code, notes, and snippets.

@vmandic
Last active May 12, 2019 19:10
Show Gist options
  • Save vmandic/1214d2cffbe1fa49987ee30d738c1691 to your computer and use it in GitHub Desktop.
Save vmandic/1214d2cffbe1fa49987ee30d738c1691 to your computer and use it in GitHub Desktop.
meds-processor, part/4, snippet #4
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MedsProcessor.Common;
using MedsProcessor.Common.Models;
namespace MedsProcessor.WebAPI.Core
{
public class HzzoData
{
public HzzoData(AppPathsInfo appPaths)
{
this._appPaths = appPaths;
}
private ISet<HzzoMedsDownloadDto> _set;
private readonly AppPathsInfo _appPaths;
public ISet<HzzoMedsDownloadDto> Set
{
get => _set ??
throw new InvalidOperationException("The dataset was not loaded.");
private set
{
if (_set != null)
throw new InvalidOperationException("The dataset was already loaded.");
_set = value ??
throw new InvalidOperationException("The loaded dataset can not be null.");
}
}
internal void Load(ISet<HzzoMedsDownloadDto> data) =>
Set = data;
internal bool IsLoaded() =>
_set != null && _set.All(x => x.IsDownloaded && x.IsDataParsed);
internal void Clear()
{
_set = null;
var downloadDir = Path.Combine(_appPaths.ApplicationRootPath, Constants.DOWNLOAD_DIR);
Directory.Delete(downloadDir, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment