Exemplo n.º 1
0
 public ONVIFControl(Connection _form)
 {
     onvifdev          = new ONVIFDevice();
     _wsdUsernameToken = new wsdUsernameToken();
     _http             = new HttpControl();
     parentForm        = _form;
 }
Exemplo n.º 2
0
        public static String getLogStr(XmlDocument doc, ONVIFDevice _onvifdev)
        {
            String      log;
            ONVIFDevice onvifdev   = _onvifdev;
            XmlNodeList xnode_list = doc.GetElementsByTagName(onvifdev.devicePrefix + ":SystemLog");

            _onvifdev.systemlogNode = xnode_list[0]; /* get elements */

            foreach (XmlElement xelement in _onvifdev.systemlogNode)
            {
                log = xelement.FirstChild.Value;
                return(log);
            }

            return("error");
        }
Exemplo n.º 3
0
        public static ONVIFDevice findAllXAddr(XmlDocument doc, ONVIFDevice _onvifdev)
        {
            ONVIFDevice onvifdev   = _onvifdev;
            XmlNodeList xnode_list = doc.GetElementsByTagName(onvifdev.devicePrefix + ":Capabilities");

            _onvifdev.profilesNode = xnode_list[0]; /* capabilities elements */

            foreach (XmlElement xelement in _onvifdev.profilesNode)
            {
                String[] attribute = xelement.Name.Split(':');
                String   tag       = attribute[attribute.Length - 1];

                switch (tag)
                {
                case "Analytics":
                    onvifdev.analysticxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Device":
                    onvifdev.devicexaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Events":
                    onvifdev.eventxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Imaging":
                    onvifdev.imagexaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Media":
                    onvifdev.mediaxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Extension":
                {
                    XmlNodeList xnode_extension = xelement.ChildNodes;
                    foreach (XmlNode xnode in xnode_extension)
                    {
                        String[] _attr = xnode.Name.Split(':');
                        String   _tag  = _attr[_attr.Length - 1];
                        switch (_tag)
                        {
                        case "DeviceIO":
                            onvifdev.devioxaddr = xnode.FirstChild.FirstChild.Value;
                            break;

                        case "Recording":
                            onvifdev.recordxaddr = xnode.FirstChild.FirstChild.Value;
                            break;

                        case "Search":
                            onvifdev.searchxaddr = xnode.FirstChild.FirstChild.Value;
                            break;

                        case "Replay":
                            onvifdev.replayxaddr = xnode.FirstChild.FirstChild.Value;
                            break;

                        default:
                            break;
                        }
                    }
                }
                break;

                case "DeviceIO":
                    onvifdev.devioxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Recording":
                    onvifdev.recordxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Search":
                    onvifdev.searchxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                case "Replay":
                    onvifdev.replayxaddr = xelement.FirstChild.FirstChild.Value;
                    break;

                default:
                    break;
                }
            }
            return(onvifdev);
        }
Exemplo n.º 4
0
        public void ONVIF_GetCapabilities()
        {
            setNonce();
            /* get synced-time using base time */
            baseDateTime = DigestPassword.getCurrentTime(startDate, baseDateTime);
            /* make createTime string */
            _wsdUsernameToken.Create = DigestPassword.getCreatedTimeString(baseDateTime);
            /* make digest password */
            //_wsdUsernameToken.Password = DigestPassword.getPasswordDigest("LKqI6G/AikKCQrN0zqZFlg==", "2010-09-16T07:50:45Z", "userpassword");
            _wsdUsernameToken.Password = DigestPassword.getPasswordDigest(_wsdUsernameToken.Nonce,
                                                                          _wsdUsernameToken.Create,
                                                                          _wsdUsernameToken.plainPassword);
            /* set packet */
            StringBuilder reqMessage = new StringBuilder();

            reqMessage.Append("<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">");
            reqMessage.Append("<s:Header>");
            reqMessage.Append("<Security ");
            reqMessage.Append("s:mustUnderstand=\"1\" ");
            reqMessage.Append("xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">");
            reqMessage.Append("<UsernameToken><Username>" + _wsdUsernameToken.Username + "</Username>");
            reqMessage.Append("<Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">" + _wsdUsernameToken.Password + "</Password>");
            reqMessage.Append("<Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + _wsdUsernameToken.Nonce + "</Nonce>");
            reqMessage.Append("<Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + _wsdUsernameToken.Create + "</Created>");
            reqMessage.Append("</UsernameToken></Security></s:Header>");
            reqMessage.Append("<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            reqMessage.Append("<GetCapabilities xmlns=\"http://www.onvif.org/ver10/device/wsdl\">");
            reqMessage.Append("<Category>All</Category></GetCapabilities></s:Body></s:Envelope>");

            /* encoding */
            byte[] reqMessageBinary = EncodingHelper.String2Byte(reqMessage.ToString());

            /* Get Url */
            String Url = deviceURL + "/onvif/device_service";

            try
            {
                _http.Connect(Url);
                _http.setONVIFHeader("\"http://www.onvif.org/ver10/device/wsdl/GetCapabilities\"");
                _http.Write(reqMessageBinary);

                String paramStr = _http.Read();
                parentForm.settbLogBox("\r\nFunction OK : " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n");

                /* parser soap response */
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(paramStr.ToString());

                XmlNamespaceManager xnamespace = XMLControl.getAllNamespaces(xdoc);
                onvifdev.schemaPrefix = xnamespace.LookupPrefix(ONVIFNamespace.schema);
                onvifdev.devicePrefix = xnamespace.LookupPrefix(ONVIFNamespace.device);

                /* get function xaddr in document */
                onvifdev = XMLControl.findAllXAddr(xdoc, onvifdev);
            }
            catch (XmlException xe)
            {
                parentForm.settbLogBox("\r\nXml Exception : " + xe.Message + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
            catch (WebException we)
            {
                parentForm.settbLogBox("\r\nWeb Exception : " + we.Message + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }