Restructuring. Added services.
This commit is contained in:
22
Aurora/Backend/Services/BaseService.cs
Normal file
22
Aurora/Backend/Services/BaseService.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace Aurora.Backend.Services
|
||||
{
|
||||
public abstract class BaseService<T> where T : class
|
||||
{
|
||||
private static volatile Lazy<T> _instance = new Lazy<T>(() => CreateInstanceOfT());
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get { return _instance.Value; }
|
||||
}
|
||||
|
||||
private static T CreateInstanceOfT()
|
||||
{
|
||||
|
||||
return Activator.CreateInstance(typeof(T), true) as T;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
Aurora/Backend/Services/LibraryService.cs
Normal file
65
Aurora/Backend/Services/LibraryService.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Aurora.Backend.Models;
|
||||
using Aurora.Backend.Utils;
|
||||
using NAudio.Wave;
|
||||
|
||||
namespace Aurora.Backend.Services
|
||||
{
|
||||
public class LibraryService : BaseService<LibraryService>
|
||||
{
|
||||
#region Fields
|
||||
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
|
||||
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
|
||||
private Dictionary<string, Song> _library;
|
||||
|
||||
|
||||
#endregion Fields
|
||||
|
||||
public LibraryService()
|
||||
{
|
||||
_library = new Dictionary<string, Song>();
|
||||
LoadLibrary();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the songs.
|
||||
/// </summary>
|
||||
/// <returns>The songs.</returns>
|
||||
public ObservableCollection<Song> GetLibrary()
|
||||
{
|
||||
ObservableCollection<Song> collection = new ObservableCollection<Song>();
|
||||
foreach (KeyValuePair<string, Song> pair in _library)
|
||||
{
|
||||
collection.Add(pair.Value);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads library from files.
|
||||
/// </summary>
|
||||
private void LoadLibrary()
|
||||
{
|
||||
//Get songs
|
||||
List<FileInfo> musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions);
|
||||
|
||||
foreach (FileInfo file in musicFiles)
|
||||
{
|
||||
TagLib.File tagFile = TagLib.File.Create(file.FullName);
|
||||
|
||||
Song song = new Song(file)
|
||||
{
|
||||
Title = tagFile.Tag.Title,
|
||||
Album = tagFile.Tag.Album,
|
||||
Artist = tagFile.Tag.FirstAlbumArtist
|
||||
};
|
||||
|
||||
_library.Add(song.Id, song);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user