Пример #1
0
        public void FormatError()
        {
            // Arrange
            var xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><getplayerstatus status=\"ok\" time=\"1295900669\"><stream><base_time>1295899356</base_time><open_time>1295899356</open_time><end_time>1295901162</end_time></stream></getplayerstatus>";
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlText);

            // Act
            var actual = new NicoLiveInfo(xmlDoc, 1000);
        }
Пример #2
0
        public void Success()
        {
            // Arrange
            var xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><getplayerstatus status=\"ok\" time=\"1295900669\"><stream><base_time>1295899356</base_time><open_time>1295899356</open_time><end_time>1295901162</end_time><start_time>1295899362</start_time></stream></getplayerstatus>";
            var xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlText);

            // Act
            var actual = new NicoLiveInfo(xmlDoc, 1500);

            // Assert
            Assert.AreEqual(new DateTime(2011, 1, 24, 20, 24, 28), actual.ServerTime);
            Assert.AreEqual(new DateTime(2011, 1, 24, 20, 02, 36), actual.BaseTime);
            Assert.AreEqual(new DateTime(2011, 1, 24, 20, 02, 36), actual.OpenTime);
            Assert.AreEqual(new DateTime(2011, 1, 24, 20, 02, 42), actual.StartTime);
            Assert.AreEqual(new DateTime(2011, 1, 24, 20, 32, 42), actual.EndTime);
        }
Пример #3
0
        private void OnTick(Object obj)
        {
            if (this.IsStart == false) {
                return;
            }
            if (this.liveId == null) {
                return;
            }
            var stopwatch = new Stopwatch();
            stopwatch.Start();

            this.ConnectLiveInfoAsync(this.liveId, xmlDoc => {
                if (stopwatch.IsRunning) {
                    stopwatch.Stop();
                }

                try {
                    var rootNode = xmlDoc.SelectSingleNode(@"/getplayerstatus");
                    if (rootNode.Attributes["status"].Value != "ok") {
                        Debug.WriteLine("放送の情報を取得できませんでした。");
                        return;
                    };

                    if (this.OnSync != null) {
                        var liveInfo = new NicoLiveInfo(xmlDoc, stopwatch.ElapsedMilliseconds);
                        this.OnSync(liveInfo);
                        Debug.WriteLine("ニコ生サーバと同期しました。");
                    }
                } catch (XPathException) {
                    Debug.WriteLine("XMLの解析に失敗しました。");
                }
            });
        }