Esempio n. 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();
            }
        }
Esempio n. 2
0
        public static HttpClient BuildJsonClient(MusicEndpoint e)
        {
            var client = BuildClient(e);

            client.DefaultRequestHeaders.Accept.ParseAdd(HttpUtil.Json);
            return(client);
        }
Esempio n. 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));
        }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
 public static SimplePimpSession BuildSession(MusicEndpoint endpoint)
 {
     if (endpoint.EndpointType == EndpointTypes.PimpCloud)
     {
         return(new CloudSession(endpoint));
     }
     else
     {
         return(new SimplePimpSession(endpoint));
     }
 }
Esempio n. 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()));
 }
Esempio n. 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;
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
        }
Esempio n. 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();
 }
Esempio n. 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;
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 18
0
 public PimpSession NewBeamSession(MusicEndpoint e)
 {
     return(impl.NewBeamSession(e));
 }
Esempio n. 19
0
 public MusicLibrary NewPimpLibrary(MusicEndpoint e)
 {
     return(impl.NewPimpLibrary(e));
 }
Esempio n. 20
0
 public SimplePimpSession(MusicEndpoint settings, bool acceptCompression = true)
     : base(settings, JSONv18, acceptCompression)
 {
     SocketResource = PlaybackSocketResource;
     IsCloud        = settings.EndpointType == EndpointTypes.PimpCloud;
 }
Esempio n. 21
0
 public PhoneBeamSession(MusicEndpoint settings)
     : base(settings)
 {
     SocketResource = BeamPlayer.webSocketResource;
 }
Esempio n. 22
0
 public PimpSession NewBeamSession(MusicEndpoint e)
 {
     return(new StoreBeamSession(e));
 }
Esempio n. 23
0
 public StorePimpSession(MusicEndpoint e)
     : base(e)
 {
 }
Esempio n. 24
0
 public virtual AuthenticationHeaderValue AuthHeader(MusicEndpoint e)
 {
     return(AuthorizationHeader(e.Username, e.Password));
 }
Esempio n. 25
0
 public SubsonicSession(MusicEndpoint settings)
     : base(settings)
 {
 }
Esempio n. 26
0
 public PhonePimpSession(MusicEndpoint settings, bool acceptCompression = true)
     : base(settings, acceptCompression)
 {
 }
Esempio n. 27
0
 public SimpleAlarmClient(MusicEndpoint pimpEndpoint, IDateTimeHelper timeHelper) :
     this(BuildSession(pimpEndpoint), timeHelper)
 {
 }
Esempio n. 28
0
 public CloudSession(MusicEndpoint e)
     : base(e)
 {
     SocketResource = CloudPlaybackSocketResource;
 }
Esempio n. 29
0
 private void libraryManager_ActiveEndpointChanged(MusicEndpoint e)
 {
     NavigationContext.QueryString.Clear();
 }
Esempio n. 30
0
 public MusicLibrary NewPimpLibrary(MusicEndpoint e)
 {
     return(new PimpLibrary(new StorePimpSession(e)));
 }