Created
February 16, 2018 08:46
-
-
Save sebakerckhof/eaf1d27563e289ef4e1b65fa42a33273 to your computer and use it in GitHub Desktop.
test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decompiled with JetBrains decompiler | |
// Type: ATSx500.Panel.Connection.CommandAndControlSession | |
// Assembly: ATSx500.Panel.Connection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=12fb96c0395fa3ed | |
// MVID: A53EC47C-87EB-4DBE-8F95-0E80DF5C83D3 | |
// Assembly location: C:\Program Files\ATS8500 Standalone Downloader\ATSx500.Panel.Connection.dll | |
using Ace; | |
using ATSx500.Panel.Connection.Common; | |
using ATSx500.Panel.Connection.Control; | |
using ATSx500.Utilities; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace ATSx500.Panel.Connection | |
{ | |
internal class CommandAndControlSession : BackgroundSession | |
{ | |
private static readonly IDictionary<Type, ControlActivator> controlSessionMap = CommandAndControlSession.LoadControlSessionMap(); | |
private static readonly IDictionary<ATSDevices, CommandAndControlSession.StatusProgram> statusProgram = (IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>) new CommandAndControlSession.StatusProgramMap(); | |
private readonly IDictionary<ATSDevices, BitArray> validObjects = (IDictionary<ATSDevices, BitArray>) new Dictionary<ATSDevices, BitArray>(); | |
private readonly IDictionary<ATSDevices, IDictionary<int, string>> objectNames = (IDictionary<ATSDevices, IDictionary<int, string>>) new Dictionary<ATSDevices, IDictionary<int, string>>(); | |
private readonly AtomicBool updateSystem = new AtomicBool(true); | |
private readonly AtomicBool updatePanel = new AtomicBool(true); | |
private readonly AtomicBool updateCalendar = new AtomicBool(true); | |
private readonly AtomicBool updateStatus = new AtomicBool(false); | |
private readonly Dictionary<int, IMessage> deviceStatuses = new Dictionary<int, IMessage>(); | |
private ATSDevices deviceType = ~ATSDevices.ZonesDev; | |
private const ATSDevices NoneDevice = ~ATSDevices.ZonesDev; | |
private readonly IMessage[] privileges; | |
internal CommandAndControlSession(PanelConnection panelConnection, IPanelStatusObserver observer, IDisposable connectionToken) | |
: base(panelConnection, observer, connectionToken) | |
{ | |
this.privileges = new IMessage[(int) panelConnection.CreateMessage("is.Alive").Factory.GetProperty("maximum-area-index", 0, (object) typeof (int)) + 1]; | |
} | |
internal MessageFlagsDictionary UpdateStatus(ATSDevices deviceType) | |
{ | |
this.CheckCancelled(); | |
string id = ""; | |
switch (deviceType) | |
{ | |
case ATSDevices.PanelDev: | |
id = "getSTAT.DGP0"; | |
break; | |
case ATSDevices.SystemDev: | |
id = "getSTAT.SYS"; | |
break; | |
case ATSDevices.CalendarDev: | |
id = "getSTAT.SCAL"; | |
break; | |
} | |
IMessage message1 = this.Panel.CreateMessage(id); | |
message1.SetProperty("objectID", 0, (object) 1); | |
IMessage message2 = this.Panel.EndSend(this.Panel.BeginSend(message1, (AsyncCallback) null)); | |
this.CheckCancelled(); | |
return new MessageFlagsDictionary(message2); | |
} | |
internal void RequestStatus(int deviceType, int[] indexes) | |
{ | |
lock (this.deviceStatuses) | |
{ | |
this.updateSystem.Value = true; | |
this.updatePanel.Value = true; | |
this.updateCalendar.Value = true; | |
this.updateStatus.Value = true; | |
this.deviceStatuses.Clear(); | |
this.deviceType = (ATSDevices) deviceType; | |
foreach (int index in indexes) | |
this.deviceStatuses.Add(index, (IMessage) null); | |
this.Update(); | |
} | |
} | |
internal BitArray GetValidObjects(ATSDevices deviceType) | |
{ | |
BitArray bits; | |
if (!this.EnsureValidObjectsAvailable(deviceType).TryGetValue(deviceType, out bits)) | |
return (BitArray) null; | |
return new BitArray(bits); | |
} | |
internal string GetObjectName(ATSDevices deviceType, int index) | |
{ | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (!CommandAndControlSession.statusProgram.TryGetValue(deviceType, out statusProgram)) | |
return (string) null; | |
if (statusProgram.GetNames == null) | |
return (string) null; | |
BitArray validObjects = this.GetValidObjects(deviceType); | |
int index1 = index - 1; | |
if (index1 < 0 || index1 >= validObjects.Length) | |
return (string) null; | |
if (!validObjects[index1]) | |
return (string) null; | |
IDictionary<int, string> dictionary; | |
if (!this.objectNames.TryGetValue(deviceType, out dictionary)) | |
{ | |
dictionary = (IDictionary<int, string>) new Dictionary<int, string>(); | |
this.objectNames[deviceType] = dictionary; | |
} | |
string str; | |
if (!dictionary.TryGetValue(index, out str)) | |
{ | |
IMessage message1 = this.Panel.CreateMessage(statusProgram.GetNames); | |
message1.SetProperty(nameof (index), 0, (object) index); | |
IMessage message2 = this.Panel.EndSend(this.Panel.BeginSend(message1, (AsyncCallback) null)); | |
int property1 = (int) message2.GetProperty(nameof (index), 0, (object) typeof (int)); | |
int count = message2.Count; | |
for (int index2 = 0; index2 < count; ++index2) | |
{ | |
int index3 = property1 + index2; | |
string property2 = (string) message2.GetProperty("name", index2 + 1, (object) typeof (string)); | |
dictionary[index3] = property2; | |
if (index3 == index) | |
str = property2; | |
} | |
} | |
return str; | |
} | |
internal T BeginControl<T>(params int[] areas) where T : IPanelControl | |
{ | |
if (CommandAndControlSession.controlSessionMap.ContainsKey(typeof (T))) | |
return (T) CommandAndControlSession.controlSessionMap[typeof (T)](this, areas); | |
throw new NotSupportedException(); | |
} | |
internal T BeginControl<T>(params string[] privileges) where T : IPanelControl | |
{ | |
return this.BeginControl<T>(this.GetAreasByPrivileges(privileges)); | |
} | |
internal override bool Received(IMessage eventMessage) | |
{ | |
string id = eventMessage.Info.Id; | |
if (id == "msgCOS.ALL") | |
return this.RefreshStatus(eventMessage); | |
if (id == "msg.MONITOR") | |
return this.LogLiveView(eventMessage); | |
return false; | |
} | |
protected override void Setup() | |
{ | |
} | |
protected override void Login() | |
{ | |
this.Panel.Login(UserAction.Upload | UserAction.Control, UserAction.Diagnostics | UserAction.Monitor, "CONTROL_NO_ACCESS"); | |
AggregateCall aggregateCall = new AggregateCall(this.Panel, this.privileges.Length, (int[]) null); | |
for (int index = 0; index < this.privileges.Length; ++index) | |
{ | |
IMessage message = this.Panel.CreateMessage("get.privileges"); | |
message.SetProperty("areaID", 0, (object) index); | |
aggregateCall.Add(message); | |
} | |
aggregateCall.EndExecute(aggregateCall.BeginExecute((Action) null, (AsyncCallback) null, (object) null)); | |
for (int index = 0; index < this.privileges.Length; ++index) | |
{ | |
KeyValuePair<IMessage, IMessage> keyValuePair = aggregateCall[index]; | |
IMessage key = keyValuePair.Key; | |
IMessage message = keyValuePair.Value; | |
this.privileges[index] = message; | |
} | |
this.LoadDateTime(); | |
} | |
protected override void Cleanup() | |
{ | |
this.updateSystem.Value = false; | |
this.updatePanel.Value = false; | |
this.updateStatus.Value = false; | |
lock (this.deviceStatuses) | |
this.deviceStatuses.Clear(); | |
} | |
protected override void Refresh() | |
{ | |
ATSDevices deviceType = this.deviceType; | |
int systemIndex = -1; | |
int panelIndex = -1; | |
int calendarIndex = -1; | |
int index = -1; | |
int validIndex = -1; | |
AggregateCall aggregateCall = new AggregateCall(this.Panel, 4, (int[]) null); | |
if (this.updateSystem.GetAndSet(false)) | |
{ | |
systemIndex = aggregateCall.Count; | |
IMessage message = this.Panel.CreateMessage(CommandAndControlSession.statusProgram[ATSDevices.SystemDev].GetStatus); | |
message.SetProperty("objectID", 0, (object) 1); | |
aggregateCall.Add(message); | |
} | |
if (this.updatePanel.GetAndSet(false)) | |
{ | |
panelIndex = aggregateCall.Count; | |
IMessage message = this.Panel.CreateMessage(CommandAndControlSession.statusProgram[ATSDevices.PanelDev].GetStatus); | |
message.SetProperty("objectID", 0, (object) 1); | |
aggregateCall.Add(message); | |
} | |
if (this.updateCalendar.GetAndSet(false)) | |
{ | |
calendarIndex = aggregateCall.Count; | |
IMessage message = this.Panel.CreateMessage(CommandAndControlSession.statusProgram[ATSDevices.CalendarDev].GetStatus); | |
message.SetProperty("objectID", 0, (object) 1); | |
aggregateCall.Add(message); | |
} | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (this.updateStatus.GetAndSet(false) && CommandAndControlSession.statusProgram.TryGetValue(deviceType, out statusProgram) && statusProgram.ListCos != null) | |
{ | |
index = aggregateCall.Count; | |
aggregateCall.Add(this.Panel.CreateMessage(statusProgram.ListCos)); | |
if (statusProgram.GetValid != null) | |
{ | |
lock (this.validObjects) | |
{ | |
if (!this.validObjects.ContainsKey(deviceType)) | |
{ | |
IMessage request; | |
try | |
{ | |
request = this.Panel.CreateMessage(statusProgram.GetValid); | |
} | |
catch (ArgumentException ex) | |
{ | |
request = (IMessage) null; | |
} | |
if (request != null) | |
{ | |
validIndex = aggregateCall.Count; | |
aggregateCall.Add(request); | |
} | |
} | |
} | |
} | |
} | |
bool refreshTime = false; | |
aggregateCall.Ready += (Action<int, IMessage, IMessage>) ((no, request, response) => | |
{ | |
if (no == systemIndex) | |
{ | |
this.Observer.UpdateDeviceFlags(17, 0, (IDictionary<string, bool>) new MessageFlagsDictionary(response)); | |
refreshTime = (bool) response.GetProperty("SYSEV_TIMECHG", 0, (object) typeof (bool)); | |
} | |
else if (no == panelIndex) | |
this.Observer.UpdateDeviceFlags(8, 0, (IDictionary<string, bool>) new MessageFlagsDictionary(response)); | |
else if (no == calendarIndex) | |
{ | |
this.Observer.UpdateDeviceFlags(20, 0, (IDictionary<string, bool>) new MessageFlagsDictionary(response)); | |
} | |
else | |
{ | |
if (no != validIndex) | |
return; | |
lock (this.validObjects) | |
this.validObjects[deviceType] = new BitArray((byte[]) aggregateCall[validIndex].Value.GetProperty("bitset", 0, (object) typeof (byte[]))); | |
} | |
}); | |
aggregateCall.EndExecute(aggregateCall.BeginExecute(new Action(((BackgroundSession) this).CheckCancelled), (AsyncCallback) null, (object) null)); | |
if (refreshTime) | |
this.LoadDateTime(); | |
if (index < 0) | |
return; | |
BitArray valid; | |
lock (this.validObjects) | |
{ | |
if (!this.validObjects.TryGetValue(deviceType, out valid)) | |
valid = (BitArray) null; | |
} | |
BitArray flags = new BitArray((byte[]) aggregateCall[index].Value.GetProperty("bitSet", 0, (object) typeof (byte[]))); | |
this.RefreshDevicesStatus(deviceType, flags, valid); | |
} | |
private static IDictionary<Type, ControlActivator> LoadControlSessionMap() | |
{ | |
return (IDictionary<Type, ControlActivator>) new Dictionary<Type, ControlActivator>() | |
{ | |
{ | |
typeof (IControlFullSetArea), | |
new ControlActivator(ControlSetAreas.ActivatorFullSet) | |
}, | |
{ | |
typeof (IControlPartSetArea), | |
new ControlActivator(ControlSetAreas.ActivatorPartSet) | |
}, | |
{ | |
typeof (IControlSecondPartSetArea), | |
new ControlActivator(ControlSetAreas.ActivatorPartSet2) | |
}, | |
{ | |
typeof (IControlWalkTest), | |
new ControlActivator(ControlWalkTest.Activator) | |
}, | |
{ | |
typeof (IControlUnsetArea), | |
new ControlActivator(ControlUnsetArea.Activator) | |
}, | |
{ | |
typeof (IControlConfirmPendingEvents), | |
new ControlActivator(ControlConfirmPendingEvents.Activator) | |
}, | |
{ | |
typeof (IControlZone), | |
new ControlActivator(ControlZone.Activator) | |
}, | |
{ | |
typeof (IControlDevice), | |
new ControlActivator(ControlDevice.Activator) | |
}, | |
{ | |
typeof (IControlOutputTrigger), | |
new ControlActivator(ControlOutputTrigger.Activator) | |
}, | |
{ | |
typeof (IControlEngineerReset), | |
new ControlActivator(ControlEngineerReset.Activator) | |
}, | |
{ | |
typeof (IControlChangeDateTime), | |
new ControlActivator(ControlChangeDateTime.Activator) | |
}, | |
{ | |
typeof (IControlRemotePCConnection), | |
new ControlActivator(ControlRemotePCConnection.Activator) | |
}, | |
{ | |
typeof (IControlOutputTest), | |
new ControlActivator(ControlOutputTest.Activator) | |
}, | |
{ | |
typeof (IControlUser), | |
new ControlActivator(ControlUser.Activator) | |
}, | |
{ | |
typeof (IControlTestCall), | |
new ControlActivator(ControlTestCall.Activator) | |
}, | |
{ | |
typeof (IUserInfo), | |
new ControlActivator(UserInfo.Activator) | |
}, | |
{ | |
typeof (IMonitorControl), | |
new ControlActivator(MonitorControl.Activator) | |
}, | |
{ | |
typeof (ISensorStateCheck), | |
new ControlActivator(SensorStateCheck.Activator) | |
}, | |
{ | |
typeof (IDiagnostics), | |
new ControlActivator(Diagnostics.Activator) | |
}, | |
{ | |
typeof (IControlCamera), | |
new ControlActivator(ControlCameras.Activator) | |
}, | |
{ | |
typeof (IControlRangeTest), | |
new ControlActivator(ControlRangeTest.Activator) | |
}, | |
{ | |
typeof (IControlInvertedWalktest), | |
new ControlActivator(ControlInvertedWalktest.Activator) | |
}, | |
{ | |
typeof (IControlWalkTestMode), | |
new ControlActivator(ControlWalkTestMode.Activator) | |
}, | |
{ | |
typeof (IControlDoor), | |
new ControlActivator(ControlDoor.Activator) | |
} | |
}; | |
} | |
private IDictionary<ATSDevices, BitArray> EnsureValidObjectsAvailable(params ATSDevices[] deviceTypes) | |
{ | |
AggregateCall aggregateCall = new AggregateCall(this.Panel, deviceTypes.Length, (int[]) null); | |
List<ATSDevices> atsDevicesList = new List<ATSDevices>(deviceTypes.Length); | |
Dictionary<ATSDevices, BitArray> dictionary = new Dictionary<ATSDevices, BitArray>(deviceTypes.Length); | |
lock (this.validObjects) | |
{ | |
foreach (ATSDevices deviceType in deviceTypes) | |
{ | |
BitArray bitArray1; | |
if (this.validObjects.TryGetValue(deviceType, out bitArray1)) | |
dictionary.Add(deviceType, bitArray1); | |
else if (deviceType == ATSDevices.RegionDev && this.Panel.Info.PanelVersion.Protocol >= 3000) | |
{ | |
BitArray bitArray2 = new BitArray((int) byte.MaxValue, true); | |
this.validObjects.Add(ATSDevices.RegionDev, bitArray2); | |
dictionary.Add(ATSDevices.RegionDev, bitArray2); | |
} | |
else | |
{ | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (CommandAndControlSession.statusProgram.TryGetValue(deviceType, out statusProgram)) | |
{ | |
if (statusProgram.GetValid != null) | |
{ | |
try | |
{ | |
aggregateCall.Add(this.Panel.CreateMessage(statusProgram.GetValid)); | |
atsDevicesList.Add(deviceType); | |
} | |
catch (ArgumentException ex) | |
{ | |
} | |
} | |
} | |
} | |
} | |
} | |
if (aggregateCall.Count > 0) | |
{ | |
aggregateCall.EndExecute(aggregateCall.BeginExecute(new Action(((BackgroundSession) this).CheckCancelled), (AsyncCallback) null, (object) null)); | |
lock (this.validObjects) | |
{ | |
for (int index = 0; index < aggregateCall.Count; ++index) | |
{ | |
byte[] property = (byte[]) aggregateCall[index].Value.GetProperty("bitset", 0, (object) typeof (byte[])); | |
ATSDevices key = atsDevicesList[index]; | |
BitArray bitArray = new BitArray(property); | |
this.validObjects[key] = bitArray; | |
dictionary.Add(key, bitArray); | |
} | |
} | |
} | |
return (IDictionary<ATSDevices, BitArray>) dictionary; | |
} | |
private int[] GetAreasByPrivileges(params string[] privileges) | |
{ | |
if (privileges.Length == 0) | |
return new int[0]; | |
Predicate<IMessage> match = (Predicate<IMessage>) (message => | |
{ | |
foreach (string privilege in privileges) | |
{ | |
if ((bool) message.GetProperty(privilege, 0, (object) typeof (bool))) | |
return true; | |
} | |
return false; | |
}); | |
List<int> intList = new List<int>(); | |
for (int index = Array.FindIndex<IMessage>(this.privileges, 1, match); index != -1 && index < this.privileges.Length; index = Array.FindIndex<IMessage>(this.privileges, index + 1, match)) | |
intList.Add(index); | |
if (intList.Count == 0 && !match(this.privileges[0])) | |
throw new UnauthorizedAccessException(); | |
return intList.ToArray(); | |
} | |
private void LoadDateTime() | |
{ | |
DateTime universalTime1 = DateTime.Now.ToUniversalTime(); | |
IMessage message = this.Panel.EndSend(this.Panel.BeginSend(this.Panel.CreateMessage("get.timedate"), (AsyncCallback) null)); | |
DateTime universalTime2 = DateTime.Now.ToUniversalTime(); | |
DateTime dateTime = universalTime1 + TimeSpan.FromMilliseconds((universalTime2 - universalTime1).TotalMilliseconds / 2.0); | |
string id = "timeStamp"; | |
int index = 0; | |
Type type = typeof (DateTime); | |
TimeSpan timeSpan = (DateTime) message.GetProperty(id, index, (object) type) - dateTime; | |
AtsTimeZoneInfo timeZone = this.Panel.TimeZone; | |
this.Observer.UpdateTime(timeSpan, timeZone.StartDaylightMonth - 1, timeZone.StartDaylightWeek, timeZone.EndDaylightMonth - 1, timeZone.EndDaylightWeek, timeZone.Utc); | |
} | |
internal DateTime GetPanelDateTime() | |
{ | |
DateTime universalTime1 = DateTime.Now.ToUniversalTime(); | |
IMessage message = this.Panel.EndSend(this.Panel.BeginSend(this.Panel.CreateMessage("get.timedate"), (AsyncCallback) null)); | |
DateTime universalTime2 = DateTime.Now.ToUniversalTime(); | |
DateTime dateTime = universalTime1 + TimeSpan.FromMilliseconds((universalTime2 - universalTime1).TotalMilliseconds / 2.0); | |
string id = "timeStamp"; | |
int index = 0; | |
Type type = typeof (DateTime); | |
return (DateTime) message.GetProperty(id, index, (object) type); | |
} | |
private bool RefreshStatus(IMessage eventMessage) | |
{ | |
if (this.deviceType == ~ATSDevices.ZonesDev) | |
return false; | |
bool flag = false; | |
if ((bool) eventMessage.GetProperty("APPOBJ_SYS", 0, (object) typeof (bool))) | |
flag |= !this.updateSystem.GetAndSet(true); | |
if ((bool) eventMessage.GetProperty("APPOBJ_DGP0", 0, (object) typeof (bool))) | |
flag |= !this.updatePanel.GetAndSet(true); | |
if ((bool) eventMessage.GetProperty("APPOBJ_SCHDL_CAL", 0, (object) typeof (bool))) | |
flag |= !this.updateCalendar.GetAndSet(true); | |
ATSDevices deviceType = this.deviceType; | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (CommandAndControlSession.statusProgram.TryGetValue(deviceType, out statusProgram) && (bool) eventMessage.GetProperty(statusProgram.GlobalName, 0, (object) typeof (bool))) | |
flag |= !this.updateStatus.GetAndSet(true); | |
if (flag) | |
this.Update(); | |
return true; | |
} | |
private bool LogLiveView(IMessage eventMessage) | |
{ | |
return this.Observer.LogEvent((DateTime) eventMessage.GetProperty("timeStamp", 0, (object) typeof (DateTime)), (int) eventMessage.GetProperty("unique_id", 0, (object) typeof (int)), (int) eventMessage.GetProperty("logType", 0, (object) typeof (int)), (int) eventMessage.GetProperty("event_ID", 0, (object) typeof (int)), (int) eventMessage.GetProperty("event_source", 0, (object) typeof (int)), (int) eventMessage.GetProperty("source_ID", 0, (object) typeof (int)), (string) eventMessage.GetProperty(eventMessage.GetPropertyStatus("user-card-data", 0) == PropertyStatus.Ok ? "user-card-data" : "event_text", 0, (object) typeof (string)), (int?) eventMessage.GetProperty("Area", 0, (object) typeof (int)), LogEventsReader.GetEventLogDetails(eventMessage)); | |
} | |
private void RefreshDevicesStatus(ATSDevices deviceType, BitArray flags, BitArray valid) | |
{ | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (!CommandAndControlSession.statusProgram.TryGetValue(deviceType, out statusProgram)) | |
return; | |
List<KeyValuePair<int, IMessage>> keyValuePairList; | |
lock (this.deviceStatuses) | |
{ | |
if (deviceType != this.deviceType) | |
return; | |
keyValuePairList = new List<KeyValuePair<int, IMessage>>((IEnumerable<KeyValuePair<int, IMessage>>) this.deviceStatuses); | |
} | |
if (keyValuePairList.Count <= 0) | |
return; | |
AggregateCall aggregateCall = new AggregateCall(this.Panel, keyValuePairList.Count, new int[2] | |
{ | |
2, | |
3 | |
}); | |
foreach (KeyValuePair<int, IMessage> keyValuePair in keyValuePairList) | |
{ | |
int index = keyValuePair.Key - 1; | |
if ((valid == null || valid[index]) && (flags[index] || keyValuePair.Value == null)) | |
{ | |
IMessage message = this.Panel.CreateMessage(statusProgram.GetStatus); | |
message.SetProperty("objectID", 0, (object) keyValuePair.Key); | |
aggregateCall.Add(message); | |
} | |
} | |
aggregateCall.Ready += (Action<int, IMessage, IMessage>) ((no, request, response) => | |
{ | |
int property = (int) request.GetProperty("objectID", 0, (object) typeof (int)); | |
lock (this.deviceStatuses) | |
{ | |
if (deviceType != this.deviceType) | |
return; | |
if (response.Info.Id == "fault") | |
{ | |
this.deviceStatuses.Remove(property); | |
return; | |
} | |
if (!this.deviceStatuses.ContainsKey(property)) | |
return; | |
this.deviceStatuses[property] = response; | |
} | |
this.Observer.UpdateDeviceFlags((int) deviceType, property, (IDictionary<string, bool>) new MessageFlagsDictionary(response)); | |
}); | |
OperationCanceledException refreshCanceled = new OperationCanceledException(); | |
try | |
{ | |
Action canceled = (Action) (() => | |
{ | |
this.CheckCancelled(); | |
lock (this.deviceStatuses) | |
{ | |
if (deviceType != this.deviceType) | |
throw refreshCanceled; | |
} | |
}); | |
aggregateCall.EndExecute(aggregateCall.BeginExecute(canceled, (AsyncCallback) null, (object) null)); | |
} | |
catch (OperationCanceledException ex) | |
{ | |
OperationCanceledException canceledException = refreshCanceled; | |
if (ex == canceledException) | |
return; | |
throw; | |
} | |
} | |
internal IList<IDictionary<string, bool>> UpdateDeviceStatus(params KeyValuePair<int, int>[] devices) | |
{ | |
if (devices == null) | |
return (IList<IDictionary<string, bool>>) null; | |
if (devices.Length == 0) | |
return (IList<IDictionary<string, bool>>) new List<IDictionary<string, bool>>(0); | |
HashSet<ATSDevices> source = new HashSet<ATSDevices>(); | |
foreach (KeyValuePair<int, int> device in devices) | |
{ | |
CommandAndControlSession.StatusProgram statusProgram; | |
if (!CommandAndControlSession.statusProgram.TryGetValue((ATSDevices) device.Key, out statusProgram)) | |
throw new ArgumentException(); | |
if (statusProgram.ListCos != null) | |
source.Add((ATSDevices) device.Key); | |
} | |
IDictionary<ATSDevices, BitArray> dictionary1 = this.EnsureValidObjectsAvailable(source.ToArray<ATSDevices>()); | |
Dictionary<KeyValuePair<int, int>, int> dictionary2 = new Dictionary<KeyValuePair<int, int>, int>(devices.Length); | |
int[] numArray; | |
if (this.Panel.Info.PanelVersion.Protocol >= 2000) | |
numArray = (int[]) null; | |
else | |
numArray = new int[2]{ 2, 3 }; | |
int[] knownFaults = numArray; | |
AggregateCall aggregateCall = new AggregateCall(this.Panel, devices.Length, knownFaults); | |
foreach (KeyValuePair<int, int> device in devices) | |
{ | |
CommandAndControlSession.StatusProgram statusProgram = CommandAndControlSession.statusProgram[(ATSDevices) device.Key]; | |
int num = statusProgram.ListCos != null ? device.Value : 1; | |
KeyValuePair<int, int> key = new KeyValuePair<int, int>(device.Key, num); | |
BitArray bitArray; | |
if (!dictionary1.TryGetValue((ATSDevices) device.Key, out bitArray)) | |
bitArray = (BitArray) null; | |
if (!dictionary2.ContainsKey(key)) | |
{ | |
if (bitArray != null && (num <= 0 || num > bitArray.Count || !bitArray[num - 1])) | |
{ | |
dictionary2.Add(key, -1); | |
} | |
else | |
{ | |
IMessage message = this.Panel.CreateMessage(statusProgram.GetStatus); | |
if (statusProgram.ListCos != null) | |
message.SetProperty("objectID", 0, (object) num); | |
dictionary2.Add(key, aggregateCall.Count); | |
aggregateCall.Add(message); | |
} | |
} | |
} | |
aggregateCall.EndExecute(aggregateCall.BeginExecute(new Action(((BackgroundSession) this).CheckCancelled), (AsyncCallback) null, (object) null)); | |
List<IDictionary<string, bool>> dictionaryList = new List<IDictionary<string, bool>>(devices.Length); | |
foreach (KeyValuePair<int, int> device in devices) | |
{ | |
int num = CommandAndControlSession.statusProgram[(ATSDevices) device.Key].ListCos != null ? device.Value : 1; | |
int index = dictionary2[new KeyValuePair<int, int>(device.Key, num)]; | |
if (index == -1) | |
{ | |
dictionaryList.Add((IDictionary<string, bool>) null); | |
} | |
else | |
{ | |
IMessage message = aggregateCall[index].Value; | |
if (StringComparer.Ordinal.Equals(message.Info.Id, "fault")) | |
dictionaryList.Add((IDictionary<string, bool>) null); | |
else | |
dictionaryList.Add((IDictionary<string, bool>) new MessageFlagsDictionary(message)); | |
} | |
} | |
return (IList<IDictionary<string, bool>>) dictionaryList; | |
} | |
private class StatusProgramMap : IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>, ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>, IEnumerable<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>, IEnumerable | |
{ | |
private IDictionary<ATSDevices, CommandAndControlSession.StatusProgram> result = (IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>) new Dictionary<ATSDevices, CommandAndControlSession.StatusProgram>(); | |
internal StatusProgramMap() | |
{ | |
this.result.Add(ATSDevices.PanelDev, new CommandAndControlSession.StatusProgram("APPOBJ_DGP0", (string) null, "getSTAT.DGP0", (string) null, (string) null)); | |
this.result.Add(ATSDevices.SystemDev, new CommandAndControlSession.StatusProgram("APPOBJ_SYS", (string) null, "getSTAT.SYS", (string) null, (string) null)); | |
this.result.Add(ATSDevices.CalendarDev, new CommandAndControlSession.StatusProgram("APPOBJ_SCHDL_CAL", (string) null, "getSTAT.SCAL", (string) null, (string) null)); | |
this.result.Add(ATSDevices.ZonesDev, new CommandAndControlSession.StatusProgram("APPOBJ_ZN", "getCOS.ZONE", "getSTAT.ZONE", "getValid.Zones", "select.ZoneNames")); | |
this.result.Add(ATSDevices.AreasDev, new CommandAndControlSession.StatusProgram("APPOBJ_AREA", "getCOS.AREA", "getSTAT.AREA", "getValid.Areas", "select.AreaNames")); | |
this.result.Add(ATSDevices.RasDev, new CommandAndControlSession.StatusProgram("APPOBJ_RAS", "getCOS.RAS", "getSTAT.RAS", "getValid.Rases", "select.RASNames")); | |
this.result.Add(ATSDevices.ReaderDev, new CommandAndControlSession.StatusProgram("APPOBJ_READER", "getCOS.READER", "getSTAT.READER", "getValid.Readers", "select.ReaderNames")); | |
this.result.Add(ATSDevices.DgpDev, new CommandAndControlSession.StatusProgram("APPOBJ_DGP", "getCOS.DGP", "getSTAT.DGP", "getValid.Dgps", "select.DGPNames")); | |
this.result.Add(ATSDevices.UserDev, new CommandAndControlSession.StatusProgram("APPOBJ_USER", "getCOS.USER", "getSTAT.USER", "getValid.Users", "select.UserNames")); | |
this.result.Add(ATSDevices.OutputDev, new CommandAndControlSession.StatusProgram("APPOBJ_OUT", "getCOS.OUT", "getSTAT.OUT", "getValid.Outputs", "select.OutputNames")); | |
this.result.Add(ATSDevices.FilterDev, new CommandAndControlSession.StatusProgram("APPOBJ_CEVFLT", "getCOS.FILTER", "getSTAT.FILTER", "getValid.CEvFilters", "select.CEvFilterNames")); | |
this.result.Add(ATSDevices.UserGrpDev, new CommandAndControlSession.StatusProgram("APPOBJ_UG", "getCOS.UG", "getSTAT.UG", "getValid.UserGroups", "select.UserGroupNames")); | |
this.result.Add(ATSDevices.DoorDev, new CommandAndControlSession.StatusProgram("APPOBJ_DOOR", "getCOS.DOOR", "getSTAT.DOOR", "getValid.Doors", "select.DoorNames")); | |
this.result.Add(ATSDevices.CSDev, new CommandAndControlSession.StatusProgram("APPOBJ_CS", "getCOS.CS", "getSTAT.CS", "getValid.CSs", "select.CSNames")); | |
this.result.Add(ATSDevices.PCConnDev, new CommandAndControlSession.StatusProgram("APPOBJ_PCC", "getCOS.PCC", "getSTAT.PCC", "getValid.PCCs", "select.PCCNames")); | |
this.result.Add(ATSDevices.TriggerDev, new CommandAndControlSession.StatusProgram("APPOBJ_TRIGG", "getCOS.TRIGG", "getSTAT.TRIGG", "getValid.Triggers", "select.TriggerNames")); | |
this.result.Add(ATSDevices.ExceptionDev, new CommandAndControlSession.StatusProgram("APPOBJ_SCHDL_EXC", "getCOS.EXCP", "getSTAT.EXCP", "getValid.SchedExcs", "select.SchedExcNames")); | |
this.result.Add(ATSDevices.FobDev, new CommandAndControlSession.StatusProgram("APPOBJ_FOB", "getCOS.FOB", "getSTAT.FOB", "getValid.Fobs", "select.FobNames")); | |
this.result.Add(ATSDevices.CameraDev, new CommandAndControlSession.StatusProgram("APPOBJ_CAMERA", "getCOS.CAMERA", "getSTAT.CAMERA", "getValid.Cameras", "select.CameraNames")); | |
this.result.Add(ATSDevices.AreaGroupsDev, new CommandAndControlSession.StatusProgram("APPOBJ_AG", "getCOS.AG", "getSTAT.AG", "getValid.AreaGroups", "select.AreaGroupNames")); | |
this.result.Add(ATSDevices.ScheduleDev3, new CommandAndControlSession.StatusProgram("APPOBJ_SCHEDULE", "getCOS.SCHDL", "getSTAT.SCHDL", "getValid.Schdls", "select.SchdlNames")); | |
this.result.Add(ATSDevices.SpecialDayDev, new CommandAndControlSession.StatusProgram("APPOBJ_SPCLDAY", "getCOS.SPCLDAY", "getSTAT.SPCLDAY", "getValid.SpclDays", "select.SpclDayNames")); | |
this.result.Add(ATSDevices.VocDev, new CommandAndControlSession.StatusProgram("APPOBJ_VOC", "getCOS.VOC", "getSTAT.VOC", "getValid.Vocs", "select.VOCNames")); | |
this.result.Add(ATSDevices.RegionDev, new CommandAndControlSession.StatusProgram("APPOBJ_REGION", (string) null, (string) null, (string) null, "select.RegionNames")); | |
} | |
void IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.Add(ATSDevices key, CommandAndControlSession.StatusProgram value) | |
{ | |
throw new NotSupportedException(); | |
} | |
bool IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.ContainsKey(ATSDevices key) | |
{ | |
lock (this.result) | |
return this.result.ContainsKey(key); | |
} | |
ICollection<ATSDevices> IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.Keys | |
{ | |
get | |
{ | |
KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[] array; | |
lock (this.result) | |
{ | |
array = new KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[this.result.Count]; | |
this.result.CopyTo(array, 0); | |
} | |
ATSDevices[] atsDevicesArray = new ATSDevices[array.Length]; | |
for (int index = 0; index < array.Length; ++index) | |
atsDevicesArray[index] = array[index].Key; | |
return (ICollection<ATSDevices>) atsDevicesArray; | |
} | |
} | |
bool IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.Remove(ATSDevices key) | |
{ | |
throw new NotSupportedException(); | |
} | |
bool IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.TryGetValue(ATSDevices key, out CommandAndControlSession.StatusProgram value) | |
{ | |
lock (this.result) | |
return this.result.TryGetValue(key, out value); | |
} | |
ICollection<CommandAndControlSession.StatusProgram> IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.Values | |
{ | |
get | |
{ | |
KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[] array; | |
lock (this.result) | |
{ | |
array = new KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[this.result.Count]; | |
this.result.CopyTo(array, 0); | |
} | |
CommandAndControlSession.StatusProgram[] statusProgramArray = new CommandAndControlSession.StatusProgram[array.Length]; | |
for (int index = 0; index < array.Length; ++index) | |
statusProgramArray[index] = array[index].Value; | |
return (ICollection<CommandAndControlSession.StatusProgram>) statusProgramArray; | |
} | |
} | |
CommandAndControlSession.StatusProgram IDictionary<ATSDevices, CommandAndControlSession.StatusProgram>.this[ATSDevices key] | |
{ | |
get | |
{ | |
lock (this.result) | |
return this.result[key]; | |
} | |
set | |
{ | |
throw new NotSupportedException(); | |
} | |
} | |
void ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.Add(KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram> item) | |
{ | |
throw new NotSupportedException(); | |
} | |
void ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.Clear() | |
{ | |
throw new NotSupportedException(); | |
} | |
bool ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.Contains(KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram> item) | |
{ | |
lock (this.result) | |
return this.result.Contains(item); | |
} | |
void ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.CopyTo(KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[] array, int arrayIndex) | |
{ | |
lock (this.result) | |
this.result.CopyTo(array, arrayIndex); | |
} | |
int ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.Count | |
{ | |
get | |
{ | |
lock (this.result) | |
return this.result.Count; | |
} | |
} | |
bool ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.IsReadOnly | |
{ | |
get | |
{ | |
return true; | |
} | |
} | |
bool ICollection<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.Remove(KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram> item) | |
{ | |
throw new NotSupportedException(); | |
} | |
IEnumerator<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>> IEnumerable<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>>.GetEnumerator() | |
{ | |
return this.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return (IEnumerator) this.GetEnumerator(); | |
} | |
private IEnumerator<KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>> GetEnumerator() | |
{ | |
KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[] array; | |
lock (this.result) | |
{ | |
array = new KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[this.result.Count]; | |
this.result.CopyTo(array, 0); | |
} | |
KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[] keyValuePairArray = array; | |
for (int index = 0; index < keyValuePairArray.Length; ++index) | |
yield return keyValuePairArray[index]; | |
keyValuePairArray = (KeyValuePair<ATSDevices, CommandAndControlSession.StatusProgram>[]) null; | |
} | |
} | |
private struct StatusProgram | |
{ | |
internal readonly string GlobalName; | |
internal readonly string ListCos; | |
internal readonly string GetStatus; | |
internal readonly string GetValid; | |
internal readonly string GetNames; | |
internal StatusProgram(string globalName, string listCos, string getStatus, string getValid, string getNames) | |
{ | |
this.GlobalName = globalName; | |
this.ListCos = listCos; | |
this.GetStatus = getStatus; | |
this.GetValid = getValid; | |
this.GetNames = getNames; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment