Example #1
0
 public static void ReloadExtractors()
 {
     lock (ExtractorServer.Extractors)
     {
         foreach (BcDevices item_2 in ExtractorServer.AllDevices)
         {
             int local_1 = 0;
             foreach (ExtractorServer.KeyExtractor item_0 in ExtractorServer.Extractors)
             {
                 if (item_0.Device.Id == item_2.Id && item_0.CurrentThread != null && item_0.CurrentThread.ThreadState != System.Threading.ThreadState.Aborted && item_0.CurrentThread.ThreadState != System.Threading.ThreadState.Stopped)
                 {
                     item_0.Device = item_2;
                     ++local_1;
                 }
             }
             if (local_1 < item_2.ExtractorCount)
             {
                 for (; local_1 < item_2.ExtractorCount; ++local_1)
                 {
                     ExtractorServer.KeyExtractor local_2_1 = new ExtractorServer.KeyExtractor()
                     {
                         Device        = item_2,
                         CurrentThread = new Thread(new ParameterizedThreadStart(ExtractorServer.WorkerThread))
                         {
                             IsBackground = true
                         }
                     };
                     local_2_1.CurrentThread.Start((object)local_2_1);
                     ExtractorServer.Extractors.Add(local_2_1);
                 }
             }
             else if (local_1 > item_2.ExtractorCount)
             {
                 while (local_1 > item_2.ExtractorCount)
                 {
                     ExtractorServer.KeyExtractor local_5 = (ExtractorServer.KeyExtractor)null;
                     foreach (ExtractorServer.KeyExtractor item_1 in ExtractorServer.Extractors)
                     {
                         if (item_1.Device.Id == item_2.Id)
                         {
                             local_5          = item_1;
                             local_5.StopFlag = true;
                             local_5.WaitForStop();
                             --local_1;
                             break;
                         }
                     }
                     if (local_5 != null)
                     {
                         local_5.CurrentThread.Abort();
                         ExtractorServer.Extractors.Remove(local_5);
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public static void WorkerThread(object extractor)
 {
     ExtractorServer.KeyExtractor keyExtractor = (ExtractorServer.KeyExtractor)extractor;
     while (!keyExtractor.StopFlag)
     {
         while (keyExtractor.BreakFlag)
         {
             keyExtractor.Breaked = true;
             if (!keyExtractor.StopFlag)
             {
                 Thread.Sleep(30);
             }
             else
             {
                 break;
             }
         }
         keyExtractor.Breaked = false;
         BcDevices bcDevices = keyExtractor.Device;
         try
         {
             Engine.Initialize(0U);
             using (Engine engine = new Engine())
             {
                 while (!keyExtractor.BreakFlag && !keyExtractor.StopFlag)
                 {
                     FaceFrame orDefault = LimitedConcurrentQueueExtensions.GetOrDefault <FaceFrame>(ExtractorServer._faceframes);
                     if (orDefault == null)
                     {
                         Thread.Sleep(10);
                     }
                     else
                     {
                         byte[] template = ExtractorServer.ExtractTemplate(orDefault, (IEngine)engine);
                         bcDevices.AddKeyFrame(new KeyFrame()
                         {
                             Frame = orDefault,
                             Key   = template
                         });
                         ++bcDevices.ExtractCount;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             ExtractorServer.Logger.Error((object)string.Concat(new object[4]
             {
                 (object)"Extractor Thread Error ",
                 (object)ex.Message,
                 (object)" Extractor Index ",
                 (object)ExtractorServer.Extractors.IndexOf(keyExtractor)
             }));
         }
     }
     keyExtractor.Stopped = true;
 }
Example #3
0
 public static void BreakExtractor(Guid id)
 {
     ExtractorServer.KeyExtractor keyExtractor = Enumerable.FirstOrDefault <ExtractorServer.KeyExtractor>((IEnumerable <ExtractorServer.KeyExtractor>)ExtractorServer.Extractors, (Func <ExtractorServer.KeyExtractor, bool>)(det => det.Device.Id == id));
     if (keyExtractor == null)
     {
         return;
     }
     keyExtractor.BreakFlag = true;
     keyExtractor.WaitForBreak();
 }
Example #4
0
 public static void UnBreakExtractor(Guid id)
 {
     lock (ExtractorServer.Extractors)
     {
         ExtractorServer.KeyExtractor local_0 = Enumerable.FirstOrDefault <ExtractorServer.KeyExtractor>((IEnumerable <ExtractorServer.KeyExtractor>)ExtractorServer.Extractors, (Func <ExtractorServer.KeyExtractor, bool>)(det => det.Device.Id == id));
         if (local_0 == null)
         {
             return;
         }
         local_0.BreakFlag = false;
         local_0.Breaked   = false;
     }
 }
Example #5
0
 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
     {
     }
 }