void SetFilter()
		{
			var archiveFilter = new ArchiveFilter() { StartDate = ArchiveFirstDate < DateTime.Now.AddDays(-1) ? DateTime.Now.AddDays(-1) : ArchiveFirstDate, EndDate = DateTime.Now, UseSystemDate = false };
			var archiveFilterViewModel = new ArchiveFilterViewModel(archiveFilter);
			ArchiveFilter = archiveFilterViewModel.GetModel();
			StartDate = archiveFilterViewModel.StartDateTime;
			EndDate = archiveFilterViewModel.EndDateTime;
		}
		public ArchiveFilterViewModel(ArchiveFilter archiveFilter)
		{
			Title = "Настройки фильтра";
			ClearCommand = new RelayCommand(OnClear);
			SaveCommand = new RelayCommand(OnSave);
			CancelCommand = new RelayCommand(OnCancel);

			Initialize();

            StartDateTime = archiveFilter.StartDate;
            EndDateTime = DateTime.Now;

			UseSystemDate = archiveFilter.UseSystemDate;

			if (archiveFilter.DescriptionAndStateInfos.IsNotNullOrEmpty())
			{
				JournalEvents.Where(x => archiveFilter.DescriptionAndStateInfos.Any(description => description.Description == x.Name && description.StateType == x.StateType)).
					AsParallel().ForAll(x => x.IsEnable = true);
				JournalTypes.Where(x => JournalEvents.Any(journalEvent => journalEvent.StateType == x.StateType && journalEvent.IsEnable)).
							 AsParallel().ForAll(x => x.IsEnable = true);
			}
			else
			{
				if (archiveFilter.Descriptions.IsNotNullOrEmpty())
				{
					JournalEvents.Where(x => archiveFilter.Descriptions.Any(description => description == x.Name)).
								  AsParallel().ForAll(x => x.IsEnable = true);
					JournalTypes.Where(x => JournalEvents.Any(journalEvent => journalEvent.StateType == x.StateType && journalEvent.IsEnable)).
								 AsParallel().ForAll(x => x.IsEnable = true);
				}
			}

			if (archiveFilter.PanelUIDs.IsNotNullOrEmpty())
			{
				foreach (var device in Devices)
				{
					device.IsChecked = archiveFilter.PanelUIDs.Any(x => x == device.DeviceUID);
				}
			}

			if (archiveFilter.Subsystems.IsNotNullOrEmpty())
			{
				foreach (var subsystem in Subsystems)
				{
					subsystem.IsEnable = archiveFilter.Subsystems.Any(x => x == subsystem.Subsystem);
				}
			}
		}
		public void BeginGetFilteredArchive(ArchiveFilter archiveFilter)
		{
			if (CurrentThread != null)
			{
				FiresecDB.DatabaseHelper.IsAbort = true;
				CurrentThread.Join(TimeSpan.FromMinutes(1));
				CurrentThread = null;
			}
			FiresecDB.DatabaseHelper.IsAbort = false;
			var thread = new Thread(new ThreadStart((new Action(() =>
			{
				FiresecDB.DatabaseHelper.ArchivePortionReady -= DatabaseHelper_ArchivePortionReady;
				FiresecDB.DatabaseHelper.ArchivePortionReady += DatabaseHelper_ArchivePortionReady;
				FiresecDB.DatabaseHelper.OnGetFilteredArchive(archiveFilter, false);
			}))));
			thread.Name = "FS1 GetFilteredArchive";
			CurrentThread = thread;
			thread.Start();
		}
		public static void BeginGetFilteredArchive(ArchiveFilter archiveFilter)
		{
			if (CurrentThread != null)
			{
				ServerFS2Database.IsAbort = true;
				CurrentThread.Join(TimeSpan.FromMinutes(1));
				CurrentThread = null;
			}
			ServerFS2Database.IsAbort = false;
			var thread = new Thread(new ThreadStart((new Action(() =>
			{
				ServerFS2Database.ArchivePortionReady -= DatabaseHelper_ArchivePortionReady;
				ServerFS2Database.ArchivePortionReady += DatabaseHelper_ArchivePortionReady;
				try
				{
					ServerFS2Database.OnGetFilteredArchive(archiveFilter, false);
				}
				catch { }
			}))));
			CurrentThread = thread;
			thread.Start();
		}
		public OperationResult<List<JournalRecord>> GetFilteredArchive(ArchiveFilter archiveFilter)
		{
			return FiresecDB.DatabaseHelper.OnGetFilteredArchive(archiveFilter, true);
		}
		public static List<FS2JournalItem> OnGetFilteredArchive(ArchiveFilter archiveFilter, bool isReport)
		{
			var result = new List<FS2JournalItem>();
			try
			{
				string dateInQuery = "DeviceTime";
				if (archiveFilter.UseSystemDate)
					dateInQuery = "SystemTime";

				var query =
					"SELECT * FROM Journal WHERE " +
					"\n " + dateInQuery + " > '" + archiveFilter.StartDate.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
					"\n AND " + dateInQuery + " < '" + archiveFilter.EndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";

				if (archiveFilter.Descriptions.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.Descriptions.Count; i++)
					{
						if (i > 0)
							query += "\n OR ";
						var description = archiveFilter.Descriptions[i];
						description = description.Replace("'", "''");
						query += " Description = '" + description + "'";
					}
					query += ")";
				}

				if (archiveFilter.Subsystems.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.Subsystems.Count; i++)
					{
						if (i > 0)
							query += "\n OR ";
						var subsystem = archiveFilter.Subsystems[i];
						query += " SubSystemType = '" + ((int)subsystem).ToString() + "'";
					}
					query += ")";
				}

				if (archiveFilter.PanelUIDs.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.PanelUIDs.Count; i++)
					{
						var panelUID = archiveFilter.PanelUIDs[i];
						if (panelUID != null)
						{
							if (i > 0)
								query += "\n OR ";
							query += " PanelUID = '" + panelUID + "'";
						}
					}
					query += ")";
				}

				query += "\n ORDER BY " + dateInQuery + " DESC";

				using (var sqlCeConnection = new SqlCeConnection(ConnectionString))
				{
					sqlCeConnection.ConnectionString = ConnectionString;
					var journalItems = new List<FS2JournalItem>();
					var sqlCeCommand = new SqlCeCommand(query, sqlCeConnection);
					sqlCeConnection.Open();
					var reader = sqlCeCommand.ExecuteReader();
					while (reader.Read())
					{
						if (IsAbort && !isReport)
							break;
						try
						{
							var journalItem = ReadOneJournalItem(reader);
							result.Add(journalItem);
							if (!isReport)
							{
								journalItems.Add(journalItem);
								if (journalItems.Count > 100)
								{
									if (ArchivePortionReady != null)
										ArchivePortionReady(journalItems.ToList());

									journalItems.Clear();
								}
							}
						}
						catch (Exception e)
						{
							Logger.Error(e, "DatabaseHelper.OnGetFilteredArchive");
						}
					}
					if (!isReport)
					{
						if (ArchivePortionReady != null)
							ArchivePortionReady(journalItems.ToList());
					}

					sqlCeConnection.Close();
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "Исключение при вызове FiresecService.GetFilteredArchive");
				throw new FS2Exception(e.Message);
			}
			return result;
		}
		public static void BeginGetFilteredArchive(ArchiveFilter archiveFilter)
		{
			//if (IsFS2Enabled)
			//{
			//    FiresecManager.FS2ClientContract.BeginGetFilteredArchive(archiveFilter);
			//}
			//else
			{
				FiresecManager.FiresecService.BeginGetFilteredArchive(archiveFilter);
			}
		}
		public OperationResult BeginGetFilteredArchive(ArchiveFilter archiveFilter)
		{
			return SafeOperationCall(() => { return FS2Contract.BeginGetFilteredArchive(archiveFilter); }, "BeginGetFilteredArchive");
		}
		public OperationResult<List<FS2JournalItem>> GetFilteredArchive(ArchiveFilter archiveFilter)
		{
			return SafeOperationCall(() => { return FS2Contract.GetFilteredArchive(archiveFilter); }, "GetFilteredArchive");
		}
