public static void ProcessAutomationCallback(AutomationCallbackResult callback, Guid? clientUid = null)
		{
			SafeContext.Execute(() =>
			{
				if (AutomationEvent != null)
					AutomationEvent(callback);
			});
		}
		public static void NotifyAutomation(AutomationCallbackResult automationCallbackResult, Guid? clientUID)
		{
			var callbackResult = new CallbackResult()
			{
				CallbackResultType = CallbackResultType.AutomationCallbackResult,
				AutomationCallbackResult = automationCallbackResult,
			};
			CallbackManager.Add(callbackResult, ClientType.Monitor | ClientType.OPC | ClientType.WebService | ClientType.Other, clientUID);
		}
		private object SendCallback(UIStep uiStep, AutomationCallbackResult callback, bool withResponse = false)
		{
			callback.CallbackUID = Guid.NewGuid();
			callback.ContextType = this.ContextType;
			if (callback.Data is UIAutomationCallbackData)
				(callback.Data as UIAutomationCallbackData).LayoutFilter = GetLayoutFilter(uiStep);
			_callbackResponse = null;
			if (withResponse)
			{
				using (_waitHandler = new AutoResetEvent(false))
				{
					_proceduresThreads.GetOrAdd(callback.CallbackUID, this);
					ProcedureExecutionContext.SendCallback(callback, GetClientUID(uiStep));
					if (!_waitHandler.WaitOne(TimeSpan.FromMinutes(1)))
						CallbackResponse(callback.CallbackUID, null);
				}
			}
			else
				ProcedureExecutionContext.SendCallback(callback, GetClientUID(uiStep));
			return _callbackResponse;
		}
		void OnAutomationCallback(AutomationCallbackResult automationCallbackResult)
		{
			if (automationCallbackResult.AutomationCallbackType == AutomationCallbackType.GetVisualProperty || automationCallbackResult.AutomationCallbackType == AutomationCallbackType.SetVisualProperty
				&& (AutomationHelper.CheckLayoutFilter(automationCallbackResult, Layout == null ? null : (Guid?)Layout.UID)))
			{
				var visuaPropertyData = (VisualPropertyCallbackData)automationCallbackResult.Data;
				var layoutPart = LayoutContainer.LayoutParts.FirstOrDefault(item => item.UID == visuaPropertyData.LayoutPart);
				if (layoutPart != null)
				{
					var sendResponse = false;
					object value = null;
					ApplicationService.Invoke(() =>
					{
						switch (automationCallbackResult.AutomationCallbackType)
						{
							case AutomationCallbackType.GetVisualProperty:
								value = layoutPart.GetProperty(visuaPropertyData.Property);
								sendResponse = true;
								break;
							case AutomationCallbackType.SetVisualProperty:
								layoutPart.SetProperty(visuaPropertyData.Property, visuaPropertyData.Value);
								break;
						}
					});
					if (sendResponse)
						ClientManager.RubezhService.ProcedureCallbackResponse(automationCallbackResult.CallbackUID, value);
				}
			}
		}
