예제 #1
0
        /// <summary>
        ///     Fetch the external source, if correctly fetched, set to <c>null</c>.
        ///     If fetched asynchronously, the method will return immediately. It has to be called synchronously
        ///     before actually using the external file source.
        /// </summary>
        /// <param name="async">Whether the external source will be fetched asynchronously or not.</param>
        protected virtual void FetchExternalSource(bool async)
        {
            if (_externalSource == null)
            {
                return;
            }

            if (!Directory.Exists(_filePath))
            {
                Directory.CreateDirectory(_filePath);
                Log.Info($"Creating directory {_filePath}");
            }

            Log.Info($"Fetching external source {_externalSource} to {_filePath}" + (async ? " asynchronously." : "."));

            if (async)
            {
                _externalSource.FetchFileAsync(_filePath);
            }
            else
            {
                string path = _externalSource.FetchFile(_filePath);

                AssignFilePath(path);

                Log.Info($"Fetched external source {_externalSource} to {path}.");

                _externalSource = null;
                _filePath       = null;
            }
        }
예제 #2
0
        /// <summary>
        ///     Fetch the external source, if correctly fetched, set to <c>null</c>.
        ///     If fetched asynchronously, the method will return immediately. It has to be called synchronously
        ///     before actually using the external file source.
        /// </summary>
        /// <param name="async">Whether the external source will be fetched asynchronously or not.</param>
        protected virtual void FetchExternalSource(bool async)
        {
            if (ExternalSource == null)
            {
                return;
            }

            if (!Directory.Exists(_filePath))
            {
                Directory.CreateDirectory(_filePath);
                Log.InfoFormat("Creating directory {0}", _filePath);
            }

            Log.InfoFormat("Fetching external source {0} to {1}" + (async ? " asynchronously." : "."),
                           ExternalSource, _filePath);

            if (async)
            {
                ExternalSource.FetchFileAsync(_filePath);
            }
            else
            {
                string path = ExternalSource.FetchFile(_filePath);

                AssignFilePath(path);

                Log.InfoFormat("Fetched external source {0} to {1}.", ExternalSource, path);

                ExternalSource = null;
                _filePath      = null;
            }
        }
예제 #3
0
        /// <summary>
        ///     Create a <see cref="BaseFileSource" /> from a given external source that will be stored to the given local path.
        /// </summary>
        /// <param name="externalSource">The external source.</param>
        /// <param name="localPath">The local directory this file will be stored to.</param>
        protected BaseFileSource(IExternalFileSource externalSource, string localPath)
        {
            if (string.IsNullOrWhiteSpace(localPath))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(localPath));
            }

            _externalSource = externalSource ?? throw new ArgumentNullException(nameof(externalSource));
            _filePath       = localPath;

            if (!_externalSource.LazyLoading)
            {
                FetchExternalSource(true);
            }
        }
예제 #4
0
 public TempFileSource(IExternalFileSource externalSource) : base(externalSource, SystemPath.GetTempPath())
 {
 }
예제 #5
0
 /// <inheritdoc />
 public FileSource(IExternalFileSource externalSource, string localPath) : base(externalSource, localPath)
 {
 }