Пример #1
0
		static IntegrationVideoStreamingClient CreateIntegrationVideoStreamingClient(RviSettings rviSettings)
		{
			var binding = new NetTcpBinding(SecurityMode.None);
			binding.TransferMode = TransferMode.Streamed;
			binding.OpenTimeout = TimeSpan.FromMinutes(10);
			binding.SendTimeout = TimeSpan.FromMinutes(10);
			binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
			binding.MaxReceivedMessageSize = Int32.MaxValue;
			binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
			binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
			binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
			binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
			binding.ReaderQuotas.MaxDepth = Int32.MaxValue;
			binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
			binding.Security.Mode = SecurityMode.None;
			binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
			binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
			binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
			var ip = rviSettings.Ip;
			var port = rviSettings.Port;
			var login = rviSettings.Login;
			var password = rviSettings.Password;
			var endpointAddress = new EndpointAddress(new Uri("net.tcp://" + ip + ":" + port + "/IntegrationVideoStreaming"));

			var client = new IntegrationVideoStreamingClient(binding, endpointAddress);
			return client;
		}
Пример #2
0
		public SystemConfiguration()
		{
			Sounds = new List<Sound>();
			JournalFilters = new List<JournalFilter>();
			EmailData = new EmailData();
			AutomationConfiguration = new AutomationConfiguration();
			RviSettings = new RviSettings();
			RviServers = new List<RviServer>();
			RviDevices = new List<RviDevice>();
			Cameras = new List<Camera>();
			Zones = new HierarchicalCollection<GKZone>();
		}
Пример #3
0
		public RviSettingsViewModel(RviSettings rviSettings)
		{
			Title = "Настройки";
			RviSettings = rviSettings;
			Ip = rviSettings.Ip;
			Port = rviSettings.Port;
			Login = rviSettings.Login;
			Password = rviSettings.Password;
			VideoWidth = rviSettings.VideoWidth.ToString();
			VideoHeight = rviSettings.VideoHeight.ToString();
			VideoMarginLeft = rviSettings.VideoMarginLeft.ToString();
			VideoMarginTop = rviSettings.VideoMarginTop.ToString();
		}
Пример #4
0
		public static void OpenWindow(RviSettings rviSettings, string name, int x, int y, int monitorNumber, string login, string ip)
		{
			using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
			{
				var sessionUID = Guid.NewGuid();

				var sessionInitialiazationIn = new SessionInitialiazationIn();
				sessionInitialiazationIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				sessionInitialiazationIn.Login = rviSettings.Login;
				sessionInitialiazationIn.Password = rviSettings.Password;
				var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);
				var windowListIn = new WindowListIn();
				windowListIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var windowListOut = client.GetWindowList(windowListIn);

				var windowClient = windowListOut.Window.FirstOrDefault(window => window.Name == name);
				if (windowClient != null)
				{
					var openWindowIn = new OpenWindowIn();
					openWindowIn.IP = ip;
					openWindowIn.Login = login;
					openWindowIn.GuidWindow = windowClient.Guid;
					openWindowIn.Monitor = new Monitor() { X = x, Y = y, Number = monitorNumber };
					openWindowIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var openWindowOut = client.OpenWindow(openWindowIn);
				}

				var sessionCloseIn = new SessionCloseIn();
				sessionCloseIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var sessionCloseOut = client.SessionClose(sessionCloseIn);
			}
		}
Пример #5
0
		public static void AlarmRuleExecute(RviSettings rviSettings, string ruleName)
		{
			using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
			{
				var sessionUID = Guid.NewGuid();

				var sessionInitialiazationIn = new SessionInitialiazationIn();
				sessionInitialiazationIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				sessionInitialiazationIn.Login = rviSettings.Login;
				sessionInitialiazationIn.Password = rviSettings.Password;
				var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

				var alarmRulesIn = new AlarmRulesIn();
				alarmRulesIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var alarmRulesOut = client.GetAlarmRules(alarmRulesIn);
				if (alarmRulesOut != null && alarmRulesOut.AlarmRules != null)
				{
					var alarmRule = alarmRulesOut.AlarmRules.FirstOrDefault(x => x.Name == ruleName);
					if (alarmRule != null)
					{
						var alarmRuleExecuteIn = new AlarmRuleExecuteIn();
						alarmRuleExecuteIn.AlarmRuleGuid = alarmRule.Guid;
						alarmRuleExecuteIn.ExternalEventGuid = Guid.NewGuid();
						alarmRuleExecuteIn.Header = new HeaderRequest()
						{
							Request = Guid.NewGuid(),
							Session = sessionUID
						};
						var alarmRuleExecuteOut = client.AlarmRuleExecute(alarmRuleExecuteIn);
					}
				}
				var sessionCloseIn = new SessionCloseIn();
				sessionCloseIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var sessionCloseOut = client.SessionClose(sessionCloseIn);
			}
		}
