private async Task<bool> CreatePlexServerConnection(string ipAddress)
        {
            var connection = new PlexServerConnection(_restConnection, ipAddress, _myPlexConnection.User);
            await connection.ConnectAsync();

            var needRebuild = false;

            lock (_syncObject)
            {
                if (!_serverConnections.ContainsKey(connection.MachineIdentifier))
                {
                    _serverConnections.Add(connection.MachineIdentifier, connection);
                    _plexServerConnections.Add(connection);
                    needRebuild = true;
                }
            }

            if (needRebuild)
            {
                await RebuildNowPlaying();
                UpdateConnections();
            }

            return connection.ConnectionStatus == ConnectionStatus.Connected;
        }
Example #2
0
        public async Task <bool> StopAsync()
        {
            if (PlexServerConnection != null)
            {
                return(await PlexServerConnection.StopVideoAsync(this));
            }

            return(false);
        }
Example #3
0
        static void Main()
        {
            Console.WriteLine("MyPlex connection:");
            var connectionHelper = new ConnectionHelper();

            IMyPlexConnection myPlexConnection = new MyPlexConnection(connectionHelper);

            myPlexConnection.ConnectAsync(TestConstants.MyPlexUserName, TestConstants.MyPlexPassword).Wait();

            var serversTask = myPlexConnection.CreateServerConnectionsAsync();

            serversTask.Wait();
            var servers = serversTask.Result;

            var server = servers.FirstOrDefault(s => s.IsOnLine);

            if (server != null)
            {
                Console.WriteLine();
                Console.WriteLine(server.Name);
                ShowNowPlaying(server);
                ShowClients(server);
            }

            // local connection
            Console.WriteLine();
            Console.WriteLine("Local server connection:");

            var localServer = new PlexServerConnection(connectionHelper, TestConstants.LocalServer);

            localServer.ConnectAsync().Wait();

            Console.WriteLine(localServer.Name);
            ShowNowPlaying(localServer);
            ShowClients(localServer);

            Console.ReadKey();
        }
        public async Task<IEnumerable<IPlexServerConnection>> CreateServerConnectionsAsync()
        {
            var serverConnections = new List<IPlexServerConnection>();

            List<Device> servers;

            lock (_deviceSyncObj)
                servers = Servers.ToList();

            foreach (var device in servers)
            {
                PlexServerConnection connection;

                lock (_deviceSyncObj)
                {
                    if (!_serverConnections.TryGetValue(device.Key, out connection))
                    {
                        connection = new PlexServerConnection(_restConnection, device, User);
                        _serverConnections.Add(device.Key, connection);
                    }
                }

                serverConnections.Add(connection);

                if (connection.User == null && User != null)
                    connection.User = User;

                if (connection.ConnectionStatus != Connection.ConnectionStatus.Connected)
                    await connection.ConnectAsync();
            }

            return serverConnections;
        }