public async Task <TivoConnection> GetConnectionAsync()
        {
            if (this.connection == null)
            {
                var localConnection = new TivoConnection();

                var serviceProvider = TivoServiceProvider.VirginMediaUK;

                try
                {
                    if (this.IsAwayModeEnabled)
                    {
                        await localConnection.ConnectAway(TivoUsername, TivoPassword, serviceProvider, TivoCertificateStore.Instance);
                    }
                    else
                    {
                        await localConnection.Connect(TivoIPAddress, TivoMak, serviceProvider, TivoCertificateStore.Instance);
                    }

                    this.connection = localConnection;

                    NotifyOfPropertyChange(() => IsConnected);
                }
                catch (Exception)
                {
                    localConnection.Dispose();
                    throw;
                }
            }

            return(this.connection);
        }
Beispiel #2
0
 private void GetNowPlaying(string hmoServer, string mediaAccessKey, Application app)
 {
     _connection = new TivoConnection(hmoServer, mediaAccessKey);
     _connection.Open();
     _query = _connection.CreateContainerQuery("/NowPlaying").Recurse();
     _query.BeginExecute(QueryUsage, app);
     //_connection.BeginQueryContainer("/NowPlaying", true, QueryUsage, app);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            string videoName = null;

            if (args.Length != 0)
            {
                videoName = args[0];
            }

            DiscoveryBeacon.Start();
            string hmoServer = DiscoveryBeacon.GetServer(tivoName, TimeSpan.FromSeconds(65));

            using (TivoConnection connection = new TivoConnection(hmoServer, mak))
            {
                connection.Open();
                var query = connection.CreateContainerQuery("/NowPlaying")
                            .Recurse();
                var container = query.Execute();

                if (videoName == null) // no name, so just download the first video that can be downloaded
                {
                    var video = (from v in container.TivoItems.OfType <TivoVideo>()
                                 where v.CustomIcon == null || v.CustomIcon.Uri.AbsoluteUri != "urn:tivo:image:in-progress-recording"
                                 select v).First();
                    connection.GetDownloader(video).DownloadFile("downloaded.tivo");
                }
                else
                {
                    ContentDownloader downloader = null;
                    while (downloader == null)
                    {
                        var namedVideos = from video in container.TivoItems.OfType <TivoVideo>()
                                          where video.Name == videoName
                                          select video;
                        if (namedVideos.Any())
                        {
                            downloader = connection.GetDownloader(namedVideos.First());
                        }
                        else
                        {
                            query     = query.Skip(container.ItemStart + container.ItemCount);
                            container = query.Execute();
                        }
                    }
                    downloader.DownloadFile("downloaded.tivo");
                }
            }
        }
