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 DataTable GetDeviceInfo() { DataTable dataTable = new DataTable(); dataTable.TableName = "IResults"; dataTable.Columns.Add("ID", typeof(Guid)); dataTable.Columns.Add("IdentifierCount", typeof(int)); dataTable.Columns.Add("ResultCount", typeof(int)); dataTable.Columns.Add("CPUUsage", typeof(int)); dataTable.Columns.Add("ThreadCount", typeof(int)); dataTable.Columns.Add("MaxThreadCount", typeof(int)); dataTable.Columns.Add("ISState", typeof(string)); int threadCount = IdentificationServer.MainServer.ThreadCount; int cpuUsage = IdentificationServer.GetCpuUsage(); int processorCount = Environment.ProcessorCount; foreach (BcDevices bcDevices in IdentificationServer.AllDevices) { dataTable.Rows.Add((object)bcDevices.Id, (object)bcDevices.IdentifierCount, (object)bcDevices.ResultCount, (object)cpuUsage, (object)threadCount, (object)processorCount, (object)"Работает"); } if (dataTable.Rows.Count > 0) { dataTable.Rows.Add((object)Guid.Empty, (object)0, (object)0, (object)cpuUsage, (object)threadCount, (object)processorCount, (object)"Работает"); } return(dataTable); }
public static void SendCommand(BcDevices dev, int accessId, int sfinksId) { try { IdentificationServer.DeviceClient.SendCommand(IdentificationServer.LoginCom); IdentificationServer.DeviceClient.SendCommand(string.Concat(new object[4] { (object)"CASCADE_FACEDETECTED ", (object)sfinksId, (object)" ", (object)dev.Id.ToString().Replace("-", "") })); if (accessId == -1) { return; } BcAccessCategory catout; IdentificationServer.ReadWriteAccessCategory(false, accessId, (BcAccessCategory)null, out catout); if (catout == null || !IdentificationServer.DeviceClient.IsConnected) { return; } BcObjects bcObjects = Enumerable.FirstOrDefault <BcObjects>((IEnumerable <BcObjects>)catout.Data, (Func <BcObjects, bool>)(o => o.Id == dev.ObjectId)); if (bcObjects == null) { return; } if (bcObjects.Device && dev.TableId == Guid.Empty) { try { IdentificationServer.DeviceClient.SendCommand(IdentificationServer.LoginCom); IdentificationServer.DeviceClient.SendCommand(IdentificationServer.AllowPass); } catch (Exception ex) { IdentificationServer.Logger.Error((object)"sfinks net error", ex); } } else if (dev.TableId != Guid.Empty) { if (BcObjectsData.GetObjectById(bcObjects.Data, dev.TableId).Device) { try { IdentificationServer.DeviceClient.SendCommand(IdentificationServer.LoginCom); IdentificationServer.DeviceClient.SendCommand(IdentificationServer.AllowPass); } catch (Exception ex) { IdentificationServer.Logger.Error((object)"sfinks net error", ex); } } } } catch (Exception ex) { IdentificationServer.Logger.Error((object)"sfinks net error", ex); } }
public static void VideoThread(object device) { BcDevices bcDevices = (BcDevices)device; while (!IdentificationServer.StopFlag) { try { if (!bcDevices.IsActive) { Thread.Sleep(1000); continue; } BcExtractorServer bcExtractorServer = BcExtractorServer.LoadById(bcDevices.Esid); using (ExtractorServerClient extractorServerClient = new ExtractorServerClient(new InstanceContext((object)new IdentificationServer.ExtarctorClient()))) { extractorServerClient.Endpoint.Address = new EndpointAddress("net.tcp://" + (object)bcExtractorServer.Ip + ":" + (string)(object)bcExtractorServer.Port + "/FaceExtractorServer/ExtractorServer"); extractorServerClient.Open(); while (!IdentificationServer.StopFlag && bcDevices.IsActive) { KeyFrame lastFrame = extractorServerClient.GetLastFrame(bcDevices.Id); if (lastFrame == null) { Thread.Sleep(50); } else { IdentificationServer.Logger.Warn((object)("New template recieved deviceId = " + (object)bcDevices.Id)); byte[] imageIcon = IdentificationServer.GetImageIcon(lastFrame.Frame.Frame); if (lastFrame.Key != null && (int)lastFrame.Key[0] != 0) { FrameInfo frameInfo = new FrameInfo() { Image = lastFrame.Frame.Frame, ImageIcon = imageIcon, Template = lastFrame.Key, Date = lastFrame.Frame.Date.Ticks, Device = bcDevices, MinScore = (double)bcDevices.MinScore, DetectedFrameId = lastFrame.Frame.FrameId }; IdentificationServer.Requests.Enqueue(frameInfo); } } } } } catch (CommunicationException ex) { IdentificationServer.Logger.Error((object)("Unable to connect to FaceExtractorServer " + ex.Message)); } catch (Exception ex) { IdentificationServer.Logger.Error((object)ex); } Thread.Sleep(1000); } }
private static void TrySyncBcAccessCategories() { try { foreach (BcAccessCategory cat in BcAccessCategory.LoadAll()) { BcAccessCategory catout; IdentificationServer.ReadWriteAccessCategory(true, cat.Id, cat, out catout); } } catch (Exception ex) { IdentificationServer.Logger.Error((object)ex); } }
public static void WorkerThread() { while (!IdentificationServer.StopFlag) { IdentificationServer.ClearCompletedTasks(); if (!IdentificationServer.IsLoaded) { Thread.Sleep(100); } else if (IdentificationServer.Requests.IsEmpty) { Thread.Sleep(100); } else { int trackingPeriod = IdentificationServer.SetGetServerSettings(false).TrackingPeriod * 1000; FrameInfo result; while (!IdentificationServer.StopFlag && IdentificationServer.Requests.TryDequeue(out result)) { try { FrameInfo frame = result; IdentificationServer.ClearCompletedTasks(); bool flag = false; foreach (CompareRequest compareRequest in Enumerable.Where <CompareRequest>((IEnumerable <CompareRequest>)IdentificationServer.CommonRequests, (Func <CompareRequest, bool>)(request => request.DeviceId == frame.Device.Id && request.RequestStatus == RequestStatus.Wait))) { if (compareRequest.HasSimilar(Settings.Default.MinScore, frame) && compareRequest.RequestStatus == RequestStatus.Wait) { compareRequest.Add(frame); flag = true; } } if (!flag) { CompareRequest compareRequest = new CompareRequest(frame.Device, IdentificationServer.Logger, IdentificationServer.EngineWorker); compareRequest.Add(frame); compareRequest.ProcessAfter(trackingPeriod); IdentificationServer.CommonRequests.Add(compareRequest); } } catch (Exception ex) { IdentificationServer.Logger.Error((object)"WorkerThread Errror - ", ex); } } } } }
public static async void RefreshDevices() { while (!IdentificationServer.StopFlag) { if (!IdentificationServer.IsLoaded) { await Task.Delay(10); } else { IdentificationServer.TrySyncNotifications(); IdentificationServer.TrySyncDevices(); IdentificationServer.TrySyncBcAccessCategories(); await Task.Delay(10000); } } }
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)); }
public static async void RefreshFaces() { while (!IdentificationServer.StopFlag) { if (IdentificationServer.IsLoaded) { try { bool flag1 = IdentificationServer.IniFileWorker.IsFileExists(); DateTime lastUpdateDate = IdentificationServer.IniFileWorker.GetLastUpdateDate(); DateTime databaseDate = IdentificationServer.GetDatabaseDate(); if (Math.Abs((lastUpdateDate - databaseDate).TotalSeconds) > 10.0) { IEnumerable <KeysDataRow> enumerable = !flag1 || IdentificationServer.EngineWorker.TemplatesCount == 0 ? IdentificationServer.GetAllFaces() : IdentificationServer.GetLastModifiedFaces(lastUpdateDate); bool flag2 = false; foreach (KeysDataRow template in enumerable) { flag2 = true; IdentificationServer.EngineWorker.UpdateTemplateInfo(template); } foreach (Guid id in IdentificationServer.GetRemovedFaces(lastUpdateDate)) { flag2 = true; IdentificationServer.EngineWorker.RemoveTemplate(id); } if (flag2) { IdentificationServer.IniFileWorker.SetLastUpdateDate(databaseDate); } } } catch (Exception ex) { IdentificationServer.Logger.Error((object)"Error", ex); } } await Task.Delay(5000); } }
public void SetServerSettings() { IdentificationServer.SetGetServerSettings(true); }