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 { } }