public static IDistinctValuedDictionary <TValue, TKey> Invert <TKey, TValue>(this IDistinctValuedDictionary <TKey, TValue> dictionary)
        {
            var invertedDictionary = new Dictionary <TValue, TKey>().AsDistinctValued();

            dictionary.ForEach(pair => invertedDictionary.Add(pair.Value, pair.Key));

            return(invertedDictionary);
        }
Ejemplo n.º 2
0
        public async Task <IDictionary <TKey, string> > ReadContentsByKey <TKey>(IDistinctValuedDictionary <TKey, string> filePathsByKey)
        {
            var output = new Dictionary <TKey, string>();

            foreach (var pair in filePathsByKey)
            {
                var content = await FileHelper.Read(pair.Value);

                output.Add(pair.Key, content);
            }

            return(output);
        }
Ejemplo n.º 3
0
        // Sync.
        public static IDictionary <TKey, TOut> ProcessByKey <TKey, TIn, TOut>(
            Func <TIn, TOut> processor,
            IDistinctValuedDictionary <TKey, TIn> inputsByKey)
        {
            var output = new Dictionary <TKey, TOut>();

            foreach (var pair in inputsByKey)
            {
                var result = processor(pair.Value);

                output.Add(pair.Key, result);
            }

            return(output);
        }
Ejemplo n.º 4
0
        public Task <IDictionary <TKey, bool> > DeleteFilesByKey <TKey>(IDistinctValuedDictionary <TKey, string> filePathsByKey)
        {
            var output = new Dictionary <TKey, bool>();

            foreach (var pair in filePathsByKey)
            {
                var exists = FileHelper.Exists(pair.Value);

                FileHelper.DeleteOnlyIfExists(pair.Value);

                output.Add(pair.Key, exists);
            }

            return(Task.FromResult(output as IDictionary <TKey, bool>));
        }
Ejemplo n.º 5
0
 public static IDistinctValuedDictionary <TKey, string> GetFilePathsByKey <TKey>(this IStringlyTypedPathOperator stringlyTypedPathOperator,
                                                                                 string directoryPath,
                                                                                 IDistinctValuedDictionary <TKey, string> fileNamesByKey)
 {
     return(fileNamesByKey.ToDictionary(
                pair => pair.Key,
                pair => stringlyTypedPathOperator.GetFilePath(directoryPath, pair.Value))
            .AsDistinctValued());
 }
Ejemplo n.º 6
0
        public static async Task <IDictionary <TKey, bool> > ExistsFilesByKey <TKey>(this IFileSystemOperator @operator, IDistinctValuedDictionary <TKey, string> filePathsByKey)
        {
            var keysByFilePath = filePathsByKey.Invert();

            var existsByFilePath = await @operator.ExistsFiles(keysByFilePath.Keys.AsDistinct());

            var output = keysByFilePath.Join(existsByFilePath,
                                             keys => keys.Key,
                                             exists => exists.Key,
                                             (keys, exists) => (Key: keys.Value, Exists: exists.Value))
                         .ToDictionary(
                x => x.Key,
                x => x.Exists);

            return(output);
        }