public override bool Insert(string json) { var data = JsonConvert.DeserializeObject <RootObject>(json); if (data == null || !data.Songlog.Any()) { return(false); } if (data.pageSize < data.Songlog.Count) { var log = new ImportInfo(); log.Messages.Add("data.pageSize < data.Songlog.Count: " + data.Id + " => " + data.pageSize + " < " + data.Songlog.Count); ImportLog.Add(log); } using (var db = new SrfPlayListContext(OptionsBuilder.Options)) { foreach (var songLogData in data.Songlog) { // check for already imported songlog var songlog = db.Songlogs.Local.FirstOrDefault(s => s.id.Equals(songLogData.id)); if (songlog == default(Songlog)) { songlog = db.Songlogs.FirstOrDefault(s => s.id.Equals(songLogData.id)); } if (songlog != default(Songlog)) { continue; } var artist = Artist.Add(db, songLogData); var song = Song.Add(db, songLogData, artist); // checked for existing above songlog = Songlog.Add(db, songLogData, song); var log = new ImportInfo { Artist = artist.name, Song = song.title, PlayedDate = songlog.playedDate }; ImportLog.Add(log); } db.SaveChanges(); } return(true); }
static void Main(string[] args) { var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(ServerAddress); // Artists with JSON var artist = new ArtistApiModel() { Name = "Pesho123", Country = "Bulgaria", DateOfBirth = DateTime.Now }; Console.WriteLine("Adding following artist " + artist); Console.WriteLine("-----------------------------------"); Artist.Add(httpClient, artist); Console.ReadLine(); Console.WriteLine("Listing all artists"); Console.WriteLine("-----------------------------------"); Artist.Print(httpClient); Console.ReadLine(); var updatedArtist = new ArtistApiModel() { Name = "PeshoUpdated", Country = "Zimbabve", DateOfBirth = DateTime.Now }; Console.WriteLine("Update artist with ID 1 to " + updatedArtist); Console.WriteLine("-----------------------------------"); Artist.Update(httpClient, 1, artist); Console.ReadLine(); Console.WriteLine("Delete artist with ID 1"); Console.WriteLine("-----------------------------------"); Artist.Delete(httpClient, 1); Console.ReadLine(); // Songs with XML var song = new SongApiModel() { Title = "Nothing else matters", Genre = "Blues", Year = 1995, ArtistId = 1 }; Song.Add(httpClient, song); Console.ReadLine(); Console.WriteLine("-----------------------------------"); Song.Print(httpClient); Console.ReadLine(); }
private async Task StartIndexing() { // TODO: Rewrite function. _artistDataRepository = new ArtistDataRepository(); var musicFolder = await KnownVLCLocation.MusicLibrary.GetFoldersAsync(CommonFolderQuery.GroupByArtist); TimeSpan period = TimeSpan.FromSeconds(10); _periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source) => { if (Locator.MusicLibraryVM.Track.Count > _numberOfTracks) { await DispatchHelper.InvokeAsync(() => Locator.MusicLibraryVM._numberOfTracks = Track.Count); } else { _periodicTimer.Cancel(); await DispatchHelper.InvokeAsync(() => { IsLoaded = true; IsBusy = false; }); } }, period); using (await _artistLock.LockAsync()) foreach (var artistItem in musicFolder) { IsMusicLibraryEmpty = false; MusicProperties artistProperties = null; try { artistProperties = await artistItem.Properties.GetMusicPropertiesAsync(); } catch { Debug.WriteLine("Could not get artist item properties."); } // If we could not get the artist information, skip it and continue. if (artistProperties == null || artistProperties.Artist == string.Empty) { continue; } StorageFolderQueryResult albumQuery = artistItem.CreateFolderQuery(CommonFolderQuery.GroupByAlbum); // Check if artist is in the database. If so, use it. ArtistItem artist = await _artistDataRepository.LoadViaArtistName(artistProperties.Artist); if (artist == null) { artist = new ArtistItem { Name = artistProperties.Artist }; Artist.Add(artist); await _artistDataRepository.Add(artist); } await artist.Initialize(albumQuery, artist); OnPropertyChanged("Track"); OnPropertyChanged("Artist"); } OnPropertyChanged("Artist"); }