Пример #1
0
		public TagBase(int tagId, GKState state, Guid uid)
		{
			TagId = tagId;
			State = state;
			UID = uid;
			state.StateChanged += state_StateChanged;
		}
Пример #2
0
		public DeviceStateViewModel(GKState deviceState, bool isStateImage)
		{
			State = deviceState;
			IsStateImage = isStateImage;
			StateClasses = new ObservableCollection<GKStateClassViewModel>();
			AdditionalStates = new ObservableCollection<GKAdditionalState>();
			State.StateChanged += OnStateChanged;
			OnStateChanged();
		}
Пример #3
0
		public GKBase()
		{
			ClearDescriptor();
			ClearClauseDependencies();
			State = new GKState();
			InputDescriptors = new List<GKBase>();
			OutputDescriptors = new List<GKBase>();
			InputDependentElements = new List<GKBase>();
			OutputDependentElements = new List<GKBase>();
		}
Пример #4
0
		public void CopyToGKState(GKState state)
		{
			state.StateClasses = StateClasses.ToList();
			state.StateClass = StateClass;
			state.AdditionalStates = AdditionalStates.ToList();
			state.OnDelay = OnDelay;
			state.OffDelay = OffDelay;
			state.HoldDelay = HoldDelay;
			state.RunningTime = RunningTime;

			if (IsInitialState || IsSuspending || IsNoLicense || IsConnectionLost)
			{
				state.AdditionalStates = new List<GKAdditionalState>();
				state.OnDelay = 0;
				state.OffDelay = 0;
				state.HoldDelay = 0;
				state.RunningTime = 0;
			}
		}
Пример #5
0
		private static string GetDeviceStatePic(GKDevice device, GKState state)
		{
			var deviceConfig =
				GKManager.DeviceLibraryConfiguration.GKDevices.FirstOrDefault(d => d.DriverUID == device.DriverUID);
			if (deviceConfig == null)
			{
				return null;
			}
			var stateWithPic =
				deviceConfig.States.FirstOrDefault(s => s.StateClass == state.StateClass) ??
				deviceConfig.States.FirstOrDefault(s => s.StateClass == XStateClass.No);
			if (stateWithPic == null)
			{
				return null;
			}
			// Перебираем кадры в состоянии и генерируем gif картинку
			byte[] bytes;
			using (var collection = new MagickImageCollection())
			{
				foreach (var frame in stateWithPic.Frames)
				{
					var frame1 = frame;
					frame1.Image = frame1.Image.Replace("#000000", "#FF0F0F0F");
					Canvas surface;
					var imageBytes = Encoding.Unicode.GetBytes(frame1.Image ?? "");
					using (var stream = new MemoryStream(imageBytes))
					{
						surface = (Canvas)XamlServices.Load(stream);
					}
					var pngBitmap = surface != null ? InternalConverter.XamlCanvasToPngBitmap(surface) : null;
					if (pngBitmap == null)
					{
						continue;
					}
					var img = new MagickImage(pngBitmap)
					{
						AnimationDelay = frame.Duration / 10,
						HasAlpha = true
					};
					collection.Add(img);
				}
				if (collection.Count == 0)
				{
					return string.Empty;
				}
				//Optionally reduce colors
				QuantizeSettings settings = new QuantizeSettings { Colors = 256 };
				collection.Quantize(settings);

				// Optionally optimize the images (images should have the same size).
				collection.Optimize();

				using (var str = new MemoryStream())
				{
					collection.Write(str, MagickFormat.Gif);
					bytes = str.ToArray();
				}


			}
			return Convert.ToBase64String(bytes);
		}
