예제 #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var endpointId  = Query(PageParams.ENDPOINT);
            var alarmId     = Query(PageParams.ID);
            var isDoNothing = endpointId == null && alarmId == null;
            var isAddNew    = endpointId != null && alarmId == null;
            var isUpdate    = alarmId != null;

            if (isDoNothing)
            {
            }
            else
            {
                // After updating the time (on a separate page), the user is
                // navigated back here, then the alarm is loaded from the backend
                // and the old time is reinstated. Clearing the navigation query
                // string fixes this. The alarm is then only loaded when clicked
                // from the Alarms page.
                MusicEndpoint endpoint = DetermineEndpointOrActive(PageParams.ENDPOINT);
                NavigationContext.QueryString.Clear();
                viewModel   = AlarmModel.Build(endpoint, timeHelper);
                DataContext = viewModel;
                if (isUpdate)
                {
                    await viewModel.Fill(alarmId);
                }
                await viewModel.InstallPlayer();

                //await viewModel.LoadTracks();
            }
        }
예제 #2
0
        public static HttpClient BuildJsonClient(MusicEndpoint e)
        {
            var client = BuildClient(e);

            client.DefaultRequestHeaders.Accept.ParseAdd(HttpUtil.Json);
            return(client);
        }
예제 #3
0
        public override AuthenticationHeaderValue AuthHeader(MusicEndpoint e)
        {
            Byte[] credBytes = Encoding.UTF8.GetBytes(String.Format("{0}:{1}:{2}", e.CloudServerID, e.Username, e.Password));
            var    encoded   = Convert.ToBase64String(credBytes);

            return(new AuthenticationHeaderValue(Pimp, encoded));
        }
예제 #4
0
 private MusicEndpoint FillIn(BeamJson src, MusicEndpoint dest)
 {
     dest.Username = src.user;
     dest.Server   = src.host;
     dest.Port     = src.supports_tls ? src.ssl_port : src.port;
     dest.Protocol = src.supports_tls ? Protocols.https : Protocols.http;
     return(dest);
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="endpoint"></param>
 /// <returns>true if the endpoint was modified, false otherwise</returns>
 public async Task <bool> SyncIfUnreachable(MusicEndpoint endpoint)
 {
     if (await IsUnreachable(endpoint))
     {
         return(await SyncEndpoint(endpoint));
     }
     return(false);
 }
예제 #6
0
 public SessionBase(MusicEndpoint settings, string mediaType, bool acceptCompression = true)
     : base(settings)
 {
     this.mediaType            = mediaType;
     UseCompression            = acceptCompression;
     Client                    = NewHttpClient(settings);
     LongTimeoutClient         = NewHttpClient(settings);
     LongTimeoutClient.Timeout = TimeSpan.FromMinutes(10);
 }
예제 #7
0
 public static SimplePimpSession BuildSession(MusicEndpoint endpoint)
 {
     if (endpoint.EndpointType == EndpointTypes.PimpCloud)
     {
         return(new CloudSession(endpoint));
     }
     else
     {
         return(new SimplePimpSession(endpoint));
     }
 }
예제 #8
0
 private Task <MusicEndpoint> AuthTest(string ip, MusicEndpoint notWorking)
 {
     return(BasicTest(
                ip,
                addr => {
         var e = new MusicEndpoint(notWorking);
         e.Server = addr;
         return e;
     },
                session => session.PingAuth()));
 }
예제 #9
0
 public RemoteBase(MusicEndpoint settings)
 {
     Endpoint      = settings;
     EndpointName  = settings.Name;
     Server        = settings.Server;
     Port          = settings.Port;
     Username      = settings.Username;
     Password      = settings.Password;
     CloudServerID = settings.CloudServerID;
     BaseUri       = settings.Uri().OriginalString;
     Describe      = Server + ":" + Port;
 }
예제 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="notWorking"></param>
 /// <returns>a working endpoint if any</returns>
 private async Task <MusicEndpoint> SearchWorking(MusicEndpoint notWorking)
 {
     if (NetworkUtils.IsNumericalIP(notWorking.Server))
     {
         var scanRange = ScanRange(notWorking.Server);
         return(await TestIPs <MusicEndpoint>(scanRange, addr => token => AuthTest(addr, notWorking)));
     }
     else
     {
         throw new Exception("Not a numerical IP: " + notWorking.Server);
     }
 }
예제 #11
0
        /// <summary>
        /// If the query parameter key contains an endpoint ID, returns that endpoint, otherwise
        /// returns the active playback endpoint.
        /// </summary>
        /// <returns></returns>
        protected MusicEndpoint ResolveEndpoint(string queryKey, MusicEndpoint def = null)
        {
            var endpointId = Query(queryKey);

            if (endpointId != null)
            {
                var end = provider.EndpointsData.Endpoints.FirstOrDefault(ep => ep.Id == endpointId);
                if (end != null)
                {
                    return(end);
                }
            }
            return(def);
        }
예제 #12
0
 private async void PlayerManager_ActiveEndpointChanged(MusicEndpoint obj)
 {
     // reloads the view with the newly selected player
     DataContext = null;
     DataContext = ViewModel;
     if (MusicPlayer.IsEventBased)
     {
         ViewModel.StopPolling();
     }
     else
     {
         ViewModel.StartPolling();
     }
     // asks server for status of new player
     await ViewModel.Player.UpdateNowPlaying();
 }
예제 #13
0
        //void AlarmClock_Loaded(object sender, RoutedEventArgs e) {
        //    AddAppBarButton.IsEnabled = vm.Endpoint != null;
        //}
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            // push notifications have query parameters
            MusicEndpoint endpoint   = ResolveEndpoint(PageParams.TAG, def: provider.PlayerManager.ActiveEndpoint);
            var           shouldStop = Query(PageParams.CMD) == STOP && endpoint != null;

            if (endpoint != null && (endpoint.EndpointType == EndpointTypes.MusicPimp || endpoint.EndpointType == EndpointTypes.PimpCloud))
            {
                await vm.UpdateUI(endpoint);
            }
            else
            {
                var item = PlayerList.SelectedItem;
                if (item != null)
                {
                    var e2 = item as MusicEndpoint;
                    await vm.UpdateUI(e2);
                }
                else
                {
                    var previous = vm.Endpoint;
                    if (previous != null)
                    {
                        await vm.UpdateUI(previous);
                    }
                    else
                    {
                        await vm.UpdateUI();
                    }
                }
            }
            if (shouldStop)
            {
                await vm.StopAlarmPlayback();
            }
            var btns = ApplicationBar.Buttons;

            if (btns.Count > 0)
            {
                var btn = btns[0] as ApplicationBarIconButton;
                btn.IsEnabled = vm.Endpoint != null;
            }
        }
