/// <summary>
        /// Change time creating photo for all photofiles in folder
        /// </summary>
        /// <param name="pathToFiles">path to files</param>
        /// <param name="l_minutes">minutes for change (allow plus or minus value)</param>
        /// <returns>count changed files</returns>
        public int ChangeCreatingDateTimeForFiles(IEnumerable<string> pathToFiles, int minutes, out string errors)
        {
            StringBuilder errorFiles = new StringBuilder();
            errors = "";
            if (pathToFiles.Count() == 0)
                return 0;

            var countChangedFiles =
                pathToFiles.AsParallel()
                         .Where(filePath =>
                            {
                                string error;
                                var res =
                                     changeExifInformationInFile(filePath,
                                     createDirectoryForOutput(filePath), out error,
                                     (EXIFFileWorker photoExifInfo, out string errorInMethod) =>
                                     {
                                         errorInMethod = "";
                                         photoExifInfo.ChangeTime(minutes);
                                         return true;
                                     });
                                if (!res)
                                    errorFiles.AppendLine(error);
                                return res;
                            })
                          .Count();

            // return count changed files
            errors = errorFiles.ToString();
            return countChangedFiles;
        }
Example #2
0
        public override IEnumerable<PvcStream> Execute(IEnumerable<PvcCore.PvcStream> inputStreams)
        {
            var outputStreams = new List<PvcStream>();
            foreach (var inputStream in inputStreams.AsParallel())
            {
                var browserifyBundle = PvcRuntimeNodeJs<PvcBrowserify>.Execute(
                    new
                    {
                        entryPoint = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(inputStream.StreamName))
                    },
                    @"
                        var browserify = require('browserify');

                        browserify(pvc.data.entryPoint)
                            .bundle(function (err, output) {
                                pvc.doneCallback(err, output);
                            })
                            .on('error', function (err) {
                                console.error(err);
                            });
                    "
                );

                outputStreams.Add(PvcUtil.StringToStream(browserifyBundle, inputStream.StreamName));
            }

            return outputStreams;
        }
        public IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
        {
            var workingItems = files.AsParallel().Select(i => new _WorkingItem {
                Path = i.FullName,
                FileInfo = i,
                Dependencies = this._GetDependencies(i.FullName),
            });

            var fileDependencies = new Dictionary<string, _WorkingItem>(_DependencyNameComparer);
            foreach (var item in workingItems) {
                _WorkingItem duplicate;
                if (fileDependencies.TryGetValue(item.Path, out duplicate))
                    throw new ArgumentException(string.Format("During dependency resolution, a collision between '{0}' and '{1}' was detected. Files in a bundle must not collide with respect to the dependency name comparer.", Path.GetFileName(item.Path), Path.GetFileName(duplicate.Path)));

                fileDependencies.Add(item.Path, item);
            }

            foreach (var item in fileDependencies.Values) {
                foreach (var dependency in item.Dependencies) {
                    if (!fileDependencies.ContainsKey(dependency))
                        throw new ArgumentException(string.Format("Dependency '{0}' referenced by '{1}' could not found. Ensure the dependency is part of the bundle and its name can be detected by the dependency name comparer. If the dependency is not supposed to be in the bundle, add it to the list of excluded dependencies.", Path.GetFileName(dependency), Path.GetFileName(item.Path)));
                }
            }

            while (fileDependencies.Count > 0) {
                var result = fileDependencies.Values.FirstOrDefault(f => f.Dependencies.All(d => !fileDependencies.ContainsKey(d)));
                if (result == null)
                    throw new ArgumentException(string.Format("During dependency resolution, a cyclic dependency was detected among the remaining dependencies {0}.", string.Join(", ", fileDependencies.Select(d => "'" + Path.GetFileName(d.Value.Path) + "'"))));
                yield return result.FileInfo;
                fileDependencies.Remove(result.Path);
            }
        }
 public IEnumerable<SelectedImage> UpdateExifProperties(IEnumerable<SelectedImage> selectedImages)
 {
     if (selectedImages == null)
         return selectedImages;
     selectedImages.AsParallel().ForAll(selectedImage =>
     {
         try
         {
             var serverPath = _mediaFileSystemService.GetServerPath(selectedImage.FilePath);
             if (!File.Exists(serverPath))
                 return;
             var fileInfo = new FileInfo(serverPath);
             if (fileInfo.Extension.ToLower() == ".jpg")
             {
                 var reader = new ExifReader(serverPath);
                 selectedImage.Latitude = reader.GetLat();
                 selectedImage.Longtitude = reader.GetLon();
             }
         }
         catch (Exception e)
         {
         } 
     });
     return selectedImages;
 }
		private IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)
		{
			assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null);

			// use parallelism only on the assembly level (avoid locks within Cecil)
			return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct));
		}
        /// <summary>
        ///		<para><see cref="IFrameworkContainer"/> 컨테이너에 등록할 개체를 Task Parallel Library 를 이용하여 병렬로 처리합니다.</para>
        ///		<para>단, 컨테이너에 개체를 등록할 때 CPU Process 의 개수를 이용하여 등록합니다.</para>
        ///		<para>단, 오버헤드가 높을 수 있는 작업이므로 <see cref="IFrameworkContainer"/> 의 내부적인 모든 작업을 병렬화 합니다.</para>
        ///		<para>단, 병렬 작업은 .NET Framework 4.0 빌드에서만 동작합니다.</para>
        /// </summary>
        /// <param name="container"></param>
        /// <param name="action"></param>
        public static void RegisterTypeAsParallel(this IFrameworkContainer container, IEnumerable<Action> action)
        {
            ConcurrentQueue<Exception> exceptions = null;
            try
            {
                exceptions = new ConcurrentQueue<Exception>();

                try
                {
                    action.AsParallel()
                            .WithDegreeOfParallelism(Environment.ProcessorCount)
                            .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
                            .ForAll( o => o());

                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            }
            catch (Exception)
            {
                if( exceptions != null )
                    exceptions.ToList().ForEach( o => Trace.WriteLine( o.Message ));

                throw;
            }
        }
Example #7
0
        /// <summary>
        /// Durchsucht die nach länge gruppierte Liste von Teilzeichenolgen nach Wiederholungen.
        /// </summary>
        /// <param name="substringsGroupedByLength">Die nach länge gruppierte Liste von Teilzeichenfolgen.</param>
        /// <param name="cores">Die Anzahl der zu benutzenden CPU-Kerne. 0 verwendet 
        /// alle zur Verfügung stehenden.</param>
        /// <returns>Eine Liste aller Teilzeichenfolgen in <paramref name="substringsGroupedByLength"/>,
        /// wobei wiederholungen in einem Element zusammen gefasst wurden.</returns>
        public static IEnumerable<Occurence> FindRepetitions(IEnumerable<IEnumerable<Substring>> substringsGroupedByLength, int cores = 0)
        {
            var enu = substringsGroupedByLength.AsParallel();
            if (cores > 0)
            {
                enu = enu.WithDegreeOfParallelism(cores);
            }
            foreach (var group in enu)
            {
                var items = group.ToArray();
                for (var index1 = 0; index1 < items.Length; ++index1)
                {
                    if (items[index1] == null) { continue; }
                    var occ = new Occurence(items[index1].Text);
                    occ.Indices.Add(items[index1].Index);
                    for (var index2 = index1 + 1; index2 < items.Length; ++index2)
                    {
                        if (items[index2] == null || items[index1].Text != items[index2].Text) { continue; }

                        occ.Indices.Add(items[index2].Index);
                        items[index2] = null;
                    }
                    yield return occ;
                }
            }
        }
        private static void UseCancellation(IEnumerable<int> data)
        {
            WriteLine(nameof(UseCancellation));
            var cts = new CancellationTokenSource();

            Task.Run(() =>
            {
                try
                {
                    var res = (from x in data.AsParallel().WithCancellation(cts.Token)
                               where Math.Log(x) < 4
                               select x).Average();

                    WriteLine($"query finished, sum: {res}");
                }
                catch (OperationCanceledException ex)
                {
                    WriteLine(ex.Message);
                }
            });

            WriteLine("query started");
            Write("cancel? ");
            string input = ReadLine();
            if (input.ToLower().Equals("y"))
            {
                cts.Cancel();
            }

            WriteLine();
        }
 public static void sameUnitPriceOriginalPLINQ(IEnumerable<Product> products)
 {
     TestingEnvironment.BenchmarkQuery(() => products.AsParallel().Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => products.Where(p2 => !p2.category.Equals(p.category) && p2.unitPrice == p.unitPrice).Select(p2 => p.productName + " and " + p2.productName)),
                ref products,
                "Original Same unitPrice Lambda Expession with PLINQ",
                "products.AsParallel().Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => products.Where(p2 => !p2.category.Equals(p.category) && p2.unitPrice == p.unitPrice).Select(p2 => p.productName + \" and \" + p2.productName))"
                );
 }
          Encrypt(IEnumerable<string> data)
        {

            OrderedParallelQuery<string> parallelGroups =
            data.AsParallel().OrderBy(item => item);

            // Show the total count of items still
            // matches the original count
            System.Diagnostics.Trace.Assert(
                data.Count() == parallelGroups.Sum(
                    item => item.Count()));
            // ...


            return data.AsParallel().Select(
                item => Encrypt(item)).ToList();
        }
