Exemplo n.º 1
0
 public static bool IsAborted(Service service)
 {
     return(Aborted.FirstOrDefault(s => s == service) != null);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Called on algorithm abort.
        /// </summary>
        /// <param name="args"><see cref="F:EventArgs.Empty"/>.</param>
        protected virtual void OnAborted([NotNull] EventArgs args)
        {
            Debug.Assert(args != null);

            Aborted?.Invoke(this, args);
        }
Exemplo n.º 3
0
 public void OnAborted(object sender, EventArgs e)
 {
     _moveThread?.Abort();
     Aborted?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 4
0
        public async Task <List <DuplicatesResult> > Find(int maxParallelism = 4)
        {
            var ts = new CancellationTokenSource();

            cancellationTokens.Add(ts);
            CancellationToken ct = ts.Token;

            try
            {
                return(await Task.Run(() =>
                {
                    PrepareCompareValues?.Invoke(this, false);
                    OnPrepareCompareValue(ct, maxParallelism);
                    PrepareCompareValues?.Invoke(this, true);
                    var result = new List <DuplicatesResult>();
                    ParallelOptions po = new ParallelOptions
                    {
                        CancellationToken = ct,
                        MaxDegreeOfParallelism = maxParallelism
                    };
                    try
                    {
                        int itemCounter = 0;
                        decimal progressValue = 0;
                        List <string> cacheIndexValues = new List <string>();
                        if (CacheDuplicateResult != null)
                        {
                            result = CacheDuplicateResult.DuplicatesResults;
                            cacheIndexValues = CacheDuplicateResult.IndexCollection;
                        }

                        Parallel.For(0, Files.Count, po, (int index) =>
                        {
                            string file = Files[index];
                            System.Diagnostics.Debug.Print($"INDEX => {index}");
                            if (!cacheIndexValues.Contains(file.ToUpper()))
                            {
                                if (itemCounter == 0)
                                {
                                    ProcessFileProgress?.Invoke(this, 0);
                                    ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(0, result, index, itemCounter, cacheIndexValues));
                                }

                                cacheIndexValues.Add(file.ToUpper());
                                ProcessFile?.Invoke(this, file);
                                var dup = OnCompareDuplicates(file, index);
                                if (dup != null)
                                {
                                    result.Add(dup);
                                }
                                var progressValue2 = Math.Round(((decimal)itemCounter / (decimal)Files.Count * 100), 2);
                                if (progressValue2 > progressValue)
                                {
                                    progressValue = progressValue2;
                                }
                                ProcessFileProgress?.Invoke(this, progressValue);
                                ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(progressValue, result, index, itemCounter, cacheIndexValues));
                            }
                            else
                            {
                                System.Diagnostics.Debug.Print($"Already collected File:{file}");
                            }
                            itemCounter++;
                        });
                        ProcessFileProgress?.Invoke(this, 100);
                        ProcessFileProgressWithItems?.Invoke(this, new ProcessFileProgressItem(100, result, -1, itemCounter, cacheIndexValues));
                    }
                    catch (Exception ex)
                    {
                        if (ex is AggregateException || ex is ObjectDisposedException || ex is OperationCanceledException)
                        {
                            Aborted?.Invoke(this, EventArgs.Empty);
                            return null;
                        }
                        throw;
                    }
                    cancellationTokens.Remove(ts);
                    return result;
                }, ct));
            }
            catch (Exception ex)
            {
                if (ex is AggregateException || ex is ObjectDisposedException || ex is OperationCanceledException)
                {
                    Aborted?.Invoke(this, EventArgs.Empty);
                    return(null);
                }
                throw;
            }
        }
Exemplo n.º 5
0
 private void OnAborted()
 {
     Aborted?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Abort resource loading.
        /// </summary>
        protected virtual bool OnAbort(PartialResource res, Exception e)
        {
            Aborted?.Invoke(this, e);

            return(false);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Raises the <see cref="Aborted"/> event.
 /// </summary>
 /// <param name="e">The event arguments.</param>
 protected virtual void OnAborted(ChaosAbortedEventArgs e) => Aborted?.Invoke(this, e);