コード例 #1
0
		void OnGKProgressCallbackEvent(GKProgressCallback gkProgressCallback)
		{
			ApplicationService.Invoke(() =>
			{
				switch (gkProgressCallback.GKProgressCallbackType)
				{
					case GKProgressCallbackType.Start:
						if (gkProgressCallback.GKProgressClientType == GKProgressClientType.Monitor)
						{
							LoadingService.Show(gkProgressCallback.Title, gkProgressCallback.Text, gkProgressCallback.StepCount, gkProgressCallback.CanCancel);
						}
						return;

					case GKProgressCallbackType.Progress:
						if (gkProgressCallback.GKProgressClientType == GKProgressClientType.Monitor)
						{
							LoadingService.DoStep(gkProgressCallback.Text, gkProgressCallback.Title, gkProgressCallback.StepCount, gkProgressCallback.CanCancel);
							if (LoadingService.IsCanceled)
								FiresecManager.FiresecService.CancelGKProgress(gkProgressCallback.UID, FiresecManager.CurrentUser.Name);
						}
						return;

					case GKProgressCallbackType.Stop:
						LoadingService.Close();
						return;
				}
			});
		}
コード例 #2
0
		static void OnGKCallbackResult(GKProgressCallback gkProgressCallback)
		{
			GKProgressCallbacks.RemoveAll(x => x.IsCanceled && (DateTime.Now - x.CancelizationDateTime).TotalMinutes > 5);
			if (gkProgressCallback.GKProgressCallbackType == GKProgressCallbackType.Stop || !gkProgressCallback.IsCanceled)
			{
				if (GKProgressCallbackEvent != null)
					GKProgressCallbackEvent(gkProgressCallback);
			}
		}
コード例 #3
0
		public static void NotifyGKProgress(GKProgressCallback gkProgressCallback)
		{
			var callbackResult = new CallbackResult()
			{
				CallbackResultType = CallbackResultType.GKProgress,
				GKProgressCallback = gkProgressCallback
			};
			CallbackManager.Add(callbackResult);
		}
コード例 #4
0
		public static void StopProgress(GKProgressCallback progressCallback)
		{
			var gkProgressCallback = new GKProgressCallback()
			{
				UID = progressCallback.UID,
				LastActiveDateTime = DateTime.Now,
				GKProgressCallbackType = GKProgressCallbackType.Stop,
			};
			GKProgressCallbacks.Remove(gkProgressCallback);
			OnGKCallbackResult(gkProgressCallback);
		}
コード例 #5
0
		public static void DoProgress(string text, GKProgressCallback progressCallback)
		{
			var gkProgressCallback = new GKProgressCallback()
			{
				UID = progressCallback.UID,
				LastActiveDateTime = DateTime.Now,
				GKProgressCallbackType = GKProgressCallbackType.Progress,
				Title = progressCallback.Title,
				Text = text,
				StepCount = progressCallback.StepCount,
				CanCancel = progressCallback.CanCancel,
				GKProgressClientType = progressCallback.GKProgressClientType
			};
			OnGKCallbackResult(gkProgressCallback);
		}
コード例 #6
0
		public static GKProgressCallback StartProgress(string title, string text, int stepCount, bool canCancel, GKProgressClientType progressClientType)
		{
			var gkProgressCallback = new GKProgressCallback()
			{
				GKProgressCallbackType = GKProgressCallbackType.Start,
				Title = title,
				Text = text,
				StepCount = stepCount,
				CanCancel = canCancel,
				GKProgressClientType = progressClientType
			};
			GKProgressCallbacks.Add(gkProgressCallback);
			OnGKCallbackResult(gkProgressCallback);
			return gkProgressCallback;
		}
コード例 #7
0
		public void Update(XDevice device, List<byte> firmWareBytes, string userName)
		{
			GKProcessorManager.AddGKMessage(EventName.Обновление_ПО_прибора, "", device, userName, true);
			ProgressCallback = GKProcessorManager.StartProgress("Обновление прошивки " + device.PresentationName, "", firmWareBytes.Count / 256, true, GKProgressClientType.Administrator);
			GKProcessorManager.DoProgress("Проверка связи " + device.PresentationName, ProgressCallback);
			if (!DeviceBytesHelper.Ping(device))
			{
				Error = "Устройство " + device.PresentationName + " недоступно";
				return;
			}
			if (!DeviceBytesHelper.GoToTechnologicalRegime(device, ProgressCallback))
			{
				Error = "Не удалось перевести " + device.PresentationName + " в технологический режим\n" +
						"Устройство не доступно, либо вашего " +
						"IP адреса нет в списке разрешенного адреса ГК";
				return;
			}
			DeviceBytesHelper.GetDeviceInfo(device);
			GKProcessorManager.DoProgress("Удаление программы " + device.PresentationName, ProgressCallback);
			if (!Clear(device))
			{
				Error = "Устройство " + device.PresentationName + " недоступно";
				return;
			}
			var data = new List<byte>();
			var offset = 0;
			if (device.Driver.IsKauOrRSR2Kau)
				offset = 0x10000;
			for (int i = 0; i < firmWareBytes.Count; i = i + 0x100)
			{
				if (ProgressCallback.IsCanceled)
				{ Error = "Операция обновления прибора " + device.PresentationName + " отменена"; return; }
				GKProcessorManager.DoProgress("Запись блока данных " + i / 0x100 + 1, ProgressCallback);
				data = new List<byte>(BitConverter.GetBytes(i + offset));
				data.AddRange(firmWareBytes.GetRange(i, 0x100));
				var result = SendManager.Send(device, 260, 0x12, 0, data, true, false, 10000);
				if (result.HasError)
				{ Error = "В заданное времени не пришел ответ от устройства"; return; }
			}
			if (!DeviceBytesHelper.GoToWorkingRegime(device, ProgressCallback))
			{
				Error = "Не удалось перевести " + device.PresentationName + " в рабочий режим\n" +
						"Устройство не доступно, либо вашего " +
						"IP адреса нет в списке разрешенного адреса ГК";
				return;
			}
		}
