示例#1
0
        public async Task <AsyncResult <MediaItem> > StartTimeshiftAsync(int slotIndex, IChannel channel)
        {
            Channel indexChannel = channel as Channel;

            if (indexChannel == null || !CheckConnection(indexChannel.ServerIndex))
            {
                return(new AsyncResult <MediaItem>(false, null));
            }

            try
            {
                ITVAccessService tvServer  = TvServer(indexChannel.ServerIndex);
                String           streamUrl = _tvServers[indexChannel.ServerIndex].IsLocalConnection ?
                                             // Prefer local timeshift file over RTSP streaming
                                             tvServer.SwitchTVServerToChannelAndGetTimeshiftFilename(GetTimeshiftUserName(slotIndex), channel.ChannelId) :
                                             tvServer.SwitchTVServerToChannelAndGetStreamingUrl(GetTimeshiftUserName(slotIndex), channel.ChannelId);

                if (String.IsNullOrEmpty(streamUrl))
                {
                    return(new AsyncResult <MediaItem>(false, null));
                }

                _channels[slotIndex] = channel;

                // assign a MediaItem, can be null if streamUrl is the same.
                var timeshiftMediaItem = CreateMediaItem(slotIndex, streamUrl, channel);
                return(new AsyncResult <MediaItem>(true, timeshiftMediaItem));
            }
            catch (Exception ex)
            {
                NotifyException(ex, indexChannel.ServerIndex);
                return(new AsyncResult <MediaItem>(false, null));
            }
        }
