Пример #1
0
        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);
            }
        }
Пример #2
0
 private void OnBeforeRemoval(MusicEndpoint e)
 {
     if (BeforeRemoval != null)
     {
         BeforeRemoval(e);
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
 private void OnActiveEndpointChanged(MusicEndpoint newEndpoint)
 {
     if (ActiveEndpointChanged != null)
     {
         ActiveEndpointChanged(newEndpoint);
     }
 }
Пример #5
0
 private Task UnsubscribeFromPush(MusicEndpoint endpoint)
 {
     return(UnsubscribeFromPush(new List <MusicEndpoint>()
     {
         Endpoint
     }));
 }
Пример #6
0
        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();
            }
        }
Пример #7
0
 private void OnEndpointRemoved(MusicEndpoint e)
 {
     if (EndpointRemoved != null)
     {
         EndpointRemoved(e);
     }
 }
Пример #8
0
 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!");
     }
 }
Пример #9
0
 private void OnEndpointModified(MusicEndpoint e)
 {
     if (EndpointModified != null)
     {
         EndpointModified(e);
     }
 }
Пример #10
0
        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);
        }
Пример #11
0
        public virtual async Task SubmitEndpoint(MusicEndpoint endpoint)
        {
            await AddOrUpdate(endpoint);

            if (MakeActiveLibrary)
            {
                LibraryManager.SetActive(endpoint);
            }
        }
Пример #12
0
        public virtual async Task RemoveAndSave(MusicEndpoint endpoint)
        {
            OnBeforeRemoval(endpoint);
            Endpoints.Remove(endpoint);
            // TODO remove credential from vault
            await persist();

            OnEndpointRemoved(endpoint);
        }
Пример #13
0
        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);
            }
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
 public EditEndpoint(string endpointName)
 {
     EndpointItem = Endpoints.Endpoints.FirstOrDefault(item => item.Name == endpointName);
     if (EndpointItem == null)
     {
         EndpointItem = new MusicEndpoint();
     }
     MakeActiveLibrary = false;
     Update();
 }
Пример #16
0
        /// <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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        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);
        }
Пример #19
0
 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;
 }
Пример #20
0
 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);
     }
 }
Пример #21
0
        /// <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);
        }
Пример #22
0
 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);
     }
 }
Пример #23
0
 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);
         }
     }
 }
Пример #24
0
 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);
         }
     }
 }
Пример #25
0
        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();
        }
Пример #26
0
        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);
            }
        }
Пример #27
0
 public override Task AddOrUpdate(MusicEndpoint endpoint)
 {
     return(Endpoints.AddAndSave(endpoint));
 }
Пример #28
0
 public NewEndpoint()
 {
     EndpointItem      = new MusicEndpoint();
     MakeActiveLibrary = true;
 }
Пример #29
0
 protected override void ActivateEndpoint(MusicEndpoint newAudioSource)
 {
     MusicProvider = BuildMusicLibrary(newAudioSource);
 }
Пример #30
0
 public override void SetActive(MusicEndpoint endpoint)
 {
     Index = Endpoints.IndexOf(endpoint);
 }