コード例 #8
0
		public static bool GoToTechnologicalRegime(XDevice device, GKProgressCallback progressCallback)
		{
			if (IsInTechnologicalRegime(device))
				return true;

			GKProcessorManager.DoProgress(device.PresentationName + " Переход в технологический режим", progressCallback);
			SendManager.Send(device, 0, 14, 0, null, device.DriverType == XDriverType.GK);
			for (int i = 0; i < 10; i++)
			{
				if (progressCallback.IsCanceled)
                    return false;
				if (IsInTechnologicalRegime(device))
					return true;
				Thread.Sleep(TimeSpan.FromSeconds(1));
			}

			return false;
		}
コード例 #9
0
ファイル: MainViewModel.cs プロジェクト: saeednazari/Rubezh
		static void OnGKProgressCallbackEvent(GKProgressCallback gkProgressCallback)
		{
			ApplicationService.Invoke(() =>
			{
				switch (gkProgressCallback.GKProgressCallbackType)
				{
					case GKProgressCallbackType.Start:
						LoadingService.Show(gkProgressCallback.Title, gkProgressCallback.Text, gkProgressCallback.StepCount, gkProgressCallback.CanCancel);
						return;

					case GKProgressCallbackType.Progress:
						LoadingService.DoStep(gkProgressCallback.Text, gkProgressCallback.Title, gkProgressCallback.StepCount, gkProgressCallback.CanCancel);
						return;

					case GKProgressCallbackType.Stop:
						LoadingService.Close();
						return;
				}
			});
		}
コード例 #10
0
ファイル: GKProcessor.cs プロジェクト: saeednazari/Rubezh
		static void OnGKProgressCallbackEvent(GKProgressCallback gkProgressCallback)
		{
			FiresecService.Service.FiresecService.NotifyGKProgress(gkProgressCallback);
		}
コード例 #11
0
		public static bool GoToWorkingRegime(XDevice device, GKProgressCallback progressCallback)
		{
			progressCallback.IsCanceled = false;
			GKProcessorManager.DoProgress(device.PresentationName + " Переход в рабочий режим", progressCallback);
			if (progressCallback.IsCanceled)
				return true;
			SendManager.Send(device, 0, 11, 0, null, device.DriverType == XDriverType.GK);

			for (int i = 0; i < 10; i++)
			{
				if (progressCallback.IsCanceled)
					return true;
				var sendResult = SendManager.Send(device, 0, 1, 1);
				if (!sendResult.HasError)
				{
					if (sendResult.Bytes.Count > 0)
					{
						var version = sendResult.Bytes[0];
						if (version <= 127)
						{
							return true;
						}
					}
				}
				Thread.Sleep(TimeSpan.FromSeconds(1));
			}

			return false;
		}
コード例 #12
0
		public static bool EraseDatabase(XDevice device, GKProgressCallback progressCallback)
		{
			GKProcessorManager.DoProgress(device.PresentationName + " Стирание базы данных", progressCallback);
			for (int i = 0; i < 3; i++)
			{
				if (progressCallback.IsCanceled)
                    return false;
				var sendResult = SendManager.Send(device, 0, 15, 0, null, true, false, 10000);
				if (!sendResult.HasError)
				{
					return true;
				}
				else
				{
					Thread.Sleep(TimeSpan.FromSeconds(1));
				}
			}
			return false;
		}
コード例 #13
0
		bool WriteConfigToDevice(CommonDatabase commonDatabase, GKProgressCallback progressCallback)
		{
			foreach (var descriptor in commonDatabase.Descriptors)
			{
				if (progressCallback.IsCanceled)
					return false;
				var progressStage = commonDatabase.RootDevice.PresentationName + ": запись " +
					descriptor.XBase.PresentationName + " " + "(" + descriptor.GetDescriptorNo() + ")" +
					" из " + commonDatabase.Descriptors.Count;
				GKProcessorManager.DoProgress(progressStage, progressCallback);
				var packs = CreateDescriptors(descriptor);
				foreach (var pack in packs)
				{
					var packBytesCount = pack.Count;
					var sendResult = SendManager.Send(commonDatabase.RootDevice, (ushort)(packBytesCount), 17, 0, pack);
					if (sendResult.HasError)
					{
						GKProcessorManager.StopProgress(progressCallback);
						Trace.WriteLine(progressStage);
						return false;
					}
				}
			}
			GKProcessorManager.DoProgress(commonDatabase.RootDevice.PresentationName + " Запись завершающего дескриптора", progressCallback);
			WriteEndDescriptor(commonDatabase);
			return true;
		}