Exemplo n.º 1
0
        public void SearchForDuplicates(string rootFolder, CriteriaSettings pCriteria)
        {
            DuplicateCollector collector = new DuplicateCollector(rootFolder, pCriteria);

            collector.FileAdded += x =>
            {
                SendMessage(Messages.FileAdded, new NotificationEventArgs(x));
            };
            collector.DuplicateFileFound += x =>
            {
                if (FoundDuplicate != null)
                {
                    FoundDuplicate(x);
                }
            };

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Starting count of files..."));
            var count = collector.CountAllFiles();

            SendMessage(Messages.FilesCount, new NotificationEventArgs(count.ToString()));
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Total of: " + count.ToString() + " files found."));

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Starting MD5 Calculation..."));
            AllFiles = collector.ScanFileInfo();
            SendMessage(Messages.NotifyString, new NotificationEventArgs("MD5 Calculation Completed."));
            SendMessage(Messages.NotifyString, new NotificationEventArgs(String.Format(@"Saving results to ""{0}""", DataFile)));

            if (File.Exists(DataFile))
            {
                File.Delete(DataFile);
            }
            var SerializationObject = new SavedSession()
            {
                Duplicates = AllFiles, SelectedPath = rootFolder, Settings = pCriteria
            };

            BinarySerializationAssistor.Serialize(SerializationObject, DataFile);
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Saved."));

            SendMessage(Messages.NotifyString, new NotificationEventArgs("Looking for duplicates..."));
            collector.CalculateDuplicate();
            AllDuplicates = collector.AllDuplicated;
            SendMessage(Messages.NotifyString, new NotificationEventArgs("Done."));
            SendMessage(Messages.NotifyString, new NotificationEventArgs(String.Format("Found {0} duplicated files.", collector.AllDuplicated.Count)));
            SendMessage(Messages.WorkingChanged, new NotificationEventArgs("false"));
            SendMessage(Messages.FilesCompleted, new NotificationEventArgs());
        }
Exemplo n.º 2
0
        // Default ctor
        public MainPageViewModel()
        {
            _MainUCDataContext = new FilesViewModel();
            AllDuplicates      = new ObservableCollection <KeyValuePair <string, List <DuplicateFile> > >();
            MainUC             = new FilesView()
            {
                DataContext = _MainUCDataContext
            };
            _MainUCDataContext.FoundDuplicate += x =>
            {
            };

            RegisterToReceiveMessages(Messages.WorkingChanged, (x, y) =>
            {
                Working(bool.Parse(y.Message));
            });

            RegisterToReceiveMessages(Messages.NotifyString, (x, y) =>
            {
                Log(y.Message);
            });

            RegisterToReceiveMessages(Messages.FileAdded, (x, y) =>
            {
                SetStatusCurrentFile(y.Message);
            });

            RegisterToReceiveMessages(Messages.FilesCount, (x, y) =>
            {
                FilesCount      = y.Message;
                ProgressMinimum = 0;
                ProgressMaximum = int.Parse(FilesCount);
                CurrentProgress = 0;
                NotifyPropertyChanged(z => z.ProgressMaximum);
                NotifyPropertyChanged(z => z.ProgressMinimum);
                NotifyPropertyChanged(z => z.CurrentProgress);
            });

            RegisterToReceiveMessages(Messages.UserSelectedFolderFromTree, (x, y) =>
            {
                SelectedPath = y.Message;
                NotifyPropertyChanged(p => p.SelectedPath);
                NotifyPropertyChanged(p => p.Criteria);
            });

            RegisterToReceiveMessages(Messages.UserSelectedBackDirectory, (x, y) =>
            {
                var parent = Path.GetDirectoryName(SelectedPath);
                if (!String.IsNullOrEmpty(parent))
                {
                    SelectedPath = parent;
                }
            });

            RegisterToReceiveMessages(Messages.FilesCompleted, (x, y) =>
            {
                //int counter = 0;
                Disp(() =>
                {
                    AllDuplicates       = new ObservableCollection <KeyValuePair <string, List <DuplicateFile> > >();
                    TruelyAllDuplicates = new ObservableCollection <KeyValuePair <string, List <DuplicateFile> > >();
                });

                var nulls = _MainUCDataContext.AllDuplicates.Where(z => z.Value == null).ToList();

                foreach (var a in _MainUCDataContext.AllDuplicates)
                {
                    TruelyAllDuplicates.Add(a);
                    //if (counter++ == 400)
                    //{
                    //    NotifyPropertyChanged(z => z.AllDuplicates);
                    //    counter = 0;
                    //}
                }
                TakeTen();

                if (TruelyAllDuplicates.Count > 9)
                {
                    Disp(() =>
                    {
                        ShowAllResultsText = tenResultsText;
                        Show10Results      = true;
                        HasMoreThanTen     = true;
                    });
                    NotifyPropertyChanged(z => z.ShowAllResultsText);
                    NotifyPropertyChanged(z => z.HasMoreThanTen);
                    NotifyPropertyChanged(z => z.Show10Results);
                }
                else
                {
                    HasMoreThanTen = false;
                    NotifyPropertyChanged(z => z.HasMoreThanTen);
                }

                //var nulls2 = AllDuplicates.Where(p => p.Value == null).ToList();
                NotifyPropertyChanged(z => z.AllDuplicates);

                Working(false);
            });

            Criteria = new CriteriaSettings()
            {
                DupCriteriaMD5  = true,
                DupCriteriaName = false,
                DupCriteriaSize = false
            };

            CurrentProgress   = 0;
            CurrentButtonText = "Start";
            SelectedPath      = (startFolder);
            IsWorking         = false;
        }