Exemplo n.º 1
0
        private async Task <bool> UnMount()
        {
            ShowLogMessage("Unmounting file...");
            var result = await VirtualCloneDrive.UnMountAsync();

            if (!result.HasError)
            {
                ShowLogMessage("Unmount successfully completed");
                return(true);
            }
            ShowLogMessage("Unmount Error: " + result.ErrorMessage);
            return(false);
        }
Exemplo n.º 2
0
        public async void Execute()
        {
            txtConsole.Text        = string.Empty;
            lblInformation.Visible = false;

            ShowLogMessage("Scan started...");
            TotalScanStartTime = DateTime.Now;

            var currentIsoFilePathIndex = 0;
            var isoFilesCount           = _isoScannerInfo.SelectedIsoFileNames.Count();
            var isoFilesFoundMessage    = string.Format("{0} iso files found", isoFilesCount);

            ShowInformationMessage(isoFilesFoundMessage);
            ShowLogMessage(isoFilesFoundMessage);
            var unmountResult = await UnMount();

            if (!unmountResult)
            {
                ShowLogMessage(string.Format("Error trying to unmount file from unit. Process aborted."));
                return;
            }

            foreach (var isoFileName in _isoScannerInfo.SelectedIsoFileNames)
            {
                var isoFilePath = Path.Combine(_isoScannerInfo.IsoFolderPath, isoFileName);
                var mountResult = await VirtualCloneDrive.MountAsync(isoFilePath);

                if (mountResult.HasError)
                {
                    ShowLogMessage(string.Format("Error trying to mount: {0}", Path.GetFileName(isoFilePath)));
                }
                else
                {
                    var volumeName = VirtualCloneDrive.VolumeLabel;
                    ShowLogMessage(string.Format("Scanning: {0}...", volumeName));
                    ShowInformationMessage(string.Format("Scanning: {0} [{1} of {2}]", volumeName,
                                                         currentIsoFilePathIndex + 1,
                                                         isoFilesCount));

                    if (!_unitOfWork.IsoVolumeRepository.Search(i => i.VolumeLabel == volumeName).Any())
                    {
                        var initialFolder = new IsoFolder {
                            Name = "$", Path = "/", IsoVolumeId = 0
                        };
                        var iso = new IsoVolume
                        {
                            Created     = DateTime.Now,
                            FileName    = Path.GetFileName(isoFileName),
                            Size        = Convert.ToDecimal(VirtualCloneDrive.TotalSize),
                            VolumeLabel = volumeName,
                            FileCount   = 0,
                            RootFolder  = initialFolder
                        };

                        _unitOfWork.IsoVolumeRepository.Insert(iso);
                        _unitOfWork.Save();

                        var fileScanResult = new FileScanResult();
                        try
                        {
                            var rootFolder = _fileScanner.ScanFolderForFiles(VirtualCloneDrive.UnitLetter, fileScanResult, iso);
                            iso.FileCount  = fileScanResult.ProcessedFileCount;
                            iso.RootFolder = rootFolder;
                        }
                        catch (Exception ex)
                        {
                            ShowLogMessage(string.Format("Error scanning iso file: {0}", Path.GetFileName(isoFilePath)));
                            ShowLogMessage(ex.Message);
                        }

                        ShowLogMessage(string.Format(
                                           "Scan finished for {0} ({1}), scan duration: {2}, files processed: {3}",
                                           volumeName, iso.FileName,
                                           fileScanResult.TotalTime.ToString("hh\\:mm\\:ss"),
                                           fileScanResult.ProcessedFileCount));
                        try
                        {
                            ShowLogMessage("Saving changes to the database...");
                            _unitOfWork.IsoVolumeRepository.Update(iso);
                            _unitOfWork.IsoFolderRepository.Delete(initialFolder);
                            _unitOfWork.Save();
                            ShowLogMessage("Changes successfully saved");
                        }
                        catch (Exception ex)
                        {
                            _unitOfWork.IsoVolumeRepository.Delete(iso);
                            _unitOfWork.IsoFolderRepository.Delete(initialFolder);
                            _unitOfWork.Save();
                            ShowLogMessage("An error has ocurred saving changes to database");
                            fileScanResult.Log.Append(ex.Message);
                            fileScanResult.Log.Append(ex.StackTrace);
                        }

                        try
                        {
                            ShowLogMessage("Saving log file...");
                            SaveScanLog(iso.FileName, fileScanResult.Log.ToString());
                            ShowLogMessage(string.Format("Log file successfully saved for {0} ", iso.FileName));
                        }
                        catch
                        {
                            ShowLogMessage("Failed to save log file");
                            ShowLogMessage(fileScanResult.Log.ToString());
                        }
                    }
                    else
                    {
                        ShowLogMessage(string.Format("Iso Volume '{0}' already exists in the database.", volumeName));
                    }

                    unmountResult = await UnMount();

                    if (!unmountResult)
                    {
                        ShowLogMessage(string.Format("Error trying to unmount '{0}'. Process aborted.", isoFilePath));
                        break;
                    }
                }

                currentIsoFilePathIndex += 1;
            }

            ShowLogMessage("Scan finished");
            var totalTime = string.Format("Total time: {0}",
                                          DateTime.Now.Subtract(TotalScanStartTime).ToString("hh\\:mm\\:ss"));

            ShowLogMessage(totalTime);
            ShowInformationMessage(string.Format("Scan finished. {0}", totalTime));

            if (WorkFinished != null)
            {
                WorkFinished();
            }
        }
