public IAsyncAction Initialize(InternetRadioConfig config) { return Task.Run(async () => { this.config = config; this.playbackRetries = 0; var telemetryInitializeProperties = new Dictionary<string, string>(); #pragma warning disable CS0618 // No current view for Background task this.resourceLoader = new ResourceLoader("Resources"); #pragma warning restore CS0618 // No current view for Background task this.radioPowerManager = new RadioPowerManager(); this.radioPowerManager.PowerStateChanged += RadioPowerManager_PowerStateChanged; this.radioPresetManager = new RadioLocalPresetManager(); this.radioPresetManager.PlaylistChanged += RadioPresetManager_PlaylistChanged; this.radioPresetManager.CurrentTrackChanged += RadioPresetManager_CurrentTrackChanged; this.radioPlaybackManager = new MediaEnginePlaybackManager(); this.radioPlaybackManager.VolumeChanged += RadioPlaybackManager_VolumeChanged; this.radioPlaybackManager.PlaybackStateChanged += RadioPlaybackManager_PlaybackStateChanged; await this.radioPlaybackManager.InitialzeAsync(); // Initialize the input managers // AllJoyn this.allJoynInterfaceManager = new AllJoynInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); this.allJoynInterfaceManager.Initialize(); // GPIO this.gpioInterfaceManager = new GpioInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); if (!this.gpioInterfaceManager.Initialize(this.config.Buttons_Debounce, this.config.Buttons_Pins)) { Debug.WriteLine("RadioManager: Failed to initialize GPIO"); telemetryInitializeProperties.Add("GpioAvailable", false.ToString()); } else { telemetryInitializeProperties.Add("GpioAvailable", true.ToString()); } // HTTP this.httpInterfaceManager = new HttpInterfaceManager(8001, this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); this.httpInterfaceManager.StartServer(); // Manage settings this.radioPlaybackManager.Volume = this.loadVolume(); var previousPlaylist = this.loadPlaylistId(); if (previousPlaylist.HasValue) { await this.radioPresetManager.LoadPlayList(previousPlaylist.Value); telemetryInitializeProperties.Add("FirstBoot", false.ToString()); } else { telemetryInitializeProperties.Add("FirstBoot", true.ToString()); } if (this.radioPresetManager.CurrentPlaylist == null) { var newPlaylistId = await this.radioPresetManager.StartNewPlaylist("DefaultPlaylist", new List<Track>(), true); this.savePlaylistId(newPlaylistId); } var displays = await TextDisplayManager.GetDisplays(); this.display = displays.FirstOrDefault(); if (null != this.display) { telemetryInitializeProperties.Add("DisplayAvailable", true.ToString()); telemetryInitializeProperties.Add("DisplayHeight", this.display.Height.ToString()); telemetryInitializeProperties.Add("DisplayWidth", this.display.Width.ToString()); } else { Debug.WriteLine("RadioManager: No displays available"); telemetryInitializeProperties.Add("DisplayAvailable", false.ToString()); } // Wake up the radio this.radioPowerManager.PowerState = PowerState.Powered; if (this.radioPresetManager.CurrentPlaylist.Tracks.Count <= 0) { this.radioPresetManager.CurrentPlaylist.Tracks.Add(this.config.Playlist_BuiltInStation); } TelemetryManager.WriteTelemetryEvent("App_Initialize", telemetryInitializeProperties); }).AsAsyncAction(); }
public async Task Initialize() { this.playbackRetries = 0; var telemetryInitializeProperties = new Dictionary<string, string>(); #pragma warning disable CS0618 // No current view for Background task this.resourceLoader = new ResourceLoader("Resources"); #pragma warning restore CS0618 // No current view for Background task this.radioPowerManager = new RadioPowerManager(); this.radioPowerManager.PowerStateChanged += RadioPowerManager_PowerStateChanged; this.radioPresetManager = new RadioLocalPresetManager(); this.radioPresetManager.PlaylistChanged += RadioPresetManager_PlaylistChanged; this.radioPresetManager.CurrentTrackChanged += RadioPresetManager_CurrentTrackChanged; this.radioPlaybackManager = new MediaEnginePlaybackManager(); this.radioPlaybackManager.VolumeChanged += RadioPlaybackManager_VolumeChanged; this.radioPlaybackManager.PlaybackStateChanged += RadioPlaybackManager_PlaybackStateChanged; await this.radioPlaybackManager.InitialzeAsync(); // Initialize the input managers allJoynInterfaceManager = new AllJoynInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); this.allJoynInterfaceManager.Initialize(); await this.tryWriteToDisplay(this.resourceLoader.GetString("AllJoynIdMessage") +"\n" + this.allJoynInterfaceManager.GetBusId(), 0); this.gpioInterfaceManager = new GpioInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); if (!this.gpioInterfaceManager.Initialize()) { Debug.WriteLine("RadioManager: Failed to initialize GPIO"); telemetryInitializeProperties.Add("GpioAvailable", false.ToString()); } else { telemetryInitializeProperties.Add("GpioAvailable", true.ToString()); } this.appServicesInterfaceManager = new AppServicesInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); // Manage settings this.radioPlaybackManager.Volume = this.loadVolume(); var previousPlaylist = this.loadPlaylistId(); if (previousPlaylist.HasValue) { await this.radioPresetManager.LoadPlayList(previousPlaylist.Value); telemetryInitializeProperties.Add("FirstBoot", false.ToString()); } else { telemetryInitializeProperties.Add("FirstBoot", true.ToString()); } if (this.radioPresetManager.CurrentPlaylist == null) { var newPlaylistId = await this.radioPresetManager.StartNewPlaylist("DefaultPlaylist", new List<Track>(), true); this.savePlaylistId(newPlaylistId); } var displays = await TextDisplayManager.GetDisplays(); this.display = displays.FirstOrDefault(); if (null != this.display) { telemetryInitializeProperties.Add("DisplayAvailable", true.ToString()); telemetryInitializeProperties.Add("DisplayHeight", this.display.Height.ToString()); telemetryInitializeProperties.Add("DisplayWidth", this.display.Width.ToString()); } else { Debug.WriteLine("RadioManager: No displays available"); telemetryInitializeProperties.Add("DisplayAvailable", false.ToString()); } // Wake up the radio this.radioPowerManager.PowerState = PowerState.Powered; StartupTask.WriteTelemetryEvent("App_Initialize", telemetryInitializeProperties); }
public IAsyncAction Initialize(InternetRadioConfig config) { return(Task.Run(async() => { this.config = config; this.playbackRetries = 0; var telemetryInitializeProperties = new Dictionary <string, string>(); #pragma warning disable CS0618 // No current view for Background task this.resourceLoader = new ResourceLoader("Resources"); #pragma warning restore CS0618 // No current view for Background task this.radioPowerManager = new RadioPowerManager(); this.radioPowerManager.PowerStateChanged += RadioPowerManager_PowerStateChanged; this.radioPresetManager = new RadioLocalPresetManager(); this.radioPresetManager.PlaylistChanged += RadioPresetManager_PlaylistChanged; this.radioPresetManager.CurrentTrackChanged += RadioPresetManager_CurrentTrackChanged; this.radioPlaybackManager = new MediaEnginePlaybackManager(); this.radioPlaybackManager.VolumeChanged += RadioPlaybackManager_VolumeChanged; this.radioPlaybackManager.PlaybackStateChanged += RadioPlaybackManager_PlaybackStateChanged; await this.radioPlaybackManager.InitialzeAsync(); // Initialize the input managers // AllJoyn this.allJoynInterfaceManager = new AllJoynInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); this.allJoynInterfaceManager.Initialize(); // GPIO this.gpioInterfaceManager = new GpioInterfaceManager(this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); if (!this.gpioInterfaceManager.Initialize(this.config.Buttons_Debounce, this.config.Buttons_Pins)) { Debug.WriteLine("RadioManager: Failed to initialize GPIO"); telemetryInitializeProperties.Add("GpioAvailable", false.ToString()); } else { telemetryInitializeProperties.Add("GpioAvailable", true.ToString()); } // HTTP this.httpInterfaceManager = new HttpInterfaceManager(8001, this.radioPlaybackManager, this.radioPresetManager, this.radioPowerManager); this.httpInterfaceManager.StartServer(); // Manage settings this.radioPlaybackManager.Volume = this.loadVolume(); var previousPlaylist = this.loadPlaylistId(); if (previousPlaylist.HasValue) { await this.radioPresetManager.LoadPlayList(previousPlaylist.Value); telemetryInitializeProperties.Add("FirstBoot", false.ToString()); } else { telemetryInitializeProperties.Add("FirstBoot", true.ToString()); this.radioPlaybackManager.Volume = .25; } if (this.radioPresetManager.CurrentPlaylist == null) { var newPlaylistId = await this.radioPresetManager.StartNewPlaylist("DefaultPlaylist", new List <Track>(), true); this.savePlaylistId(newPlaylistId); } var displays = await TextDisplayManager.GetDisplays(); this.display = displays.FirstOrDefault(); if (null != this.display) { telemetryInitializeProperties.Add("DisplayAvailable", true.ToString()); telemetryInitializeProperties.Add("DisplayHeight", this.display.Height.ToString()); telemetryInitializeProperties.Add("DisplayWidth", this.display.Width.ToString()); } else { Debug.WriteLine("RadioManager: No displays available"); telemetryInitializeProperties.Add("DisplayAvailable", false.ToString()); } // Wake up the radio this.radioPowerManager.PowerState = PowerState.Powered; if (this.radioPresetManager.CurrentPlaylist.Tracks.Count <= 0) { this.radioPresetManager.CurrentPlaylist.Tracks.Add(this.config.Playlist_BuiltInStation); } TelemetryManager.WriteTelemetryEvent("App_Initialize", telemetryInitializeProperties); }).AsAsyncAction()); }