Beispiel #10
0
		public static OperationResult<List<JournalRecord>> OnGetFilteredArchive(ArchiveFilter archiveFilter, bool isReport)
		{
			var operationResult = new OperationResult<List<JournalRecord>>();
			operationResult.Result = new List<JournalRecord>();
			try
			{
				string dateInQuery = "DeviceTime";
				if (archiveFilter.UseSystemDate)
					dateInQuery = "SystemTime";

				var query =
					"SELECT * FROM Journal WHERE " +
					"\n " + dateInQuery + " > '" + archiveFilter.StartDate.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
					"\n AND " + dateInQuery + " < '" + archiveFilter.EndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";

				if (archiveFilter.Descriptions.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.Descriptions.Count; i++)
					{
						if (i > 0)
							query += "\n OR ";
						var description = archiveFilter.Descriptions[i];
						description = description.Replace("'", "''");
						query += " Description = '" + description + "'";
					}
					query += ")";
				}

				if (archiveFilter.Subsystems.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.Subsystems.Count; i++)
					{
						if (i > 0)
							query += "\n OR ";
						var subsystem = archiveFilter.Subsystems[i];
						query += " SubSystemType = '" + ((int)subsystem).ToString() + "'";
					}
					query += ")";
				}

				if (archiveFilter.PanelUIDs.Count > 0)
				{
					query += "\n AND (";
					for (int i = 0; i < archiveFilter.PanelUIDs.Count; i++)
					{
						var deviceName = archiveFilter.PanelUIDs[i];
						if (deviceName != null)
						{
							if (i > 0)
								query += "\n OR ";
							query += " PanelDatabaseId = '" + deviceName + "'";
						}
					}
					query += ")";
				}

				query += "\n ORDER BY " + dateInQuery + " DESC";

				using (var DataBaseContext = new SqlCeConnection(ConnectionString))
				{
					DataBaseContext.ConnectionString = ConnectionString;
					var journalRecords = new List<JournalRecord>();
					var result = new SqlCeCommand(query, DataBaseContext);
					DataBaseContext.Open();
					var reader = result.ExecuteReader();
					while (reader.Read())
					{
						if (IsAbort && !isReport)
							break;
						try
						{
							var journalRecord = ReadOneJournalRecord(reader);
							operationResult.Result.Add(journalRecord);
							if (!isReport)
							{
								journalRecords.Add(journalRecord);
								if (journalRecords.Count > 100)
								{
									if (ArchivePortionReady != null)
										ArchivePortionReady(journalRecords.ToList());

									journalRecords.Clear();
								}
							}
						}
						catch (Exception e)
						{
							Logger.Error(e, "DatabaseHelper.OnGetFilteredArchive");
						}
					}
					if (!isReport)
					{
						if (ArchivePortionReady != null)
							ArchivePortionReady(journalRecords.ToList());
					}

					DataBaseContext.Close();
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "Исключение при вызове FiresecService.GetFilteredArchive");
				operationResult.HasError = true;
				operationResult.Error = e.Message.ToString();
			}
			return operationResult;
		}
 public void BeginGetFilteredArchive(ArchiveFilter archiveFilter)
 {
     SafeOperationCall(() => { FiresecService.BeginGetFilteredArchive(archiveFilter); });
 }
 public OperationResult<List<JournalRecord>> GetFilteredArchive(ArchiveFilter archiveFilter)
 {
     return SafeOperationCall(() => { return FiresecService.GetFilteredArchive(archiveFilter); });
 }