Example #11
0
 public static void ImportAccounts(IEnumerable<string> importAccounts)
 {
     importAccounts
         .AsParallel()
         .ForAll(account => {
             var completionTask = ImportAccountAsync(account);
         });
 }
 public static Company FunctionalParallelMerge(Company bigCompany, IEnumerable<Company> smallCompanies)
 {
     return smallCompanies
         .AsParallel()
         .Aggregate(CreateShell,
             (shell, smallCompany) => shell.Merge(smallCompany),
             (shell1, shell2) => shell1.Merge(shell2),
             bigCompany.Merge);
 }
 public UpdaterClientEventArgs(IEnumerable<AvailableUpdate> items)
     : this("Finished checking for Updates")
 {
     items.AsParallel().ForAll(item =>
     {
         this.items.Add(item.Date, item);
     });
     this.Completed = true;
 }
        /// <summary>
        /// Resolves the fastest Uri in a collection.
        /// </summary>
        /// <param name="uris">Enumerable collection of Uris.</param>
        /// <returns>Fastest Uri in the collection.</returns>
        public Uri Fastest(IEnumerable<Uri> uris)
        {
            if (uris == null)
                throw new ArgumentNullException("uris");

            return uris.AsParallel()
                .OrderBy(_ => _score.Score(_.DnsSafeHost))
                .First();
        }
 private static void LinqQuery(IEnumerable<int> data)
 {
     WriteLine(nameof(LinqQuery));
     var res = (from x in data.AsParallel()
                where Math.Log(x) < 4
                select x).Average();
     WriteLine($"result from {nameof(LinqQuery)}: {res}");
     WriteLine();
 }
 private static IEnumerable<DownloaderMatch> SearchDownloaders(IEnumerable<IEpisodeSubtitleDownloader> compatibleDownloaders, Language[] languageArray, TvReleaseIdentity tvReleaseIdentity)
 {
     var searchResults = compatibleDownloaders
         .AsParallel()
         .SelectMany(downloader => downloader.SearchSubtitle(tvReleaseIdentity, languageArray)
             .Select(match => new DownloaderMatch(downloader, match)))
         .AsSequential().ToArray();
     return FilterOutLanguagesNotInRequest(searchResults, languageArray);
 }
        private static void ExtensionMethods(IEnumerable<int> data)
        {
            WriteLine(nameof(ExtensionMethods));
            var res = data.AsParallel()
                .Where(x => Math.Log(x) < 4)
                .Select(x => x).Average();

            WriteLine($"result from {nameof(ExtensionMethods)}: {res}");
            WriteLine();
        }
        public void Play(IEnumerable<FileNode> content, IVideoPlayerController videoPlayer)
        {
            var statMusicFolder = _processor.Process(new GetFolderFromStringSettingQuery()
            {
                SettingName = Constants.PlayerStatMusicFolderSettingName
            });

            var statVideoFolder = _processor.Process(new GetFolderFromStringSettingQuery()
            {
                SettingName = Constants.PlayerStatVideoFolderSettingName
            });

            var statPictureFolder = _processor.Process(new GetFolderFromStringSettingQuery()
            {
                SettingName = Constants.PlayerStatPictureFolderSettingName
            });

            // TODO : If folder is null then notify user

            var music = content.AsParallel().SingleOrDefault(x => statMusicFolder.Contains(x));
            var video = content.AsParallel().SingleOrDefault(x => statVideoFolder.Contains(x)); // TODO : Fix if no Video exists
            var picture = content.AsParallel().SingleOrDefault(x => statPictureFolder.Contains(x));

            if (video == null)
            {
                var pictureFolder = _processor.Process(new GetFolderFromStringSettingQuery()
                {
                    SettingName = Constants.PlayerPictureFolderSettingName
                });
                video = content.AsParallel().SingleOrDefault(x => pictureFolder.Contains(x));
            }

            var res = new List<FileNode>()
            {
                music, video, picture
            }.Where(x => x != null);

            videoPlayer.Queue.SetQueue(res);

            Console.WriteLine("Using PlayerStatPlayStrategy");

            videoPlayer.PlayQueue();
        }
 public UpdaterClientEventArgs(IEnumerable<Release> items)
     : this("Finished checking for Updates")
 {
     items.AsParallel().ForAll(item =>
     {
         var update = new AvailableUpdate(item);
         this.items.Add(update.Date, update);
     });
     this.Completed = true;
 }
