public void SetDevice(Guid id, Hashtable row, bool delete) { BcDevices deviceById = IdentificationServer.GetDeviceById(id); BcDevices bcDevices1 = BcDevicesStorageExtensions.LoadById(id); if (bcDevices1.Isid != IdentificationServer.MainServer.Id) { delete = true; } if (delete) { BcDevices bcDevices2 = Enumerable.FirstOrDefault <BcDevices>((IEnumerable <BcDevices>)IdentificationServer.AllDevices, (Func <BcDevices, bool>)(d => d.Id == id)); if (bcDevices2 == null) { return; } IdentificationServer.DestroyIfNeeded(bcDevices2.CurrentThread); IdentificationServer.AllDevices.Remove(bcDevices2); } else if (deviceById.Id != Guid.Empty) { deviceById.SetData(row); } else if (bcDevices1.Isid == IdentificationServer.MainServer.Id) { deviceById.SetData(row); IdentificationServer.AllDevices.Add(deviceById); deviceById.CurrentThread = new Thread(new ParameterizedThreadStart(IdentificationServer.VideoThread)) { IsBackground = true }; deviceById.CurrentThread.Start((object)deviceById); } }
private static void TrySyncDevices() { try { List <BcDevices> devices = BcDevicesStorageExtensions.LoadByIsid(IdentificationServer.ServerId); foreach (BcDevices bcDevices1 in devices) { BcDevices newDev = bcDevices1; BcDevices bcDevices2 = Enumerable.FirstOrDefault <BcDevices>((IEnumerable <BcDevices>)IdentificationServer.AllDevices, (Func <BcDevices, bool>)(n => n.Id == newDev.Id)); if (bcDevices2 == null) { IdentificationServer.AllDevices.Add(newDev); newDev.CurrentThread = new Thread(new ParameterizedThreadStart(IdentificationServer.VideoThread)) { IsBackground = true }; newDev.CurrentThread.Start((object)newDev); } else { bcDevices2.SetData(newDev.GetData()); } } foreach (BcDevices bcDevices in Enumerable.ToArray <BcDevices>(Enumerable.Where <BcDevices>((IEnumerable <BcDevices>)IdentificationServer.AllDevices, (Func <BcDevices, bool>)(n => Enumerable.All <BcDevices>((IEnumerable <BcDevices>)devices, (Func <BcDevices, bool>)(nn => nn.Id != n.Id)))))) { IdentificationServer.DestroyIfNeeded(bcDevices.CurrentThread); } } catch (Exception ex) { IdentificationServer.Logger.Error((object)ex); } }
public static void LoadServer(Guid serverId) { IdentificationServer.ServerId = serverId; IdentificationServer.MainServer = BcIdentificationServer.LoadById(IdentificationServer.ServerId); try { List <BcDevices> actualDevices = BcDevicesStorageExtensions.LoadByIsid(IdentificationServer.ServerId); foreach (BcDevices bcDevices in Enumerable.ToArray <BcDevices>(Enumerable.Where <BcDevices>((IEnumerable <BcDevices>)IdentificationServer.AllDevices, (Func <BcDevices, bool>)(devices => Enumerable.All <BcDevices>((IEnumerable <BcDevices>)actualDevices, (Func <BcDevices, bool>)(bcDevices => bcDevices.Id != devices.Id)))))) { if (bcDevices.CurrentThread != null) { IdentificationServer.DestroyIfNeeded(bcDevices.CurrentThread); } IdentificationServer.AllDevices.Remove(bcDevices); } foreach (BcDevices bcDevices1 in actualDevices) { BcDevices d1 = bcDevices1; BcDevices bcDevices2 = Enumerable.FirstOrDefault <BcDevices>((IEnumerable <BcDevices>)IdentificationServer.AllDevices, (Func <BcDevices, bool>)(dev => dev.Id == d1.Id)); if (bcDevices2 != null) { bcDevices2.SetData(d1.GetData()); } else { IdentificationServer.AllDevices.Add(d1); d1.CurrentThread = new Thread(new ParameterizedThreadStart(IdentificationServer.VideoThread)) { IsBackground = true }; d1.CurrentThread.Start((object)d1); } } } catch (Exception ex) { IdentificationServer.Logger.Error((object)ex); } IdentificationServer.IsLoaded = true; IdentificationServer.SetGetServerSettings(true); Task.Factory.StartNew(new Action(IdentificationServer.RefreshFaces)); Task.Factory.StartNew(new Action(IdentificationServer.RefreshDevices)); }
private static void SyncCurrentAndActualDevices(List <BcDevices> actualDevices) { foreach (BcDevices bcDevices in actualDevices) { BcDevices d1 = bcDevices; BcDevices d2 = Enumerable.FirstOrDefault <BcDevices>((IEnumerable <BcDevices>)ExtractorServer.AllDevices, (Func <BcDevices, bool>)(bcDevice => bcDevice.Id == d1.Id)); if (d2 != null) { if (ExtractorServer.HasDifferProperties(d1, d2)) { ExtractorServer.BreakExtractor(d2.Id); d2.SetData(d1.GetData()); ExtractorServer.UnBreakExtractor(d2.Id); } } else { d1.CurrentThread = new Thread(new ParameterizedThreadStart(ExtractorServer.VideoThread)) { IsBackground = true }; d1.CurrentThread.Start((object)d1); ExtractorServer.AllDevices.Add(d1); } ExtractorServer.ReloadExtractors(); } foreach (BcDevices bcDevices in Enumerable.ToArray <BcDevices>(Enumerable.Where <BcDevices>((IEnumerable <BcDevices>)ExtractorServer.AllDevices, (Func <BcDevices, bool>)(d => Enumerable.All <BcDevices>((IEnumerable <BcDevices>)actualDevices, (Func <BcDevices, bool>)(d2 => d2.Id != d.Id)))))) { BcDevices bcDevicese = bcDevices; ExtractorServer.AllDevices.Remove(bcDevicese); foreach (ExtractorServer.KeyExtractor keyExtractor in Enumerable.ToArray <ExtractorServer.KeyExtractor>(Enumerable.Where <ExtractorServer.KeyExtractor>((IEnumerable <ExtractorServer.KeyExtractor>)ExtractorServer.Extractors, (Func <ExtractorServer.KeyExtractor, bool>)(d => d.Device.Id == bcDevicese.Id)))) { keyExtractor.StopFlag = true; keyExtractor.WaitForStop(); ExtractorServer.DestroyIfNeeded(keyExtractor.Device.CurrentThread); } } }
public void SetDevice(Guid id, Hashtable row, bool delete) { try { BcDevices deviceById = ExtractorServer.GetDeviceById(id); BcDevices bcDevices1 = BcDevicesStorageExtensions.LoadById(id); if (bcDevices1.Esid != ExtractorServer.MainServer.Id) { delete = true; } if (!delete) { if (deviceById.Id != Guid.Empty) { int extractorCount = deviceById.ExtractorCount; ExtractorServer.BreakExtractor(deviceById.Id); deviceById.SetData(row); if (extractorCount != deviceById.ExtractorCount) { ExtractorServer.ReloadExtractors(); } ExtractorServer.UnBreakExtractor(deviceById.Id); } else { try { if (bcDevices1.Esid != ExtractorServer.MainServer.Id) { BcDevices bcDevices2 = BcDevicesStorageExtensions.LoadById(id); bcDevices2.CurrentThread = new Thread(new ParameterizedThreadStart(ExtractorServer.VideoThread)) { IsBackground = true }; bcDevices2.CurrentThread.Start((object)bcDevices2); ExtractorServer.AllDevices.Add(bcDevices2); ExtractorServer.ReloadExtractors(); } } catch (Exception ex) { ExtractorServer.Logger.Error((object)"Set device error", ex); } } } else { for (int index = 0; index < ExtractorServer.Extractors.Count; ++index) { if (ExtractorServer.Extractors.Count > 0 && index >= 0 && index < ExtractorServer.Extractors.Count) { ExtractorServer.KeyExtractor keyExtractor = ExtractorServer.Extractors[index]; if (keyExtractor.Device.Id == id) { keyExtractor.StopFlag = true; keyExtractor.WaitForStop(); ExtractorServer.Extractors.RemoveAt(index); break; } } } for (int index = 0; index < ExtractorServer.AllDevices.Count; ++index) { if (ExtractorServer.AllDevices[index].Id == id) { ExtractorServer.AllDevices.RemoveAt(index); break; } } } } catch { } }