public async Task PullInputsAsync(System.Threading.CancellationToken cancellationToken) { if (m_DeviceIOPortClient == null) { return; } OnvifDevice.Capabilities capabilities = await this.m_onVifDevice.GetDeviceCapabilitiesAsync(); if (capabilities.Device.IO.InputConnectors == 0) { return; } try { while (!cancellationToken.IsCancellationRequested) { OnVifServices.OnvifDeviceIO10.GetDigitalInputsResponse inputresponse = await m_DeviceIOPortClient.GetDigitalInputsAsync(); foreach (var digital in inputresponse.DigitalInputs) { bool idlestate = digital.IdleStateSpecified; if (digital.IdleState == OnvifDeviceIO10.DigitalIdleState.closed) { } if (digital.IdleState == OnvifDeviceIO10.DigitalIdleState.open) { } { var @event = new DeviceRelaisEvent(); OnEventReceived(@event); } } } } catch (Exception ex) { m_ErrorMessage = ex.Message; } }
public async Task PullRelaisOutputsAsync(System.Threading.CancellationToken cancellationToken) { if (m_DeviceIOPortClient == null) { return; } OnvifDevice.Capabilities capabilities = await this.m_onVifDevice.GetDeviceCapabilitiesAsync(); try { while (!cancellationToken.IsCancellationRequested) { OnVifServices.OnvifDeviceIO10.GetDigitalInputsResponse inputresponse = await m_DeviceIOPortClient.GetDigitalInputsAsync(); OnVifServices.OnvifDeviceIO10.GetRelayOutputsResponse1 relayresponse = await m_DeviceIOPortClient.GetRelayOutputsAsync(); foreach (var digital in inputresponse.DigitalInputs) { if (digital.IdleState == OnvifDeviceIO10.DigitalIdleState.closed) { } if (digital.IdleState == OnvifDeviceIO10.DigitalIdleState.open) { } { var @event = new DeviceRelaisEvent(); OnEventReceived(@event); } } foreach (var relay in relayresponse.RelayOutputs) { // RelayLogicalState logigalstate = RelayLogicalState.active; // if (relay.. == OnvifMedia10.R.closed) OnVifServices.OnvifDeviceIO10.GetRelayOutputOptionsResponse relayoptions = await m_DeviceIOPortClient.GetRelayOutputOptionsAsync(relay.token); if (relay.Properties.IdleState == OnvifDeviceIO10.RelayIdleState.open) { OnVifServices.OnvifDeviceIO10.SetRelayOutputStateResponse resp = await m_DeviceIOPortClient.SetRelayOutputStateAsync(relay.token, OnvifDeviceIO10.RelayLogicalState.inactive); var @event = new DeviceRelaisEvent(); OnEventReceived(@event); } if (relay.Properties.IdleState == OnvifDeviceIO10.RelayIdleState.closed) { OnVifServices.OnvifDeviceIO10.SetRelayOutputStateResponse resp1 = await m_DeviceIOPortClient.SetRelayOutputStateAsync(relay.token, OnvifDeviceIO10.RelayLogicalState.active); var @event = new DeviceRelaisEvent(); OnEventReceived(@event); } } } } catch (Exception ex) { m_ErrorMessage = ex.Message; } }
public override async Task <bool> InitalizeAsync() { if (this.m_onVifDevice.ServicesResponse == null) { bool b = await this.m_onVifDevice.InitalizeDeviceAsync(); if (this.m_onVifDevice.ServicesResponse == null) { return(false); } } try { foreach (var service in this.m_onVifDevice.ServicesResponse.Service) { if (service.Namespace == "http://www.onvif.org/ver10/events/wsdl") { string serviceAdress = service.XAddr; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10); CustomBinding binding = new CustomBinding(messageElement, httpBinding); /* * this.m_EventPortTypeClient = new EventPortTypeClient(binding, new EndpointAddress($"http://{ this.m_onVifDevice.Hostname}/onvif/event_service")); * this.m_EventPortTypeClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); * CreatePullPointSubscriptionRequest request = new CreatePullPointSubscriptionRequest(); * request.InitialTerminationTime = "PT60S"; * request.SubscriptionPolicy = new CreatePullPointSubscriptionSubscriptionPolicy(); * * * m_PullPointResponse = await this.m_EventPortTypeClient.CreatePullPointSubscriptionAsync(request); * * * * * PullMessagesRequest message = new PullMessagesRequest("PT1S", 1024, null); * * await m_PullPointSubscriptionClient.PullMessagesAsync(message); * * GetEventPropertiesRequest eventrequest = new GetEventPropertiesRequest(); * m_EventPropertiesResponse =await this.m_EventPortTypeClient.GetEventPropertiesAsync(eventrequest); */ OnvifDevice.Capabilities response = await this.m_onVifDevice.GetDeviceCapabilitiesAsync(); NotificationConsumerClient consclient = new NotificationConsumerClient(binding, new EndpointAddress(serviceAdress)); consclient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); consclient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); OnvifEvent10.Notify request = new OnvifEvent10.Notify(); // await consclient.NotifyAsync(request); // await consclient.OpenAsync(); NotificationConsumerService _notificationConsumerService = new NotificationConsumerService(); // _notificationConsumerService.NewNotification += _notificationConsumerService_NewNotification; // ServiceHost _notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://localhost:8085/NotificationConsumerService")); // _notificationConsumerServiceHost.Open(); NotificationProducerClient client = new NotificationProducerClient(binding, new EndpointAddress(serviceAdress)); client.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); client.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); var subScribe = new Subscribe() { ConsumerReference = new EndpointReferenceType { Address = new AttributedURIType { Value = consclient.Endpoint.Address.Uri.ToString() }, } }; subScribe.InitialTerminationTime = "PT2H"; SubscribeResponse1 resp = await client.SubscribeAsync(subScribe); if ((response.Events != null) && response.Events.WSSubscriptionPolicySupport) { m_PullPointSubscriptionClient = new PullPointSubscriptionClient(binding, new EndpointAddress(serviceAdress)); m_SubscriptionManagerClient = new SubscriptionManagerClient(binding, new EndpointAddress(serviceAdress)); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); return(true); } else { // throw new DeviceEventReceiverException("Device doesn't support pull point subscription"); } if ((response.Events != null) && response.Events.WSPullPointSupport) { m_PullPointSubscriptionClient = new PullPointSubscriptionClient(binding, new EndpointAddress(serviceAdress)); m_SubscriptionManagerClient = new SubscriptionManagerClient(binding, new EndpointAddress(serviceAdress)); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); return(true); } else { throw new DeviceEventReceiverException("Device doesn't support pull point subscription"); } } } } catch (Exception ex) { m_ErrorMessage = ex.Message; return(false); } return(m_initialised); }