Пример #6
0
		public static void UpdateDeviceState(GKState state)
		{
			if (state.BaseObjectType != GKBaseObjectType.Device)
			{
				throw new ArgumentException(@"BaseObjectType должен быть GKBaseObjectType.Device", "state");
			}
			var device = GKManager.Devices.FirstOrDefault(x => x.UID == state.UID);
			if (device == null)
			{
				throw new Exception(string.Format("Устройство {0} не найдено.", state.UID));
			}

			// Получаем обновленную картинку устройства
			var getPictureTask = Task.Factory.StartNewSta(() => GetDeviceStatePic(device, state));
			Task.WaitAll(getPictureTask);
			var pic = getPictureTask.Result;

			var hint = new ElementHint();

			var hintImageSource = device.ImageSource.Replace("/Controls;component/", "");
			hint.StateHintLines.Add(new HintLine { Text = device.PresentationName, Icon = (hintImageSource.Trim() != string.Empty) ? GetImageResource(hintImageSource).Item1 : null });

			// Добавляем состояния
			foreach (var stateClass in device.State.StateClasses)
			{
				//Получаем источник иконки для основного класса
				var iconSourceForStateClasses = stateClass.ToIconSource();
				hint.StateHintLines.Add(
					new HintLine
					{
						Text = stateClass.ToDescription(),
						Icon = iconSourceForStateClasses != null ? GetImageResource(iconSourceForStateClasses.Replace("/Controls;component/", "")).Item1 : null
					});
			}
			// Добавляем доп. состояния
			foreach (var stateClass in device.State.AdditionalStates)
			{
				//Получаем источник иконки для основного класса
				var iconSourceForAdditionalStateClasses = stateClass.StateClass.ToIconSource();
				hint.StateHintLines.Add(
					new HintLine
					{
						Text = stateClass.Name,
						Icon = iconSourceForAdditionalStateClasses != null ? GetImageResource(iconSourceForAdditionalStateClasses.Replace("/Controls;component/", "")).Item1 : null
					});
			}
			// Собираем обновление для передачи
			var statusUpdate = new
			{
				Id = "pe" + state.UID,
				Picture = pic,
				Hint = hint
			};
			PlansUpdater.Instance.UpdateDeviceState(statusUpdate);
		}
Пример #7
0
		public static void UpdateZoneState(GKState state)
		{
			var zone = GKManager.Zones.Union<GKBase>(GKManager.GuardZones).Union(GKManager.SKDZones).FirstOrDefault(z => state.UID == z.UID);
			if (zone == null)
			{
				throw new Exception(string.Format("Зона {0} не найдена.", state.UID));
			}
			var hint = new ElementHint();

			var hintImageSource = zone.ImageSource.Replace("/Controls;component/", "");
			hint.StateHintLines.Add(new HintLine { Text = zone.PresentationName, Icon = (hintImageSource.Trim() != string.Empty) ? GetImageResource(hintImageSource).Item1 : null });

			// Добавляем состояния
			foreach (var stateClass in zone.State.StateClasses)
			{
				//Получаем источник иконки для основного класса
				var iconSourceForStateClasses = stateClass.ToIconSource();
				hint.StateHintLines.Add(
					new HintLine
					{
						Text = stateClass.ToDescription(),
						Icon = iconSourceForStateClasses != null ? GetImageResource(iconSourceForStateClasses.Replace("/Controls;component/", "")).Item1 : null
					});
			}
			// Добавляем доп. состояния
			foreach (var stateClass in zone.State.AdditionalStates)
			{
				//Получаем источник иконки для основного класса
				var iconSourceForAdditionalStateClasses = stateClass.StateClass.ToIconSource();
				hint.StateHintLines.Add(
					new HintLine
					{
						Text = stateClass.Name,
						Icon = iconSourceForAdditionalStateClasses != null ? GetImageResource(iconSourceForAdditionalStateClasses.Replace("/Controls;component/", "")).Item1 : null
					});
			}

			System.Windows.Media.Color background;
			switch (zone.GetType().ToString())
			{
				case "RubezhAPI.GK.GKZone":
					{
						background = GetGKZoneStateColor(state.StateClass);
						break;
					}
				case "RubezhAPI.GK.GKSKDZone":
					{
						background = GetGKSKDZoneStateColor(state.StateClass);
						break;
					}
				case "RubezhAPI.GK.GKGuardZone":
					{
						background = GetGKGuardZoneStateColor(state.StateClass);
						break;
					}
				default:
					{
						background = System.Windows.Media.Colors.Transparent;
						break;
					}
			}

			// Собираем обновление для передачи
			var statusUpdate = new
			{
				Id = "pe" + state.UID,
				Background = new { R = background.R, G = background.G, B = background.B, A = background.A },
				Hint = hint
			};
			PlansUpdater.Instance.UpdateZoneState(statusUpdate);
		}
Пример #8
0
		public void CopyTo(GKState state)
		{
			state.AdditionalStates = AdditionalStates;
			state.OnDelay = OnDelay;
			state.HoldDelay = HoldDelay;
			state.OffDelay = OffDelay;
			state.RunningTime = RunningTime;
			state.StateClasses = StateClasses;
			state.StateClass = StateClass;
		}
Пример #9
0
		public GKStateModel(GKState state)
		{
		}