Ejemplo n.º 1
0
        public static async Task ConvertTest(IConverter converter, string name, string expected, CancellationToken cancellationToken = default)
        {
            var bytes  = ResourcesUtilities.ReadFileAsBytes(name);
            var actual = await converter.ConvertAsync(bytes, cancellationToken);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                //инициализация и проверка входных аргументов.
                InputArguments inputArguments         = new InputArguments();
                var            verifiedInputArguments = inputArguments.GetCheckingInputArguments(args);

                Console.SetWindowSize(100, 20);

                //'revert'выбор типа преобразования:
                //-(true)-преобразование из бинарного файла в файл Csv;
                //-(false)-преобразование из файла Csv в бинарный файл.
                bool             revert           = true;
                ConversionSwitch conversionSwitch = new ConversionSwitch();
                IConverter       converter        = conversionSwitch.GetConverter(verifiedInputArguments.pathBinaryFile, verifiedInputArguments.pathCsvFile, revert);

                //задача.
                var task = converter.ConvertAsync(verifiedInputArguments.pathBinaryFile, verifiedInputArguments.pathCsvFile);
                Console.WriteLine($"Состояние задачи: {task.Status}");
                Console.WriteLine(new string('_', 29));
                task.Wait();
                Console.WriteLine(new string('_', 29));
                Console.WriteLine($"Состояние задачи: {task.Status}");

                Console.ReadLine();
            }
            catch (Exception m)
            {
                Console.WriteLine(m.Message);
            }
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public async Task <Track> SaveAsync(WebSong song)
        {
            var track = await _webSongConverter.ConvertAsync(song);

            await SaveAsync(track);

            return(track);
        }
Ejemplo n.º 4
0
        private async Task <Track> ConvertToTrackAsync(WebSong webSong)
        {
            var track = webSong.PreviousConversion as Track;

            if (track == null)
            {
                using (var blocker = new UiBlocker())
                {
                    blocker.UpdateProgress("Getting data...");
                    track = await _webSongConverter.ConvertAsync(webSong);
                }
            }
            return(track);
        }
Ejemplo n.º 5
0
        private async void SearchTracks(string query, ISearchMetadataProvider provider)
        {
            try
            {
                TracksResults = null;
                var result = await provider.SearchAsync(query);

                TracksResults = await _webToTrackConverter.ConvertAsync(result?.Songs);
            }
            catch
            {
                CurtainPrompt.ShowError("Something happened while searching for tracks!");
            }
        }
