コード例 #1
0
        public void EnsurePositionCanBeCorrectlyParsedFromXml()
        {
            var statusFile = TestUtilities.GetTestFile("status.xml");
            var statusXml = File.ReadAllText(statusFile.FullName);

            var statusSource = MockRepository.GenerateMock<IVlcStatusSource>();
            statusSource.Expect(x => x.GetXml()).Return(statusXml);

            var parser = new StatusParser
            {
                Xml = statusXml
            };
            parser.Parse();
            Assert.AreEqual(0.01635168120265, parser.Position);
        }
コード例 #2
0
ファイル: VlcJob.cs プロジェクト: PlumpMath/VlcDriver
        public void UpdateProgress()
        {
            if (State != JobState.Started)
            {
                return;
            }
            //Todo, Error handling

            var statusUrl = string.Format("http://localhost:{0}/requests/status.xml", AllocatedPort);

            StatusSource.Url = statusUrl;

            string xml = string.Empty;

            try
            {
                xml = StatusSource.GetXml();
            }
            catch (WebException ex)
            {
                logger.Warn(ex, string.Format("Could not connect to vlc http service to get position, Looking in {0}", statusUrl));
                return;
            }

            StatusParser.Xml = xml;
            StatusParser.Parse();
            PercentComplete = StatusParser.Position;

            var startTimeUtc     = Instance.StartTime.ToUniversalTime();
            var now              = TimeSouce.getDateTime.ToUniversalTime();
            var elapsed          = now - startTimeUtc;
            var percentPerSecond = PercentComplete / elapsed.TotalSeconds;

            if (Math.Abs(percentPerSecond) < 0.001)
            {
                EstimatedTimeToCompletion = new TimeSpan(0, 0, 0);
            }
            else
            {
                var secondsToCompletion = (1 - PercentComplete) / percentPerSecond;
                EstimatedTimeToCompletion = TimeSpan.FromSeconds(secondsToCompletion);
            }
        }