public BasePlayer BuildPlayer(MusicEndpoint e) { switch (e.EndpointType) { case EndpointTypes.Local: return(Provider.LocalPlayer); case EndpointTypes.PimpCloud: return(NewCloudPlayer(e)); case EndpointTypes.MusicPimp: switch (playbackMode) { case PlaybackMode.server: return(NewPimpPlayer(e, () => LibraryManager.ActiveEndpoint)); case PlaybackMode.web: var s = Provider.NewPimpSession(e); return(new PimpWebPlayer(s, NewPimpSocket(s))); default: throw new NotImplementedException("Invalid playback mode: " + playbackMode); } case EndpointTypes.Beam: var s2 = Provider.NewBeamSession(e); return(Provider.NewBeamPlayer(s2, NewPimpSocket(s2))); case EndpointTypes.Subsonic: return(NewSubsonicPlayer(e)); default: throw new NotImplementedException("Create player for: " + e.EndpointType); } }
private void OnBeforeRemoval(MusicEndpoint e) { if (BeforeRemoval != null) { BeforeRemoval(e); } }
private async Task <bool> IsServerOld(MusicEndpoint endpoint) { if (endpoint.EndpointType == EndpointTypes.MusicPimp) { var s = new PimpSessionBase(endpoint); // throws if expired var pingResponse = await s.GetPingAuth(); var serverVersionStr = pingResponse.version; if (serverVersionStr == null) { return(true); } else { Version version; Version.TryParse(serverVersionStr, out version); if (version < PimpSessionBase.SearchSupportingVersion) { return(true); } } } return(false); }
private void OnActiveEndpointChanged(MusicEndpoint newEndpoint) { if (ActiveEndpointChanged != null) { ActiveEndpointChanged(newEndpoint); } }
private Task UnsubscribeFromPush(MusicEndpoint endpoint) { return(UnsubscribeFromPush(new List <MusicEndpoint>() { Endpoint })); }
public async Task UpdateUI(MusicEndpoint pimpEndpoint) { var index = PimpEndpoints.FindIndex(e => e.Name == pimpEndpoint.Name); if (index >= 0) { //pimpEndpointIndex = index; ResetClient(pimpEndpoint); UpdateToggleSilently(Push.IsChannelOpen()); if (IsPushEnabled) { try { await SubscribeToPush(silent : true); } catch (Exception) { } } await UpdateAlarmList(client); OnPropertyChanged("EnableEndpoints"); PimpEndpointIndex = index; //OnPropertyChanged("PimpEndpointIndex"); } else { await UpdateUI(); } }
private void OnEndpointRemoved(MusicEndpoint e) { if (EndpointRemoved != null) { EndpointRemoved(e); } }
protected async Task CheckServerVersion(MusicEndpoint endpoint) { if (await IsServerOld(endpoint)) { Send("New version available", "A new version of the MusicPimp server is available. The current version might not work well with this app. Get the new version from www.musicpimp.org. Enjoy!"); } }
private void OnEndpointModified(MusicEndpoint e) { if (EndpointModified != null) { EndpointModified(e); } }
private Task WithClient(MusicEndpoint endpoint, Func <PushClient, Task> f) { var client = new PushClient(endpoint); var task = f(client); var t = task.ContinueWith(t2 => client.Dispose()); return(task); }
public virtual async Task SubmitEndpoint(MusicEndpoint endpoint) { await AddOrUpdate(endpoint); if (MakeActiveLibrary) { LibraryManager.SetActive(endpoint); } }
public virtual async Task RemoveAndSave(MusicEndpoint endpoint) { OnBeforeRemoval(endpoint); Endpoints.Remove(endpoint); // TODO remove credential from vault await persist(); OnEndpointRemoved(endpoint); }
public async Task Test(MusicEndpoint endpoint) { string userFeedback = null; RemoteBase session = null; try { switch (endpoint.EndpointType) { case EndpointTypes.Local: break; case EndpointTypes.MusicPimp: session = ProviderService.Instance.NewPimpSession(endpoint); break; case EndpointTypes.PimpCloud: session = new CloudSession(endpoint); break; case EndpointTypes.Subsonic: session = new SubsonicSession(endpoint); break; } if (session != null) { try { FeedbackMessage = String.Empty; IsLoading = true; await session.TestConnectivity(); userFeedback = "Connection successfully established."; } finally { IsLoading = false; } } } catch (UnauthorizedException) { userFeedback = "Check your credentials."; } catch (ConnectivityException) { userFeedback = GetFeedback(endpoint, session); } catch (NotFoundException) { userFeedback = GetFeedback(endpoint, session); } catch (PimpException pe) { userFeedback = pe.Message; } catch (ServerResponseException sre) { userFeedback = sre.Message; } catch (HttpRequestException) { userFeedback = GetFeedback(endpoint, session); } catch (Exception) { userFeedback = "Something went wrong. Please check that all the fields are filled in properly."; } if (userFeedback != null) { OnFeedback(userFeedback); } }
/// <summary> /// The playbackMode variable determines which MusicPimp endpoint to activate /// if the endpoint is a MusicPimp endpoint. Keep this in mind or don't use /// this method otherwise. /// </summary> /// <param name="endpoint">existing endpoint to activate</param> public override void SetActive(MusicEndpoint endpoint) { var name = endpoint.Name; if (endpoint.EndpointType == EndpointTypes.MusicPimp && playbackMode == PlaybackMode.web) { name = webPlayerPrefix + name; } Index = PlayerEndpoints.IndexOf(name); }
public EditEndpoint(string endpointName) { EndpointItem = Endpoints.Endpoints.FirstOrDefault(item => item.Name == endpointName); if (EndpointItem == null) { EndpointItem = new MusicEndpoint(); } MakeActiveLibrary = false; Update(); }
/// <summary> /// Saves changes to all endpoints. /// </summary> /// <param name="endpoint">the modified endpoint</param> public async Task SaveChanges(MusicEndpoint endpoint) { if (Endpoints.Count(e => e.Name == endpoint.Name) > 1) { ThrowAlreadyExists(endpoint.Name); } await persist(); OnEndpointModified(endpoint); }
private string GetFeedback(MusicEndpoint e, RemoteBase s) { string userFeedback = s != null && e.EndpointType != EndpointTypes.PimpCloud ? "Unable to connect to " + s.BaseUri + "." : "Unable to connect."; var extraInfo = ""; if (e.Protocol == Protocols.https && e.EndpointType != EndpointTypes.PimpCloud) { extraInfo = " Perhaps the certificate validation failed? Untrusted SSL certificates are not accepted."; } userFeedback += extraInfo; return(userFeedback); }
public override async Task RemoveAndSave(MusicEndpoint endpoint) { // removes credential from credential store var vault = new PasswordVault(); var cred = GetCredential(vault.RetrieveAll(), endpoint); if (cred != null) { vault.Remove(cred); } await base.RemoveAndSave(endpoint); }
public MusicEndpoint(MusicEndpoint blueprint) { Id = blueprint.Id; Name = blueprint.Name; Protocol = blueprint.Protocol; CloudServerID = blueprint.CloudServerID; Server = blueprint.Server; Port = blueprint.Port; Username = blueprint.Username; Password = blueprint.Password; EndpointType = blueprint.EndpointType; }
private void ResetClient(MusicEndpoint endpoint) { Endpoint = endpoint; if (client != null) { Utils.Suppress <Exception>(client.Session.Dispose); client = null; } if (endpoint != null) { client = new SimpleAlarmClient(endpoint, DateTimeHelper.Instance); } }
/// <summary> /// /// </summary> /// <param name="endpoint"></param> /// <returns>the index of the added endpoint</returns> public async Task AddAndSave(MusicEndpoint endpoint) { var sameName = Endpoints.FirstOrDefault(e => e.Name == endpoint.Name); if (sameName != null) { ThrowAlreadyExists(endpoint.Name); } Endpoints.Add(endpoint); await persist(); OnEndpointAdded(endpoint); }
protected void SetEndpoint(MusicEndpoint newEndpoint) { try { ActivateEndpoint(newEndpoint); OnActiveEndpointChanged(newEndpoint); } catch (NotFoundException) { Send("Unable to connect to endpoint " + newEndpoint.Name); } catch (ServerResponseException sre) { Send(sre.Message); } catch (Exception ex) { Send("There's a problem with music endpoint " + newEndpoint.Name + ". Please check your settings. " + ex.Message); } }
protected override void ActivateEndpoint(MusicEndpoint newPlaybackEndpoint) { SetPlayer(BuildPlayer(newPlaybackEndpoint)); // if the player endpoint cannot receive music, it means it must be the source as well if (!newPlaybackEndpoint.CanReceiveMusic) { // LibraryManager is null when this is called from the superclass before the constructor is finished. // TODO fix this bullshit. if (LibraryManager != null) { LibraryManager.SetActive(newPlaybackEndpoint); } } }
public MusicEndpoint withNameOrElse(string name, MusicEndpoint orElse) { if (name == null || name == String.Empty) { return(orElse); } else { var tmp = Endpoints.FirstOrDefault(item => item.Name == name); if (tmp == null) { return(orElse); } else { return(tmp); } } }
public void AskForPasswordThenAdd(MusicEndpoint endpoint) { var passwordBox = new PasswordBox(); var passwordMessageBox = new CustomMessageBox() { Caption = "Password required", Message = "Found a MusicPimp server at " + endpoint.Server + ":" + endpoint.Port + ". Please enter the password.", Content = passwordBox, LeftButtonContent = "submit", RightButtonContent = "cancel" }; passwordMessageBox.Dismissed += async(s, e) => { switch (e.Result) { case CustomMessageBoxResult.LeftButton: var pass = passwordBox.Password; endpoint.Password = pass; try { await new PhonePimpSession(endpoint).PingAuth(); await AddAndSave(endpoint); PhoneLibraryManager.Instance.SetActive(endpoint); //Debug.WriteLine("Added endpoint: " + endpoint); } catch (UnauthorizedException) { ShowBox("Invalid password. No endpoint was added."); } catch (PimpException pe) { ShowBox(pe.Message); } catch (Exception) { ShowBox("An error occurred. Please try adding the endpoint manually."); } break; case CustomMessageBoxResult.RightButton: // user clicked cancel break; case CustomMessageBoxResult.None: break; } }; passwordMessageBox.Show(); }
public MusicLibrary BuildMusicLibrary(MusicEndpoint source) { switch (source.EndpointType) { case EndpointTypes.Local: return(LocalLibrary); case EndpointTypes.MusicPimp: case EndpointTypes.MusicPimpWeb: return(new MasterChildLibrary(Provider.NewPimpLibrary(source), Provider.LocalLibrary)); case EndpointTypes.PimpCloud: return(new MasterChildLibrary(new PimpLibrary(new CloudSession(source)), Provider.LocalLibrary)); case EndpointTypes.Subsonic: return(new SubsonicLibrary(new SubsonicSession(source))); default: throw new PimpException("Unsupported music library type: " + source.EndpointType); } }
public override Task AddOrUpdate(MusicEndpoint endpoint) { return(Endpoints.AddAndSave(endpoint)); }
public NewEndpoint() { EndpointItem = new MusicEndpoint(); MakeActiveLibrary = true; }
protected override void ActivateEndpoint(MusicEndpoint newAudioSource) { MusicProvider = BuildMusicLibrary(newAudioSource); }
public override void SetActive(MusicEndpoint endpoint) { Index = Endpoints.IndexOf(endpoint); }