Exemple #5
0
		void OnAutomationCallback(AutomationCallbackResult automationCallbackResult)
		{
			if (automationCallbackResult.AutomationCallbackType == AutomationCallbackType.GlobalVariable)
			{
				var data = automationCallbackResult.Data as GlobalVariableCallBackData;
				if (data != null)
				{
					var variable = ProcedureExecutionContext.GlobalVariables.FirstOrDefault(x => x.Uid == data.VariableUID);
					variable.Value = data.ExplicitValue.Value;
				}
				return;
			}

			if (automationCallbackResult.AutomationCallbackType == AutomationCallbackType.OpcDaTag)
			{
				var data = automationCallbackResult.Data as OpcDaTagCallBackData;
				if (data != null)
					OpcDaHelper.SetTagValue(data.TagUID, data.Value);
				return;
			}

			if (!AutomationHelper.CheckLayoutFilter(automationCallbackResult, GetLayoutUID()))
				return;

			switch (automationCallbackResult.AutomationCallbackType)
			{
				case AutomationCallbackType.ShowDialog:
					var showDialogData = automationCallbackResult.Data as ShowDialogCallbackData;
					if (showDialogData != null)
						LayoutDialogViewModel.Show(showDialogData);
					break;
				case AutomationCallbackType.CloseDialog:
					var closeDialogData = automationCallbackResult.Data as CloseDialogCallbackData;
					if (closeDialogData != null)
						LayoutDialogViewModel.Close(closeDialogData);
					break;
				case AutomationCallbackType.Sound:
					var soundData = (SoundCallbackData)automationCallbackResult.Data;
					var sound =
						ClientManager.SystemConfiguration.AutomationConfiguration.AutomationSounds.FirstOrDefault(
							x => x.Uid == soundData.SoundUID);
					if (sound != null)
						ApplicationService.Invoke(
							() =>
								AlarmPlayerHelper.Play(
									FileHelper.GetSoundFilePath(Path.Combine(ServiceFactoryBase.ContentService.ContentFolder, sound.Uid.ToString())), false));
					break;
				case AutomationCallbackType.Message:
					var messageData = (MessageCallbackData)automationCallbackResult.Data;
					ApplicationService.Invoke(() =>
					{
						if (messageData.WithConfirmation)
						{
							ApplicationService.BeginInvoke(() =>
								{
									var confirm = MessageBoxService.ShowConfirmation(messageData.Message, "Сообщение");
									ProcedureExecutionContext.CallbackResponse(RubezhServiceFactory.UID, automationCallbackResult.ContextType, automationCallbackResult.CallbackUID, confirm);
								});
						}
						else
							MessageBoxService.ShowExtended(messageData.Message, "Сообщение", messageData.IsModalWindow);
					});
					break;
				case AutomationCallbackType.Property:
					{
						var propertyData = (PropertyCallBackData)automationCallbackResult.Data;
						var ShowObjectDetailsEvent = new CompositePresentationEvent<Guid>();
						switch (propertyData.ObjectType)
						{
							case ObjectType.Device:
								var device = GKManager.Devices.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (device != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKDeviceDetailsEvent>();
								break;

							case ObjectType.Zone:
								var zone = GKManager.Zones.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (zone != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKZoneDetailsEvent>();
								break;

							case ObjectType.Direction:
								var direction = GKManager.Directions.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (direction != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKDirectionDetailsEvent>();
								break;

							case ObjectType.Delay:
								var delay = GKManager.Delays.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (delay != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKDelayDetailsEvent>();
								break;

							case ObjectType.GuardZone:
								var guardZone = GKManager.GuardZones.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (guardZone != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKGuardZoneDetailsEvent>();
								break;

							case ObjectType.VideoDevice:
								var videoDevice = ClientManager.SystemConfiguration.Cameras.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (videoDevice != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowCameraDetailsEvent>();
								break;

							case ObjectType.GKDoor:
								var gkDoor = GKManager.Doors.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (gkDoor != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKDoorDetailsEvent>();
								break;

							case ObjectType.PumpStation:
								var pumpStation = GKManager.PumpStations.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (pumpStation != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKPumpStationDetailsEvent>();
								break;

							case ObjectType.MPT:
								var mpt = GKManager.MPTs.FirstOrDefault(x => x.UID == propertyData.ObjectUid);
								if (mpt != null)
									ShowObjectDetailsEvent = ServiceFactory.Events.GetEvent<ShowGKMPTDetailsEvent>();
								break;
						}
						if (ShowObjectDetailsEvent != null)
							ApplicationService.BeginInvoke(() => ShowObjectDetailsEvent.Publish(propertyData.ObjectUid));
					}
					break;
				case AutomationCallbackType.GetPlanProperty:
					var controlPlanEventArg = new ControlPlanEventArg
					{
						ControlElementType = ControlElementType.Get,
						PlanCallbackData = (PlanCallbackData)automationCallbackResult.Data
					};
					ServiceFactory.Events.GetEvent<ControlPlanEvent>().Publish(controlPlanEventArg);
					ProcedureExecutionContext.CallbackResponse(RubezhServiceFactory.UID, automationCallbackResult.ContextType, automationCallbackResult.CallbackUID, controlPlanEventArg.PlanCallbackData.Value);
					break;
				case AutomationCallbackType.SetPlanProperty:
					controlPlanEventArg = new ControlPlanEventArg
					{
						ControlElementType = ControlElementType.Set,
						PlanCallbackData = (PlanCallbackData)automationCallbackResult.Data
					};
					ServiceFactory.Events.GetEvent<ControlPlanEvent>().Publish(controlPlanEventArg);
					break;
			}

		}
		public void ShowPropertyStep(ProcedureStep procedureStep)
		{
			var showPropertyStep = (ShowPropertyStep)procedureStep;
			var objectRef = (ObjectReference)GetValue(showPropertyStep.ObjectArgument);
			if (showPropertyStep.ObjectType == ObjectType.Zone && !LicenseManager.CurrentLicenseInfo.HasFirefighting ||
				showPropertyStep.ObjectType == ObjectType.GuardZone && !LicenseManager.CurrentLicenseInfo.HasGuard ||
				showPropertyStep.ObjectType == ObjectType.GKDoor && !LicenseManager.CurrentLicenseInfo.HasSKD ||
				showPropertyStep.ObjectType == ObjectType.VideoDevice && !LicenseManager.CurrentLicenseInfo.HasVideo)
			{
				ProcedureExecutionContext.AddJournalItem(ClientUID, "Выполнение функции \"Показать свойства объекта\" заблокировано в связи с отсутствием лицензии", objectRef.UID);
				return;
			}
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.Property,
				Data = new PropertyCallBackData()
				{
					ObjectType = showPropertyStep.ObjectType,
					ObjectUid = objectRef.UID
				},
			};
			SendCallback(showPropertyStep, automationCallbackResult);
		}
		public void CloseDialogStep(ProcedureStep procedureStep)
		{
			var closeDialogStep = (CloseDialogStep)procedureStep;
			var windowID = GetStringValue(closeDialogStep.WindowIDArgument);
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.CloseDialog,
				Data = new CloseDialogCallbackData()
				{
					WindowID = windowID
				}
			};
			SendCallback(closeDialogStep, automationCallbackResult);
		}
		public void ShowDialogStep(ProcedureStep procedureStep)
		{
			var showDialogStep = (ShowDialogStep)procedureStep;
			var windowID = GetStringValue(showDialogStep.WindowIDArgument);
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.ShowDialog,
				Data = new ShowDialogCallbackData()
				{
					IsModalWindow = showDialogStep.IsModalWindow,
					Layout = showDialogStep.Layout,
					Title = showDialogStep.Title,
					AllowClose = showDialogStep.AllowClose,
					AllowMaximize = showDialogStep.AllowMaximize,
					Height = showDialogStep.Height,
					MinHeight = showDialogStep.MinHeight,
					MinWidth = showDialogStep.MinWidth,
					Sizable = showDialogStep.Sizable,
					TopMost = showDialogStep.TopMost,
					Width = showDialogStep.Width,
					CustomPosition = showDialogStep.CustomPosition,
					Left = showDialogStep.Left,
					Top = showDialogStep.Top,
					WindowID = windowID
				},
			};
			SendCallback(showDialogStep, automationCallbackResult);
		}
		public void ControlPlanSetStep(ProcedureStep procedureStep)
		{
			var controlPlanSetStep = (ControlPlanSetStep)procedureStep;

			var value = GetValue(controlPlanSetStep.ValueArgument);
			if (value is int && (int)value < 0)
				return;

			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.SetPlanProperty,
				Data = new PlanCallbackData()
				{
					PlanUid = controlPlanSetStep.PlanUid,
					ElementUid = controlPlanSetStep.ElementUid,
					ElementPropertyType = controlPlanSetStep.ElementPropertyType,
					Value = value
				},
			};

			SendCallback(controlPlanSetStep, automationCallbackResult);
			if (controlPlanSetStep.ForAllClients)
				ProcedurePropertyCache.SetProperty((PlanCallbackData)automationCallbackResult.Data);
		}
		public void ControlPlanGetStep(ProcedureStep procedureStep)
		{
			var controlPlanGetStep = (ControlPlanGetStep)procedureStep;

			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.GetPlanProperty,
				Data = new PlanCallbackData()
				{
					PlanUid = controlPlanGetStep.PlanUid,
					ElementUid = controlPlanGetStep.ElementUid,
					ElementPropertyType = controlPlanGetStep.ElementPropertyType
				},
			};

			var value = SendCallback(controlPlanGetStep, automationCallbackResult, true);
			SetValue(controlPlanGetStep.ValueArgument, value);

		}
		public void ControlVisualSetStep(ProcedureStep procedureStep)
		{
			var controlVisualSetStep = (ControlVisualSetStep)procedureStep;

			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.SetVisualProperty,
				Data = new VisualPropertyCallbackData()
				{
					LayoutPart = controlVisualSetStep.LayoutPart,
					Property = controlVisualSetStep.Property.Value
				},
			};
			SendCallback(controlVisualSetStep, automationCallbackResult);
			if (controlVisualSetStep.ForAllClients)
				ProcedurePropertyCache.SetProperty(controlVisualSetStep.Layout, (VisualPropertyCallbackData)automationCallbackResult.Data);
		}
		public void ControlVisualGetStep(ProcedureStep procedureStep)
		{
			var controlVisualGetStep = (ControlVisualGetStep)procedureStep;
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.GetVisualProperty,
				Data = new VisualPropertyCallbackData()
				{
					LayoutPart = controlVisualGetStep.LayoutPart,
					Property = controlVisualGetStep.Property.Value
				},
			};

			var value = SendCallback(controlVisualGetStep, automationCallbackResult, true);
			SetValue(controlVisualGetStep.Argument, value);
		}
		public void ShowMessageStep(ProcedureStep procedureStep)
		{
			var showMessageStep = (ShowMessageStep)procedureStep;
			var messageString = GetStringValue(showMessageStep.MessageArgument);
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.Message,
				Data = new MessageCallbackData()
				{
					IsModalWindow = showMessageStep.IsModalWindow,
					Message = messageString,
					WithConfirmation = showMessageStep.WithConfirmation
				},
			};

			if (showMessageStep.WithConfirmation)
			{
				var value = SendCallback(showMessageStep, automationCallbackResult, true);
				SetValue(showMessageStep.ConfirmationValueArgument, value);
			}
			else
				SendCallback(showMessageStep, automationCallbackResult);
		}
		public void SoundStep(ProcedureStep procedureStep)
		{
			var soundStep = (SoundStep)procedureStep;
			var automationCallbackResult = new AutomationCallbackResult()
			{
				AutomationCallbackType = AutomationCallbackType.Sound,
				Data = new SoundCallbackData()
				{
					SoundUID = soundStep.SoundUid,
				},
			};
			SendCallback(soundStep, automationCallbackResult);
		}
		public static void SendCallback(AutomationCallbackResult callback, Guid? clientUID)
		{
			if (OnSendCallback != null)
				OnSendCallback(callback, clientUID);
		}