Пример #6
0
		public static bool PrepareToTranslation(RviSettings rviSettings, RviStream rviStream, out IPEndPoint ipEndPoint, out int vendorId)
		{
			ipEndPoint = null;
			vendorId = -1;
			bool isNotConnected;

			var devices = GetDevices(rviSettings.Url, rviSettings.Login, rviSettings.Password, out isNotConnected);
			var device = devices.FirstOrDefault(d => d.Guid == rviStream.RviDeviceUid);

			if (device == null)
				return false;

			var channel = device.Channels.FirstOrDefault(ch => ch.Number == rviStream.RviChannelNumber);

			if (channel == null)
				return false;

			vendorId = channel.Vendor;

			using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
			{
				var sessionUID = Guid.NewGuid();

				var sessionInitialiazationIn = new SessionInitialiazationIn();
				sessionInitialiazationIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				sessionInitialiazationIn.Login = rviSettings.Login;
				sessionInitialiazationIn.Password = rviSettings.Password;
				var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);
				//var errorMessage = sessionInitialiazationOut.Header.HeaderResponseMessage.Information;

				var response = client.VideoStreamingStart(new ChannelStreamingStartIn()
				{
					Header = new HeaderRequest() { Request = new Guid(), Session = sessionUID },
					DeviceGuid = device.Guid,
					ChannelNumber = channel.Number,
					StreamNumber = rviStream.Number
				});

				var sessionCloseIn = new SessionCloseIn();
				sessionCloseIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var sessionCloseOut = client.SessionClose(sessionCloseIn);

				if (response.EndPointPort == 0)
				{
					return false;
				}
				ipEndPoint = new IPEndPoint(IPAddress.Parse(response.EndPointAdress), response.EndPointPort);
			}
			return true;
		}
Пример #7
0
		public static bool GetVideoFile(RviSettings rviSettings, Guid eventUID, Camera camera, string videoPath, out string errorInformation)
		{
			try
			{
				using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
				{
					var sessionUID = Guid.NewGuid();

					var sessionInitialiazationIn = new SessionInitialiazationIn();
					sessionInitialiazationIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					sessionInitialiazationIn.Login = rviSettings.Login;
					sessionInitialiazationIn.Password = rviSettings.Password;
					var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

					using (IntegrationVideoStreamingClient streamingClient = CreateIntegrationVideoStreamingClient(rviSettings))
					{
						System.IO.Stream stream = null;
						var requestUID = new Guid();
						var result = streamingClient.GetVideoFile(camera.Number, camera.RviDeviceUID, eventUID, ref requestUID, ref sessionUID, out errorInformation, out stream);
						var videoFileStream = File.Create(videoPath);
						CopyStream(stream, videoFileStream);
					}

					var sessionCloseIn = new SessionCloseIn();
					sessionCloseIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var sessionCloseOut = client.SessionClose(sessionCloseIn);
					if (errorInformation != "Запись существует")
						return false;
					return true;
				}
			}
			catch (CommunicationException e)
			{
				Logger.Error(e, "RViClientHelper.GetVideoFile");
				errorInformation = "Видео не получено. Проверьте запущен ли сервер RVi, правильно ли указаны логин и пароль.";
				return false;
			}
		}