Ejemplo n.º 6
0
        public override async void OnNavigatedTo(
            object parameter,
            NavigationMode mode,
            IDictionary <string, object> state)
        {
            var name = parameter as string;

            Artist = _libraryService.Artists.FirstOrDefault(p => p.Name.EqualsIgnoreCase(name));
            if (Artist?.ArtworkUri == null)
            {
                foreach (var provider in _metadataProviders)
                {
                    try
                    {
                        var webArtist = await provider.GetArtistByNameAsync(name);

                        if (Artist != null && Artist.ArtworkUri == null)
                        {
                            Artist.ArtworkUri = webArtist.Artwork.ToString();
                        }
                        else
                        {
                            Artist = await _webArtistConverter.ConvertAsync(webArtist);
                        }
                        if (Artist != null)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }

                if (Artist == null)
                {
                    _navigationService.GoBack();
                    return;
                }
            }

            if (_settingsUtility.Read(ApplicationSettingsConstants.IsArtistAdaptiveColorEnabled, true))
            {
                DetectColorFromArtwork();
            }
            LoadWebData();
        }
Ejemplo n.º 7
0
        public async Task <Album> ConvertAsync(WebAlbum other, bool ignoreLibrary = false)
        {
            await FillPartialAsync(other);

            // fill the album partial for each track
            foreach (var webSong in other.Tracks)
            {
                webSong.Album = other;
            }

            var album = new Album
            {
                Title      = other.Title,
                ArtworkUri = other.Artwork.ToString(),
                Artist     = await _webArtistConverter.ConvertAsync(other.Artist),
                Year       = (uint?)other.ReleaseDate?.Year,
            };

            // TODO: ISupportIncrementalLoading?
            if (other.Tracks != null)
            {
                // only let 10 concurrent conversions
                using (var semaphoreSlim = new SemaphoreSlim(10, 10))
                {
                    // ReSharper disable AccessToDisposedClosure
                    var trackTasks = other.Tracks.Select(async p =>
                    {
                        await semaphoreSlim.WaitAsync();
                        var track = await _webTrackConverter.ConvertAsync(p);
                        semaphoreSlim.Release();
                        return(track);
                    });
                    album.Tracks =
                        other.Tracks != null
                            ? new OptimizedObservableCollection <Track>(
                            await Task.WhenAll(trackTasks))
                            : null;
                    // ReSharper restore AccessToDisposedClosure
                }
            }

            var libraryAlbum = _libraryService.Albums.FirstOrDefault(p => p.Title.EqualsIgnoreCase(album.Title));

            other.PreviousConversion = libraryAlbum ?? album;

            return(ignoreLibrary ? album : libraryAlbum ?? album);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> RegisterAsync([FromForm] RegisterUserViewModel model)
        {
            bool didCreate = false;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                // convert dto to applicationUser.
                ApplicationUser newUser = await _registerConverter.ConvertAsync(model);


                // try to create user
                IdentityResult result = await _userManager.CreateAsync(newUser, model.Password);

                // reget uesr
                ApplicationUser usr = _userManager.Users.Where(u => u.Email == newUser.Email).FirstOrDefault();

                if (result.Succeeded)
                {
                    // assign a default role.
                    IdentityResult roleCreate = await _userManager.AddToRoleAsync(usr, RoleType.Reader.ToString());

                    var x = _roleManager.GetRoleNameAsync(new ApplicationRole {
                        Name = RoleType.Reader.ToString()
                    });

                    if (roleCreate.Succeeded)
                    {
                        didCreate = true;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to get Users:");
                return(BadRequest(ex.Message));
            }

            return(Ok(didCreate));
        }
Ejemplo n.º 9
0
        private async void LoadTopSongs(int count)
        {
            foreach (var metadataProvider in _metadataProviders)
            {
                try
                {
                    var results = await metadataProvider.GetTopSongsAsync(count);

                    TopSongs = await _webToTrackConverter.ConvertAsync(results.Songs);

                    break;
                }
                catch (NotImplementedException)
                {
                }
                catch (ProviderException)
                {
                }
            }
        }
Ejemplo n.º 10
0
        public static async Task ConvertTest_RealTime(IRecorder recorder, IConverter converter)
        {
            await recorder.InitializeAsync();

            await recorder.StartAsync();

            await Task.Delay(TimeSpan.FromMilliseconds(5000));

            await recorder.StopAsync();

            var bytes = recorder.WavData;

            Assert.IsNotNull(bytes, "bytes != null");
            if (bytes == null)
            {
                return;
            }

            var result = await converter.ConvertAsync(bytes.ToArray());

            Console.WriteLine(result);
        }
Ejemplo n.º 11
0
        public async Task Convert(Uri fromUri, Uri toUri)
        {
            var fromFileType = GetFileExtension(fromUri);
            var toFileType   = GetFileExtension(toUri);

            var fromStorage = _storageProvider.GetStorage(fromUri.Scheme);
            var toStorage   = _storageProvider.GetStorage(toUri.Scheme);

            if (!fromStorage.CanRead)
            {
                throw new Exception($"Cannot read from {fromStorage.StorageType} ({fromUri.AbsolutePath}).");
            }
            if (!toStorage.CanWrite)
            {
                throw new Exception($"Cannot write to {toStorage.StorageType} ({toUri.AbsolutePath}).");
            }

            using (var fromStream = await fromStorage.OpenReadAsync(fromUri))
                using (var toStream = await toStorage.OpenWriteAsync(toUri))
                {
                    await _converter.ConvertAsync(fromStream, fromFileType, toStream, toFileType);
                }
        }
Ejemplo n.º 12
0
        private async void LoadWebData()
        {
            IsNewAlbumsLoading = true;
            IsAlbumsLoading    = true;
            IsTopSongsLoading  = true;

            foreach (var metadataProvider in _metadataProviders)
            {
                try
                {
                    var webArtist = await metadataProvider.GetArtistByNameAsync(Artist.Name);

                    if (webArtist == null)
                    {
                        continue;
                    }

                    try
                    {
                        // since it will remove duplicates request 4
                        if (NewAlbums == null)
                        {
                            NewAlbums =
                                await _webAlbumConverter.FillPartialAsync(
                                    (await metadataProvider.GetArtistNewAlbumsAsync(webArtist.Token, 4)).Albums.Take(2));

                            IsNewAlbumsLoading = false;
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        if (TopAlbums == null)
                        {
                            TopAlbums =
                                await
                                _webAlbumConverter.FillPartialAsync(
                                    (await metadataProvider.GetArtistAlbumsAsync(webArtist.Token, 10)).Albums);

                            IsAlbumsLoading = false;
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        if (TopSongs == null)
                        {
                            TopSongs = await _webSongConverter.ConvertAsync(
                                (await metadataProvider.GetArtistTopSongsAsync(webArtist.Token, 5)).Songs);

                            IsTopSongsLoading = false;
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    if (TopSongs != null && TopAlbums != null && NewAlbums != null)
                    {
                        break;
                    }
                }
                catch
                {
                    // ignored
                }
            }

            IsNewAlbumsLoading = false;
            IsAlbumsLoading    = false;
            IsTopSongsLoading  = false;
        }