Exemplo n.º 1
0
        private void ConnectBtn_Click(object sender, EventArgs e)
        {
            ProfilesListBox.Items.Clear();
            InfoLabel.Text = "";

            deviceUri = new UriBuilder("http:/onvif/device_service");
            string[] addr = IpAdressTextBox.Text.Split(':');
            deviceUri.Host = addr[0];
            if (addr.Length == 2)
            {
                deviceUri.Port = Convert.ToInt16(addr[1]);
            }

            System.ServiceModel.Channels.Binding binding;
            HttpTransportBindingElement          httpTransport = new HttpTransportBindingElement();

            httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest;
            binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8), httpTransport);


            Device.DeviceClient device   = new Device.DeviceClient(binding, new EndpointAddress(deviceUri.ToString()));
            Device.Service[]    services = device.GetServices(false);

            //TODO media 20
            //Device.Service xmedia = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver20/media/wsdl");
            Device.Service xmedia = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver10/media/wsdl");
            if (xmedia != null)
            {
                //TODO media 20
                //media = new Media.Ver20.Media2Client(binding, new EndpointAddress(deviceUri.ToString()));
                media = new Media.Ver10.MediaClient(binding, new EndpointAddress(deviceUri.ToString()));
                media.ClientCredentials.HttpDigest.ClientCredential.UserName = UsernameTextBox.Text;
                media.ClientCredentials.HttpDigest.ClientCredential.Password = PasswordTextBox.Text;
                media.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

                //TODO media 20
                //profiles = media.GetProfiles(null, null);
                profiles = media.GetProfiles();
                if (profiles != null)
                {
                    foreach (var p in profiles)
                    {
                        ProfilesListBox.Items.Add(p.Name);
                    }
                }
            }
            else
            {
                MessageBox.Show("No media was found.");
            }

            VideoPlayer.EndInit();
        }
Exemplo n.º 2
0
        private void SetupSystem()
        {
            try
            {
                System.ServiceModel.Channels.CustomBinding binding;
                Device_Client = CustomBindingsAndClients.GetClient(IPAddress, 80, 0, out binding, out deviceUri, userName, password);
                Device.Service[] service = Device_Client.GetServices(false);
                //Check if they contain media and that we have made contact TODO wrap in a try catch block
                Device.Service checkk_media = service.FirstOrDefault(s => s.Namespace == "");
                if (checkk_media != null)
                {
                    media_client = new Media2Client(binding, new EndpointAddress(deviceUri.ToString()));
                    media_client.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
                    media_client.ClientCredentials.HttpDigest.ClientCredential.Password = password;
                    media_client.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

                    //Get camera Profiles.
                    try
                    {
                        profiles = media_client.GetProfiles(null, null);
                    }
                    catch
                    {
                        //Do something
                    }
                    if (profiles != null)
                    {
                        foreach (var p in profiles)
                        {
                            listBox_Profiles.Add(p.Name);
                            //Confirmed: Profiles listed in box are a match to profiles setup on camera.
                        }
                    }
                }
            }
            catch
            {
                string            message = "You did not enter a valid IP address, username, or password?";
                string            caption = "Error Detected in Input";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;

                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
            }
        }
Exemplo n.º 3
0
        public void connectIPC()
        {
            try
            {
                Device.DeviceClient deviceClient = GetDeviceClient(ipad);
                Device.Service[]    services     = deviceClient.GetServices(false);
                Device.Service      xmedia       = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver10/media/wsdl");
                if (xmedia != null)
                {
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                (ThreadStart) delegate()
                    {
                        mediaClient = GetMediaClient();

                        profiles = GetProfiles(mediaClient);
                        Media.StreamSetup streamSetup = GetstreamSetup(mediaClient, profiles);
                        if (profiles != null)
                        {
                            foreach (var p in profiles)
                            {
                                if (combobox.Items.Contains(p.Name))
                                {
                                    break;
                                }
                                else
                                {
                                    this.Dispatcher.Invoke(() => { combobox.Items.Add(p.Name); });
                                }
                            }
                        }
                    });
                }

                combobox.SelectionChanged += new SelectionChangedEventHandler(listBox_SelectionChanged);
            }
            catch (Exception ex)
            { //System.Windows.MessageBox.Show(ex.ToString(), "aa");
            }
        }