Exemplo n.º 3
0
        private async Task ScanIsoCompilations()
        {
            IsoFilesPath = GetIsoFilesReadyToScan();
            ShowLogMessage("Scanning ISO compilations...");
            var isoFilesFoundMessage = string.Format("{0} ISO files found", IsoFilesPath.Count);

            ShowInformationMessage(isoFilesFoundMessage);
            ShowLogMessage(isoFilesFoundMessage);
            var currentIsoFilePathIndex = 0;
            var unmountResult           = await UnMount();

            if (!unmountResult)
            {
                ShowLogMessage(string.Format("Error trying to unmount file from unit. Process aborted."));
                return;
            }

            foreach (var isoFilePath in IsoFilesPath)
            {
                var mountResult = await VirtualCloneDrive.MountAsync(isoFilePath);

                if (mountResult.HasError)
                {
                    ShowLogMessage(string.Format("Error trying to mount: {0}", Path.GetFileName(isoFilePath)));
                }
                else
                {
                    var volumeName = VirtualCloneDrive.VolumeLabel;
                    ShowLogMessage(string.Format("Scanning: {0}...", volumeName));
                    ShowInformationMessage(string.Format("Scanning: {0} [{1} of {2}]", volumeName,
                                                         currentIsoFilePathIndex + 1,
                                                         IsoFilesPath.Count));

                    if (!Entities.IsoVolumes.Any(i => i.VolumeLabel == volumeName))
                    {
                        var iso = new IsoVolume
                        {
                            DateCreated = DateTime.Now,
                            FileName    = Path.GetFileName(IsoFilesPath[currentIsoFilePathIndex]),
                            Size        = Convert.ToDecimal(VirtualCloneDrive.TotalSize),
                            VolumeLabel = volumeName
                        };

                        Entities.IsoVolumes.Add(iso);
                        Entities.SaveChanges();

                        var fileScanResult = new FileScanResult();
                        await IsoFileScanner.ScanFolderForFilesAsync(Entities, iso,
                                                                     VirtualCloneDrive.UnitLetter,
                                                                     fileScanResult);

                        iso.FileCount             = fileScanResult.ProcessedFileCount;
                        Entities.Entry(iso).State = EntityState.Modified;
                        Entities.SaveChanges();
                        ShowLogMessage(string.Format(
                                           "Scan finished for {0} ({1}), scan time: {2}, files processed: {3}",
                                           volumeName, iso.FileName,
                                           fileScanResult.TotalTime.ToString("hh\\:mm\\:ss"),
                                           fileScanResult.ProcessedFileCount));
                        SaveScanLog(iso.FileName, fileScanResult.Log.ToString());
                    }
                    else
                    {
                        ShowLogMessage(string.Format("ISO '{0}' already exists on the database.", volumeName));
                    }

                    unmountResult = await UnMount();

                    if (!unmountResult)
                    {
                        ShowLogMessage(string.Format("Error trying to unmount '{0}'. Process aborted.", isoFilePath));
                        break;
                    }
                }

                currentIsoFilePathIndex += 1;
            }
        }