using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Aurora.Proto.Party;
using Aurora.Services.Library;
using Aurora.Services.Settings;
using Aurora.Models.Media;
using Aurora.Services.EventManager;
using Autofac;
namespace Aurora.Services.Server.Controllers
{
public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase
{
private ILibraryService _libraryService;
private ISettingsService _settingsService;
private IEventManager _eventManager;
///
/// Constructor for partial class
///
public RemotePartyController(string partyName, string description, ILibraryService libraryService, ISettingsService settingsService, IEventManager eventManager)
{
this._startDateTime = DateTime.UtcNow;
this._displayName = partyName;
this._description = description;
this._memberList = new SortedList();
this._mediaList = new SortedList();
_libraryService = libraryService;
this._settingsService = settingsService;
string userName = _settingsService.Username;
this._eventManager = eventManager;
this._hostMember = new Member()
{
Name = GetNewMemberResourceName(_partyResourceName, ServerService.GetLocalIPAddress(), userName),
UserName = userName,
IpAddress = ServerService.GetLocalIPAddress(),
};
this._memberList.Add(_hostMember.Name, _hostMember);
//Add media from library
//This will change as queuing operation gets solidified
//Simply return the hosts library
ObservableCollection queue = _libraryService.GetLibrary();
foreach (BaseMedia media in queue)
{
AudioMetadata metadata = new AudioMetadata();
try
{
if (media.Metadata is AudioMetadata)
{
metadata = media.Metadata as AudioMetadata;
Media data = new Media();
data.Name = string.Format("{0}/{1}", partyName, media.Id);
if (metadata.Title != null)
{
data.Title = metadata.Title;
}
if (metadata.Artist != null)
{
data.Artist = metadata.Artist;
}
if (metadata.Album != null)
{
data.Album = metadata.Album;
}
if (metadata.Duration != null)
{
data.Duration = metadata.Duration;
}
_mediaList.Add(data.Name, data);
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error preparing queue: {0}", ex.Message));
}
}
}
}
}