예제 #14
0
        private async Task <bool> IsUnreachable(MusicEndpoint e)
        {
            var isUnreachable = false;

            if (e.EndpointType == EndpointTypes.MusicPimp)
            {
                try {
                    var s = Provider.NewPimpSession(e);
                    await s.PingAuth();
                } catch (NotFoundException) {
                    // HttpClient returns a 404 status code even if the server is unreachable,
                    // which seems wrong, but that's why we also need to catch NotFoundExceptions.
                    isUnreachable = true;
                } catch (ConnectivityException) {
                    isUnreachable = true;
                } catch (Exception) {
                }
            }
            return(isUnreachable);
        }
예제 #15
0
        public static HttpClient BuildClient(MusicEndpoint e)
        {
            var handler = new HttpClientHandler();

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }
            else
            {
                handler.AutomaticDecompression = DecompressionMethods.None;
            }
            var client = new HttpClient(handler);

            client.BaseAddress = new Uri(e.Protocol + "://" + e.Server + ":" + e.Port);
            var headers = client.DefaultRequestHeaders;

            headers.Authorization = HttpUtil.BasicAuthHeaderValue(e.Username, e.Password);
            return(client);
        }
예제 #16
0
        protected HttpClient NewHttpClient(MusicEndpoint e)
        {
            var handler = new HttpClientHandler();

            if (UseCompression && handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }
            else
            {
                handler.AutomaticDecompression = DecompressionMethods.None;
            }
            var client = new HttpClient(handler);

            client.BaseAddress = new Uri(e.Protocol + "://" + e.Server + ":" + e.Port);
            var headers = client.DefaultRequestHeaders;

            headers.Authorization = AuthHeader(e);
            headers.Accept.ParseAdd(mediaType);
            return(client);
        }
예제 #17
0
        public async Task <bool> SyncEndpoint(MusicEndpoint endpoint)
        {
            try {
                if (NetworkUtils.IsNumericalIP(endpoint.Server))
                {
                    var working = await SearchWorking(endpoint);

                    // submits changes
                    var current = EndpointsInfo.Endpoints.FirstOrDefault(e => e.Name == working.Name);
                    if (current != null)
                    {
                        current.Server = working.Server;
                        await EndpointsInfo.SaveChanges(current);

                        return(true);
                    }
                }
            } catch (Exception) {
            }
            return(false);
        }
예제 #18
0
 public PimpSession NewBeamSession(MusicEndpoint e)
 {
     return(impl.NewBeamSession(e));
 }
예제 #19
0
 public MusicLibrary NewPimpLibrary(MusicEndpoint e)
 {
     return(impl.NewPimpLibrary(e));
 }
예제 #20
0
 public SimplePimpSession(MusicEndpoint settings, bool acceptCompression = true)
     : base(settings, JSONv18, acceptCompression)
 {
     SocketResource = PlaybackSocketResource;
     IsCloud        = settings.EndpointType == EndpointTypes.PimpCloud;
 }
예제 #21
0
 public PhoneBeamSession(MusicEndpoint settings)
     : base(settings)
 {
     SocketResource = BeamPlayer.webSocketResource;
 }
예제 #22
0
 public PimpSession NewBeamSession(MusicEndpoint e)
 {
     return(new StoreBeamSession(e));
 }
예제 #23
0
 public StorePimpSession(MusicEndpoint e)
     : base(e)
 {
 }
예제 #24
0
 public virtual AuthenticationHeaderValue AuthHeader(MusicEndpoint e)
 {
     return(AuthorizationHeader(e.Username, e.Password));
 }
예제 #25
0
 public SubsonicSession(MusicEndpoint settings)
     : base(settings)
 {
 }
예제 #26
0
 public PhonePimpSession(MusicEndpoint settings, bool acceptCompression = true)
     : base(settings, acceptCompression)
 {
 }
예제 #27
0
 public SimpleAlarmClient(MusicEndpoint pimpEndpoint, IDateTimeHelper timeHelper) :
     this(BuildSession(pimpEndpoint), timeHelper)
 {
 }
예제 #28
0
 public CloudSession(MusicEndpoint e)
     : base(e)
 {
     SocketResource = CloudPlaybackSocketResource;
 }
예제 #29
0
 private void libraryManager_ActiveEndpointChanged(MusicEndpoint e)
 {
     NavigationContext.QueryString.Clear();
 }
예제 #30
0
 public MusicLibrary NewPimpLibrary(MusicEndpoint e)
 {
     return(new PimpLibrary(new StorePimpSession(e)));
 }