Example #20
0
 /// <summary>
 /// Filtert eine Liste von Vorkommen danach, ob die Vorkommen in anderen 
 /// Teilzeichenfolgen enthalten sind, die genauso oft vorkommen.
 /// </summary>
 /// <param name="repetitions">Eine zu filtrnde Liste von Teilzeichenfolgen. 
 /// Diese wird einmal durchlaufen</param>
 /// <param name="repetitions2">Die Vergleichsliste zu <paramref name="repetitions"/>. 
 /// Die Listen sollten die gleichen Elemente enbthalten, diese hier 
 /// wird jedoch mehrfach durchlaufen.</param>
 /// <param name="cores">Die Anzahl der zu benutzenden CPU-Kerne. 0 verwendet 
 /// alle zur Verfügung stehenden.</param>
 /// <returns>Eine Auflistung mit den Elementen aus <paramref name="repetitions"/>
 /// ohne denen, deren Teilzeichenfolge in einer anderen, gleichhäufig enthaltenen, 
 /// auftritt.</returns>
 public static IEnumerable<Occurence> FilterRepetitions(IEnumerable<Occurence> repetitions, IEnumerable<Occurence> repetitions2, int cores = 0)
 {
     var enu = repetitions.AsParallel();
     if (cores > 0)
     {
         enu = enu.WithDegreeOfParallelism(cores);
     }
     return enu.Where(first => !repetitions2.Any(second => first.Indices.Count == second.Indices.Count
                                                        && first.Text.Length != second.Text.Length
                                                        && second.Text.Contains(first.Text)));
 }
