Esempio n. 1
0
        private void fireOnNodeTree(VideoParser.Node tree, string xml)
        {
            OnNodeTree callback = NodeTreeEvent;

            if (callback != null)
            {
                callback(tree, xml);
            }
        }
Esempio n. 2
0
        private void updateTree(VideoParser.Node tree)
        {
            HashSet <ulong> servers             = new HashSet <ulong>();
            Dictionary <ulong, VideoInfo> infos = new Dictionary <ulong, VideoInfo>();

            getInfos(servers, infos, tree);

            lock (_videoInfos)
            {
                _videoInfos.Clear();
                foreach (var pair in infos)
                {
                    _videoInfos.Add(pair.Key, pair.Value);
                }
            }
        }
Esempio n. 3
0
        private void getInfos(HashSet <ulong> servers, Dictionary <ulong, VideoInfo> infos, VideoParser.Node node)
        {
            VideoParser.Server server = node as VideoParser.Server;
            if (server != null && !servers.Contains(server.Id))
            {
                servers.Add(server.Id);
                foreach (VideoParser.Node child in server.Childs)
                {
                    getInfos(servers, infos, child);
                }
            }

            VideoParser.Front front = node as VideoParser.Front;
            if (front != null)
            {
                DVRCustom custom = new DVRCustom()
                {
                    User = front.User,
                    Pass = front.Pass,
                    Port = front.Port,
                };
                _dvrCustoms[front.Id] = custom;

                int index = 1;
                foreach (VideoParser.Video video in front.Childs)
                {
                    getInfo(infos, video, front.Id, front.Host, front.Type, index);
                    index++;
                }
            }
        }
Esempio n. 4
0
        private void onMessage(byte[] message)
        {
            MessageReader reader = new MessageReader(message);

            MessageReader.StreamReader stream = reader.Reader;
            switch (reader.MessageID)
            {
            case 0x11017:     // Msg_NetCtrl_Nodebase_Name
                _serverName = stream.ReadString();
                break;

            case 0x11013:     // Msg_NetCtrl_User_Params
            {
                string user  = stream.ReadString();
                bool   valid = stream.ReadInt32() != 0;
                if (valid)
                {
                    if (!Ready)
                    {
                        _userStage  = stream.ReadInt32();
                        _userRights = stream.ReadInt32();
                        _serverID   = stream.ReadUInt64();
                        int len = stream.ReadInt32();
                        _userAuth = new ulong[len];
                        for (int i = 0; i < len; i++)
                        {
                            _userAuth[i] = stream.ReadUInt64();
                        }
                        Ready = true;
                        fireOnAuthentication(true);

                        sendGetRealtimeMessage();
                    }
                }
                else
                {
                    Ready = false;
                    cancelLoginChecker();
                    fireOnAuthentication(false);
                    _connection.Reconnect();
                }
            }
            break;

            case 0x11015:     // Msg_NetCtrl_ID
                _netctrlID = stream.ReadInt32();
                break;

            case 0x10030:     // Msg_Tree_Info
                break;

            case 0x10032:     // Msg_Xml_Tree
            {
                bool   up           = stream.ReadInt32() != 0;
                int    size         = stream.ReadInt32();
                int    uncompSize   = stream.ReadInt32();
                byte[] compressed   = stream.ReadBytes(size - sizeof(Int32));
                byte[] uncompressed = ZLibUtil.Uncompress(compressed, uncompSize);
                string xml          = Encoding.Default.GetString(uncompressed);
                if (xml.Last() == 0)
                {
                    xml = xml.Substring(0, xml.Length - 1);
                }

                VideoParser.Node tree = null;
                if (xml != _lastBaseXml && VideoParser.TryParseNode(xml, out tree))
                {
                    fireOnNodeTree(tree, xml);
                    _lastBaseXml = xml;
                    updateTree(tree);
                }
            }
            break;

            case 0x11021:     // Msg_Video_Port
            {
                ulong videoID   = stream.ReadUInt64();
                int   oldPort   = stream.ReadInt32();
                int   bandwidth = stream.ReadInt32();
                int   port      = stream.ReadInt32();
                fireOnVideoPort(videoID, port, bandwidth);
            }
            break;

            case 0x11022:     // Msg_Video_Miss
            {
                ulong videoID = stream.ReadUInt64();
                fireOnVideoMiss(videoID);
            }
            break;

            case 0x100B1:     //Msg_Realtime_Info
            {
                string             xml    = stream.ReadString();
                VideoParser.Camera camera = null;
                VideoParser.GPS    gps    = null;
                if (VideoParser.TryParseRealtime(xml, out camera) || VideoParser.TryParseRealtime(xml, out gps))
                {
                    fireOnRealtimeInfo(camera, gps);
                }
            }
            break;

            case 0x11028:     // Msg_Video_Ctrl
            {
                ulong videoId = stream.ReadUInt64();
                int   msgId   = stream.ReadInt32();
                onFeedbackMessage(videoId, msgId, reader);
            }
            break;
            }
        }