protected override void InternalRunWorker(object arg)
        {
            try
            {
                _log.Info("Processing: " + arg);
                var currentFolder = new PowerPath(arg.ToString());

                // check for ignore pattern
                var lastName = currentFolder.GetLastDirectoryName();
                if (lastName.StartsWith("[") && lastName.EndsWith("]"))
                {
                    _log.Debug("Process skipped due to directory name.");
                    return;
                }

                // find first movie
                var currentMoviePath = _persistentDataManager.FindFirstMovieFile(arg.ToString());
                if (currentMoviePath == null)
                {
                    _log.Debug("Process skipped due to unavaliable movie file.");
                    return;
                }

                // find metadata
                TmdbResult entry;
                if (_persistentDataManager.HasPersistentData(currentMoviePath.GetDirectoryPath()))
                {
                    _log.Debug("Using saved presist data.");
                    entry = _persistentDataManager.LoadData(currentMoviePath);
                }
                else
                {
                    _log.Debug("Creating new data using GetByFilename.");
                    entry = _tmdb.GetByFilename(currentMoviePath.GetFileNameWithoutExtension());
                }

                // pop to event
                var result = new MovieEntryFacade(entry, currentMoviePath);
                OnProgressChanged(this, new ProgressChangedEventArgs(-1, new DirectoryAnalyzeWorkerState
                {
                    Entry = result
                }));

                _log.Info("Processed: " + arg);
            }
            catch (Exception e)
            {
                _log.Error(e, "Process error. Path: " + arg);
            }
        }
示例#2
0
        private async void InternalOpenDirectory(string path)
        {
            // save states
            UpdateUi(UiState.Working);
            _settings.LastOpenDirectory = path;
            _settings.Save();

            // clear data
            Model.Invoke(() => Model.DataView.Clear());

            // enumerate
            var tmdb = _kernel.Get <ITmdb>();
            var persistFileManager = _kernel.Get <IPersistFileManager>();
            var dirEnumbEnumerable = Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly).ToList();
            var calc = new PercentageCalculator(dirEnumbEnumerable.Count);

            // walk
            foreach (var basePath in dirEnumbEnumerable)
            {
                try
                {
                    string currentMoviePath;
                    var    currentFolder = new PowerPath(basePath);

                    // check for ignore pattern
                    var lastName = currentFolder.GetLastDirectoryName();
                    if (lastName.StartsWith("[") && lastName.EndsWith("]"))
                    {
                        continue;
                    }

                    // find first movie
                    if ((currentMoviePath = HelperFindFirstFile(basePath)) == null)
                    {
                        continue;
                    }

                    // find metadata
                    MovieEntry entry;
                    if (persistFileManager.HasPersistentData(Path.GetDirectoryName(currentMoviePath)))
                    {
                        entry = persistFileManager.Load(currentMoviePath);
                    }
                    else
                    {
                        var currentResult = await tmdb.GetByFilename(currentMoviePath);

                        entry = new MovieEntry();
                        entry.SetFullPath(currentMoviePath);
                        entry.SetData(currentResult);
                    }

                    // push to collection
                    Model.Invoke(() => Model.DataView.Add(entry));
                }
                catch (Exception e)
                {
                    Debug.Print("Analyze error: {0}. {1}", basePath, e.Message);
                }

                // sync
                _lastSelectedIndex = -1;
                UpdateUi(UiState.StatusUpdate, calc.Increment());
                if (IsCancellationRequested)
                {
                    break;
                }
            }

            // finish
            UpdateUi(UiState.Ready);
        }