Example #21
0
        private IEnumerable<Product> FindChangedProducts(IEnumerable<Product> products, IEnumerable<ProductSignature> existsProducts) {
            Func<string, string, string> createKey = (source, number) => {
                return source + "-" + number;
            };
            var existsProductsMap = existsProducts.AsParallel().GroupBy(p => createKey(p.Source, p.Number), p => p.Signature).ToDictionary(p => p.Key, p => p.First());

            return products.AsParallel().Where(p => {
                var key = createKey(p.Source, p.Number);
                return !existsProductsMap.ContainsKey(key) || !Signature.IsMatch(existsProductsMap[key], p.Signature);
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RouteReader"/> class.
        /// </summary>
        /// <param name="routeSources">The route sources.</param>
        /// <param name="interceptors">Route interceptors</param>
        public RouteReader(IEnumerable<IRouteSource> routeSources, IEnumerable<IRouteInterceptor> interceptors)
        {
            if (routeSources == null) throw new ArgumentNullException("routeSources");
            if (interceptors == null) throw new ArgumentNullException("interceptors");

            this.Definitions = from source in routeSources
                               from route in source.Routes
                               let def = new RouteDefinition(route.Item2) { Name = route.Item1 }
                               where interceptors.AsParallel().All(interceptor => interceptor.Intercept(def))
                               select def;
        }
        public static void sameUnitPricePLINQ(IEnumerable<Product> products)
        {
            TestingEnvironment.BenchmarkQuery(() => products.AsParallel().GroupBy(p => p.unitPrice).SelectMany(prodGroup => prodGroup.Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodGroup.Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + " and " + p2.productName))),
                           ref products,
                           "Groupby Same unitPrice Lambda Expession with PLINQ",
                           "products.AsParallel().GroupBy(p => p.unitPrice).SelectMany(prodGroup => prodGroup.Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodGroup.Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + \" and \" + p2.productName)))"
                           );

            TestingEnvironment.BenchmarkQuery(() => products.GroupBy(p => p.unitPrice).AsParallel().SelectMany(prodGroup => prodGroup.Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodGroup.Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + " and " + p2.productName))),
                           ref products,
                           "Groupby Same unitPrice Lambda Expession with PLINQv2",
                           "products.GroupBy(p => p.unitPrice).AsParallel().SelectMany(prodGroup => prodGroup.Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodGroup.Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + \" and \" + p2.productName)))"
                           );

            TestingEnvironment.BenchmarkQuery(() => OptimizerExtensions.AsGroupSuspendedThreadSafe(() => products.ToRelaxedVolatileIndex(p => p.unitPrice)).SelectMany(prodPriceIdxThunk => products.AsParallel().Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodPriceIdxThunk.Value.Lookup(() => p.unitPrice).Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + " and " + p2.productName))),
                           ref products,
                           "Relaxed (Exception Ignoring) Volatile Index Same unitPrice Lambda Expession with PLINQ",
                           "OptimizerExtensions.AsGroupSuspendedThreadSafe(() => products.ToRelaxedVolatileIndex(p => p.unitPrice)).SelectMany(prodPriceIdxThunk => products.AsParallel().Where(p => categoriesToAudit.Contains(p.category)).SelectMany(p => prodPriceIdxThunk.Value.lookup(() => p.unitPrice).Where(p2 => !p2.category.Equals(p.category)).Select(p2 => p.productName + \" and \" + p2.productName)))"
                           );
        }
