Esempio n. 1
0
        private async Task StartIndexing(CancellationToken ct, bool onlyNewFiles = false)
        {
            if (_fileList == null || !_fileList.Any())
            {
                return;
            }

            try
            {
                var fi        = new FileIndexer(ct);
                var stopwatch = Stopwatch.StartNew();

                await Task.Run(() => fi.StartIndexing(_fileList, IndexingProgress, onlyNewFiles), ct);

                stopwatch.Stop();
                _duration = stopwatch.Elapsed;

                IndexingFinished();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
            }
            finally
            {
                _cts.Dispose();
                _cts = null;
            }
        }
Esempio n. 2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (dgFilesSelected.SelectedRows.Count == 0)
            {
                return;
            }
            if (txtAlbum.Text.Equals(Constants.MultipleValues) &&
                txtArtist.Text.Equals(Constants.MultipleValues) &&
                txtGenre.Text.Equals(Constants.MultipleValues) &&
                txtTrackNumber.Text.Equals(Constants.MultipleValues) &&
                txtTrackTitle.Text.Equals(Constants.MultipleValues) &&
                txtYear.Text.Equals(Constants.MultipleValues))
            {
                return;
            }

            this.Enabled       = false;
            gbMetaTags.Enabled = false;

            var metaTagsService = new MetaTagsService();
            await metaTagsService.SetMetaTags(Files);

            var cts = new CancellationTokenSource(30000);
            var fi  = new FileIndexer(cts.Token);

            await Task.Run(() => fi.StartIndexing(Files.Select(x => x.Id), null), cts.Token);

            this.Enabled       = true;
            gbMetaTags.Enabled = true;
            MessageBox.Show(this, "Saved succesfully!", "Meta tags saved", MessageBoxButtons.OK);
        }