示例#2
0
        public async Task <bool> RemoveScheduleForProgramAsync(IProgram program, ScheduleRecordingType recordingType)
        {
            Program indexProgram = program as Program;

            if (indexProgram == null)
            {
                return(false);
            }

            if (!CheckConnection(indexProgram.ServerIndex))
            {
                return(false);
            }

            try
            {
                ITVAccessService tvAccessService = TvServer(indexProgram.ServerIndex);
                if (recordingType == ScheduleRecordingType.Once)
                {
                    return(tvAccessService.CancelSchedule(program.ProgramId));
                }

                // TODO: find matching schedule? return tvAccessService.DeleteSchedule(indexProgram);
                return(false);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        private void ScanForRequiredLogos()
        {
            ITVAccessService tas = TVAccessService.Instance;

            if (!tas.TestConnectionToTVService())
            {
                return;
            }
            channelLogosRequired = tas.GetChannelsBasic()
                                   .Where(ch => logos.FindLocation(ch.Title) == null)
                                   .ToList();
        }
示例#4
0
        public async Task <AsyncResult <IList <ISchedule> > > GetSchedulesAsync()
        {
            // TODO: lookup by ID cannot guess which server might be adressed, so we force the first one.
            int serverIndex = 0;

            if (!CheckConnection(serverIndex))
            {
                return(new AsyncResult <IList <ISchedule> >(false, null));
            }

            try
            {
                ITVAccessService tvAccessService = TvServer(serverIndex);
                var webSchedules = tvAccessService.GetSchedules();
                var schedules    = webSchedules.Select(s => new Schedule(s, serverIndex)).Cast <ISchedule>().ToList();
                return(new AsyncResult <IList <ISchedule> >(true, schedules));
            }
            catch
            {
                return(new AsyncResult <IList <ISchedule> >(false, null));
            }
        }
示例#5
0
            public void CreateChannel()
            {
                Binding         binding;
                EndpointAddress endpointAddress;
                bool            useAuth = !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);

                IsLocalConnection = IsLocal(ServerName);
                if (IsLocalConnection)
                {
                    endpointAddress = new EndpointAddress("net.pipe://localhost/MPExtended/TVAccessService");
                    binding         = new NetNamedPipeBinding {
                        MaxReceivedMessageSize = 10000000
                    };
                }
                else
                {
                    endpointAddress = new EndpointAddress(string.Format("http://{0}:4322/MPExtended/TVAccessService", ServerName));
                    BasicHttpBinding basicBinding = new BasicHttpBinding {
                        MaxReceivedMessageSize = 10000000
                    };
                    if (useAuth)
                    {
                        basicBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                        basicBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                    }
                    basicBinding.ReaderQuotas.MaxStringContentLength = 5 * 1024 * 1024; // 5 MB
                    binding = basicBinding;
                }
                binding.OpenTimeout = TimeSpan.FromSeconds(5);
                Factory             = new ChannelFactory <ITVAccessService>(binding);
                if (Factory.Credentials != null && useAuth)
                {
                    Factory.Credentials.UserName.UserName = Username;
                    Factory.Credentials.UserName.Password = Password;
                }
                TvServer = Factory.CreateChannel(endpointAddress);
            }
示例#6
0
        public async Task <bool> RemoveScheduleAsync(ISchedule schedule)
        {
            Schedule indexSchedule = schedule as Schedule;

            if (indexSchedule == null)
            {
                return(false);
            }

            if (!CheckConnection(indexSchedule.ServerIndex))
            {
                return(false);
            }

            try
            {
                ITVAccessService tvAccessService = TvServer(indexSchedule.ServerIndex);
                return(tvAccessService.DeleteSchedule(indexSchedule.ScheduleId));
            }
            catch
            {
                return(false);
            }
        }
示例#7
0
        private void Init()
        {
            // load list of channel logos that we don't have yet
            logos = new ChannelLogos();
            ITVAccessService tas = TVAccessService.Instance;

            if (!tas.TestConnectionToTVService())
            {
                return;
            }
            channelLogosRequired = tas.GetChannelsBasic()
                                   .Where(ch => logos.FindLocation(ch.Title) == null)
                                   .ToList();

            // exit if we already got all logos
            if (channelLogosRequired.Count == 0)
            {
                Log.Trace("All channel logos already available, not downloading any...");
                return;
            }

            // try downloading them on starting and exit if successful
            if (PerformCheck())
            {
                return;
            }

            // setup timer
            backgroundTimer = new Timer()
            {
                AutoReset = true,
                Interval  = 60 * 60 * 1000,
            };
            backgroundTimer.Elapsed += new ElapsedEventHandler(TimerElapsed);
            backgroundTimer.Start();
        }
        public bool GetSchedules(out IList <ISchedule> schedules)
        {
            schedules = new List <ISchedule>();

            // TODO: lookup by ID cannot guess which server might be adressed, so we force the first one.
            int serverIndex = 0;

            if (!CheckConnection(serverIndex))
            {
                return(false);
            }

            try
            {
                ITVAccessService tvAccessService = TvServer(serverIndex);
                var webSchedules = tvAccessService.GetSchedules();
                schedules = webSchedules.Select(s => new Schedule(s, serverIndex)).Cast <ISchedule>().ToList();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
示例#9
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            if (CURRENT_IP == "127.0.0.1" || CURRENT_IP == "localhost")
            {
                mWebStreamClient = ChannelFactory <IWebStreamingService> .CreateChannel(new NetNamedPipeBinding()
                {
                    MaxReceivedMessageSize = 10000000
                }, new EndpointAddress("net.pipe://localhost/MPExtended/StreamingService"));

                mStreamClient = ChannelFactory <IStreamingService> .CreateChannel(new NetNamedPipeBinding()
                {
                    MaxReceivedMessageSize = 10000000
                }, new EndpointAddress("net.pipe://localhost/MPExtended/StreamingService"));

                mServiceClient = ChannelFactory <IMediaAccessService> .CreateChannel(new NetNamedPipeBinding()
                {
                    MaxReceivedMessageSize = 10000000
                }, new EndpointAddress("net.pipe://localhost/MPExtended/MediaAccessService"));

                mTvClient = ChannelFactory <ITVAccessService> .CreateChannel(new NetNamedPipeBinding()
                {
                    MaxReceivedMessageSize = 10000000
                }, new EndpointAddress("net.pipe://localhost/MPExtended/TVAccessService"));
            }
            else
            {
#pragma warning disable 0162
                mWebStreamClient = ChannelFactory <IWebStreamingService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/StreamingService"));

                mStreamClient = ChannelFactory <IStreamingService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/StreamingService"));

                mServiceClient = ChannelFactory <IMediaAccessService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/MediaAccessService"));

                mTvClient = ChannelFactory <ITVAccessService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/TVAccessService"));

#pragma warning restore 0162
            }

            Log("Initialized");

            // providers
            var config = mServiceClient.GetServiceDescription();
            movieProvider = config.AvailableMovieLibraries.First().Id;
            fileProvider  = config.AvailableFileSystemLibraries.First().Id;

            // load movies
            try
            {
                cbMovies.Items.Clear();
                mMovies = mServiceClient.GetMoviesDetailed(movieProvider, null, null);
                foreach (WebMovieDetailed movie in mMovies)
                {
                    cbMovies.Items.Add(movie.Title);
                }

                Log("Loaded movies");
            }
            catch (Exception)
            {
                Log("Failed to connect to MAS");
            }

            // load chanels
            try
            {
                cbChannels.Items.Clear();
                mChannels = new List <WebChannelBasic>();
                foreach (WebChannelGroup group in mTvClient.GetGroups())
                {
                    WebChannelBasic[] channels = mTvClient.GetChannelsBasic(group.Id).ToArray();
                    foreach (WebChannelBasic ch in channels)
                    {
                        cbChannels.Items.Add(ch.Title);
                        mChannels.Add(ch);
                    }
                }
                Log("Loaded channels");
            }
            catch (Exception)
            {
                Log("Failed to connect to TV4Home");
            }

            // load profiles
            try
            {
                cbProfiles.Items.Clear();
                mProfiles = mWebStreamClient.GetTranscoderProfiles();
                foreach (WebTranscoderProfile profile in mProfiles)
                {
                    cbProfiles.Items.Add(profile.Name);
                }
                cbProfiles.SelectedIndex = 0;
            }
            catch (Exception)
            {
                Log("Failed to load profiles");
            }
        }
 public void CreateChannel()
 {
     Binding binding;
     EndpointAddress endpointAddress;
     bool useAuth = !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);
     if (IsLocal(ServerName))
     {
       endpointAddress = new EndpointAddress("net.pipe://localhost/MPExtended/TVAccessService");
       binding = new NetNamedPipeBinding { MaxReceivedMessageSize = 10000000 };
     }
     else
     {
       endpointAddress = new EndpointAddress(string.Format("http://{0}:4322/MPExtended/TVAccessService", ServerName));
       BasicHttpBinding basicBinding = new BasicHttpBinding { MaxReceivedMessageSize = 10000000 };
       if (useAuth)
       {
     basicBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
     basicBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
       }
       binding = basicBinding;
     }
     binding.OpenTimeout = TimeSpan.FromSeconds(5);
     ChannelFactory<ITVAccessService> factory = new ChannelFactory<ITVAccessService>(binding);
     if (factory.Credentials != null && useAuth)
     {
       factory.Credentials.UserName.UserName = Username;
       factory.Credentials.UserName.Password = Password;
     }
     TvServer = factory.CreateChannel(endpointAddress);
 }
示例#11
0
 public void SetAsInstance()
 {
     Instance = this;
 }
示例#12
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            if (CURRENT_IP == "127.0.0.1" || CURRENT_IP == "localhost")
            {

                mWebStreamClient = ChannelFactory<IWebStreamingService>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/MPExtended/StreamingService"));
                mStreamClient = ChannelFactory<IStreamingService>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/MPExtended/StreamingService"));
                mServiceClient = ChannelFactory<IMediaAccessService>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/MPExtended/MediaAccessService"));
                mTvClient = ChannelFactory<ITVAccessService>.CreateChannel(new NetNamedPipeBinding() { MaxReceivedMessageSize = 10000000 }, new EndpointAddress("net.pipe://localhost/MPExtended/TVAccessService"));
            }
            else
            {
            #pragma warning disable 0162
                mWebStreamClient = ChannelFactory<IWebStreamingService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/StreamingService"));
                mStreamClient = ChannelFactory<IStreamingService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/StreamingService"));
                mServiceClient = ChannelFactory<IMediaAccessService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/MediaAccessService"));
                mTvClient = ChannelFactory<ITVAccessService>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://" + CURRENT_IP + ":4321/MPExtended/TVAccessService"));
            #pragma warning restore 0162
            }

            Log("Initialized");

            // providers
            var config = mServiceClient.GetServiceDescription();
            movieProvider = config.AvailableMovieLibraries.First().Id;
            fileProvider = config.AvailableFileSystemLibraries.First().Id;

            // load movies
            try
            {
                cbMovies.Items.Clear();
                mMovies = mServiceClient.GetAllMoviesDetailed(movieProvider, null, null);
                foreach (WebMovieDetailed movie in mMovies)
                {
                    cbMovies.Items.Add(movie.Title);
                }

                Log("Loaded movies");
            }
            catch (Exception)
            {
                Log("Failed to connect to MAS");
            }

            // load chanels
            try
            {
                cbChannels.Items.Clear();
                mChannels = new List<WebChannelBasic>();
                foreach (WebChannelGroup group in mTvClient.GetGroups())
                {
                    WebChannelBasic[] channels = mTvClient.GetChannelsBasic(group.Id).ToArray();
                    foreach (WebChannelBasic ch in channels)
                    {
                        cbChannels.Items.Add(ch.DisplayName);
                        mChannels.Add(ch);
                    }
                }
                Log("Loaded channels");
            }
            catch (Exception)
            {
                Log("Failed to connect to TV4Home");
            }

            // load profiles
            try
            {
                cbProfiles.Items.Clear();
                mProfiles = mWebStreamClient.GetTranscoderProfiles();
                foreach (WebTranscoderProfile profile in mProfiles)
                {
                    cbProfiles.Items.Add(profile.Name);
                }
                cbProfiles.SelectedIndex = 0;
            }
            catch (Exception)
            {
                Log("Failed to load profiles");
            }
        }
示例#13
0
 public void SetAsInstance()
 {
     Instance = this;
 }