public DicomOrganizer(IPatternApplier patternApplier, IErrorHandler errorHandler, ILogger logger, IFilesFromConsoleInputReader filesFromConsoleInputReader) { _patternApplier = patternApplier ?? throw new ArgumentNullException(nameof(patternApplier)); _errorHandler = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _filesFromConsoleInputReader = filesFromConsoleInputReader ?? throw new ArgumentNullException(nameof(filesFromConsoleInputReader)); _ioPolicy = Policy.Handle <IOException>().Retry(3); }
/// <summary> /// Add or Replace the <paramref name="applier"/> to the correspondig collection inside the <paramref name="source"/>. /// </summary> /// <typeparam name="TSubject">The subject of the pattern.</typeparam> /// <typeparam name="TApplyTo">The target of the applier.</typeparam> /// <param name="source">An instance of <see cref="IPatternsAppliersHolder"/>>.</param> /// <param name="applier">The instance of the applier to add.</param> /// <returns>The <paramref name="source"/> instance (to chain 'union')</returns> /// <remarks> /// The Replace action is performed removing all appliers with the same type-name, where exists, and then adding the new applier. /// This method is usefull when you want override a behaviour of an existing applier in an existing <see cref="IPatternsAppliersHolder"/>. /// </remarks> public static IPatternsAppliersHolder UnionWith <TSubject, TApplyTo>(this IPatternsAppliersHolder source, IPatternApplier <TSubject, TApplyTo> applier) { if (source == null) { throw new ArgumentNullException("source"); } if (applier == null) { return(source); } var patternsAppliersCollection = GetCollectionPropertyOf <TSubject, TApplyTo>(source); if (patternsAppliersCollection != null) { PerformUnionWith(patternsAppliersCollection, applier); } else { throw new ArgumentOutOfRangeException("applier", string.Format(NotSupportedApplierExceptionMessageTemplate, typeof(TSubject).FullName, typeof(TApplyTo).FullName)); } return(source); }
private static void PerformMerge <TSubject, TApplyTo>(ICollection <IPatternApplier <TSubject, TApplyTo> > destination, IPatternApplier <TSubject, TApplyTo> applier) { var applierType = applier.GetType(); if (IsDelegatedApplier(applierType) || !destination.Any(a => a.GetType() == applierType)) { destination.Add(applier); } }
private static void PerformUnionWith <TSubject, TApplyTo>(ICollection <IPatternApplier <TSubject, TApplyTo> > destination, IPatternApplier <TSubject, TApplyTo> applier) { var applierType = applier.GetType(); var existingAppliers = destination.Where(a => a.GetType().Name == applierType.Name && !IsDelegatedApplier(applierType)).ToList(); if (existingAppliers.Count > 0) { foreach (var existingApplier in existingAppliers) { destination.Remove(existingApplier); } } destination.Add(applier); }