private System.DateTime GetDeviceTime(DeviceClient client) { // Should compare recieved timestamp with local machine. If out of sync, authentication may fail SystemDateTime dt = client.GetSystemDateAndTime(); System.DateTime deviceTime = new System.DateTime(dt.UTCDateTime.Date.Year, dt.UTCDateTime.Date.Month, dt.UTCDateTime.Date.Day, dt.UTCDateTime.Time.Hour, dt.UTCDateTime.Time.Minute, dt.UTCDateTime.Time.Second); double offset = (deviceTime - System.DateTime.UtcNow).TotalSeconds; return(deviceTime); }
public static void MuestraInfo(string uri) { System.DateTime UTCTime = System.DateTime.UtcNow; Console.Write(string.Format("Client UTC Time: {0}", UTCTime.ToString("HH:mm:ss"))); HttpTransportBindingElement httpTransport = new HttpTransportBindingElement(); var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding); TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8); EndpointAddress serviceAddress = new EndpointAddress(uri); ChannelFactory <Device> channelFactory = new ChannelFactory <Device>(customBinding, serviceAddress); var passwordDigestBehavior = new PasswordDigestBehavior("julian", "julian"); channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); channelFactory.Endpoint.Behaviors.Add(passwordDigestBehavior); var deviceClient = new DeviceClient(customBinding, serviceAddress); deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior); var unitTime = deviceClient.GetSystemDateAndTime(); Console.Write((string.Format(" Camera UTC Time: {0}:{1}:{2}", unitTime.UTCDateTime.Time.Hour, unitTime.UTCDateTime.Time.Minute, unitTime.UTCDateTime.Time.Second))); ServiceReference1.CapabilityCategory[] cc = new ServiceReference1.CapabilityCategory[100]; deviceClient.GetCapabilities(cc); Console.Write(" GetHostname: " + deviceClient.GetHostname().Name); Console.Write(" GetWsdlUrl: " + deviceClient.GetWsdlUrl()); string model, firmwareVersion, serialNumber, hardwareId; deviceClient.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId); Console.Write(" Model: " + model); Console.Write(" firmwareVersion: " + firmwareVersion); Console.Write(" serialNumber: " + serialNumber); Console.WriteLine("hardwareId: " + hardwareId + "\n\n"); }
public static SystemDateTime GetCameraDate(Structures set) { var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic; CustomBinding bind = new CustomBinding(messageElement, httpBinding); EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/Device"); DeviceClient client = new DeviceClient(bind, mediaAddress); client.ClientCredentials.UserName.UserName = set.Login; client.ClientCredentials.UserName.Password = set.Password; return(client.GetSystemDateAndTime()); }
/// <summary> /// Get the device time. Per spec, the time in the Onvif header must be within 5 seconds of the device time /// Some devices will fail to authenticate or accept commands if the timestamp difference is too great /// </summary> /// <param name="ip">IP Address</param> /// <param name="onvifPort">Port to connect on (normally HTTP - 80)</param> public void GetDeviceTime(Camera cam, int onvifPort) { DeviceClient client = OnvifServices.GetOnvifDeviceClient(cam.IP, onvifPort, deviceTimeOffset: 0); SystemDateTime deviceTime = client.GetSystemDateAndTime(); DeviceTime = new System.DateTime( deviceTime.UTCDateTime.Date.Year, deviceTime.UTCDateTime.Date.Month, deviceTime.UTCDateTime.Date.Day, deviceTime.UTCDateTime.Time.Hour, deviceTime.UTCDateTime.Time.Minute, deviceTime.UTCDateTime.Time.Second ); LastTimeCheck = System.DateTime.UtcNow; DeviceTimeOffset = (DeviceTime - LastTimeCheck).TotalSeconds; if (Math.Abs(DeviceTimeOffset) > MaxTimeOffset) { log.Warn(string.Format("Camera #{0} [{1}] Time difference between PC and client [{2:0.0} seconds] exceeds MaxTimeOffset [{3:0.0} seconds]. ", cam.Number, cam.IP, DeviceTimeOffset, MaxTimeOffset)); } }
public static void MuestraInfoTest(string uri) { System.DateTime UTCTime = System.DateTime.UtcNow; Console.Write(string.Format("Client UTC Time: {0}", UTCTime.ToString("HH:mm:ss"))); HttpTransportBindingElement httpTransport = new HttpTransportBindingElement(); var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Anonymous }; var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding); EndpointAddress serviceAddress = new EndpointAddress(uri); var deviceClient = new DeviceClient(customBinding, serviceAddress); Console.Write(" GetHostname: " + deviceClient.GetHostname().Name); var unitTime = deviceClient.GetSystemDateAndTime(); Console.Write((string.Format(" Camera UTC Time: {0}:{1}:{2}", unitTime.UTCDateTime.Time.Hour, unitTime.UTCDateTime.Time.Minute, unitTime.UTCDateTime.Time.Second))); CapabilityCategory[] cc = new CapabilityCategory[100]; deviceClient.GetCapabilities(cc); Console.Write(" GetHostname: " + deviceClient.GetHostname().Name); Console.Write(" GetWsdlUrl: " + deviceClient.GetWsdlUrl()); string model, firmwareVersion, serialNumber, hardwareId; deviceClient.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId); Console.Write(" Model: " + model); Console.Write(" firmwareVersion: " + firmwareVersion); Console.Write(" serialNumber: " + serialNumber); Console.WriteLine("hardwareId: " + hardwareId + "\n\n"); }
private System.DateTime GetDeviceTime(DeviceClient client) { // Should compare recieved timestamp with local machine. If out of sync, authentication may fail SystemDateTime dt = client.GetSystemDateAndTime(); System.DateTime deviceTime = new System.DateTime(dt.UTCDateTime.Date.Year, dt.UTCDateTime.Date.Month, dt.UTCDateTime.Date.Day, dt.UTCDateTime.Time.Hour, dt.UTCDateTime.Time.Minute, dt.UTCDateTime.Time.Second); File.AppendAllText("info.txt", string.Format("\n\nDate and Time from: {0}:{1} [UTC Date: {2}, UTC Time: {3}]", IP.ToString(), Port, deviceTime.Date.ToLongDateString(), deviceTime.TimeOfDay.ToString())); double offset = (deviceTime - System.DateTime.UtcNow).TotalSeconds; if (Math.Abs(offset) >= 5) { lblDeviceTime.ForeColor = System.Drawing.Color.Red; } else { lblDeviceTime.ForeColor = System.Drawing.Color.Black; } lblDeviceTime.Text = string.Format("Device Time: {0:u} ({1:0.0} sec)", deviceTime, offset); return(deviceTime); }
public IDeviceDateAndTime Get() { Parse(_client.GetSystemDateAndTime()); return(this); }