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(); } }
public static HttpClient BuildJsonClient(MusicEndpoint e) { var client = BuildClient(e); client.DefaultRequestHeaders.Accept.ParseAdd(HttpUtil.Json); return(client); }
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)); }
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); }
/// <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); }
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); }
public static SimplePimpSession BuildSession(MusicEndpoint endpoint) { if (endpoint.EndpointType == EndpointTypes.PimpCloud) { return(new CloudSession(endpoint)); } else { return(new SimplePimpSession(endpoint)); } }
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())); }
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; }
/// <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); } }
/// <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); }
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(); }
//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; } }
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); }
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); }
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); }
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); }
public PimpSession NewBeamSession(MusicEndpoint e) { return(impl.NewBeamSession(e)); }
public MusicLibrary NewPimpLibrary(MusicEndpoint e) { return(impl.NewPimpLibrary(e)); }
public SimplePimpSession(MusicEndpoint settings, bool acceptCompression = true) : base(settings, JSONv18, acceptCompression) { SocketResource = PlaybackSocketResource; IsCloud = settings.EndpointType == EndpointTypes.PimpCloud; }
public PhoneBeamSession(MusicEndpoint settings) : base(settings) { SocketResource = BeamPlayer.webSocketResource; }
public PimpSession NewBeamSession(MusicEndpoint e) { return(new StoreBeamSession(e)); }
public StorePimpSession(MusicEndpoint e) : base(e) { }
public virtual AuthenticationHeaderValue AuthHeader(MusicEndpoint e) { return(AuthorizationHeader(e.Username, e.Password)); }
public SubsonicSession(MusicEndpoint settings) : base(settings) { }
public PhonePimpSession(MusicEndpoint settings, bool acceptCompression = true) : base(settings, acceptCompression) { }
public SimpleAlarmClient(MusicEndpoint pimpEndpoint, IDateTimeHelper timeHelper) : this(BuildSession(pimpEndpoint), timeHelper) { }
public CloudSession(MusicEndpoint e) : base(e) { SocketResource = CloudPlaybackSocketResource; }
private void libraryManager_ActiveEndpointChanged(MusicEndpoint e) { NavigationContext.QueryString.Clear(); }
public MusicLibrary NewPimpLibrary(MusicEndpoint e) { return(new PimpLibrary(new StorePimpSession(e))); }