Пример #8
0
		public static void AlarmDisableChannel(RviSettings rviSettings, Camera camera)
		{
			try
			{
				using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
				{
					var sessionUID = Guid.NewGuid();

					var sessionInitialiazationIn = new SessionInitialiazationIn();
					sessionInitialiazationIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					sessionInitialiazationIn.Login = rviSettings.Login;
					sessionInitialiazationIn.Password = rviSettings.Password;
					var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

					var alarmDisableChannelIn = new AlarmDisableChannelIn();
					alarmDisableChannelIn.DeviceGuid = camera.RviDeviceUID;
					alarmDisableChannelIn.ChannelNumber = camera.Number;
					alarmDisableChannelIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var alarmDisableChannelOut = client.AlarmDisableChannel(alarmDisableChannelIn);

					var sessionCloseIn = new SessionCloseIn();
					sessionCloseIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var sessionCloseOut = client.SessionClose(sessionCloseIn);
				}
			}
			catch (CommunicationException e)
			{
				Logger.Error(e, "RViClientHelper.AlarmDisableChannel");
			}
		}
Пример #9
0
		public static void VideoRecordStop(RviSettings rviSettings, Camera camera, Guid eventUID)
		{
			try
			{
				using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
				{
					var sessionUID = Guid.NewGuid();

					var sessionInitialiazationIn = new SessionInitialiazationIn();
					sessionInitialiazationIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					sessionInitialiazationIn.Login = rviSettings.Login;
					sessionInitialiazationIn.Password = rviSettings.Password;
					var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

					var videoRecordStopIn = new VideoRecordStopIn();
					videoRecordStopIn.DeviceGuid = camera.RviDeviceUID;
					videoRecordStopIn.ChannelNumber = camera.Number;
					videoRecordStopIn.EventGuid = eventUID;
					videoRecordStopIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var videoRecordStopOut = client.VideoRecordStop(videoRecordStopIn);

					var sessionCloseIn = new SessionCloseIn();
					sessionCloseIn.Header = new HeaderRequest()
					{
						Request = Guid.NewGuid(),
						Session = sessionUID
					};
					var sessionCloseOut = client.SessionClose(sessionCloseIn);
				}
			}
			catch (CommunicationException e)
			{
				Logger.Error(e, "RViClientHelper.VideoRecordStop");
			}
		}
Пример #10
0
		public static void SetPtzPreset(RviSettings rviSettings, Camera camera, int number)
		{
			using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
			{
				var sessionUID = Guid.NewGuid();

				var sessionInitialiazationIn = new SessionInitialiazationIn();
				sessionInitialiazationIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				sessionInitialiazationIn.Login = rviSettings.Login;
				sessionInitialiazationIn.Password = rviSettings.Password;
				var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

				var ptzPresetIn = new PtzPresetIn();
				ptzPresetIn.DeviceGuid = camera.RviDeviceUID;
				ptzPresetIn.ChannelNumber = camera.Number;
				ptzPresetIn.Number = number;
				ptzPresetIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var ptzPresetOut = client.SetPtzPreset(ptzPresetIn);

				var sessionCloseIn = new SessionCloseIn();
				sessionCloseIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var sessionCloseOut = client.SessionClose(sessionCloseIn);
			}
		}
Пример #11
0
		public static void GetSnapshot(RviSettings rviSettings, Camera camera)
		{
			using (IntegrationClient client = CreateIntegrationClient(rviSettings.Url))
			{
				var sessionUID = Guid.NewGuid();

				var sessionInitialiazationIn = new SessionInitialiazationIn();
				sessionInitialiazationIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				sessionInitialiazationIn.Login = rviSettings.Login;
				sessionInitialiazationIn.Password = rviSettings.Password;
				var sessionInitialiazationOut = client.SessionInitialiazation(sessionInitialiazationIn);

				var snapshotDoIn = new SnapshotDoIn();
				snapshotDoIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};

				var snapshotUID = new Guid();
				snapshotDoIn.DeviceGuid = camera.RviDeviceUID;
				snapshotDoIn.ChannelNumber = camera.Number;
				snapshotDoIn.EventGuid = snapshotUID;
				var snapshotDoOut = client.SnapshotDo(new SnapshotDoIn());

				var snapshotImageIn = new SnapshotImageIn();
				snapshotImageIn.DeviceGuid = camera.RviDeviceUID;
				snapshotImageIn.ChannelNumber = camera.Number;
				snapshotImageIn.EventGuid = snapshotUID;
				snapshotImageIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var snapshotImageOut = client.GetSnapshotImage(snapshotImageIn);

				var sessionCloseIn = new SessionCloseIn();
				sessionCloseIn.Header = new HeaderRequest()
				{
					Request = Guid.NewGuid(),
					Session = sessionUID
				};
				var sessionCloseOut = client.SessionClose(sessionCloseIn);
			}
		}