public static void Add(string description, string userName, Device panelDevice = null, Device device = null, Zone zone = null, StateType stateType = StateType.Info) { var journalItem = new FS2JournalItem { DeviceTime = DateTime.Now, SystemTime = DateTime.Now, Description = description, UserName = userName, PanelDevice = panelDevice, Device = device, StateType = stateType, SubsystemType = SubsystemType.Other, }; if (panelDevice != null) { journalItem.PanelName = panelDevice.DottedPresentationNameAndAddress; journalItem.PanelUID = panelDevice.UID; } if (device != null) { journalItem.DeviceName = device.DottedPresentationNameAndAddress; journalItem.DeviceUID = device.UID; } if (zone != null) { journalItem.ZoneNo = zone.No; journalItem.ZoneName = zone.PresentationName; } AddJournalItem(journalItem); }
static void AddJournalItem(FS2JournalItem fsJournalItem) { lock (Locker) { CallbackManager.NewJournalItems(new List<FS2JournalItem>() { fsJournalItem }); ServerFS2Database.AddJournalItem(fsJournalItem); } }
void ShowNewItem(FS2JournalItem journalItem) { Dispatcher.Invoke(new Action(() => { JournalItems.Insert(0, journalItem); JournalItemsCount++; })); }
void OnNewJournalItem(FS2JournalItem fsJournalItem) { CallbackManager.NewJournalItems(new List<FS2JournalItem>() { fsJournalItem }); ServerFS2Database.AddJournalItem(fsJournalItem); }
public static List<FS2JournalItem> GetJournalItems(Guid deviceUID) { var result = new List<FS2JournalItem>(); using (var sqlCeConnection = new SqlCeConnection(ConnectionString)) { sqlCeConnection.ConnectionString = ConnectionString; sqlCeConnection.Open(); var sqlCeCommand = new SqlCeCommand(); sqlCeCommand.Connection = sqlCeConnection; sqlCeCommand.CommandText = @"SELECT Description, Detalization, DeviceCategory, DeviceUID, DeviceName, DeviceTime, PanelUID, PanelName, StateType, SubsystemType, SystemTime, UserName, ZoneName FROM Journal"; var reader = sqlCeCommand.ExecuteReader(); while (reader.Read()) { try { var fsJournalItem = new FS2JournalItem(); fsJournalItem.Description = TryGetNullableString(reader, 0);// reader.GetString(0); fsJournalItem.Detalization = TryGetNullableString(reader, 1); fsJournalItem.DeviceCategory = reader.GetInt32(2); fsJournalItem.DeviceUID = reader.GetGuid(3); if (!reader.IsDBNull(4)) fsJournalItem.DeviceName = TryGetNullableString(reader, 4); fsJournalItem.DeviceTime = reader.GetDateTime(5); fsJournalItem.PanelUID = reader.GetGuid(6); fsJournalItem.PanelName = TryGetNullableString(reader, 7); fsJournalItem.StateType = (StateType)reader.GetInt32(8); fsJournalItem.SubsystemType = (SubsystemType)reader.GetInt32(9); fsJournalItem.SystemTime = reader.GetDateTime(10); fsJournalItem.UserName = TryGetNullableString(reader, 11); fsJournalItem.ZoneName = TryGetNullableString(reader, 12); result.Add(fsJournalItem); } catch { ;} } sqlCeConnection.Close(); } return result; }
public static void AddJournalItem(FS2JournalItem journalItem) { using (var dataContext = new SqlCeConnection(ConnectionString)) { dataContext.ConnectionString = ConnectionString; dataContext.Open(); AddItemSqlCommand(dataContext, journalItem); dataContext.Close(); } }
private static void AddItemSqlCommand(SqlCeConnection sqlCeConnection, FS2JournalItem journalItem) { try { var sqlCeCommand = new SqlCeCommand(); sqlCeCommand.Connection = sqlCeConnection; sqlCeCommand.CommandText = @"Insert Into Journal" + "(DeviceTime, SystemTime, Description, Detalization, DeviceName, PanelName, DeviceUID, PanelUID, ZoneName, DeviceCategory, StateType, SubsystemType, UserName) Values" + "(@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13)"; sqlCeCommand.Parameters.AddWithValue("@p1", (object)journalItem.DeviceTime ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p2", (object)journalItem.SystemTime ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p3", (object)journalItem.Description ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p4", (object)journalItem.Detalization ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p5", (object)journalItem.DeviceName ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p6", (object)journalItem.PanelName ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p7", (object)journalItem.DeviceUID ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p8", (object)journalItem.PanelUID ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p9", (object)journalItem.ZoneName ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p10", (object)journalItem.DeviceCategory ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p11", (object)journalItem.StateType ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p12", (object)journalItem.SubsystemType ?? DBNull.Value); sqlCeCommand.Parameters.AddWithValue("@p13", (object)journalItem.UserName ?? DBNull.Value); sqlCeCommand.ExecuteNonQuery(); } catch (Exception e) { Logger.Error(e, "DatabaseHelper.AddItemSqlCommand"); } }
static FS2JournalItem ReadOneJournalItem(SqlCeDataReader reader) { var journalItem = new FS2JournalItem(); if (!reader.IsDBNull(reader.GetOrdinal("Id"))) journalItem.No = reader.GetInt32(reader.GetOrdinal("Id")); if (!reader.IsDBNull(reader.GetOrdinal("SystemTime"))) journalItem.SystemTime = reader.GetDateTime(reader.GetOrdinal("SystemTime")); if (!reader.IsDBNull(reader.GetOrdinal("DeviceTime"))) journalItem.DeviceTime = reader.GetDateTime(reader.GetOrdinal("DeviceTime")); if (!reader.IsDBNull(reader.GetOrdinal("Description"))) journalItem.Description = reader.GetString(reader.GetOrdinal("Description")); if (!reader.IsDBNull(reader.GetOrdinal("Detalization"))) journalItem.Detalization = reader.GetString(reader.GetOrdinal("Detalization")); if (!reader.IsDBNull(reader.GetOrdinal("DeviceName"))) journalItem.DeviceName = reader.GetString(reader.GetOrdinal("DeviceName")); if (!reader.IsDBNull(reader.GetOrdinal("PanelName"))) journalItem.PanelName = reader.GetString(reader.GetOrdinal("PanelName")); if (!reader.IsDBNull(reader.GetOrdinal("DeviceUID"))) journalItem.DeviceUID = reader.GetGuid(reader.GetOrdinal("DeviceUID")); if (!reader.IsDBNull(reader.GetOrdinal("PanelUID"))) journalItem.PanelUID = reader.GetGuid(reader.GetOrdinal("PanelUID")); if (!reader.IsDBNull(reader.GetOrdinal("ZoneName"))) journalItem.ZoneName = reader.GetString(reader.GetOrdinal("ZoneName")); if (!reader.IsDBNull(reader.GetOrdinal("DeviceCategory"))) journalItem.DeviceCategory = reader.GetInt32(reader.GetOrdinal("DeviceCategory")); if (!reader.IsDBNull(reader.GetOrdinal("StateType"))) journalItem.StateType = (StateType)reader.GetInt32(reader.GetOrdinal("StateType")); if (!reader.IsDBNull(reader.GetOrdinal("SubsystemType"))) journalItem.SubsystemType = (SubsystemType)reader.GetInt32(reader.GetOrdinal("SubsystemType")); if (!reader.IsDBNull(reader.GetOrdinal("UserName"))) journalItem.UserName = reader.GetString(reader.GetOrdinal("UserName")); return journalItem; }
public void Compare(FS2JournalItem fs2JournalItem) { FS1No = fs2JournalItem.No; FS1DateTime = fs2JournalItem.DeviceTime; FS1Name = fs2JournalItem.Description; FS1Detalization = fs2JournalItem.Detalization; if (No != FS1No.ToString()) { IsNoMissmatch = true; Missmatch += "Несовпадают номера" + "\n"; } if (DateTime != FS1DateTime) { IsDateTimeMissmatch = true; Missmatch += "Несовпадают даты" + "\n"; } if (Name != FS1Name) { IsNameMissmatch = true; Missmatch += "Несовпадают названия" + "\n"; } if (Detalization != FS1Detalization) { IsDetalizationMissmatch = true; Missmatch += "Несовпадает детализация" + "\n"; } }
static void AddInfoMessage(string userName, string mesage) { var journalItem = new FS2JournalItem() { DeviceTime = DateTime.Now, SystemTime = DateTime.Now, StateType = StateType.Info, Description = mesage, UserName = userName, }; ServerFS2Database.AddJournalItems(new List<FS2JournalItem>() { journalItem }); //NotifyNewJournal(new List<FS2JournalItem>() { journalItem }); }
void ParceDeviceStateEnterLeave(FS2JournalItem journalItem, Device device, bool isDevice) { var metadataDeviceStates = MetadataHelper.GetMetadataDeviceStates(device, true); foreach (var metadataDeviceState in metadataDeviceStates) { if (metadataDeviceState.enter != null) { foreach (var deviceStateEnter in metadataDeviceState.enter) { string eventValue = null; if (isDevice) { eventValue = MetadataHelper.GetDeviceStateEventEnter(deviceStateEnter, journalItem.AdditionalEventCode); } else { eventValue = MetadataHelper.GetZoneStateEventEnter(deviceStateEnter, journalItem.AdditionalEventCode); } if (eventValue != null) { if (eventValue == "$" + journalItem.EventCode.ToString("X2")) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == metadataDeviceState.ID); if (driverState != null) { if (!device.DeviceState.States.Any(x => x.DriverState != null && x.DriverState.Code == driverState.Code)) { var deviceDriverState = new DeviceDriverState() { DriverState = driverState, Time = DateTime.Now }; device.DeviceState.States.Add(deviceDriverState); ForseUpdateDeviceStates(device); } } } } } } if (metadataDeviceState.leave != null) { foreach (var deviceStateLeave in metadataDeviceState.leave) { string eventValue = null; if (isDevice) { eventValue = MetadataHelper.GetDeviceStateEventLeave(deviceStateLeave, journalItem.AdditionalEventCode); } else { eventValue = MetadataHelper.GetZoneStateEventLeave(deviceStateLeave, journalItem.AdditionalEventCode); } if (eventValue != null) { if (eventValue == "$" + journalItem.EventCode.ToString("X2")) { var driverState = device.Driver.States.FirstOrDefault(x => x.Code == metadataDeviceState.ID); if (driverState != null) { var deviceDriverState = device.DeviceState.States.FirstOrDefault(x => x.DriverState.Code == driverState.Code); if (deviceDriverState != null) { device.DeviceState.States.Remove(deviceDriverState); ForseUpdateDeviceStates(device); } } } } } } } UpdateDeviceStateAndParameters(device); }
public FS2JournalItem Parce(DeviceConfiguration deviceConfiguration, Device panelDevice, List<byte> bytes, int journalType) { if (bytes.Count != 32) return null; Bytes = bytes; DeviceConfiguration = deviceConfiguration; FSInternalJournal = new FSInternalJournal() { ShleifNo = bytes[17] + 1, EventCode = bytes[0], AdditionalEventCode = bytes[5], DeviceType = bytes[7], AddressOnShleif = bytes[8], State = bytes[9], UnusedDescriptorNo = BytesHelper.ExtractTriple(bytes, 12), ZoneNo = BytesHelper.ExtractShort(bytes, 10) }; FS2JournalItem = new FS2JournalItem() { BytesString = BytesHelper.BytesToString(bytes), PanelDevice = panelDevice, PanelUID = panelDevice.UID, PanelName = panelDevice.DottedPresentationNameAndAddress, DeviceTime = TimeParceHelper.ParceDateTime(bytes.GetRange(1, 4)), SystemTime = DateTime.Now, EventCode = FSInternalJournal.EventCode, AdditionalEventCode = FSInternalJournal.AdditionalEventCode }; switch (journalType) { case 0x00: FS2JournalItem.SubsystemType = SubsystemType.Fire; break; case 0x02: FS2JournalItem.SubsystemType = SubsystemType.Guard; break; } MetadataEvent = MetadataHelper.Metadata.events.FirstOrDefault(x => x.rawEventCode == "$" + FSInternalJournal.EventCode.ToString("X2")); if (MetadataHelper.HasDevise(FSInternalJournal.EventCode)) { var intAddress = FSInternalJournal.AddressOnShleif + 256 * FSInternalJournal.ShleifNo; FS2JournalItem.Device = ConfigurationManager.Devices.FirstOrDefault(x => x.IntAddress == intAddress && x.ParentPanel == FS2JournalItem.PanelDevice && !x.Driver.IsGroupDevice); if (FS2JournalItem.Device != null) { FS2JournalItem.DeviceUID = FS2JournalItem.Device.UID; FS2JournalItem.DeviceName = FS2JournalItem.Device.PresentationName + " " + FS2JournalItem.Device.PresentationAddress; if (FSInternalJournal.DeviceType == 1) FS2JournalItem.DeviceName = "АСПТ " + (FSInternalJournal.ShleifNo - 1) + "."; } else { if (FSInternalJournal.DeviceType > 0) { var driverUID = MetadataHelper.GetUidById(FSInternalJournal.DeviceType); if (driverUID != Guid.Empty) { var driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.UID == driverUID); FS2JournalItem.DeviceName = driver.ShortName + " " + FSInternalJournal.ShleifNo + "." + FSInternalJournal.AddressOnShleif; } } } } FS2JournalItem.HasZone = MetadataHelper.HasZone(FSInternalJournal.AdditionalEventCode); InitializeZone(); FS2JournalItem.StateType = GetEventStateType(); FS2JournalItem.Description = GetEventName(); FS2JournalItem.Detalization = GetDetalization(); FS2JournalItem.UserName = GetUserName(); //Initialize_0x80_Event(); if (FS2JournalItem.Description.Contains("Пожарная тревога")) { ; } return FS2JournalItem; }