Exemple #1
0
        /// <summary>
        /// Renames the recognized files.
        /// </summary>
        private void RenameRecognizedFiles()
        {
            Log.Info(_operationVerb + " of recognized files started...");
            var st = DateTime.Now;

            var i = 0;

            foreach (var file in FilesListViewItemCollection.Where(f => f.Enabled && f.Checked).ToList())
            {
                var name = Utils.SanitizeFileName(FileNames.Parser.FormatFileName(Format, file.Information));
                SetStatus(_operationVerb + " " + name + "...", true);

                Log.Info(_operationVerb + " file " + Path.GetFileName(file.Location) + " to " + name + "...");

                try
                {
                    ProcessFile(name, file.Location, Path.Combine(TargetDir, name));
                }
                catch (Exception ex)
                {
                    Log.Warn("Exception while " + _operationVerb.ToLower() + " file " + Path.GetFileName(file.Location) + " to " + name + ".", ex);
                }

                file.Enabled = file.Checked = false;
                i++;
            }

            Dispatcher.Invoke((Action)(() =>
            {
                startRenamingButton.Content = "Start renaming";
                startRenamingButton.IsEnabled = FilesListViewItemCollection.Count(f => f.Enabled && f.Checked) != 0;
                settingsTabItem.IsEnabled = listView.ContextMenu.IsEnabled = true;
            }));

            Log.Info(_operationPast + " " + Utils.FormatNumber(i, "file") + " in " + (DateTime.Now - st).TotalSeconds + "s.");
            SetStatus(_operationPast + " " + Utils.FormatNumber(i, "file") + "!");
            _parsing = _renaming = false;
        }
Exemple #2
0
        /// <summary>
        /// Handles the Elapsed event of the ParserTimer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        private void ParserTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (_parsing)
            {
                return;
            }

            _parsing = true;

            var files = FilesListViewItemCollection.Where(f => !f.Processed).ToList();

            if (files.Count == 0)
            {
                goto end;
            }

            Log.Info("Starting to identify files in renamer queue...");
            var st = DateTime.Now;

            foreach (var file in files)
            {
                SetStatus("Identifying " + file.Information.Name + "...", true);
                Log.Debug("Identifying file " + file.Information.Name + "...");

                try
                {
                    file.Information = FileNames.Parser.ParseFile(file.Information.Name, Path.GetDirectoryName(file.Location).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries));
                    file.Checked     = file.Recognized = file.Enabled = file.Information.Success;
                    file.Processed   = true;

                    if (file.Information.Success)
                    {
                        file.ShowStatusImage = "Collapsed";
                        file.ShowCheckBox    = "Visible";

                        Log.Debug("Identified file " + file.Information.Name + " as " + file.Information + ".");
                    }
                    else
                    {
                        file.StatusImage = "/RSTVShowTracker;component/Images/exclamation-red.png";

                        Log.Debug("Unable to identify file " + file.Information.Name + ": " + file.Information + ".");
                    }
                }
                catch (Exception ex)
                {
                    file.Information.ParseError = ShowFile.FailureReasons.ExceptionOccurred;
                    file.Checked     = file.Recognized = file.Enabled = false;
                    file.Processed   = true;
                    file.StatusImage = "/RSTVShowTracker;component/Images/exclamation-red.png";

                    Log.Warn("Exception while identifying file " + file.Information.Name + ".", ex);
                }

                file.RefreshEnabled();
            }

            Log.Info("File identification queue finished in " + (DateTime.Now - st).TotalSeconds + "s.");

            SetStatus();

end:
            _parsing = false;
        }