Beispiel #13
0
		ArchiveFilter GerFilterFromDefaultState(ArchiveDefaultState archiveDefaultState)
		{
			var archiveFilter = new ArchiveFilter()
			{
				StartDate = ArchiveFirstDate,
				EndDate = DateTime.Now
			};

			switch (archiveDefaultState.ArchiveDefaultStateType)
			{
				case ArchiveDefaultStateType.LastHours:
					if (archiveDefaultState.Count.HasValue)
						archiveFilter.StartDate = archiveFilter.EndDate.AddHours(-archiveDefaultState.Count.Value);
					break;

				case ArchiveDefaultStateType.LastDays:
					if (archiveDefaultState.Count.HasValue)
						archiveFilter.StartDate = archiveFilter.EndDate.AddDays(-archiveDefaultState.Count.Value);
					break;

				case ArchiveDefaultStateType.FromDate:
					if (archiveDefaultState.StartDate.HasValue)
						archiveFilter.StartDate = archiveDefaultState.StartDate.Value;
					break;

				case ArchiveDefaultStateType.RangeDate:
					if (archiveDefaultState.StartDate.HasValue)
						archiveFilter.StartDate = archiveDefaultState.StartDate.Value;
					if (archiveDefaultState.EndDate.HasValue)
						archiveFilter.EndDate = archiveDefaultState.EndDate.Value;
					break;
			}

			return archiveFilter;
		}
Beispiel #14
0
		void OnShowSettings()
		{
			try
			{
				var archiveSettingsViewModel = new ArchiveSettingsViewModel(ArchiveDefaultState);
				if (DialogService.ShowModalWindow(archiveSettingsViewModel))
				{
					ArchiveFilter = null;
					ArchiveDefaultState = archiveSettingsViewModel.GetModel();
					ClientSettings.ArchiveDefaultState = ArchiveDefaultState;
					IsFilterOn = false;
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ArchiveViewModel.ShowSettingsCommand");
				MessageBoxService.ShowException(e);
			}
		}
Beispiel #15
0
		void OnShowFilter()
		{
			try
			{
				if (ArchiveFilter == null)
					ArchiveFilter = GerFilterFromDefaultState(ArchiveDefaultState);

				ArchiveFilterViewModel archiveFilterViewModel = null;

				var result = WaitHelper.Execute(() =>
				{
					archiveFilterViewModel = new ArchiveFilterViewModel(ArchiveFilter);
				});

				if (result)
				{
					if (DialogService.ShowModalWindow(archiveFilterViewModel))
					{
						ArchiveFilter = archiveFilterViewModel.GetModel();
						OnPropertyChanged("IsFilterExists");
						IsFilterOn = true;
					}
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ArchiveViewModel.ShowSettingsCommand");
				MessageBoxService.ShowException(e);
			}
		}
		public static List<FS2JournalItem> GetFilteredArchive(ArchiveFilter archiveFilter)
		{
			return ServerFS2Database.OnGetFilteredArchive(archiveFilter, true);
		}