<commit_before>﻿using Crystal3.Core;
using Crystal3.InversionOfControl;
using Crystal3.Model;
using Neptunium.Managers;
using Neptunium.Media;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System.RemoteSystems;

namespace Neptunium.Fragments
{
    public class HandOffFlyoutViewFragment : ViewModelFragment
    {
        internal HandOffFlyoutViewFragment()
        {
            ContinuedAppExperienceManager.RemoteSystemsListUpdated += ContinuedAppExperienceManager_RemoteSystemsListUpdated;

            IsBusy = true;

            if (ContinuedAppExperienceManager.RemoteSystemsList != null)
                AvailableDevices = new ObservableCollection<RemoteSystem>(ContinuedAppExperienceManager.RemoteSystemsList);
        }

        private void ContinuedAppExperienceManager_RemoteSystemsListUpdated(object sender, EventArgs e)
        {
            App.Dispatcher.RunWhenIdleAsync(() =>
            {
                AvailableDevices = new ObservableCollection<RemoteSystem>(ContinuedAppExperienceManager.RemoteSystemsList);
                //RaisePropertyChanged(nameof(AvailableDevices));

                IsBusy = false;
            });
        }

        public override async void Invoke(ViewModelBase viewModel, object data)
        {
            var device = data as RemoteSystem;

            if (device != null && StationMediaPlayer.IsPlaying)
            {
                IsBusy = true;
                try
                {
                    var results = await ContinuedAppExperienceManager.HandoffStationToRemoteDeviceAsync(device, StationMediaPlayer.CurrentStation);

                    if (results)
                    {
                        await IoC.Current.Resolve<IMessageDialogService>()
                            .ShowAsync("YAY!", 
                                string.Format("Hand off was successful. '{0}' should begin playing on '{1}' shortly.",
                                    StationMediaPlayer.CurrentStation.Name, device.DisplayName));
                    }
                    else
                    {
                        await IoC.Current.Resolve<IMessageDialogService>()
                            .ShowAsync("Uh-oh!",
                                string.Format("Hand off failed. Unable to get '{0}' playing on '{1}'.",
                                    StationMediaPlayer.CurrentStation.Name, device.DisplayName));
                    }<commit_msg>Fixed message box titles/messages in the hand off flyout.<commit_after>﻿using Crystal3.Core;
using Crystal3.InversionOfControl;
using Crystal3.Model;
using Neptunium.Managers;
using Neptunium.Media;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System.RemoteSystems;

namespace Neptunium.Fragments
{
    public class HandOffFlyoutViewFragment : ViewModelFragment
    {
        internal HandOffFlyoutViewFragment()
        {
            ContinuedAppExperienceManager.RemoteSystemsListUpdated += ContinuedAppExperienceManager_RemoteSystemsListUpdated;

            IsBusy = true;

            if (ContinuedAppExperienceManager.RemoteSystemsList != null)
                AvailableDevices = new ObservableCollection<RemoteSystem>(ContinuedAppExperienceManager.RemoteSystemsList);
        }

        private void ContinuedAppExperienceManager_RemoteSystemsListUpdated(object sender, EventArgs e)
        {
            App.Dispatcher.RunWhenIdleAsync(() =>
            {
                AvailableDevices = new ObservableCollection<RemoteSystem>(ContinuedAppExperienceManager.RemoteSystemsList);
                //RaisePropertyChanged(nameof(AvailableDevices));

                IsBusy = false;
            });
        }

        public override async void Invoke(ViewModelBase viewModel, object data)
        {
            var device = data as RemoteSystem;

            if (device != null && StationMediaPlayer.IsPlaying)
            {
                IsBusy = true;
                try
                {
                    var results = await ContinuedAppExperienceManager.HandoffStationToRemoteDeviceAsync(device, StationMediaPlayer.CurrentStation);

                    if (results)
                    {
                        await IoC.Current.Resolve<IMessageDialogService>()
                            .ShowAsync( 
                                string.Format("Hand off was successful. '{0}' should begin playing on '{1}' shortly.",
                                    StationMediaPlayer.CurrentStation.Name, device.DisplayName),
                                "YAY!");
                    }
                    else
                    {
                        await IoC.Current.Resolve<IMessageDialogService>()
                            .ShowAsync(
                                string.Format("Hand off failed. Unable to get '{0}' playing on '{1}'.",
                                    StationMediaPlayer.CurrentStation.Name, device.DisplayName),
                                "Uh-oh!");
                    }
{'fraction_non_alphanumeric': 0.07288854608561511, 'fraction_numerical': 0.002699575780948708, 'mean_word_length': 1.861003861003861, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2008601', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1170, 'n_words': 238}