Beispiel #4
0
        private async Task ConnectAsync()
        {
            var localConnection = new TivoConnection();
            var serviceProvider = TivoServiceProvider.VirginMediaUK;

            try
            {
                await localConnection.ConnectAway(this.Username, this.Password, serviceProvider, TivoCertificateStore.Instance);

                this.MediaAccessKey = localConnection.MediaAccessKey;
                foreach (var body in localConnection.AssociatedTivos)
                {
                    this.AssociatedTivos.Add(body);
                }
            }
            catch (Exception)
            {
                localConnection.Dispose();
                throw;
            }
        }
        private async Task <TivoConnection> ConnectAsync(bool forceAwayMode)
        {
            if (!this.SettingsAppearValid ||
                !this.IsConnectionEnabled)
            {
                return(null);
            }

            using (this.progressService.Show())
            {
                this.isConnected = false;
                this.isAwayMode  = false;

                var localConnection = new TivoConnection();

                // TODO: detect this based on the Tivo mDNS data
                var service = TivoServiceProvider.VirginMediaUK;

                if (!forceAwayMode)
                {
                    var lanSettings = ConnectionSettings.KnownTivos
                                      .FirstOrDefault(x => x.TSN.Equals(ConnectionSettings.SelectedTivoTsn, StringComparison.Ordinal));

                    if (lanSettings != null &&
                        ConnectionSettings.LanSettingsAppearValid(lanSettings.LastIpAddress, lanSettings.MediaAccessKey) &&
                        lanSettings.NetworkName == this.ConnectedNetworkName)
                    {
                        try
                        {
                            await localConnection.Connect(lanSettings.LastIpAddress.ToString(), lanSettings.MediaAccessKey, service, TivoCertificateStore.Instance);

                            this.isConnected = true;
                            this.isAwayMode  = false;

                            Execute.BeginOnUIThread(() =>
                            {
                                var toast = new ToastPrompt()
                                {
                                    Title   = "Connected",
                                    Message = "Home Mode",
                                    MillisecondsUntilHidden = 600,
                                };

                                toast.Show();
                            });

                            this.analyticsService.ConnectedHomeMode();
                        }
                        catch (Exception ex)
                        {
                            this.Error = ex.Message;
                        }
                    }
                }

                if (!this.isConnected)
                {
                    try
                    {
                        await localConnection.ConnectAway(
                            ConnectionSettings.AwayModeUsername,
                            ConnectionSettings.AwayModePassword,
                            service,
                            TivoCertificateStore.Instance);

                        this.isConnected = true;
                        this.isAwayMode  = true;

                        Execute.BeginOnUIThread(() =>
                        {
                            var toast = new ToastPrompt()
                            {
                                Title   = "Connected",
                                Message = "Away Mode",
                                MillisecondsUntilHidden = 600,
                            };

                            toast.Show();
                        });

                        this.analyticsService.ConnectedAwayMode();
                    }
                    catch (Exception ex)
                    {
                        this.Error = ex.Message;
                    }
                }

                NotifyOfPropertyChange(() => IsConnected);
                NotifyOfPropertyChange(() => IsAwayMode);

                if (!this.isConnected)
                {
                    localConnection.Dispose();
                    localConnection = null;
                }

                return(localConnection);
            }
        }
        public async void TestLANConnection()
        {
            var connection = new TivoConnection();
            // TODO: Detect this
            var serviceProvider = TivoServiceProvider.VirginMediaUK;

            try
            {
                using (ShowProgress())
                {
                    await connection.Connect(this.LanSettings.LastIpAddress.ToString(), this.LanSettings.MediaAccessKey, serviceProvider, TivoCertificateStore.Instance);

                    if (!this.LanSettings.TSN.Equals(connection.ConnectedTsn, StringComparison.Ordinal))
                    {
                        this.LanSettings.TSN = connection.ConnectedTsn;
                    }

                    var knownTivosByTsn = ConnectionSettings.KnownTivos.ToDictionary(x => x.TSN);

                    knownTivosByTsn[connection.ConnectedTsn] = this.LanSettings;

                    ConnectionSettings.KnownTivos      = knownTivosByTsn.Values.ToArray();
                    ConnectionSettings.SelectedTivoTsn = connection.ConnectedTsn;

                    this.eventAggregator.Publish(new ConnectionSettingsChanged());
                }

                var toast = new ToastPrompt()
                {
                    Title           = "Connection succeeded",
                    Message         = "Home Mode",
                    TextOrientation = Orientation.Vertical,
                };

                toast.Show();
            }
            catch (ActionNotSupportedException)
            {
                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = "Network remote control not enabled on TiVo.",
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            catch (UnauthorizedAccessException)
            {
                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = "Incorrect Media Access Key",
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            catch (TivoException ex)
            {
                string message = ex.Message;

                if (ex.Code == "authenticationFailed")
                {
                    message = "Incorrect Media Access Key";
                }

                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = message,
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            catch (Exception)
            {
            }
            finally
            {
                connection.Dispose();
            }
        }
        public async void TestAwayConnection()
        {
            var connection = new TivoConnection();

            // TODO: Detect this
            var serviceProvider = TivoServiceProvider.VirginMediaUK;

            try
            {
                using (ShowProgress())
                {
                    await connection.ConnectAway(this.Username, this.Password, serviceProvider, TivoCertificateStore.Instance);

                    ConnectionSettings.AwayModeUsername = this.Username;
                    ConnectionSettings.AwayModePassword = this.Password;
                    this.eventAggregator.Publish(new ConnectionSettingsChanged());
                }

                var toast = new ToastPrompt()
                {
                    Title           = "Connection succeeded",
                    Message         = "Away Mode",
                    TextOrientation = Orientation.Vertical,
                };

                toast.Show();
            }
            catch (UnauthorizedAccessException)
            {
                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = "Invalid username or password",
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            catch (TivoException ex)
            {
                string message = ex.Message;

                if (ex.Code == "authenticationFailed")
                {
                    message = "Invalid username or password";
                }

                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = message,
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            catch (Exception ex)
            {
                var toast = new ToastPrompt()
                {
                    Title           = "Connection Failed",
                    Message         = ex.Message,
                    TextOrientation = Orientation.Vertical,
                    TextWrapping    = TextWrapping.Wrap,
                    Background      = new SolidColorBrush(Colors.Red),
                };

                toast.Show();
            }
            finally
            {
                connection.Dispose();
            }
        }