Exemple #1
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="name">The name of the repository.</param>
        /// <param name="path">The path of the repository,</param>
        /// <param name="tokenProvider">The token provider.</param>
        /// <param name="eventLog">The event log.</param>
        /// <param name="cleanupInterval">Cleanup interval for the repository.</param>
        /// <param name="retentionPeriod">The retention period for the repository</param>
        public FileRepository(string name, string path, IFileTokenProvider tokenProvider, IEventLog eventLog, TimeSpan retentionPeriod, TimeSpan cleanupInterval)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (tokenProvider == null)
            {
                throw new ArgumentNullException(nameof(tokenProvider));
            }

            if (eventLog == null)
            {
                throw new ArgumentNullException(nameof(eventLog));
            }

            if (retentionPeriod.TotalMilliseconds <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(retentionPeriod));
            }

            if (cleanupInterval.TotalMilliseconds <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(cleanupInterval));
            }

            // Try and create the file repository path if it does not exist
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            eventLog.WriteInformation("Creating file repository {0} at {1}.", name, path);

            Name = name;

            _repositoryPath  = path.TrimEnd(Path.DirectorySeparatorChar);
            _tokenProvider   = tokenProvider;
            _eventLog        = eventLog;
            _cleanupInterval = cleanupInterval;
            _retentionPeriod = retentionPeriod;

            // Get the temp directory path
            _tempDirectoryPath = Path.Combine(path, TempDirectory);
            Directory.CreateDirectory(_tempDirectoryPath);
        }
        /// <summary>
        /// Creates a file repository with the given name and token provider.
        /// </summary>
        /// <param name="name">The name of the file repository.</param>
        /// <param name="tokenProvider">The token provider to use.</param>
        /// <param name="defaultPath">The default path for the repository.</param>
        /// <param name="retentionPeriod">The retention period.</param>
        /// <returns>The file repository.</returns>
        internal static FileRepository CreateFileRepository(string name, IFileTokenProvider tokenProvider, string defaultPath, TimeSpan retentionPeriod)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (tokenProvider == null)
            {
                throw new ArgumentNullException("tokenProvider");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("defaultPath");
            }

            FileRepositoryConfiguration fileRepoConfig = ConfigurationSettings.GetFileRepositoryConfigurationSection();
            FileRepositoryConfigElement configElement  = null;

            if (fileRepoConfig != null &&
                fileRepoConfig.FileRepositories != null)
            {
                configElement = fileRepoConfig.FileRepositories.Cast <FileRepositoryConfigElement>().FirstOrDefault(f => f.Name == name);
            }

            string path = string.Empty;

            if (configElement != null)
            {
                path = configElement.Path;
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                path = defaultPath;
            }

            return(new FileRepository(name, path, tokenProvider, EventLog.Application, retentionPeriod));
        }
Exemple #3
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="name">The name of the repository.</param>
 /// <param name="path">The path of the repository,</param>
 /// <param name="tokenProvider">The token provider.</param>
 /// <param name="eventLog">The event log.</param>
 /// <param name="retentionPeriod">The retention period for the repository</param>
 public FileRepository(string name, string path, IFileTokenProvider tokenProvider, IEventLog eventLog, TimeSpan retentionPeriod) : this(name, path, tokenProvider, eventLog, retentionPeriod, TimeSpan.FromHours(12))
 {
 }