Example #24
0
        private static void OrderBy(IEnumerable<int> numbers)
        {
            var evenNumbers =
                from number in numbers
                    .AsParallel()
                where number%2 == 0
                orderby number
                select number;

            evenNumbers.AsEnumerable().Print();
        }
Example #25
0
 internal static async Task AddDevices(Environment environment, IEnvironmentService service,
     IEnumerable<Guid> deviceIds, INotifyList<IDevice, Guid> devices)
 {
     IEnumerable<IDevice> localDevices = null;
     await Task.Run(() =>
     {
         localDevices = deviceIds.
           AsParallel().AsOrdered().
           Select(did => Device.Create(did, environment, service).Result);
     });
     devices.Add(localDevices);
 }
Example #26
0
 /// <summary>
 /// Updates the bag.
 /// </summary>
 /// <param name="types">The types.</param>
 private void UpdateBag(IEnumerable<SubscriptionKey> types)
 {
     types.AsParallel().ForAll(x =>
                                 {
                                     if (!_bagTypes.ContainsKey(x))
                                     {
                                         _bagTypes.TryAdd(x,
                                                          new MessageType
                                                              { FullName = x.Key});
                                     }
                                 });
 }
          Encrypt(IEnumerable<string> data)
        {

            ParallelQuery<IGrouping<char, string>> parallelGroups;
            parallelGroups =
                from text in data.AsParallel()
                orderby text
                group text by text[0];


            // Show the total count of items still
            // matches the original count
            System.Diagnostics.Trace.Assert(
                data.Count() == parallelGroups.Sum(
                    item => item.Count()));
            // ...


            return data.AsParallel().Select(
                item => Encrypt(item)).ToList();
        }
 private static IEnumerable<Type> SelectPotentialTypes(IEnumerable<ITypesProvider> typesProviders, ITypeSelector convention)
 {
     try
     {
         var potentialTypes = typesProviders.AsParallel().SelectMany(provider => provider.RetrieveTypes(convention));
         return potentialTypes.ToList();
     }
     catch (AggregateException e)
     {
         throw e.FlattenTryBubbleUp();
     }
 }
Example #29
0
 public static IEnumerable<ServiceDescriptor> Describe(IEnumerable<Type> typesToRegistration)
 {
     try
     {
         var serviceDescriptors = typesToRegistration.AsParallel().SelectMany(CreateDescriptors);
         return serviceDescriptors.ToList();
     }
     catch (AggregateException e)
     {
         throw e.FlattenTryBubbleUp();
     }
 }
        public IEnumerable<WordsForPrefix> GetWordsForPrefixes(IEnumerable<string> prefixes)
        {
            bool useParallelization = prefixes.Count() >= Configuration.Default.MinPrefixesNumberForConcurrentProcessing;

            var prefixToMostPopularWords = useParallelization
                                           ? prefixes
                                             .AsParallel().AsOrdered()
                                             .Select(prefix => new WordsForPrefix(prefix, GetMostPopularWords(prefix)))
                                           : prefixes
                                             .Select(prefix => new WordsForPrefix(prefix, GetMostPopularWords(prefix)));
            return prefixToMostPopularWords.ToArray();
        }