public void RunReplacements()
        {
            if (FilePaths.Length <= 0)
            {
                throw new ArgumentException("No files to replace tokens in");
            }
            var results            = new List <FileTokenReplaceResult>();
            var fileTokenReplacers = new List <FileTokenReplace>();
            var doneEvents         = new List <ManualResetEvent>();

            for (var i = 0; i < FilePaths.Length; i++)
            {
                var doneEvent         = new ManualResetEvent(false);
                var fileTokenReplacer = new FileTokenReplace(FilePaths[i], ReplaceTokensService,
                                                             doneEvent);
                fileTokenReplacers.Add(fileTokenReplacer);
                ThreadPool.QueueUserWorkItem(fileTokenReplacer.ReplaceTokens, i);
                doneEvents.Add(doneEvent);
                if (doneEvents.Count < MaxWaitHandleThreads || i == FilePaths.Length - 1)
                {
                    continue;
                }
                WaitHandle.WaitAll(doneEvents.ToArray());
                doneEvents.Clear();
            }

            results.AddRange(fileTokenReplacers.Select(ftr => new FileTokenReplaceResult
            {
                FilePath           = ftr.FilePath,
                Success            = ftr.Success,
                ReplacementCounter = ftr.ReplacementCounter
            }));
            //TODO: Log replacement results.!
        }
Ejemplo n.º 2
0
        public void RunReplacements()
        {
            if (FilePaths.Length <= 0)
            {
                throw new ArgumentException("No files to replace tokens in");
            }
            var results    = new List <FileTokenReplaceResult>();
            var doneEvents = new List <ManualResetEvent>();

            for (var i = 0; i < FilePaths.Length; i++)
            {
                var doneEvent         = new ManualResetEvent(false);
                var fileTokenReplacer = new FileTokenReplace(FilePaths[i], ReplaceTokensService,
                                                             doneEvent);
                var result = new FileTokenReplaceResult();
                results.Add(result);
                ThreadPool.QueueUserWorkItem(fileTokenReplacer.ReplaceTokens, result);
                doneEvents.Add(doneEvent);
                if (doneEvents.Count < MaxWaitHandleThreads && i != FilePaths.Length - 1)
                {
                    continue;
                }
                WaitHandle.WaitAll(doneEvents.ToArray());
                doneEvents.Clear();
            }

            WriteTraceService.WriteToTrace("File content token replacement results:", "\nInfo",
                                           results.Select(GetResultAsString).ToArray());
        }
        public void RunReplacements()
        {
            if (FilePaths.Length <= 0)
            {
                throw new ArgumentException("No files to replace tokens in");
            }
            var doneEvents         = new WaitHandle[FilePaths.Length];
            var fileTokenReplacers = new List <FileTokenReplace>();

            for (var i = 0; i < FilePaths.Length; i++)
            {
                doneEvents[i] = new ManualResetEvent(false);
                var fileTokenReplacer = new FileTokenReplace(FilePaths[i], ReplaceTokensService, (ManualResetEvent)doneEvents[i]);
                fileTokenReplacers.Add(fileTokenReplacer);
                ThreadPool.QueueUserWorkItem(fileTokenReplacer.ReplaceTokens, i);
            }
            WaitHandle.WaitAll(doneEvents);
            var results = fileTokenReplacers.Select(ftr => new FileTokenReplaceResult
            {
                FilePath           = ftr.FilePath,
                Success            = ftr.Success,
                ReplacementCounter = ftr.ReplacementCounter
            }).ToArray();

            //TODO: Log replacement results.!
        }