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();
        }
Beispiel #2
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");
            }
        }
Beispiel #3
0
        public DeviceClient(EndpointAddress epa, string username, string password)
        {
            EndPointAddress = epa;
            Username        = username;
            Password        = password;

            var httpBinding = new HttpTransportBindingElement
            {
                AuthenticationScheme = AuthenticationSchemes.Digest
            };

            var messageElement = new TextMessageEncodingBindingElement
            {
                MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
            };

            var bind = new CustomBinding(messageElement, httpBinding);

            Client = new Device.DeviceClient(bind, epa);
            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                Client.Endpoint.EndpointBehaviors.Add(new PasswordDigestBehavior(username, password));
            }
        }
Beispiel #4
0
        static async Task Main(string[] args)
        {
            // setup client
            var channel = new Channel("127.0.0.1", 8020, ChannelCredentials.Insecure);
            var cli     = new Device.DeviceClient(channel);

            // setup event polling
            var q      = new ConcurrentQueue <Event>();
            var cancel = new CancellationTokenSource();
            var t      = Task.Run(async() =>
            {
                using var enumerator = cli.GetEventStream(new Google.Protobuf.WellKnownTypes.Empty(), cancellationToken: cancel.Token);

                while (!cancel.IsCancellationRequested && await enumerator.ResponseStream.MoveNext())
                {
                    q.Enqueue(enumerator.ResponseStream.Current);
                }
            });

            try
            {
                // run user commands
                while (true)
                {
                    Console.Write("> ");
                    var command = Console.ReadLine();

                    if (command == "exit")
                    {
                        break;
                    }

                    if (command == "flush")
                    {
                        while (q.TryDequeue(out var ev))
                        {
                            Console.Write(ev.EventCase);
                            var pos = ev.ButtonClickEvent?.Button ?? ev.ButtonDownEvent?.Button ?? ev.ButtonUpEvent.Button;
                            Console.WriteLine($" {pos.X} {pos.Y}");
                        }
                    }
                    else if (command.StartsWith("label "))
                    {
                        var arguments = command.Substring(command.IndexOf(' ') + 1);
                        var xStr      = arguments.Substring(0, arguments.IndexOf(' '));
                        var x         = uint.Parse(xStr);
                        arguments = arguments.Substring(arguments.IndexOf(' ') + 1);
                        var yStr = arguments.Substring(0, arguments.IndexOf(' '));
                        var y    = uint.Parse(yStr);
                        arguments = arguments.Substring(arguments.IndexOf(' ') + 1);

                        await cli.SetButtonLabelAsync(new SetButtonLabelRequest { Button = new ButtonPos {
                                                                                      X = x, Y = y
                                                                                  }, Label = arguments });
                    }
                    else if (command == "info")
                    {
                        var meta = await cli.GetMetaAsync(new Google.Protobuf.WellKnownTypes.Empty());

                        Console.WriteLine(meta.DeviceId);
                        Console.WriteLine(meta.DeviceTypeId);
                        Console.WriteLine($"{meta.GridSize.Width}x{meta.GridSize.Height}");

                        foreach (var feature in meta.Features)
                        {
                            Console.Write("+ ");
                            switch (feature.FeatureCase)
                            {
                            case Meta.Types.Feature.FeatureOneofCase.ButtonLabelFeature:
                                Console.WriteLine($"label:{feature.ButtonLabelFeature.MaxLength}");
                                break;

                            case Meta.Types.Feature.FeatureOneofCase.ButtonDisplayFeature:
                                Console.WriteLine($"display:{feature.ButtonDisplayFeature.PreferredResolution.Width}x{feature.ButtonDisplayFeature.PreferredResolution.Height}");
                                break;

                            case Meta.Types.Feature.FeatureOneofCase.CustomGridFeature:
                                Console.WriteLine($"custom_grid:{feature.CustomGridFeature.MinSize.Width}x{feature.CustomGridFeature.MinSize.Height}:{feature.CustomGridFeature.MaxSize.Width}x{feature.CustomGridFeature.MaxSize.Height}");
                                break;

                            case Meta.Types.Feature.FeatureOneofCase.CustomFeature:
                                Console.WriteLine($"custom:{feature.CustomFeature.Name}");
                                break;

                            default:
                                Console.WriteLine("unknown feature");
                                break;
                            }
                        }
                    }
                }
            }
            finally
            {
                // cleanup
                cancel.Cancel();
                await t;
            }
        }
Beispiel #5
0
        static async Task Main(string[] args)
        {
            // setup client
            var channel = new Channel("127.0.0.1", 8020, ChannelCredentials.Insecure);
            var cli     = new Device.DeviceClient(channel);

            // setup event polling
            var q      = new ConcurrentQueue <Event>();
            var cancel = new CancellationTokenSource();
            var t      = Task.Run(async() =>
            {
                using var enumerator = cli.GetEventStream(new Google.Protobuf.WellKnownTypes.Empty(), cancellationToken: cancel.Token);

                while (!cancel.IsCancellationRequested && await enumerator.ResponseStream.MoveNext())
                {
                    q.Enqueue(enumerator.ResponseStream.Current);
                }
            });

            // run user commands
            while (true)
            {
                Console.Write("> ");
                var command = Console.ReadLine();

                if (command == "exit")
                {
                    break;
                }

                if (command == "flush")
                {
                    while (q.TryDequeue(out var ev))
                    {
                        Console.Write(ev.EventCase);
                        var pos = ev.ButtonClickEvent?.Button ?? ev.ButtonDownEvent?.Button ?? ev.ButtonUpEvent.Button;
                        Console.WriteLine($" {pos.X} {pos.Y}");
                    }
                }
                else if (command.StartsWith("label "))
                {
                    var arguments = command.Substring(command.IndexOf(' ') + 1);
                    var xStr      = arguments.Substring(0, arguments.IndexOf(' '));
                    var x         = uint.Parse(xStr);
                    arguments = arguments.Substring(arguments.IndexOf(' ') + 1);
                    var yStr = arguments.Substring(0, arguments.IndexOf(' '));
                    var y    = uint.Parse(yStr);
                    arguments = arguments.Substring(arguments.IndexOf(' ') + 1);

                    await cli.SetButtonLabelAsync(new SetButtonLabelRequest { Button = new ButtonPos {
                                                                                  X = x, Y = y
                                                                              }, Label = arguments });
                }
                else if (command == "info")
                {
                    var meta = await cli.GetMetaAsync(new Google.Protobuf.WellKnownTypes.Empty());

                    Console.WriteLine(meta.DeviceId);
                    Console.WriteLine(meta.DeviceTypeId);
                }
            }

            // cleanup
            cancel.Cancel();
            await t;
        }